annotate loader/module.c @ 2051:596653943fa1

tired
author gabucino
date Tue, 02 Oct 2001 21:59:43 +0000
parents d8c1b0b38edc
children ce45cce7f7a5
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 * Modules
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 * Copyright 1995 Alexandre Julliard
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 #include <assert.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 #include <errno.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 #include <fcntl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 #include <unistd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 #include <sys/mman.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 #include <sys/types.h>
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
18 #ifdef HAVE_LIBDL
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
19 #include <wine/elfdll.h>
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
20 #include <dlfcn.h>
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
21 #endif
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
22
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 #ifdef __linux__
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 #include <asm/unistd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 #include <asm/ldt.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 #define LDT_ENTRIES 8192
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 #define LDT_ENTRY_SIZE 8
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 struct modify_ldt_ldt_s {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 unsigned int entry_number;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 unsigned long base_addr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 unsigned int limit;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 unsigned int seg_32bit:1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 unsigned int contents:2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 unsigned int read_exec_only:1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 unsigned int limit_in_pages:1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 unsigned int seg_not_present:1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 unsigned int useable:1;
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 #define MODIFY_LDT_CONTENTS_DATA 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 #define MODIFY_LDT_CONTENTS_STACK 1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 #define MODIFY_LDT_CONTENTS_CODE 2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 #define __NR_modify_ldt 123
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 #endif
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 #include <wine/windef.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 #include <wine/winerror.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 #include <wine/heap.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 #include <wine/module.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 #include <wine/pe_image.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 #include <wine/debugtools.h>
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
56 #include "win32.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 struct modref_list_t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 typedef struct modref_list_t
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 WINE_MODREF* wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 struct modref_list_t *next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 struct modref_list_t *prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 modref_list;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 //WINE_MODREF *local_wm=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 modref_list* local_wm=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 WINE_MODREF *MODULE_FindModule(LPCSTR m)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 modref_list* list=local_wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 TRACE("Module %s request\n", m);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 if(list==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 while(strcmp(m, list->wm->filename))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 {
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
79 TRACE("%s: %x\n", list->wm->filename, list->wm->module);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 list=list->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 if(list==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 TRACE("Resolved to %s\n", list->wm->filename);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 return list->wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
88 static void MODULE_RemoveFromList(WINE_MODREF *mod)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 modref_list* list=local_wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 if(list==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 if(mod==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 if((list->prev==NULL)&&(list->next==NULL))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 free(list);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 local_wm=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 // uninstall_fs();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 for(;list;list=list->prev)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 if(list->wm==mod)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 if(list->prev)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 list->prev->next=list->next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 if(list->next)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 list->next->prev=list->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 if(list==local_wm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 local_wm=list->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 free(list);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 return;
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 modref_list* list=local_wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 TRACE("Module %X request\n", m);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 if(list==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 while(m!=list->wm->module)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 // printf("Checking list %X wm %X module %X\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 // list, list->wm, list->wm->module);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 list=list->prev;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 if(list==NULL)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 TRACE("LookupHMODULE hit %X\n", list->wm);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 return list->wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 /*************************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 * MODULE_InitDll
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 WIN_BOOL retv = TRUE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 static LPCSTR typeName[] = { "PROCESS_DETACH", "PROCESS_ATTACH",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 "THREAD_ATTACH", "THREAD_DETACH" };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 assert( wm );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 /* Skip calls for modules loaded with special load flags */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 if ( ( wm->flags & WINE_MODREF_DONT_RESOLVE_REFS )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 || ( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE ) )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 return TRUE;
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 TRACE("(%s,%s,%p) - CALL\n", wm->modname, typeName[type], lpReserved );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 /* Call the initialization routine */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 switch ( wm->type )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 case MODULE32_PE:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 retv = PE_InitDLL( wm, type, lpReserved );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 case MODULE32_ELF:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 /* no need to do that, dlopen() already does */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 default:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 ERR("wine_modref type %d not handled.\n", wm->type );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 retv = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 /* The state of the module list may have changed due to the call
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 to PE_InitDLL. We cannot assume that this module has not been
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 deleted. */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 TRACE("(%p,%s,%p) - RETURN %d\n", wm, typeName[type], lpReserved, retv );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 return retv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 /*************************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 * MODULE_DllProcessAttach
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 * Send the process attach notification to all DLLs the given module
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 * depends on (recursively). This is somewhat complicated due to the fact that
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 * - we have to respect the module dependencies, i.e. modules implicitly
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 * referenced by another module have to be initialized before the module
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 * itself can be initialized
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 * - the initialization routine of a DLL can itself call LoadLibrary,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 * thereby introducing a whole new set of dependencies (even involving
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 * the 'old' modules) at any time during the whole process
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 * (Note that this routine can be recursively entered not only directly
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 * from itself, but also via LoadLibrary from one of the called initialization
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 * routines.)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 * Furthermore, we need to rearrange the main WINE_MODREF list to allow
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 * the process *detach* notifications to be sent in the correct order.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 * This must not only take into account module dependencies, but also
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 * 'hidden' dependencies created by modules calling LoadLibrary in their
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 * attach notification routine.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 * The strategy is rather simple: we move a WINE_MODREF to the head of the
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 * list after the attach notification has returned. This implies that the
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 * detach notifications are called in the reverse of the sequence the attach
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 * notifications *returned*.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 * NOTE: Assumes that the process critical section is held!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 WIN_BOOL retv = TRUE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 assert( wm );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 /* prevent infinite recursion in case of cyclical dependencies */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 if ( ( wm->flags & WINE_MODREF_MARKER )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 || ( wm->flags & WINE_MODREF_PROCESS_ATTACHED ) )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 return retv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 TRACE("(%s,%p) - START\n", wm->modname, lpReserved );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 /* Tag current MODREF to prevent recursive loop */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 wm->flags |= WINE_MODREF_MARKER;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 /* Recursively attach all DLLs this one depends on */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 /* for ( i = 0; retv && i < wm->nDeps; i++ )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 if ( wm->deps[i] )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 retv = MODULE_DllProcessAttach( wm->deps[i], lpReserved );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 /* Call DLL entry point */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 //local_wm=wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 if(local_wm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 local_wm->next=malloc(sizeof(modref_list));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 local_wm->next->prev=local_wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 local_wm->next->next=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 local_wm->next->wm=wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 local_wm=local_wm->next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 local_wm=malloc(sizeof(modref_list));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 local_wm->next=local_wm->prev=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 local_wm->wm=wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 /* Remove recursion flag */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 wm->flags &= ~WINE_MODREF_MARKER;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 if ( retv )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 retv = MODULE_InitDll( wm, DLL_PROCESS_ATTACH, lpReserved );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 if ( retv )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 wm->flags |= WINE_MODREF_PROCESS_ATTACHED;
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 TRACE("(%s,%p) - END\n", wm->modname, lpReserved );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 return retv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 }
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 * MODULE_DllProcessDetach
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 * Send DLL process detach notifications. See the comment about calling
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 * sequence at MODULE_DllProcessAttach. Unless the bForceDetach flag
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 * is set, only DLLs with zero refcount are notified.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 void MODULE_DllProcessDetach( WINE_MODREF* wm, WIN_BOOL bForceDetach, LPVOID lpReserved )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 // WINE_MODREF *wm=local_wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 wm->flags &= ~WINE_MODREF_PROCESS_ATTACHED;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 MODULE_InitDll( wm, DLL_PROCESS_DETACH, lpReserved );
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 * LoadLibraryExA (KERNEL32)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288 WINE_MODREF *wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 if(!libname)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 SetLastError(ERROR_INVALID_PARAMETER);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 // if(fs_installed==0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 // install_fs();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 wm = MODULE_LoadLibraryExA( libname, hfile, flags );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 if ( wm )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 if ( !MODULE_DllProcessAttach( wm, NULL ) )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304 WARN_(module)("Attach failed for module '%s', \n", libname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 MODULE_FreeLibrary(wm);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306 SetLastError(ERROR_DLL_INIT_FAILED);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 MODULE_RemoveFromList(wm);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308 wm = NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 return wm ? wm->module : 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
314
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
315
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316 /***********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
317 * MODULE_LoadLibraryExA (internal)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319 * Load a PE style module according to the load order.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321 * The HFILE parameter is not used and marked reserved in the SDK. I can
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 * only guess that it should force a file to be mapped, but I rather
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 * ignore the parameter because it would be extremely difficult to
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324 * integrate this with different types of module represenations.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329 DWORD err = GetLastError();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 WINE_MODREF *pwm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332 // module_loadorder_t *plo;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
333
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
334
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
335 SetLastError( ERROR_FILE_NOT_FOUND );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
336 TRACE("Trying native dll '%s'\n", libname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
337 pwm = PE_LoadLibraryExA(libname, flags);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
338 #ifdef HAVE_LIBDL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
339 if(!pwm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
340 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
341 TRACE("Trying ELF dll '%s'\n", libname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
342 pwm=(WINE_MODREF*)ELFDLL_LoadLibraryExA(libname, flags);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
345 // printf("0x%08x\n", pwm);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346 // break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347 if(pwm)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 /* Initialize DLL just loaded */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 TRACE("Loaded module '%s' at 0x%08x, \n", libname, pwm->module);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 /* Set the refCount here so that an attach failure will */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352 /* decrement the dependencies through the MODULE_FreeLibrary call. */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353 pwm->refCount++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355 SetLastError( err ); /* restore last error */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 return pwm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
358
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
359
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
360 WARN("Failed to load module '%s'; error=0x%08lx, \n", libname, GetLastError());
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
361 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
362 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
363
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
364 /***********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
365 * LoadLibraryA (KERNEL32)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367 HMODULE WINAPI LoadLibraryA(LPCSTR libname) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
368 return LoadLibraryExA(libname,0,0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
372 /***********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
373 * FreeLibrary
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375 WIN_BOOL WINAPI FreeLibrary(HINSTANCE hLibModule)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377 WIN_BOOL retv = FALSE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
378 WINE_MODREF *wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
379
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
380 wm=MODULE32_LookupHMODULE(hLibModule);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
381 // wm=local_wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
382
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
383 if ( !wm || !hLibModule )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
384 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
385 SetLastError( ERROR_INVALID_HANDLE );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
386 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
387 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
388 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
389 retv = MODULE_FreeLibrary( wm );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
390
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
391 MODULE_RemoveFromList(wm);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
392
128
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
393 /* garbage... */
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
394 if (local_wm == NULL) my_garbagecollection();
28091b3caff9 DLL loader updated from avifile-0.60beta4
arpi_esp
parents: 1
diff changeset
395
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
396 return retv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
397 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
398
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
399 /***********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
400 * MODULE_DecRefCount
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
401 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
402 * NOTE: Assumes that the process critical section is held!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
403 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
404 static void MODULE_DecRefCount( WINE_MODREF *wm )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
405 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
406 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
407
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
408 if ( wm->flags & WINE_MODREF_MARKER )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
409 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
410
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
411 if ( wm->refCount <= 0 )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
412 return;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
413
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
414 --wm->refCount;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
415 TRACE("(%s) refCount: %d\n", wm->modname, wm->refCount );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
416
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
417 if ( wm->refCount == 0 )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
418 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
419 wm->flags |= WINE_MODREF_MARKER;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
420
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
421 for ( i = 0; i < wm->nDeps; i++ )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
422 if ( wm->deps[i] )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
423 MODULE_DecRefCount( wm->deps[i] );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
424
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
425 wm->flags &= ~WINE_MODREF_MARKER;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
426 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
427 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
428
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
429 /***********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
430 * MODULE_FreeLibrary
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
431 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
432 * NOTE: Assumes that the process critical section is held!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
433 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
434 WIN_BOOL MODULE_FreeLibrary( WINE_MODREF *wm )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
435 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
436 TRACE("(%s) - START\n", wm->modname );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
437
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
438 /* Recursively decrement reference counts */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
439 //MODULE_DecRefCount( wm );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
440
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
441 /* Call process detach notifications */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
442 MODULE_DllProcessDetach( wm, FALSE, NULL );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
443
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
444 PE_UnloadLibrary(wm);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
445
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
446 TRACE("END\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
447
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
448 return TRUE;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
449 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
450
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
451 /***********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
452 * GetProcAddress (KERNEL32.257)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
453 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
454 FARPROC WINAPI GetProcAddress( HMODULE hModule, LPCSTR function )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
455 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
456 return MODULE_GetProcAddress( hModule, function, TRUE );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
457 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
458
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
459 /***********************************************************************
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
460 * MODULE_GetProcAddress (internal)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
461 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
462 FARPROC MODULE_GetProcAddress(
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
463 HMODULE hModule, /* [in] current module handle */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
464 LPCSTR function, /* [in] function to be looked up */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
465 WIN_BOOL snoop )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
466 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
467 WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
468 // WINE_MODREF *wm=local_wm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
469 FARPROC retproc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
470
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
471 if (HIWORD(function))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
472 TRACE_(win32)("(%08lx,%s)\n",(DWORD)hModule,function);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
473 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
474 TRACE_(win32)("(%08lx,%p)\n",(DWORD)hModule,function);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
475 if (!wm) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
476 SetLastError(ERROR_INVALID_HANDLE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
477 return (FARPROC)0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
478 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
479 switch (wm->type)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
480 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
481 case MODULE32_PE:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
482 retproc = PE_FindExportedFunction( wm, function, snoop );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
483 if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
484 return retproc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
485 #ifdef HAVE_LIBDL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
486 case MODULE32_ELF:
1307
d8c1b0b38edc Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents: 128
diff changeset
487 retproc = (FARPROC) dlsym( (void*)wm->module, function);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
488 if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
489 return retproc;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
490 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
491 default:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
492 ERR("wine_modref type %d not handled.\n",wm->type);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
493 SetLastError(ERROR_INVALID_HANDLE);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
494 return (FARPROC)0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
495 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
496 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
497