Changeset 117 for trunk/kLdr/kLdrModNative.c
- Timestamp:
- Mar 15, 2020, 4:23:36 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrModNative.c
r82 r117 165 165 KLDRFOFF offNewHdr, PPKLDRMOD ppMod) 166 166 { 167 int rc = kLdrModOpenNative(kRdrName(pRdr), ppMod);167 int rc = kLdrModOpenNative(kRdrName(pRdr), fFlags, ppMod); 168 168 if (rc) 169 169 return rc; … … 180 180 * @returns non-zero native or kLdr status code on failure. 181 181 * @param pszFilename The filename or module name to be loaded. 182 * @param fFlags Module open flags, KLDRMOD_OPEN_FLAGS_XXX. 182 183 * @param ppMod Where to store the module interpreter instance pointer. 183 184 */ 184 int kLdrModOpenNative(const char *pszFilename, PPKLDRMOD ppMod)185 int kLdrModOpenNative(const char *pszFilename, KU32 fFlags, PPKLDRMOD ppMod) 185 186 { 186 187 int rc; … … 191 192 #if K_OS == K_OS_OS2 192 193 HMODULE hmod; 194 kHlpAssertReturn(!(fFlags & ~KLDRMOD_OPEN_FLAGS_VALID_MASK), KERR_INVALID_PARAMETER); 193 195 194 196 rc = DosLoadModule(NULL, 0, (PCSZ)pszFilename, &hmod); 195 197 if (rc) 196 198 return rc; 197 rc = kLdrModOpenNativeByHandle((KUPTR)hmod, ppMod);199 rc = kLdrModOpenNativeByHandle((KUPTR)hmod, fFlags, ppMod); 198 200 if (rc) 199 201 DosFreeModule(hmod); … … 201 203 #elif K_OS == K_OS_WINDOWS 202 204 HMODULE hmod; 205 kHlpAssertReturn(!(fFlags & ~KLDRMOD_OPEN_FLAGS_VALID_MASK), KERR_INVALID_PARAMETER); 203 206 204 207 hmod = LoadLibrary(pszFilename); 205 208 if (!hmod) 206 209 return GetLastError(); 207 rc = kLdrModOpenNativeByHandle((KUPTR)hmod, ppMod);210 rc = kLdrModOpenNativeByHandle((KUPTR)hmod, fFlags, ppMod); 208 211 if (rc) 209 212 FreeLibrary(hmod); … … 211 214 #elif K_OS == K_OS_DARWIN 212 215 void *pvMod; 216 kHlpAssertReturn(!(fFlags & ~KLDRMOD_OPEN_FLAGS_VALID_MASK), KERR_INVALID_PARAMETER); 213 217 214 218 pvMod = dlopen(pszFilename, 0); 215 219 if (!pvMod) 216 220 return ENOENT; 217 rc = kLdrModOpenNativeByHandle((KUPTR)pvMod, ppMod);221 rc = kLdrModOpenNativeByHandle((KUPTR)pvMod, fFlags, ppMod); 218 222 if (rc) 219 223 dlclose(pvMod); … … 233 237 * @returns non-zero native or kLdr status code on failure. 234 238 * @param pszFilename The filename or module name to be loaded. 239 * @param fFlags Module open flags, KLDRMOD_OPEN_FLAGS_XXX. 235 240 * @param ppMod Where to store the module interpreter instance pointer. 236 241 * @remark This will not make the native loader increment the load count. 237 242 */ 238 int kLdrModOpenNativeByHandle(KUPTR uHandle, PPKLDRMOD ppMod)243 int kLdrModOpenNativeByHandle(KUPTR uHandle, KU32 fFlags, PPKLDRMOD ppMod) 239 244 { 240 245 KSIZE cb; … … 305 310 # error "Port me" 306 311 #endif 312 313 kHlpAssertReturn(!(fFlags & ~KLDRMOD_OPEN_FLAGS_VALID_MASK), KERR_INVALID_PARAMETER); 307 314 308 315 /* … … 328 335 pMod->pszName = kHlpGetFilename(pMod->pszFilename); /** @todo get soname */ 329 336 pMod->cchName = cchFilename - (KU32)(pMod->pszName - pMod->pszFilename); 330 pMod->fFlags = 0;337 pMod->fFlags = fFlags; 331 338 #if defined(__i386__) || defined(__X86__) || defined(_M_IX86) 332 339 pMod->enmCpu = KCPU_I386; … … 1050 1057 1051 1058 1059 #if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS || defined(__NT__) 1060 /** Common worker on platforms where there is one entrypoint which does both. */ 1061 static int kLdrModNativeCallInitTerm(PKLDRMODNATIVE pModNative, KUPTR uHandle, KBOOL fInit) 1062 { 1063 # if K_OS == K_OS_WINDOWS || defined(__NT__) 1064 /* No TLS init/term for now. */ 1065 KU32 const uRvaEntrypoint = pModNative->pNtHdrs->OptionalHeader.AddressOfEntryPoint; 1066 if ( uRvaEntrypoint != 0 1067 && uRvaEntrypoint < pModNative->pNtHdrs->OptionalHeader.SizeOfCode 1068 && (pModNative->pNtHdrs->FileHeader.Characteristics & IMAGE_FILE_DLL)) 1069 { 1070 KI32 rc = kldrModPEDoCall(uRvaEntrypoint + (KUPTR)pModNative->hmod, uHandle, 1071 fInit ? DLL_PROCESS_ATTACH : DLL_PROCESS_DETACH, NULL /*pvReserved*/); 1072 if (rc) 1073 return 0; 1074 return fInit ? KLDR_ERR_MODULE_INIT_FAILED : KLDR_ERR_THREAD_ATTACH_FAILED; 1075 } 1076 # elif K_OS == K_OS_OS2 1077 //KI32 kldrModLXDoCall(KUPTR uEntrypoint, KUPTR uHandle, KU32 uOp, void *pvReserved) 1078 # endif 1079 return 0; 1080 } 1081 #endif 1082 1052 1083 /** @copydoc kLdrModCallInit */ 1053 1084 static int kldrModNativeCallInit(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 1054 1085 { 1086 #if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS || defined(__NT__) 1087 if (pMod->fFlags & KLDRMOD_OPEN_FLAGS_NATIVE_ALLOW_INIT_TERM) 1088 return kLdrModNativeCallInitTerm((PKLDRMODNATIVE)pMod->pvData, uHandle, K_TRUE /*fInit*/); 1089 #endif 1055 1090 return 0; 1056 1091 } … … 1060 1095 static int kldrModNativeCallTerm(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle) 1061 1096 { 1097 #if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS || defined(__NT__) 1098 if (pMod->fFlags & KLDRMOD_OPEN_FLAGS_NATIVE_ALLOW_INIT_TERM) 1099 return kLdrModNativeCallInitTerm((PKLDRMODNATIVE)pMod->pvData, uHandle, K_FALSE /*fInit*/); 1100 #endif 1062 1101 return 0; 1063 1102 }
Note:
See TracChangeset
for help on using the changeset viewer.