/**************************************************************************** PARAMETERS: shared - True to load the driver into shared memory. REMARKS: Loads the Nucleus binary portable DLL into memory and initilises it. ****************************************************************************/ static ibool LoadDriver(void) { JPEG_initLibrary_t JPEG_initLibrary; JPEG_exports *jpegExp; char filename[_MAX_PATH]; char bpdpath[_MAX_PATH]; FILE *f; int i,max; ulong *p; /* Check if we have already loaded the driver */ if (loaded) return true; /* Open the BPD file */ if (!PM_findBPD(DLL_NAME,bpdpath)) return false; strcpy(filename,bpdpath); strcat(filename,DLL_NAME); if ((f = fopen(filename,"rb")) == NULL) return false; hModBPD = PE_loadLibraryExt(f,0,&hModSize,false); fclose(f); if (!hModBPD) return false; if ((JPEG_initLibrary = (JPEG_initLibrary_t)PE_getProcAddress(hModBPD,"_JPEG_initLibrary")) == NULL) return false; if ((jpegExp = JPEG_initLibrary(&_PM_imports,&_JPEG_imports)) == NULL) PM_fatalError("JPEG_initLibrary failed!\n"); /* Initialize all default imports to point to fatal error handler * for upwards compatibility, and copy the exported functions. */ max = sizeof(_JPEG_exports)/sizeof(JPEG_initLibrary_t); for (i = 0,p = (ulong*)&_JPEG_exports; i < max; i++) *p++ = (ulong)_JPEG_fatalErrorHandler; memcpy(&_JPEG_exports,jpegExp,MIN(sizeof(_JPEG_exports),jpegExp->dwSize)); loaded = true; return true; }
/**************************************************************************** DESCRIPTION: Loads a Portable Binary DLL into memory HEADER: peloader.h PARAMETERS: fd - File descriptor to load PE module from szDLLName - Name of the PE DLL library to load (for debug symbols) RETURNS: Handle to loaded PE DLL, or NULL on failure. REMARKS: Same as above but for an open file handle. szDLLName must be correct in order to load debug symbols under the debugger. ****************************************************************************/ PE_MODULE * PE_loadLibraryHandle( int fd, const char *szDLLName) { PE_MODULE *hMod; FILE *f; u_long size; /* Attempt to open the file on disk */ if ((f = fdopen(fd,"rb")) == NULL) { result = PE_fileNotFound; return NULL; } hMod = PE_loadLibraryExt(f,0,&size); fclose(f); /* Notify the Watcom Debugger of module load and let it load symbolic info */ #ifdef WATCOM_DEBUG_SYMBOLS if (hMod) { u_long size; char *modname; /* Store the file name in the hMod structure; this must be the real * file name where the debugger will try to load symbolic info from */ size = strlen(szDLLName) + 1; modname = malloc(size); if (modname) { if (szDLLName[1] == ':') strcpy(modname, szDLLName+2); else strcpy(modname, szDLLName); hMod->modname = modname; NotifyWDLoad(hMod->modname, (u_long)hMod->pbase); } } #endif return hMod; }