- Timestamp:
- Aug 18, 2016 10:10:38 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/k/kLdr.h
r58 r81 637 637 int kLdrModMap(PKLDRMOD pMod); 638 638 int kLdrModUnmap(PKLDRMOD pMod); 639 int kLdrModAllocTLS(PKLDRMOD pMod);640 void kLdrModFreeTLS(PKLDRMOD pMod);641 639 int kLdrModReload(PKLDRMOD pMod); 642 640 int kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 643 int kLdrModCallInit(PKLDRMOD pMod, KUPTR uHandle);644 int kLdrModCallTerm(PKLDRMOD pMod, KUPTR uHandle);645 int kLdrModCallThread(PKLDRMOD pMod, KUPTR uHandle, unsigned fAttachingOrDetaching);646 641 /** @} */ 647 642 … … 652 647 int kLdrModRelocateBits(PKLDRMOD pMod, void *pvBits, KLDRADDR NewBaseAddress, KLDRADDR OldBaseAddress, 653 648 PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 649 /** @} */ 650 651 /** @name Operations on both internally and externally managed mappings. 652 * @{ */ 653 /** Special pvMapping value to pass to kLdrModAllocTLS, 654 * kLdrModFreeTLS, kLdrModCallInit, kLdrModCallTerm, and kLdrModCallThread that 655 * specifies the internal mapping (kLdrModMap). */ 656 #define KLDRMOD_INT_MAP ((void *)~(KUPTR)0) 657 int kLdrModAllocTLS(PKLDRMOD pMod, void *pvMapping); 658 void kLdrModFreeTLS(PKLDRMOD pMod, void *pvMapping); 659 int kLdrModCallInit(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle); 660 int kLdrModCallTerm(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle); 661 int kLdrModCallThread(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle, unsigned fAttachingOrDetaching); 654 662 /** @} */ 655 663 … … 726 734 int (* pfnUnmap)(PKLDRMOD pMod); 727 735 /** @copydoc kLdrModAllocTLS */ 728 int (* pfnAllocTLS)(PKLDRMOD pMod );736 int (* pfnAllocTLS)(PKLDRMOD pMod, void *pvMapping); 729 737 /** @copydoc kLdrModFreeTLS */ 730 void (*pfnFreeTLS)(PKLDRMOD pMod );738 void (*pfnFreeTLS)(PKLDRMOD pMod, void *pvMapping); 731 739 /** @copydoc kLdrModReload */ 732 740 int (* pfnReload)(PKLDRMOD pMod); … … 734 742 int (* pfnFixupMapping)(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 735 743 /** @copydoc kLdrModCallInit */ 736 int (* pfnCallInit)(PKLDRMOD pMod, KUPTR uHandle);744 int (* pfnCallInit)(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle); 737 745 /** @copydoc kLdrModCallTerm */ 738 int (* pfnCallTerm)(PKLDRMOD pMod, KUPTR uHandle);746 int (* pfnCallTerm)(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle); 739 747 /** @copydoc kLdrModCallThread */ 740 int (* pfnCallThread)(PKLDRMOD pMod, KUPTR uHandle, unsigned fAttachingOrDetaching);748 int (* pfnCallThread)(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle, unsigned fAttachingOrDetaching); 741 749 /** @copydoc kLdrModSize */ 742 750 KLDRADDR (* pfnSize)(PKLDRMOD pMod); -
trunk/kLdr/kLdrDyldMod.c
r33 r81 256 256 if (pMod->fAllocatedTLS) 257 257 { 258 kLdrModFreeTLS(pMod->pMod );258 kLdrModFreeTLS(pMod->pMod, KLDRMOD_INT_MAP); 259 259 pMod->fAllocatedTLS = 0; 260 260 } … … 820 820 if (!rc) 821 821 { 822 rc = kLdrModAllocTLS(pMod->pMod );822 rc = kLdrModAllocTLS(pMod->pMod, KLDRMOD_INT_MAP); 823 823 if (!rc) 824 824 { … … 861 861 if (pMod->fAllocatedTLS) 862 862 { 863 kLdrModFreeTLS(pMod->pMod );863 kLdrModFreeTLS(pMod->pMod, KLDRMOD_INT_MAP); 864 864 pMod->fAllocatedTLS = 0; 865 865 } … … 911 911 if (pMod->fAllocatedTLS) 912 912 { 913 kLdrModFreeTLS(pMod->pMod );913 kLdrModFreeTLS(pMod->pMod, KLDRMOD_INT_MAP); 914 914 pMod->fAllocatedTLS = 0; 915 915 } … … 919 919 if (!rc) 920 920 { 921 rc = kLdrModAllocTLS(pMod->pMod );921 rc = kLdrModAllocTLS(pMod->pMod, KLDRMOD_INT_MAP); 922 922 if (!rc) 923 923 { … … 1060 1060 1061 1061 pMod->enmState = KLDRSTATE_INITIALIZING; 1062 rc = kLdrModCallInit(pMod->pMod, (KUPTR)pMod->hMod);1062 rc = kLdrModCallInit(pMod->pMod, KLDRMOD_INT_MAP, (KUPTR)pMod->hMod); 1063 1063 if (!rc) 1064 1064 { … … 1092 1092 1093 1093 pMod->enmState = KLDRSTATE_TERMINATING; 1094 kLdrModCallTerm(pMod->pMod, (KUPTR)pMod->hMod);1094 kLdrModCallTerm(pMod->pMod, KLDRMOD_INT_MAP, (KUPTR)pMod->hMod); 1095 1095 pMod->enmState = KLDRSTATE_PENDING_GC; 1096 1096 /* unlinking on destruction. */ … … 1108 1108 KLDRDYLDMOD_ASSERT(pMod->enmState == KLDRSTATE_GOOD); 1109 1109 1110 return kLdrModCallThread(pMod->pMod, (KUPTR)pMod->hMod, 1 /* attach */);1110 return kLdrModCallThread(pMod->pMod, KLDRMOD_INT_MAP, (KUPTR)pMod->hMod, 1 /* attach */); 1111 1111 } 1112 1112 … … 1122 1122 KLDRDYLDMOD_ASSERT(pMod->enmState == KLDRSTATE_GOOD); 1123 1123 1124 kLdrModCallThread(pMod->pMod, (KUPTR)pMod->hMod, 0 /* detach */);1124 kLdrModCallThread(pMod->pMod, KLDRMOD_INT_MAP, (KUPTR)pMod->hMod, 0 /* detach */); 1125 1125 } 1126 1126 -
trunk/kLdr/kLdrMod.c
r79 r81 736 736 737 737 /** 738 * Allocates Thread Local Storage for module mapped by kLdrModMap().739 *740 * Calling kLdrModAllocTLS() more than once without calling kLdrModFreeTLS()741 * between each invocation is not supported.742 *743 * @returns 0 on success, non-zero OS or kLdr status code on failure.744 * @param pMod The module.745 */746 int kLdrModAllocTLS(PKLDRMOD pMod)747 {748 KLDRMOD_VALIDATE(pMod);749 return pMod->pOps->pfnAllocTLS(pMod);750 }751 752 753 /**754 * Frees Thread Local Storage previously allocated by kLdrModAllocTLS().755 *756 * The caller is responsible for only calling kLdrModFreeTLS() once757 * after calling kLdrModAllocTLS().758 *759 * @returns 0 on success, non-zero OS or kLdr status code on failure.760 * @param pMod The module.761 */762 void kLdrModFreeTLS(PKLDRMOD pMod)763 {764 KLDRMOD_VALIDATE_VOID(pMod);765 pMod->pOps->pfnFreeTLS(pMod);766 }767 768 769 /**770 738 * Reloads all dirty pages in a module previously mapped by kLdrModMap(). 771 739 * … … 800 768 KLDRMOD_VALIDATE(pMod); 801 769 return pMod->pOps->pfnFixupMapping(pMod, pfnGetImport, pvUser); 802 }803 804 805 /**806 * Call the module initializiation function of a mapped module (if any).807 *808 * @returns 0 on success or no init function, non-zero on init function failure or invalid pMod.809 * @param pMod The module.810 * @param uHandle The module handle to use if any of the init functions requires the module handle.811 */812 int kLdrModCallInit(PKLDRMOD pMod, KUPTR uHandle)813 {814 KLDRMOD_VALIDATE(pMod);815 return pMod->pOps->pfnCallInit(pMod, uHandle);816 }817 818 819 /**820 * Call the module termination function of a mapped module (if any).821 *822 * @returns 0 on success or no term function, non-zero on invalid pMod.823 * @param pMod The module.824 * @param uHandle The module handle to use if any of the term functions requires the module handle.825 *826 * @remark Termination function failure will be ignored by the module interpreter.827 */828 int kLdrModCallTerm(PKLDRMOD pMod, KUPTR uHandle)829 {830 KLDRMOD_VALIDATE(pMod);831 return pMod->pOps->pfnCallTerm(pMod, uHandle);832 }833 834 835 /**836 * Call the thread attach or detach function of a mapped module (if any).837 *838 * Any per-thread TLS initialization/termination will have to be done at this time too.839 *840 * @returns 0 on success or no attach/detach function, non-zero on attach failure or invalid pMod.841 * @param pMod The module.842 * @param uHandle The module handle to use if any of the thread attach/detach functions843 * requires the module handle.844 *845 * @remark Detach function failure will be ignored by the module interpreter.846 */847 int kLdrModCallThread(PKLDRMOD pMod, KUPTR uHandle, unsigned fAttachingOrDetaching)848 {849 KLDRMOD_VALIDATE(pMod);850 K_VALIDATE_FLAGS(fAttachingOrDetaching, 1);851 return pMod->pOps->pfnCallThread(pMod, uHandle, fAttachingOrDetaching);852 770 } 853 771 … … 906 824 } 907 825 826 827 /** 828 * Allocates Thread Local Storage for module mapped by kLdrModMap(). 829 * 830 * Calling kLdrModAllocTLS() more than once without calling kLdrModFreeTLS() 831 * between each invocation is not supported. 832 * 833 * @returns 0 on success, non-zero OS or kLdr status code on failure. 834 * @param pMod The module. 835 * @param pvMapping The external mapping address or RTLDRMOD_INT_MAP. 836 */ 837 int kLdrModAllocTLS(PKLDRMOD pMod, void *pvMapping) 838 { 839 KLDRMOD_VALIDATE(pMod); 840 return pMod->pOps->pfnAllocTLS(pMod, pvMapping); 841 } 842 843 844 /** 845 * Frees Thread Local Storage previously allocated by kLdrModAllocTLS(). 846 * 847 * The caller is responsible for only calling kLdrModFreeTLS() once 848 * after calling kLdrModAllocTLS(). 849 * 850 * @returns 0 on success, non-zero OS or kLdr status code on failure. 851 * @param pMod The module. 852 * @param pvMapping The external mapping address or RTLDRMOD_INT_MAP. 853 */ 854 void kLdrModFreeTLS(PKLDRMOD pMod, void *pvMapping) 855 { 856 KLDRMOD_VALIDATE_VOID(pMod); 857 pMod->pOps->pfnFreeTLS(pMod, pvMapping); 858 } 859 860 861 862 863 /** 864 * Call the module initializiation function of a mapped module (if any). 865 * 866 * @returns 0 on success or no init function, non-zero on init function failure or invalid pMod. 867 * @param pMod The module. 868 * @param pvMapping The external mapping address or RTLDRMOD_INT_MAP. 869 * @param uHandle The module handle to use if any of the init functions requires the module handle. 870 */ 871 int kLdrModCallInit(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 872 { 873 KLDRMOD_VALIDATE(pMod); 874 return pMod->pOps->pfnCallInit(pMod, pvMapping, uHandle); 875 } 876 877 878 /** 879 * Call the module termination function of a mapped module (if any). 880 * 881 * @returns 0 on success or no term function, non-zero on invalid pMod. 882 * @param pMod The module. 883 * @param pvMapping The external mapping address or RTLDRMOD_INT_MAP. 884 * @param uHandle The module handle to use if any of the term functions requires the module handle. 885 * 886 * @remark Termination function failure will be ignored by the module interpreter. 887 */ 888 int kLdrModCallTerm(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 889 { 890 KLDRMOD_VALIDATE(pMod); 891 return pMod->pOps->pfnCallTerm(pMod, pvMapping, uHandle); 892 } 893 894 895 /** 896 * Call the thread attach or detach function of a mapped module (if any). 897 * 898 * Any per-thread TLS initialization/termination will have to be done at this time too. 899 * 900 * @returns 0 on success or no attach/detach function, non-zero on attach failure or invalid pMod. 901 * @param pMod The module. 902 * @param pvMapping The external mapping address or RTLDRMOD_INT_MAP. 903 * @param uHandle The module handle to use if any of the thread attach/detach functions 904 * requires the module handle. 905 * 906 * @remark Detach function failure will be ignored by the module interpreter. 907 */ 908 int kLdrModCallThread(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle, unsigned fAttachingOrDetaching) 909 { 910 KLDRMOD_VALIDATE(pMod); 911 K_VALIDATE_FLAGS(fAttachingOrDetaching, 1); 912 return pMod->pOps->pfnCallThread(pMod, pvMapping, uHandle, fAttachingOrDetaching); 913 } 914 -
trunk/kLdr/kLdrModLX.c
r80 r81 128 128 static void kLdrModLXMemCopyW(KU8 *pbDst, const KU8 *pbSrc, int cb); 129 129 static int kldrModLXDoProtect(PKLDRMODLX pModLX, void *pvBits, unsigned fUnprotectOrProtect); 130 static int kldrModLXDoCallDLL(PKLDRMODLX pModLX, unsigned uOp, KUPTR uHandle);130 static int kldrModLXDoCallDLL(PKLDRMODLX pModLX, void *pvMapping, unsigned uOp, KUPTR uHandle); 131 131 static int kldrModLXDoForwarderQuery(PKLDRMODLX pModLX, const struct e32_entry *pEntry, 132 132 PFNKLDRMODGETIMPORT pfnGetForwarder, void *pvUser, PKLDRADDR puValue, KU32 *pfKind); … … 1937 1937 1938 1938 /** @copydoc kLdrModAllocTLS */ 1939 static int kldrModLXAllocTLS(PKLDRMOD pMod )1939 static int kldrModLXAllocTLS(PKLDRMOD pMod, void *pvMapping) 1940 1940 { 1941 1941 PKLDRMODLX pModLX = (PKLDRMODLX)pMod->pvData; 1942 1942 1943 1943 /* no tls, just do the error checking. */ 1944 if (!pModLX->pvMapping) 1944 if ( pvMapping == KLDRMOD_INT_MAP 1945 && pModLX->pvMapping) 1945 1946 return KLDR_ERR_NOT_MAPPED; 1946 1947 return 0; … … 1949 1950 1950 1951 /** @copydoc kLdrModFreeTLS */ 1951 static void kldrModLXFreeTLS(PKLDRMOD pMod )1952 static void kldrModLXFreeTLS(PKLDRMOD pMod, void *pvMapping) 1952 1953 { 1953 1954 /* no tls. */ 1954 1955 K_NOREF(pMod); 1956 K_NOREF(pvMapping); 1955 1957 1956 1958 } … … 2027 2029 2028 2030 /** @copydoc kLdrModCallInit */ 2029 static int kldrModLXCallInit(PKLDRMOD pMod, KUPTR uHandle)2031 static int kldrModLXCallInit(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 2030 2032 { 2031 2033 PKLDRMODLX pModLX = (PKLDRMODLX)pMod->pvData; … … 2035 2037 * Mapped? 2036 2038 */ 2037 if (!pModLX->pvMapping) 2038 return KLDR_ERR_NOT_MAPPED; 2039 if (pvMapping == KLDRMOD_INT_MAP) 2040 { 2041 pvMapping = pModLX->pvMapping; 2042 if (!pvMapping) 2043 return KLDR_ERR_NOT_MAPPED; 2044 } 2039 2045 2040 2046 /* … … 2042 2048 */ 2043 2049 if ((pModLX->Hdr.e32_mflags & E32MODMASK) == E32MODDLL) 2044 rc = kldrModLXDoCallDLL(pModLX, 0 /* attach */, uHandle);2050 rc = kldrModLXDoCallDLL(pModLX, pvMapping, 0 /* attach */, uHandle); 2045 2051 else 2046 2052 rc = 0; … … 2055 2061 * @returns KLDR_ERR_MODULE_INIT_FAILED or KLDR_ERR_THREAD_ATTACH_FAILED on failure. 2056 2062 * @param pModLX The LX module interpreter instance. 2063 * @param pvMapping The module mapping to use (resolved). 2057 2064 * @param uOp The operation (DLL_*). 2058 2065 * @param uHandle The module handle to present. 2059 2066 */ 2060 static int kldrModLXDoCallDLL(PKLDRMODLX pModLX, unsigned uOp, KUPTR uHandle)2067 static int kldrModLXDoCallDLL(PKLDRMODLX pModLX, void *pvMapping, unsigned uOp, KUPTR uHandle) 2061 2068 { 2062 2069 int rc; … … 2072 2079 * Invoke the entrypoint and convert the boolean result to a kLdr status code. 2073 2080 */ 2074 rc = kldrModLXDoCall((KUPTR)p ModLX->pvMapping2081 rc = kldrModLXDoCall((KUPTR)pvMapping 2075 2082 + (KUPTR)pModLX->pMod->aSegments[pModLX->Hdr.e32_startobj - 1].RVA 2076 2083 + pModLX->Hdr.e32_eip, … … 2150 2157 2151 2158 /** @copydoc kLdrModCallTerm */ 2152 static int kldrModLXCallTerm(PKLDRMOD pMod, KUPTR uHandle)2159 static int kldrModLXCallTerm(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 2153 2160 { 2154 2161 PKLDRMODLX pModLX = (PKLDRMODLX)pMod->pvData; … … 2157 2164 * Mapped? 2158 2165 */ 2159 if (!pModLX->pvMapping) 2160 return KLDR_ERR_NOT_MAPPED; 2166 if (pvMapping == KLDRMOD_INT_MAP) 2167 { 2168 pvMapping = pModLX->pvMapping; 2169 if (!pvMapping) 2170 return KLDR_ERR_NOT_MAPPED; 2171 } 2161 2172 2162 2173 /* … … 2164 2175 */ 2165 2176 if ((pModLX->Hdr.e32_mflags & E32MODMASK) == E32MODDLL) 2166 kldrModLXDoCallDLL(pModLX, 1 /* detach */, uHandle);2177 kldrModLXDoCallDLL(pModLX, pvMapping, 1 /* detach */, uHandle); 2167 2178 2168 2179 return 0; … … 2171 2182 2172 2183 /** @copydoc kLdrModCallThread */ 2173 static int kldrModLXCallThread(PKLDRMOD pMod, KUPTR uHandle, unsigned fAttachingOrDetaching)2184 static int kldrModLXCallThread(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle, unsigned fAttachingOrDetaching) 2174 2185 { 2175 2186 /* no thread attach/detach callout. */ 2176 2187 K_NOREF(pMod); 2188 K_NOREF(pvMapping); 2177 2189 K_NOREF(uHandle); 2178 2190 K_NOREF(fAttachingOrDetaching); -
trunk/kLdr/kLdrModMachO.c
r79 r81 2491 2491 2492 2492 /** @copydoc kLdrModAllocTLS */ 2493 static int kldrModMachOAllocTLS(PKLDRMOD pMod )2493 static int kldrModMachOAllocTLS(PKLDRMOD pMod, void *pvMapping) 2494 2494 { 2495 2495 PKLDRMODMACHO pModMachO = (PKLDRMODMACHO)pMod->pvData; … … 2498 2498 * Mapped? 2499 2499 */ 2500 if (!pModMachO->pvMapping) 2500 if ( pvMapping == KLDRMOD_INT_MAP 2501 && !pModMachO->pvMapping ) 2501 2502 return KLDR_ERR_NOT_MAPPED; 2502 2503 return 0; … … 2505 2506 2506 2507 /** @copydoc kLdrModFreeTLS */ 2507 static void kldrModMachOFreeTLS(PKLDRMOD pMod )2508 static void kldrModMachOFreeTLS(PKLDRMOD pMod, void *pvMapping) 2508 2509 { 2509 2510 K_NOREF(pMod); 2511 K_NOREF(pvMapping); 2510 2512 } 2511 2513 … … 3455 3457 3456 3458 /** @copydoc kLdrModCallInit */ 3457 static int kldrModMachOCallInit(PKLDRMOD pMod, KUPTR uHandle)3459 static int kldrModMachOCallInit(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 3458 3460 { 3459 3461 /* later */ 3460 3462 K_NOREF(pMod); 3463 K_NOREF(pvMapping); 3461 3464 K_NOREF(uHandle); 3462 3465 return 0; … … 3465 3468 3466 3469 /** @copydoc kLdrModCallTerm */ 3467 static int kldrModMachOCallTerm(PKLDRMOD pMod, KUPTR uHandle)3470 static int kldrModMachOCallTerm(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 3468 3471 { 3469 3472 /* later */ 3470 3473 K_NOREF(pMod); 3474 K_NOREF(pvMapping); 3471 3475 K_NOREF(uHandle); 3472 3476 return 0; … … 3475 3479 3476 3480 /** @copydoc kLdrModCallThread */ 3477 static int kldrModMachOCallThread(PKLDRMOD pMod, KUPTR uHandle, unsigned fAttachingOrDetaching)3481 static int kldrModMachOCallThread(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle, unsigned fAttachingOrDetaching) 3478 3482 { 3479 3483 /* Relevant for Mach-O? */ 3480 3484 K_NOREF(pMod); 3485 K_NOREF(pvMapping); 3481 3486 K_NOREF(uHandle); 3482 3487 K_NOREF(fAttachingOrDetaching); -
trunk/kLdr/kLdrModNative.c
r58 r81 145 145 static KI32 kldrModNativeNumberOfImports(PKLDRMOD pMod, const void *pvBits); 146 146 147 /********************************************************************************************************************************* 148 * Global Variables * 149 *********************************************************************************************************************************/ 150 extern KLDRMODOPS g_kLdrModNativeOps; 151 147 152 148 153 … … 157 162 * @param ppMod Where to store the module instance pointer. 158 163 */ 159 static int kldrModNativeCreate(PCKLDRMODOPS pOps, PKRDR pRdr, KLDRFOFF offNewHdr, PPKLDRMOD ppMod) 164 static int kldrModNativeCreate(PCKLDRMODOPS pOps, PKRDR pRdr, KU32 fFlags, KCPUARCH enmCpuArch, 165 KLDRFOFF offNewHdr, PPKLDRMOD ppMod) 160 166 { 161 167 int rc = kLdrModOpenNative(kRdrName(pRdr), ppMod); … … 510 516 * We're done. 511 517 */ 518 pMod->u32Magic = KLDRMOD_MAGIC; 519 pMod->pOps = &g_kLdrModNativeOps; 512 520 *ppMod = pMod; 513 521 return 0; … … 943 951 944 952 rc = pfnCallback(pMod, iDbgInfo, 945 enmDbgInfoType, pDbgDir->MajorVersion, pDbgDir->MinorVersion, 953 enmDbgInfoType, pDbgDir->MajorVersion, pDbgDir->MinorVersion, NULL /*pszPartNm*/, 946 954 pDbgDir->PointerToRawData ? pDbgDir->PointerToRawData : -1, 947 955 pDbgDir->AddressOfRawData ? pDbgDir->AddressOfRawData : NIL_KLDRADDR, 948 956 pDbgDir->SizeOfData, 949 NULL, 950 pvUser); 957 NULL /*pszExtFile*/, pvUser); 951 958 if (rc) 952 959 break; … … 1016 1023 1017 1024 /** @copydoc kLdrModAllocTLS */ 1018 static int kldrModNativeAllocTLS(PKLDRMOD pMod )1025 static int kldrModNativeAllocTLS(PKLDRMOD pMod, void *pvMapping) 1019 1026 { 1020 1027 return 0; … … 1023 1030 1024 1031 /** @copydoc kLdrModFreeTLS */ 1025 static void kldrModNativeFreeTLS(PKLDRMOD pMod )1032 static void kldrModNativeFreeTLS(PKLDRMOD pMod, void *pvMapping) 1026 1033 { 1027 1034 } … … 1043 1050 1044 1051 /** @copydoc kLdrModCallInit */ 1045 static int kldrModNativeCallInit(PKLDRMOD pMod, KUPTR uHandle)1052 static int kldrModNativeCallInit(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 1046 1053 { 1047 1054 return 0; … … 1050 1057 1051 1058 /** @copydoc kLdrModCallTerm */ 1052 static int kldrModNativeCallTerm(PKLDRMOD pMod, KUPTR uHandle)1059 static int kldrModNativeCallTerm(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 1053 1060 { 1054 1061 return 0; … … 1057 1064 1058 1065 /** @copydoc kLdrModCallThread */ 1059 static int kldrModNativeCallThread(PKLDRMOD pMod, KUPTR uHandle, unsigned fAttachingOrDetaching)1066 static int kldrModNativeCallThread(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle, unsigned fAttachingOrDetaching) 1060 1067 { 1061 1068 return 0; -
trunk/kLdr/kLdrModPE.c
r79 r81 121 121 PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 122 122 static int kldrModPEDoImports(PKLDRMODPE pModPE, void *pvMapping, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 123 static int kldrModPEDoCallDLL(PKLDRMODPE pModPE, unsigned uOp, KUPTR uHandle);124 static int kldrModPEDoCallTLS(PKLDRMODPE pModPE, unsigned uOp, KUPTR uHandle);123 static int kldrModPEDoCallDLL(PKLDRMODPE pModPE, void *pvMapping, unsigned uOp, KUPTR uHandle); 124 static int kldrModPEDoCallTLS(PKLDRMODPE pModPE, void *pvMapping, unsigned uOp, KUPTR uHandle); 125 125 static KI32 kldrModPEDoCall(KUPTR uEntrypoint, KUPTR uHandle, KU32 uOp, void *pvReserved); 126 126 … … 1283 1283 1284 1284 /** @copydoc kLdrModAllocTLS */ 1285 static int kldrModPEAllocTLS(PKLDRMOD pMod )1285 static int kldrModPEAllocTLS(PKLDRMOD pMod, void *pvMapping) 1286 1286 { 1287 1287 PKLDRMODPE pModPE = (PKLDRMODPE)pMod->pvData; … … 1290 1290 * Mapped? 1291 1291 */ 1292 if (!pModPE->pvMapping) 1293 return KLDR_ERR_NOT_MAPPED; 1292 if (pvMapping == KLDRMOD_INT_MAP) 1293 { 1294 pvMapping = pModPE->pvMapping; 1295 if (!pvMapping) 1296 return KLDR_ERR_NOT_MAPPED; 1297 } 1294 1298 1295 1299 /* … … 1305 1309 1306 1310 /** @copydoc kLdrModFreeTLS */ 1307 static void kldrModPEFreeTLS(PKLDRMOD pMod )1311 static void kldrModPEFreeTLS(PKLDRMOD pMod, void *pvMapping) 1308 1312 { 1309 1313 PKLDRMODPE pModPE = (PKLDRMODPE)pMod->pvData; … … 1312 1316 * Mapped? 1313 1317 */ 1314 if (!pModPE->pvMapping) 1315 return; 1318 if (pvMapping == KLDRMOD_INT_MAP) 1319 { 1320 pvMapping = pModPE->pvMapping; 1321 if (!pvMapping) 1322 return; 1323 } 1316 1324 1317 1325 /* … … 1709 1717 1710 1718 /** @copydoc kLdrModCallInit */ 1711 static int kldrModPECallInit(PKLDRMOD pMod, KUPTR uHandle)1719 static int kldrModPECallInit(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 1712 1720 { 1713 1721 PKLDRMODPE pModPE = (PKLDRMODPE)pMod->pvData; … … 1717 1725 * Mapped? 1718 1726 */ 1719 if (!pModPE->pvMapping) 1720 return KLDR_ERR_NOT_MAPPED; 1727 if (pvMapping == KLDRMOD_INT_MAP) 1728 { 1729 pvMapping = pModPE->pvMapping; 1730 if (!pvMapping) 1731 return KLDR_ERR_NOT_MAPPED; 1732 } 1721 1733 1722 1734 /* 1723 1735 * Do TLS callbacks first and then call the init/term function if it's a DLL. 1724 1736 */ 1725 rc = kldrModPEDoCallTLS(pModPE, DLL_PROCESS_ATTACH, uHandle);1737 rc = kldrModPEDoCallTLS(pModPE, pvMapping, DLL_PROCESS_ATTACH, uHandle); 1726 1738 if ( !rc 1727 1739 && (pModPE->Hdrs.FileHeader.Characteristics & IMAGE_FILE_DLL)) 1728 1740 { 1729 rc = kldrModPEDoCallDLL(pModPE, DLL_PROCESS_ATTACH, uHandle);1741 rc = kldrModPEDoCallDLL(pModPE, pvMapping, DLL_PROCESS_ATTACH, uHandle); 1730 1742 if (rc) 1731 kldrModPEDoCallTLS(pModPE, DLL_PROCESS_DETACH, uHandle);1743 kldrModPEDoCallTLS(pModPE, pvMapping, DLL_PROCESS_DETACH, uHandle); 1732 1744 } 1733 1745 … … 1742 1754 * @returns KLDR_ERR_MODULE_INIT_FAILED or KLDR_ERR_THREAD_ATTACH_FAILED on failure. 1743 1755 * @param pModPE The PE module interpreter instance. 1756 * @param pvMapping The module mapping to use (resolved). 1744 1757 * @param uOp The operation (DLL_*). 1745 1758 * @param uHandle The module handle to present. 1746 1759 */ 1747 static int kldrModPEDoCallDLL(PKLDRMODPE pModPE, unsigned uOp, KUPTR uHandle)1760 static int kldrModPEDoCallDLL(PKLDRMODPE pModPE, void *pvMapping, unsigned uOp, KUPTR uHandle) 1748 1761 { 1749 1762 int rc; … … 1758 1771 * Invoke the entrypoint and convert the boolean result to a kLdr status code. 1759 1772 */ 1760 rc = kldrModPEDoCall((KUPTR)pModPE->pvMapping + pModPE->Hdrs.OptionalHeader.AddressOfEntryPoint, 1761 uHandle, uOp, NULL); 1773 rc = kldrModPEDoCall((KUPTR)pvMapping + pModPE->Hdrs.OptionalHeader.AddressOfEntryPoint, uHandle, uOp, NULL); 1762 1774 if (rc) 1763 1775 rc = 0; … … 1778 1790 * @returns KLDR_ERR_THREAD_ATTACH_FAILED on failure. 1779 1791 * @param pModPE The PE module interpreter instance. 1792 * @param pvMapping The module mapping to use (resolved). 1780 1793 * @param uOp The operation (DLL_*). 1781 1794 * @param uHandle The module handle to present. 1782 1795 */ 1783 static int kldrModPEDoCallTLS(PKLDRMODPE pModPE, unsigned uOp, KUPTR uHandle)1796 static int kldrModPEDoCallTLS(PKLDRMODPE pModPE, void *pvMapping, unsigned uOp, KUPTR uHandle) 1784 1797 { 1785 1798 /** @todo implement TLS support. */ 1786 1799 K_NOREF(pModPE); 1800 K_NOREF(pvMapping); 1787 1801 K_NOREF(uOp); 1788 1802 K_NOREF(uHandle); … … 1862 1876 1863 1877 /** @copydoc kLdrModCallTerm */ 1864 static int kldrModPECallTerm(PKLDRMOD pMod, KUPTR uHandle)1878 static int kldrModPECallTerm(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 1865 1879 { 1866 1880 PKLDRMODPE pModPE = (PKLDRMODPE)pMod->pvData; … … 1869 1883 * Mapped? 1870 1884 */ 1871 if (!pModPE->pvMapping) 1872 return KLDR_ERR_NOT_MAPPED; 1885 if (pvMapping == KLDRMOD_INT_MAP) 1886 { 1887 pvMapping = pModPE->pvMapping; 1888 if (!pvMapping) 1889 return KLDR_ERR_NOT_MAPPED; 1890 } 1873 1891 1874 1892 /* 1875 1893 * Do TLS callbacks first. 1876 1894 */ 1877 kldrModPEDoCallTLS(pModPE, DLL_PROCESS_DETACH, uHandle);1895 kldrModPEDoCallTLS(pModPE, pvMapping, DLL_PROCESS_DETACH, uHandle); 1878 1896 if (pModPE->Hdrs.FileHeader.Characteristics & IMAGE_FILE_DLL) 1879 kldrModPEDoCallDLL(pModPE, DLL_PROCESS_DETACH, uHandle);1897 kldrModPEDoCallDLL(pModPE, pvMapping, DLL_PROCESS_DETACH, uHandle); 1880 1898 1881 1899 return 0; … … 1884 1902 1885 1903 /** @copydoc kLdrModCallThread */ 1886 static int kldrModPECallThread(PKLDRMOD pMod, KUPTR uHandle, unsigned fAttachingOrDetaching)1904 static int kldrModPECallThread(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle, unsigned fAttachingOrDetaching) 1887 1905 { 1888 1906 PKLDRMODPE pModPE = (PKLDRMODPE)pMod->pvData; … … 1891 1909 1892 1910 /* 1911 * Mapped? 1912 */ 1913 if (pvMapping == KLDRMOD_INT_MAP) 1914 { 1915 pvMapping = pModPE->pvMapping; 1916 if (!pvMapping) 1917 return KLDR_ERR_NOT_MAPPED; 1918 } 1919 1920 /* 1893 1921 * Do TLS callbacks first and then call the init/term function if it's a DLL. 1894 1922 */ 1895 rc = kldrModPEDoCallTLS(pModPE, uOp, uHandle);1923 rc = kldrModPEDoCallTLS(pModPE, pvMapping, uOp, uHandle); 1896 1924 if (!fAttachingOrDetaching) 1897 1925 rc = 0; … … 1899 1927 && (pModPE->Hdrs.FileHeader.Characteristics & IMAGE_FILE_DLL)) 1900 1928 { 1901 rc = kldrModPEDoCallDLL(pModPE, uOp, uHandle);1929 rc = kldrModPEDoCallDLL(pModPE, pvMapping, uOp, uHandle); 1902 1930 if (!fAttachingOrDetaching) 1903 1931 rc = 0; 1904 1932 if (rc) 1905 kldrModPEDoCallTLS(pModPE, uOp, uHandle);1933 kldrModPEDoCallTLS(pModPE, pvMapping, uOp, uHandle); 1906 1934 } 1907 1935 -
trunk/kRdr/kRdrFile.cpp
r29 r81 1298 1298 pRdrFile->cb = cb; 1299 1299 pRdrFile->off = 0; 1300 pRdrFile->cPreps = 0; 1300 1301 pRdrFile->cMappings = 0; 1301 pRdrFile-> cPreps = 0;1302 pRdrFile->pvMapping = NULL; 1302 1303 kHlpMemCopy(&pRdrFile->szFilename[0], szFilename, cchFilename + 1); 1303 1304
Note:
See TracChangeset
for help on using the changeset viewer.