annotate loader/elfdll.c @ 3956:be47e35801dc

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