2 * Win32 builtin functions
4 * Copyright 1997 Alexandre Julliard
11 #include "builtin32.h"
18 #include "debugtools.h"
20 DECLARE_DEBUG_CHANNEL(relay
)
21 DECLARE_DEBUG_CHANNEL(win32
)
22 DECLARE_DEBUG_CHANNEL(module
)
26 BYTE call
; /* 0xe8 call callfrom32 (relative) */
27 DWORD callfrom32 WINE_PACKED
; /* RELAY_CallFrom32 relative addr */
28 BYTE ret
; /* 0xc2 ret $n or 0xc3 ret */
29 WORD args
; /* nb of args to remove from the stack */
35 const DWORD nresources
;
36 const DWORD restabsize
;
37 const IMAGE_RESOURCE_DATA_ENTRY
*entries
;
42 const BUILTIN32_DESCRIPTOR
*descr
; /* DLL descriptor */
45 const BUILTIN32_RESOURCE
*rsc
;
48 #define BI32_INSTANTIATED 0x01
49 #define BI32_DANGER 0x02
51 extern const BUILTIN32_DESCRIPTOR ADVAPI32_Descriptor
;
52 extern const BUILTIN32_DESCRIPTOR AVIFIL32_Descriptor
;
53 extern const BUILTIN32_DESCRIPTOR COMCTL32_Descriptor
;
54 extern const BUILTIN32_DESCRIPTOR COMDLG32_Descriptor
;
55 extern const BUILTIN32_DESCRIPTOR CRTDLL_Descriptor
;
56 extern const BUILTIN32_DESCRIPTOR DCIMAN32_Descriptor
;
57 extern const BUILTIN32_DESCRIPTOR DDRAW_Descriptor
;
58 extern const BUILTIN32_DESCRIPTOR DINPUT_Descriptor
;
59 extern const BUILTIN32_DESCRIPTOR DPLAY_Descriptor
;
60 extern const BUILTIN32_DESCRIPTOR DPLAYX_Descriptor
;
61 extern const BUILTIN32_DESCRIPTOR DSOUND_Descriptor
;
62 extern const BUILTIN32_DESCRIPTOR GDI32_Descriptor
;
63 extern const BUILTIN32_DESCRIPTOR ICMP_Descriptor
;
64 extern const BUILTIN32_DESCRIPTOR IMAGEHLP_Descriptor
;
65 extern const BUILTIN32_DESCRIPTOR IMM32_Descriptor
;
66 extern const BUILTIN32_DESCRIPTOR KERNEL32_Descriptor
;
67 extern const BUILTIN32_DESCRIPTOR LZ32_Descriptor
;
68 extern const BUILTIN32_DESCRIPTOR MPR_Descriptor
;
69 extern const BUILTIN32_DESCRIPTOR MCIANIM_Descriptor
;
70 extern const BUILTIN32_DESCRIPTOR MCIAVI_Descriptor
;
71 extern const BUILTIN32_DESCRIPTOR MCICDA_Descriptor
;
72 extern const BUILTIN32_DESCRIPTOR MCISEQ_Descriptor
;
73 extern const BUILTIN32_DESCRIPTOR MCIWAVE_Descriptor
;
74 extern const BUILTIN32_DESCRIPTOR MIDIMAP_Descriptor
;
75 extern const BUILTIN32_DESCRIPTOR MSACM32_Descriptor
;
76 extern const BUILTIN32_DESCRIPTOR MSACMMAP_Descriptor
;
77 extern const BUILTIN32_DESCRIPTOR MSNET32_Descriptor
;
78 extern const BUILTIN32_DESCRIPTOR MSVFW32_Descriptor
;
79 extern const BUILTIN32_DESCRIPTOR NTDLL_Descriptor
;
80 extern const BUILTIN32_DESCRIPTOR ODBC32_Descriptor
;
81 extern const BUILTIN32_DESCRIPTOR OLE32_Descriptor
;
82 extern const BUILTIN32_DESCRIPTOR OLEAUT32_Descriptor
;
83 extern const BUILTIN32_DESCRIPTOR OLECLI32_Descriptor
;
84 extern const BUILTIN32_DESCRIPTOR OLEDLG_Descriptor
;
85 extern const BUILTIN32_DESCRIPTOR OLESVR32_Descriptor
;
86 extern const BUILTIN32_DESCRIPTOR PSAPI_Descriptor
;
87 extern const BUILTIN32_DESCRIPTOR RASAPI32_Descriptor
;
88 extern const BUILTIN32_DESCRIPTOR SHELL32_Descriptor
;
89 extern const BUILTIN32_DESCRIPTOR SHLWAPI_Descriptor
;
90 extern const BUILTIN32_DESCRIPTOR TAPI32_Descriptor
;
91 extern const BUILTIN32_DESCRIPTOR USER32_Descriptor
;
92 extern const BUILTIN32_DESCRIPTOR VERSION_Descriptor
;
93 extern const BUILTIN32_DESCRIPTOR W32SKRNL_Descriptor
;
94 extern const BUILTIN32_DESCRIPTOR WINEOSS_Descriptor
;
95 extern const BUILTIN32_DESCRIPTOR WINMM_Descriptor
;
96 extern const BUILTIN32_DESCRIPTOR WINSPOOL_Descriptor
;
97 extern const BUILTIN32_DESCRIPTOR WNASPI32_Descriptor
;
98 extern const BUILTIN32_DESCRIPTOR WOW32_Descriptor
;
99 extern const BUILTIN32_DESCRIPTOR WSOCK32_Descriptor
;
101 extern const BUILTIN32_RESOURCE comctl32_ResourceDescriptor
;
102 extern const BUILTIN32_RESOURCE comdlg32_ResourceDescriptor
;
103 extern const BUILTIN32_RESOURCE shell32_ResourceDescriptor
;
104 extern const BUILTIN32_RESOURCE user32_ResourceDescriptor
;
105 extern const BUILTIN32_RESOURCE winmm_ResourceDescriptor
;
107 static BUILTIN32_DLL BuiltinDLLs
[] =
109 { &ADVAPI32_Descriptor
, 0, 0, NULL
},
110 { &AVIFIL32_Descriptor
, 0, 0, NULL
},
111 { &COMCTL32_Descriptor
, BI32_DANGER
, 0, &comctl32_ResourceDescriptor
},
112 { &COMDLG32_Descriptor
, BI32_DANGER
, 0, &comdlg32_ResourceDescriptor
},
113 { &CRTDLL_Descriptor
, BI32_DANGER
, 0, NULL
},
114 { &DCIMAN32_Descriptor
, 0, 0, NULL
},
115 { &DDRAW_Descriptor
, 0, 0, NULL
},
116 { &DINPUT_Descriptor
, 0, 0, NULL
},
117 { &DPLAY_Descriptor
, 0, 0, NULL
},
118 { &DPLAYX_Descriptor
, 0, 0, NULL
},
119 { &DSOUND_Descriptor
, 0, 0, NULL
},
120 { &GDI32_Descriptor
, 0, 0, NULL
},
121 { &ICMP_Descriptor
, 0, 0, NULL
},
122 { &IMAGEHLP_Descriptor
, BI32_DANGER
, 0, NULL
},
123 { &IMM32_Descriptor
, 0, 0, NULL
},
124 { &KERNEL32_Descriptor
, 0, 0, NULL
},
125 { &LZ32_Descriptor
, 0, 0, NULL
},
126 { &MCIANIM_Descriptor
, 0, 0, NULL
},
127 { &MCIAVI_Descriptor
, 0, 0, NULL
},
128 { &MCICDA_Descriptor
, 0, 0, NULL
},
129 { &MCISEQ_Descriptor
, 0, 0, NULL
},
130 { &MCIWAVE_Descriptor
, 0, 0, NULL
},
131 { &MIDIMAP_Descriptor
, 0, 0, NULL
},
132 { &MPR_Descriptor
, 0, 0, NULL
},
133 { &MSACM32_Descriptor
, BI32_DANGER
, 0, NULL
},
134 { &MSACMMAP_Descriptor
, 0, 0, NULL
},
135 { &MSNET32_Descriptor
, 0, 0, NULL
},
136 { &MSVFW32_Descriptor
, 0, 0, NULL
},
137 { &NTDLL_Descriptor
, 0, 0, NULL
},
138 { &ODBC32_Descriptor
, 0, 0, NULL
},
139 { &OLE32_Descriptor
, 0, 0, NULL
},
140 { &OLEAUT32_Descriptor
, 0, 0, NULL
},
141 { &OLECLI32_Descriptor
, 0, 0, NULL
},
142 { &OLEDLG_Descriptor
, 0, 0, NULL
},
143 { &OLESVR32_Descriptor
, 0, 0, NULL
},
144 { &PSAPI_Descriptor
, 0, 0, NULL
},
145 { &RASAPI32_Descriptor
, 0, 0, NULL
},
146 { &SHELL32_Descriptor
, BI32_DANGER
, 0, &shell32_ResourceDescriptor
},
147 { &SHLWAPI_Descriptor
, 0, 0, NULL
},
148 { &TAPI32_Descriptor
, 0, 0, NULL
},
149 { &USER32_Descriptor
, 0, 0, &user32_ResourceDescriptor
},
150 { &VERSION_Descriptor
, 0, 0, NULL
},
151 { &W32SKRNL_Descriptor
, 0, 0, NULL
},
152 { &WINMM_Descriptor
, 0, 0, &winmm_ResourceDescriptor
},
153 { &WINSPOOL_Descriptor
, 0, 0, NULL
},
154 { &WINEOSS_Descriptor
, 0, 0, NULL
},
155 { &WNASPI32_Descriptor
, 0, 0, NULL
},
156 { &WOW32_Descriptor
, 0, 0, NULL
},
157 { &WSOCK32_Descriptor
, 0, 0, NULL
},
162 extern void RELAY_CallFrom32();
163 extern void RELAY_CallFrom32Regs();
165 /***********************************************************************
166 * BUILTIN32_DoLoadImage
168 * Load a built-in Win32 module. Helper function for BUILTIN32_LoadImage.
170 static HMODULE
BUILTIN32_DoLoadImage( BUILTIN32_DLL
*dll
)
173 IMAGE_DATA_DIRECTORY
*dir
;
174 IMAGE_DOS_HEADER
*dos
;
175 IMAGE_NT_HEADERS
*nt
;
176 IMAGE_SECTION_HEADER
*sec
;
177 IMAGE_EXPORT_DIRECTORY
*exp
;
178 IMAGE_IMPORT_DESCRIPTOR
*imp
;
182 DEBUG_ENTRY_POINT
*debug
;
183 INT i
, size
, nb_sections
;
186 /* Allocate the module */
188 nb_sections
= 2; /* exports + code */
189 if (dll
->descr
->nb_imports
) nb_sections
++;
190 size
= (sizeof(IMAGE_DOS_HEADER
)
191 + sizeof(IMAGE_NT_HEADERS
)
192 + nb_sections
* sizeof(IMAGE_SECTION_HEADER
)
193 + (dll
->descr
->nb_imports
+1) * sizeof(IMAGE_IMPORT_DESCRIPTOR
)
194 + sizeof(IMAGE_EXPORT_DIRECTORY
)
195 + dll
->descr
->nb_funcs
* sizeof(LPVOID
)
196 + dll
->descr
->nb_names
* sizeof(LPSTR
)
197 + dll
->descr
->fwd_size
);
199 if (WARN_ON(relay
) || TRACE_ON(relay
))
200 size
+= dll
->descr
->nb_funcs
* sizeof(DEBUG_ENTRY_POINT
);
202 addr
= VirtualAlloc( NULL
, size
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
204 dos
= (IMAGE_DOS_HEADER
*)addr
;
205 nt
= (IMAGE_NT_HEADERS
*)(dos
+ 1);
206 sec
= (IMAGE_SECTION_HEADER
*)(nt
+ 1);
207 imp
= (IMAGE_IMPORT_DESCRIPTOR
*)(sec
+ nb_sections
);
208 exp
= (IMAGE_EXPORT_DIRECTORY
*)(imp
+ dll
->descr
->nb_imports
+ 1);
209 funcs
= (LPVOID
*)(exp
+ 1);
210 names
= (LPSTR
*)(funcs
+ dll
->descr
->nb_funcs
);
211 pfwd
= (LPSTR
)(names
+ dll
->descr
->nb_names
);
212 debug
= (DEBUG_ENTRY_POINT
*)(pfwd
+ dll
->descr
->fwd_size
);
214 /* Build the DOS and NT headers */
216 dos
->e_magic
= IMAGE_DOS_SIGNATURE
;
217 dos
->e_lfanew
= sizeof(*dos
);
219 nt
->Signature
= IMAGE_NT_SIGNATURE
;
220 nt
->FileHeader
.Machine
= IMAGE_FILE_MACHINE_I386
;
221 nt
->FileHeader
.NumberOfSections
= nb_sections
;
222 nt
->FileHeader
.SizeOfOptionalHeader
= sizeof(nt
->OptionalHeader
);
223 nt
->FileHeader
.Characteristics
= IMAGE_FILE_DLL
;
225 nt
->OptionalHeader
.Magic
= IMAGE_NT_OPTIONAL_HDR_MAGIC
;
226 nt
->OptionalHeader
.SizeOfCode
= 0x1000;
227 nt
->OptionalHeader
.SizeOfInitializedData
= 0;
228 nt
->OptionalHeader
.SizeOfUninitializedData
= 0;
229 nt
->OptionalHeader
.ImageBase
= (DWORD
)addr
;
230 nt
->OptionalHeader
.SectionAlignment
= 0x1000;
231 nt
->OptionalHeader
.FileAlignment
= 0x1000;
232 nt
->OptionalHeader
.MajorOperatingSystemVersion
= 1;
233 nt
->OptionalHeader
.MinorOperatingSystemVersion
= 0;
234 nt
->OptionalHeader
.MajorSubsystemVersion
= 4;
235 nt
->OptionalHeader
.MinorSubsystemVersion
= 0;
236 nt
->OptionalHeader
.SizeOfImage
= size
;
237 nt
->OptionalHeader
.SizeOfHeaders
= (BYTE
*)exp
- addr
;
238 nt
->OptionalHeader
.NumberOfRvaAndSizes
= IMAGE_NUMBEROF_DIRECTORY_ENTRIES
;
239 if (dll
->descr
->dllentrypoint
)
240 nt
->OptionalHeader
.AddressOfEntryPoint
= (DWORD
)dll
->descr
->dllentrypoint
- (DWORD
)addr
;
242 /* Build the code section */
244 strcpy( sec
->Name
, ".code" );
245 sec
->SizeOfRawData
= 0;
247 if (WARN_ON(relay
) || TRACE_ON(relay
))
248 sec
->SizeOfRawData
+= dll
->descr
->nb_funcs
* sizeof(DEBUG_ENTRY_POINT
);
250 sec
->Misc
.VirtualSize
= sec
->SizeOfRawData
;
251 sec
->VirtualAddress
= (BYTE
*)debug
- addr
;
252 sec
->PointerToRawData
= (BYTE
*)debug
- addr
;
253 sec
->Characteristics
= (IMAGE_SCN_CNT_INITIALIZED_DATA
|
254 IMAGE_SCN_MEM_EXECUTE
| IMAGE_SCN_MEM_READ
);
257 /* Build the import directory */
259 if (dll
->descr
->nb_imports
)
261 dir
= &nt
->OptionalHeader
.DataDirectory
[IMAGE_FILE_IMPORT_DIRECTORY
];
262 dir
->VirtualAddress
= (BYTE
*)imp
- addr
;
263 dir
->Size
= sizeof(*imp
) * (dll
->descr
->nb_imports
+ 1);
265 /* Build the imports section */
266 strcpy( sec
->Name
, ".idata" );
267 sec
->Misc
.VirtualSize
= dir
->Size
;
268 sec
->VirtualAddress
= (BYTE
*)imp
- addr
;
269 sec
->SizeOfRawData
= dir
->Size
;
270 sec
->PointerToRawData
= (BYTE
*)imp
- addr
;
271 sec
->Characteristics
= (IMAGE_SCN_CNT_INITIALIZED_DATA
|
272 IMAGE_SCN_MEM_EXECUTE
| IMAGE_SCN_MEM_READ
|
273 IMAGE_SCN_MEM_WRITE
);
276 /* Build the imports */
277 for (i
= 0; i
< dll
->descr
->nb_imports
; i
++)
279 imp
[i
].u
.Characteristics
= 0;
280 imp
[i
].ForwarderChain
= -1;
281 imp
[i
].Name
= (BYTE
*)dll
->descr
->imports
[i
] - addr
;
282 /* hack: make first thunk point to some zero value */
283 imp
[i
].FirstThunk
= (PIMAGE_THUNK_DATA
)((BYTE
*)&imp
[i
].u
.Characteristics
- addr
);
287 /* Build the export directory */
289 dir
= &nt
->OptionalHeader
.DataDirectory
[IMAGE_FILE_EXPORT_DIRECTORY
];
290 dir
->VirtualAddress
= (BYTE
*)exp
- addr
;
291 dir
->Size
= sizeof(*exp
)
292 + dll
->descr
->nb_funcs
* sizeof(LPVOID
)
293 + dll
->descr
->nb_names
* sizeof(LPSTR
)
294 + dll
->descr
->fwd_size
;
296 /* Build the exports section */
298 strcpy( sec
->Name
, ".edata" );
299 sec
->Misc
.VirtualSize
= dir
->Size
;
300 sec
->VirtualAddress
= (BYTE
*)exp
- addr
;
301 sec
->SizeOfRawData
= dir
->Size
;
302 sec
->PointerToRawData
= (BYTE
*)exp
- addr
;
303 sec
->Characteristics
= (IMAGE_SCN_CNT_INITIALIZED_DATA
|
304 IMAGE_SCN_MEM_EXECUTE
| IMAGE_SCN_MEM_READ
|
305 IMAGE_SCN_MEM_WRITE
);
308 /* Build the resource directory */
313 IMAGE_RESOURCE_DATA_ENTRY
*rdep
;
315 rtab
= HeapAlloc(GetProcessHeap(), 0, dll
->rsc
->restabsize
);
318 ERR_(module
)("Failed to get memory for resource directory\n");
319 VirtualFree(addr
, size
, MEM_RELEASE
);
324 * The resource directory has to be copied because it contains
325 * RVAs. These would be invalid if the dll is instantiated twice.
327 memcpy(rtab
, dll
->rsc
->restab
, dll
->rsc
->restabsize
);
329 dir
= &nt
->OptionalHeader
.DataDirectory
[IMAGE_FILE_RESOURCE_DIRECTORY
];
330 dir
->VirtualAddress
= (DWORD
)rtab
- (DWORD
)addr
;
331 dir
->Size
= dll
->rsc
->restabsize
;
332 rdep
= (IMAGE_RESOURCE_DATA_ENTRY
*)((DWORD
)rtab
+ (DWORD
)dll
->rsc
->entries
- (DWORD
)dll
->rsc
->restab
);
333 for(i
= 0; i
< dll
->rsc
->nresources
; i
++)
335 rdep
[i
].OffsetToData
+= (DWORD
)dll
->rsc
->restab
- (DWORD
)addr
;
339 /* Build the exports section data */
341 exp
->Name
= ((BYTE
*)dll
->descr
->name
) - addr
; /*??*/
342 exp
->Base
= dll
->descr
->base
;
343 exp
->NumberOfFunctions
= dll
->descr
->nb_funcs
;
344 exp
->NumberOfNames
= dll
->descr
->nb_names
;
345 exp
->AddressOfFunctions
= (LPDWORD
*)((BYTE
*)funcs
- addr
);
346 exp
->AddressOfNames
= (LPDWORD
*)((BYTE
*)names
- addr
);
347 exp
->AddressOfNameOrdinals
= (LPWORD
*)((BYTE
*)dll
->descr
->ordinals
- addr
);
349 /* Build the funcs table */
351 for (i
= 0; i
< dll
->descr
->nb_funcs
; i
++, funcs
++, debug
++)
353 BYTE args
= dll
->descr
->args
[i
];
356 if (!dll
->descr
->functions
[i
]) continue;
358 if (args
== 0xfd) /* forward func */
360 strcpy( pfwd
, (LPSTR
)dll
->descr
->functions
[i
] );
361 *funcs
= (LPVOID
)((BYTE
*)pfwd
- addr
);
362 pfwd
+= strlen(pfwd
) + 1;
364 else *funcs
= (LPVOID
)((BYTE
*)dll
->descr
->functions
[i
] - addr
);
367 if (!(WARN_ON(relay
) || TRACE_ON(relay
))) continue;
368 for (j
=0;j
<dll
->descr
->nb_names
;j
++)
369 if (dll
->descr
->ordinals
[j
] == i
)
371 if (j
<dll
->descr
->nb_names
) {
372 if (dll
->descr
->names
[j
]) {
374 sprintf(buffer
,"%s.%d: %s",dll
->descr
->name
,i
,dll
->descr
->names
[j
]);
375 if (!RELAY_ShowDebugmsgRelay(buffer
))
381 case 0xfd: /* forward */
382 case 0xff: /* stub or extern */
384 default: /* normal function (stdcall or cdecl or register) */
385 if (TRACE_ON(relay
)) {
386 debug
->call
= 0xe8; /* lcall relative */
387 if (args
& 0x40) /* register func */
388 debug
->callfrom32
= (DWORD
)RELAY_CallFrom32Regs
-
391 debug
->callfrom32
= (DWORD
)RELAY_CallFrom32
-
394 debug
->call
= 0xe9; /* ljmp relative */
395 debug
->callfrom32
= (DWORD
)dll
->descr
->functions
[i
] -
398 debug
->ret
= (args
& 0x80) ? 0xc3 : 0xc2; /*ret/ret $n*/
399 debug
->args
= (args
& 0x3f) * sizeof(int);
400 *funcs
= (LPVOID
)((BYTE
*)debug
- addr
);
403 #endif /* __i386__ */
406 /* Build the names table */
408 for (i
= 0; i
< exp
->NumberOfNames
; i
++, names
++)
409 if (dll
->descr
->names
[i
])
410 *names
= (LPSTR
)((BYTE
*)dll
->descr
->names
[i
] - addr
);
412 return (HMODULE
)addr
;
415 /***********************************************************************
416 * BUILTIN32_LoadLibraryExA
418 * Partly copied from the original PE_ version.
421 WINE_MODREF
*BUILTIN32_LoadLibraryExA(LPCSTR path
, DWORD flags
, DWORD
*err
)
423 BUILTIN32_DLL
*table
;
427 char dllname
[256], *p
;
429 /* Fix the name in case we have a full path and extension */
430 if ((p
= strrchr( path
, '\\' ))) path
= p
+ 1;
431 lstrcpynA( dllname
, path
, sizeof(dllname
) );
433 p
= strrchr( dllname
, '.' );
434 if (!p
) strcat( dllname
, ".dll" );
436 /* Search built-in descriptor */
437 for ( table
= BuiltinDLLs
; table
->descr
; table
++ )
438 if (!lstrcmpiA( table
->descr
->filename
, dllname
)) break;
442 *err
= ERROR_FILE_NOT_FOUND
;
446 /* Load built-in module */
447 if ( (table
->flags
& BI32_INSTANTIATED
) && (table
->flags
& BI32_DANGER
) )
448 ERR_(module
)( "Attempt to instantiate built-in dll '%s' twice "
449 "in the same address-space. Expect trouble!\n",
450 table
->descr
->name
);
452 if ( !table
->hModule
)
453 table
->hModule
= BUILTIN32_DoLoadImage( table
);
454 if ( table
->hModule
)
455 table
->flags
|= BI32_INSTANTIATED
;
458 *err
= ERROR_FILE_NOT_FOUND
;
462 /* Create 16-bit dummy module */
463 if ((hModule16
= MODULE_CreateDummyModule( dllname
, 0 )) < 32)
465 *err
= (DWORD
)hModule16
;
466 return NULL
; /* FIXME: Should unload the builtin module */
469 pModule
= (NE_MODULE
*)GlobalLock16( hModule16
);
470 pModule
->flags
= NE_FFLAGS_LIBMODULE
| NE_FFLAGS_SINGLEDATA
| NE_FFLAGS_WIN32
| NE_FFLAGS_BUILTIN
;
471 pModule
->module32
= table
->hModule
;
473 /* Create 32-bit MODREF */
474 if ( !(wm
= PE_CreateModule( table
->hModule
, dllname
, flags
, TRUE
)) )
476 ERR_(win32
)( "can't load %s\n", path
);
477 FreeLibrary16( hModule16
); /* FIXME: Should unload the builtin module */
478 *err
= ERROR_OUTOFMEMORY
;
482 if (wm
->binfmt
.pe
.pe_export
)
483 SNOOP_RegisterDLL(wm
->module
,wm
->modname
,wm
->binfmt
.pe
.pe_export
->NumberOfFunctions
);
490 /***********************************************************************
491 * BUILTIN32_UnloadLibrary
493 * Unload the built-in library and free the modref.
495 void BUILTIN32_UnloadLibrary(WINE_MODREF
*wm
)
497 /* FIXME: do something here */
501 /***********************************************************************
502 * BUILTIN32_GetEntryPoint
504 * Return the name of the DLL entry point corresponding
505 * to a relay entry point address. This is used only by relay debugging.
507 * This function _must_ return the real entry point to call
508 * after the debug info is printed.
510 ENTRYPOINT32
BUILTIN32_GetEntryPoint( char *buffer
, void *relay
,
511 unsigned int *typemask
)
516 /* First find the module */
518 for (dll
= BuiltinDLLs
; dll
->descr
; dll
++)
519 if ( dll
->flags
& BI32_INSTANTIATED
)
521 IMAGE_SECTION_HEADER
*sec
= PE_SECTIONS(dll
->hModule
);
522 DEBUG_ENTRY_POINT
*debug
=
523 (DEBUG_ENTRY_POINT
*)((DWORD
)dll
->hModule
+ sec
[0].VirtualAddress
);
524 DEBUG_ENTRY_POINT
*func
= (DEBUG_ENTRY_POINT
*)relay
;
526 if (debug
<= func
&& func
< debug
+ dll
->descr
->nb_funcs
)
528 ordinal
= func
- debug
;
534 return (ENTRYPOINT32
)NULL
;
536 /* Now find the function */
538 for (i
= 0; i
< dll
->descr
->nb_names
; i
++)
539 if (dll
->descr
->ordinals
[i
] == ordinal
) break;
541 sprintf( buffer
, "%s.%d: %s", dll
->descr
->name
, ordinal
+ dll
->descr
->base
,
542 (i
< dll
->descr
->nb_names
) ? dll
->descr
->names
[i
] : "@" );
543 *typemask
= dll
->descr
->argtypes
[ordinal
];
544 return dll
->descr
->functions
[ordinal
];
547 /***********************************************************************
548 * BUILTIN32_SwitchRelayDebug
550 * FIXME: enhance to do it module relative.
552 void BUILTIN32_SwitchRelayDebug(BOOL onoff
) {
557 if (!(TRACE_ON(relay
) || WARN_ON(relay
)))
559 for (dll
= BuiltinDLLs
; dll
->descr
; dll
++) {
560 IMAGE_SECTION_HEADER
*sec
;
561 DEBUG_ENTRY_POINT
*debug
;
562 if (!(dll
->flags
& BI32_INSTANTIATED
))
565 sec
= PE_SECTIONS(dll
->hModule
);
566 debug
= (DEBUG_ENTRY_POINT
*)((DWORD
)dll
->hModule
+ sec
[1].VirtualAddress
);
567 for (i
= 0; i
< dll
->descr
->nb_funcs
; i
++,debug
++) {
568 if (!dll
->descr
->functions
[i
]) continue;
569 if ((dll
->descr
->args
[i
]==0xff) || (dll
->descr
->args
[i
]==0xfe))
572 debug
->call
= 0xe8; /* lcall relative */
573 debug
->callfrom32
= (DWORD
)RELAY_CallFrom32
-
576 debug
->call
= 0xe9; /* ljmp relative */
577 debug
->callfrom32
= (DWORD
)dll
->descr
->functions
[i
] -
582 #endif /* __i386__ */
586 /***********************************************************************
587 * BUILTIN32_Unimplemented
589 * This function is called for unimplemented 32-bit entry points (declared
590 * as 'stub' in the spec file).
592 void BUILTIN32_Unimplemented( const BUILTIN32_DESCRIPTOR
*descr
, int ordinal
)
594 const char *func_name
= "???";
597 __RESTORE_ES
; /* Just in case */
599 for (i
= 0; i
< descr
->nb_names
; i
++)
600 if (descr
->ordinals
[i
] + descr
->base
== ordinal
) break;
601 if (i
< descr
->nb_names
) func_name
= descr
->names
[i
];
603 MESSAGE( "No handler for Win32 routine %s.%d: %s",
604 descr
->name
, ordinal
, func_name
);
606 MESSAGE( " (called from %p)", __builtin_return_address(1) );