annotate loader/elfdll.c @ 615:b96e45bcb178

init.
author pontscho
date Tue, 24 Apr 2001 11:35:07 +0000
parents 3b5f5d1c5041
children d8c1b0b38edc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 * Elf-dll loader functions
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 * Copyright 1999 Bertho A. Stultiens
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 #include <config.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 #ifdef HAVE_LIBDL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 #include <ctype.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 #include <wine/config.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 #include <wine/windef.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 //#include <wine/global.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 //#include <wine/process.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 #include <wine/module.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 #include <wine/heap.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 #include <wine/elfdll.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 #include <wine/debugtools.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 #include <wine/winerror.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 //DEFAULT_DEBUG_CHANNEL(elfdll)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 #include <dlfcn.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 struct modref_list_t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 typedef struct modref_list_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 WINE_MODREF* wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 struct modref_list_t *next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 struct modref_list_t *prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 modref_list;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 //WINE_MODREF *local_wm=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 extern modref_list* local_wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 /*------------------ HACKS -----------------*/
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 extern DWORD fixup_imports(WINE_MODREF *wm);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 extern void dump_exports(HMODULE hModule);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 /*---------------- END HACKS ---------------*/
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 //char *extra_ld_library_path = "/usr/lib/win32";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 extern char* def_path;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 struct elfdll_image
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 HMODULE pe_module_start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 DWORD pe_module_size;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 /****************************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 * ELFDLL_dlopen
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 * Wrapper for dlopen to search the EXTRA_LD_LIBRARY_PATH from wine.conf
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 * manually because libdl.so caches the environment and does not accept our
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 * changes.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 void *ELFDLL_dlopen(const char *libname, int flags)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 char buffer[256];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 int namelen;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 void *handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 char *ldpath;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 /* First try the default path search of dlopen() */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 handle = dlopen(libname, flags);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 if(handle)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 return handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 /* Now try to construct searches through our extra search-path */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 namelen = strlen(libname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 ldpath = def_path;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 while(ldpath && *ldpath)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 char *cptr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 char *from;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 from = ldpath;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 cptr = strchr(ldpath, ':');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 if(!cptr)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 len = strlen(ldpath);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 ldpath = NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 len = cptr - ldpath;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 ldpath = cptr + 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 if(len + namelen + 1 >= sizeof(buffer))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 ERR("Buffer overflow! Check EXTRA_LD_LIBRARY_PATH or increase buffer size.\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 strncpy(buffer, from, len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 if(len)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 buffer[len] = '/';
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 strcpy(buffer + len + 1, libname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 strcpy(buffer + len, libname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 TRACE("Trying dlopen('%s', %d)\n", buffer, flags);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 handle = dlopen(buffer, flags);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 if(handle)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 return handle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 /****************************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 * get_sobasename (internal)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 static LPSTR get_sobasename(LPCSTR path, LPSTR name)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 char *cptr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 /* Strip the path from the library name */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 if((cptr = strrchr(path, '/')))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 char *cp = strrchr(cptr+1, '\\');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 if(cp && cp > cptr)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 cptr = cp;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 cptr = strrchr(path, '\\');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 if(!cptr)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 cptr = (char *)path; /* No '/' nor '\\' in path */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 cptr++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 strcpy(name, cptr);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 cptr = strrchr(name, '.');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 if(cptr)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 *cptr = '\0'; /* Strip extension */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 /* Convert to lower case.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 * This must be done manually because it is not sure that
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 * other modules are accessible.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 for(cptr = name; *cptr; cptr++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 *cptr = tolower(*cptr);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 return name;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 /****************************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 * ELFDLL_CreateModref (internal)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 * INPUT
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 * hModule - the header from the elf-dll's data-segment
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 * path - requested path from original call
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 * OUTPUT
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 * A WINE_MODREF pointer to the new object
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 * BUGS
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 * - Does not handle errors due to dependencies correctly
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 * - path can be wrong
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 #define RVA(base, va) (((DWORD)base) + ((DWORD)va))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 static WINE_MODREF *ELFDLL_CreateModref(HMODULE hModule, LPCSTR path)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 // IMAGE_NT_HEADERS *nt = PE_HEADER(hModule);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 IMAGE_DATA_DIRECTORY *dir;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 IMAGE_IMPORT_DESCRIPTOR *pe_import = NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 WINE_MODREF *wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 HANDLE procheap = GetProcessHeap();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 wm = (WINE_MODREF *)HeapAlloc(procheap, HEAP_ZERO_MEMORY, sizeof(*wm));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 if(!wm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 wm->module = hModule;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 wm->type = MODULE32_ELF; /* FIXME */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 // dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_EXPORT;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 // if(dir->Size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 // wm->binfmt.pe.pe_export = (PIMAGE_EXPORT_DIRECTORY)RVA(hModule, dir->VirtualAddress);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 // dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_IMPORT;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 // if(dir->Size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 // pe_import = wm->binfmt.pe.pe_import = (PIMAGE_IMPORT_DESCRIPTOR)RVA(hModule, dir->VirtualAddress);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 // dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_RESOURCE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 // if(dir->Size)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 // wm->binfmt.pe.pe_resource = (PIMAGE_RESOURCE_DIRECTORY)RVA(hModule, dir->VirtualAddress);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 wm->filename = malloc(strlen(path)+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 strcpy(wm->filename, path);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 wm->modname = strrchr( wm->filename, '\\' );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 if (!wm->modname) wm->modname = wm->filename;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 else wm->modname++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 len = GetShortPathNameA( wm->filename, NULL, 0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 wm->short_filename = (char *)HeapAlloc( procheap, 0, len+1 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 GetShortPathNameA( wm->filename, wm->short_filename, len+1 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 wm->short_modname = strrchr( wm->short_filename, '\\' );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 if (!wm->short_modname) wm->short_modname = wm->short_filename;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 else wm->short_modname++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 /* Link MODREF into process list */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 // EnterCriticalSection( &PROCESS_Current()->crit_section );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 if(local_wm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 local_wm->next=malloc(sizeof(modref_list));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 local_wm->next->prev=local_wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 local_wm->next->next=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 local_wm->next->wm=wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 local_wm=local_wm->next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 local_wm=malloc(sizeof(modref_list));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 local_wm->next=local_wm->prev=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 local_wm->wm=wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 // LeaveCriticalSection( &PROCESS_Current()->crit_section );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 return wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 /****************************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 * ELFDLL_LoadLibraryExA (internal)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 * Implementation of elf-dll loading for PE modules
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR path, DWORD flags)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 LPVOID dlhandle;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 struct elfdll_image *image;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 char name[129];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 char soname[129];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 WINE_MODREF *wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 get_sobasename(path, name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 strcpy(soname, name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 strcat(soname, ".so");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 /* Try to open the elf-dll */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 dlhandle = ELFDLL_dlopen(soname, RTLD_LAZY);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 if(!dlhandle)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 WARN("Could not load %s (%s)\n", soname, dlerror());
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 SetLastError( ERROR_FILE_NOT_FOUND );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 /* Get the 'dllname_elfdll_image' variable */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 /* strcpy(soname, name);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 strcat(soname, "_elfdll_image");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 image = (struct elfdll_image *)dlsym(dlhandle, soname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 if(!image)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 ERR("Could not get elfdll image descriptor %s (%s)\n", soname, dlerror());
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 dlclose(dlhandle);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 SetLastError( ERROR_BAD_FORMAT );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
283 wm = ELFDLL_CreateModref((int)dlhandle, path);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284 if(!wm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 ERR("Could not create WINE_MODREF for %s\n", path);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 dlclose(dlhandle);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288 SetLastError( ERROR_OUTOFMEMORY );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 return wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 /****************************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297 * ELFDLL_UnloadLibrary (internal)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 * Unload an elf-dll completely from memory and deallocate the modref
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301 void ELFDLL_UnloadLibrary(WINE_MODREF *wm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 #endif /*HAVE_LIBDL*/