annotate loader/elfdll.c @ 18537:7efe8416e9d2

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