annotate loader/elfdll.c @ 13754:1e2495e9462e

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