2 * Elf-dll loader functions
4 * Copyright 1999 Bertho A. Stultiens
17 #include "wine/winbase16.h"
19 #include "debugtools.h"
22 DEFAULT_DEBUG_CHANNEL(elfdll
);
24 #if defined(HAVE_DL_API)
27 /*------------------ HACKS -----------------*/
28 extern DWORD
fixup_imports(WINE_MODREF
*wm
);
29 extern void dump_exports(HMODULE hModule
);
30 /*---------------- END HACKS ---------------*/
32 char *extra_ld_library_path
= NULL
; /* The extra search-path set in wine.conf */
36 HMODULE pe_module_start
;
38 NE_MODULE
*ne_module_start
;
43 /****************************************************************************
46 * Wrapper for dlopen to search the EXTRA_LD_LIBRARY_PATH from wine.conf
47 * manually because libdl.so caches the environment and does not accept our
50 void *ELFDLL_dlopen(const char *libname
, int flags
)
57 /* First try the default path search of dlopen() */
58 handle
= dlopen(libname
, flags
);
59 /* do NOT call dlerror() here ! (check after return) */
63 /* Now try to construct searches through our extra search-path */
64 namelen
= strlen(libname
);
65 ldpath
= extra_ld_library_path
;
66 while(ldpath
&& *ldpath
)
73 cptr
= strchr(ldpath
, ':');
85 if(len
+ namelen
+ 1 >= sizeof(buffer
))
87 ERR("Buffer overflow! Check EXTRA_LD_LIBRARY_PATH or increase buffer size.\n");
91 strncpy(buffer
, from
, len
);
95 strcpy(buffer
+ len
+ 1, libname
);
98 strcpy(buffer
+ len
, libname
);
100 TRACE("Trying dlopen('%s', %d)\n", buffer
, flags
);
102 handle
= dlopen(buffer
, flags
);
103 /* do NOT call dlerror() here ! (check after return) */
111 /****************************************************************************
112 * get_sobasename (internal)
115 static LPSTR
get_sobasename(LPCSTR path
, LPSTR name
)
119 /* Strip the path from the library name */
120 if((cptr
= strrchr(path
, '/')))
122 char *cp
= strrchr(cptr
+1, '\\');
127 cptr
= strrchr(path
, '\\');
130 cptr
= (char *)path
; /* No '/' nor '\\' in path */
135 cptr
= strrchr(name
, '.');
136 if(cptr
&& !strcasecmp(cptr
,".dll")) *cptr
= '\0'; /* Strip extension */
138 /* Convert to lower case.
139 * This must be done manually because it is not sure that
140 * other modules are accessible.
142 for(cptr
= name
; *cptr
; cptr
++)
143 *cptr
= tolower(*cptr
);
149 /****************************************************************************
150 * ELFDLL_LoadLibraryExA (internal)
152 * Implementation of elf-dll loading for PE modules
154 WINE_MODREF
*ELFDLL_LoadLibraryExA(LPCSTR path
, DWORD flags
)
157 struct elfdll_image
*image
;
162 get_sobasename(path
, name
);
163 strcpy(soname
, name
);
164 strcat(soname
, ".so");
166 /* Try to open the elf-dll */
167 dlhandle
= ELFDLL_dlopen(soname
, RTLD_LAZY
);
170 WARN("Could not load %s (%s)\n", soname
, dlerror());
171 SetLastError( ERROR_FILE_NOT_FOUND
);
175 /* Get the 'dllname_elfdll_image' variable */
176 strcpy(soname
, name
);
177 strcat(soname
, "_elfdll_image");
178 image
= (struct elfdll_image
*)dlsym(dlhandle
, soname
);
181 ERR("Could not get elfdll image descriptor %s (%s)\n", soname
, dlerror());
183 SetLastError( ERROR_BAD_FORMAT
);
187 wm
= PE_CreateModule( image
->pe_module_start
, path
, 0, -1, FALSE
);
190 ERR("Could not create WINE_MODREF for %s\n", path
);
192 SetLastError( ERROR_OUTOFMEMORY
);
195 wm
->dlhandle
= dlhandle
;
197 dump_exports(image
->pe_module_start
);
204 * No elfdlls possible
205 * Just put stubs in here.
208 WINE_MODREF
*ELFDLL_LoadLibraryExA(LPCSTR libname
, DWORD flags
)
210 SetLastError( ERROR_FILE_NOT_FOUND
);