2 * Elf-dll loader functions
4 * Copyright 1999 Bertho A. Stultiens
18 #include "wine/winbase16.h"
20 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(elfdll)
25 #if defined(HAVE_DL_API)
28 /*------------------ HACKS -----------------*/
29 extern DWORD fixup_imports(WINE_MODREF *wm);
30 extern void dump_exports(HMODULE hModule);
31 /*---------------- END HACKS ---------------*/
33 char *extra_ld_library_path = NULL; /* The extra search-path set in wine.conf */
37 HMODULE pe_module_start;
39 NE_MODULE *ne_module_start;
44 /****************************************************************************
47 * Wrapper for dlopen to search the EXTRA_LD_LIBRARY_PATH from wine.conf
48 * manually because libdl.so caches the environment and does not accept our
51 void *ELFDLL_dlopen(const char *libname, int flags)
58 /* First try the default path search of dlopen() */
59 handle = dlopen(libname, flags);
60 /* do NOT call dlerror() here ! (check after return) */
64 /* Now try to construct searches through our extra search-path */
65 namelen = strlen(libname);
66 ldpath = extra_ld_library_path;
67 while(ldpath && *ldpath)
74 cptr = strchr(ldpath, ':');
86 if(len + namelen + 1 >= sizeof(buffer))
88 ERR("Buffer overflow! Check EXTRA_LD_LIBRARY_PATH or increase buffer size.\n");
92 strncpy(buffer, from, len);
96 strcpy(buffer + len + 1, libname);
99 strcpy(buffer + len, libname);
101 TRACE("Trying dlopen('%s', %d)\n", buffer, flags);
103 handle = dlopen(buffer, flags);
104 /* do NOT call dlerror() here ! (check after return) */
112 /****************************************************************************
113 * get_sobasename (internal)
116 static LPSTR get_sobasename(LPCSTR path, LPSTR name)
120 /* Strip the path from the library name */
121 if((cptr = strrchr(path, '/')))
123 char *cp = strrchr(cptr+1, '\\');
128 cptr = strrchr(path, '\\');
131 cptr = (char *)path; /* No '/' nor '\\' in path */
136 cptr = strrchr(name, '.');
137 if(cptr && !strcasecmp(cptr,".dll")) *cptr = '\0'; /* Strip extension */
139 /* Convert to lower case.
140 * This must be done manually because it is not sure that
141 * other modules are accessible.
143 for(cptr = name; *cptr; cptr++)
144 *cptr = tolower(*cptr);
150 /****************************************************************************
151 * ELFDLL_LoadLibraryExA (internal)
153 * Implementation of elf-dll loading for PE modules
155 WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR path, DWORD flags)
158 struct elfdll_image *image;
163 get_sobasename(path, name);
164 strcpy(soname, name);
165 strcat(soname, ".so");
167 /* Try to open the elf-dll */
168 dlhandle = ELFDLL_dlopen(soname, RTLD_LAZY);
171 WARN("Could not load %s (%s)\n", soname, dlerror());
172 SetLastError( ERROR_FILE_NOT_FOUND );
176 /* Get the 'dllname_elfdll_image' variable */
177 strcpy(soname, name);
178 strcat(soname, "_elfdll_image");
179 image = (struct elfdll_image *)dlsym(dlhandle, soname);
182 ERR("Could not get elfdll image descriptor %s (%s)\n", soname, dlerror());
184 SetLastError( ERROR_BAD_FORMAT );
188 wm = PE_CreateModule( image->pe_module_start, path, 0, -1, FALSE );
191 ERR("Could not create WINE_MODREF for %s\n", path);
193 SetLastError( ERROR_OUTOFMEMORY );
196 wm->dlhandle = dlhandle;
198 dump_exports(image->pe_module_start);
205 * No elfdlls possible
206 * Just put stubs in here.
209 WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR libname, DWORD flags)
211 SetLastError( ERROR_FILE_NOT_FOUND );