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
, '.');
138 *cptr
= '\0'; /* Strip extension */
140 /* Convert to lower case.
141 * This must be done manually because it is not sure that
142 * other modules are accessible.
144 for(cptr
= name
; *cptr
; cptr
++)
145 *cptr
= tolower(*cptr
);
151 /****************************************************************************
152 * ELFDLL_LoadLibraryExA (internal)
154 * Implementation of elf-dll loading for PE modules
156 WINE_MODREF
*ELFDLL_LoadLibraryExA(LPCSTR path
, DWORD flags
)
159 struct elfdll_image
*image
;
164 get_sobasename(path
, name
);
165 strcpy(soname
, name
);
166 strcat(soname
, ".so");
168 /* Try to open the elf-dll */
169 dlhandle
= ELFDLL_dlopen(soname
, RTLD_LAZY
);
172 WARN("Could not load %s (%s)\n", soname
, dlerror());
173 SetLastError( ERROR_FILE_NOT_FOUND
);
177 /* Get the 'dllname_elfdll_image' variable */
178 strcpy(soname
, name
);
179 strcat(soname
, "_elfdll_image");
180 image
= (struct elfdll_image
*)dlsym(dlhandle
, soname
);
183 ERR("Could not get elfdll image descriptor %s (%s)\n", soname
, dlerror());
185 SetLastError( ERROR_BAD_FORMAT
);
189 wm
= PE_CreateModule( image
->pe_module_start
, path
, 0, -1, FALSE
);
192 ERR("Could not create WINE_MODREF for %s\n", path
);
194 SetLastError( ERROR_OUTOFMEMORY
);
197 wm
->dlhandle
= dlhandle
;
199 dump_exports(image
->pe_module_start
);
206 * No elfdlls possible
207 * Just put stubs in here.
210 WINE_MODREF
*ELFDLL_LoadLibraryExA(LPCSTR libname
, DWORD flags
)
212 SetLastError( ERROR_FILE_NOT_FOUND
);