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 IMAGEHLP_Descriptor
;
64 extern const BUILTIN32_DESCRIPTOR IMM32_Descriptor
;
65 extern const BUILTIN32_DESCRIPTOR KERNEL32_Descriptor
;
66 extern const BUILTIN32_DESCRIPTOR LZ32_Descriptor
;
67 extern const BUILTIN32_DESCRIPTOR MPR_Descriptor
;
68 extern const BUILTIN32_DESCRIPTOR MCIAVI_Descriptor
;
69 extern const BUILTIN32_DESCRIPTOR MCIANIM_Descriptor
;
70 extern const BUILTIN32_DESCRIPTOR MCICDA_Descriptor
;
71 extern const BUILTIN32_DESCRIPTOR MCISEQ_Descriptor
;
72 extern const BUILTIN32_DESCRIPTOR MCIWAVE_Descriptor
;
73 extern const BUILTIN32_DESCRIPTOR MSACM32_Descriptor
;
74 extern const BUILTIN32_DESCRIPTOR MSNET32_Descriptor
;
75 extern const BUILTIN32_DESCRIPTOR MSVFW32_Descriptor
;
76 extern const BUILTIN32_DESCRIPTOR NTDLL_Descriptor
;
77 extern const BUILTIN32_DESCRIPTOR OLE32_Descriptor
;
78 extern const BUILTIN32_DESCRIPTOR OLEAUT32_Descriptor
;
79 extern const BUILTIN32_DESCRIPTOR OLECLI32_Descriptor
;
80 extern const BUILTIN32_DESCRIPTOR OLEDLG_Descriptor
;
81 extern const BUILTIN32_DESCRIPTOR OLESVR32_Descriptor
;
82 extern const BUILTIN32_DESCRIPTOR PSAPI_Descriptor
;
83 extern const BUILTIN32_DESCRIPTOR RASAPI32_Descriptor
;
84 extern const BUILTIN32_DESCRIPTOR SHELL32_Descriptor
;
85 extern const BUILTIN32_DESCRIPTOR TAPI32_Descriptor
;
86 extern const BUILTIN32_DESCRIPTOR USER32_Descriptor
;
87 extern const BUILTIN32_DESCRIPTOR VERSION_Descriptor
;
88 extern const BUILTIN32_DESCRIPTOR W32SKRNL_Descriptor
;
89 extern const BUILTIN32_DESCRIPTOR WINMM_Descriptor
;
90 extern const BUILTIN32_DESCRIPTOR WINSPOOL_Descriptor
;
91 extern const BUILTIN32_DESCRIPTOR WNASPI32_Descriptor
;
92 extern const BUILTIN32_DESCRIPTOR WOW32_Descriptor
;
93 extern const BUILTIN32_DESCRIPTOR WSOCK32_Descriptor
;
95 extern const BUILTIN32_RESOURCE comctl32_ResourceDescriptor
;
96 extern const BUILTIN32_RESOURCE comdlg32_ResourceDescriptor
;
97 extern const BUILTIN32_RESOURCE shell32_ResourceDescriptor
;
98 extern const BUILTIN32_RESOURCE user32_ResourceDescriptor
;
100 static BUILTIN32_DLL BuiltinDLLs
[] =
102 { &ADVAPI32_Descriptor
, 0, 0, NULL
},
103 { &AVIFIL32_Descriptor
, 0, 0, NULL
},
104 { &COMCTL32_Descriptor
, BI32_DANGER
, 0, &comctl32_ResourceDescriptor
},
105 { &COMDLG32_Descriptor
, BI32_DANGER
, 0, &comdlg32_ResourceDescriptor
},
106 { &CRTDLL_Descriptor
, BI32_DANGER
, 0, NULL
},
107 { &DCIMAN32_Descriptor
, 0, 0, NULL
},
108 { &DDRAW_Descriptor
, 0, 0, NULL
},
109 { &DINPUT_Descriptor
, 0, 0, NULL
},
110 { &DPLAY_Descriptor
, 0, 0, NULL
},
111 { &DPLAYX_Descriptor
, 0, 0, NULL
},
112 { &DSOUND_Descriptor
, 0, 0, NULL
},
113 { &GDI32_Descriptor
, 0, 0, NULL
},
114 { &IMAGEHLP_Descriptor
, BI32_DANGER
, 0, NULL
},
115 { &IMM32_Descriptor
, 0, 0, NULL
},
116 { &KERNEL32_Descriptor
, 0, 0, NULL
},
117 { &LZ32_Descriptor
, 0, 0, NULL
},
118 { &MCIANIM_Descriptor
, 0, 0, NULL
},
119 { &MCIAVI_Descriptor
, 0, 0, NULL
},
120 { &MCICDA_Descriptor
, 0, 0, NULL
},
121 { &MCISEQ_Descriptor
, 0, 0, NULL
},
122 { &MCIWAVE_Descriptor
, 0, 0, NULL
},
123 { &MPR_Descriptor
, 0, 0, NULL
},
124 { &MSACM32_Descriptor
, BI32_DANGER
, 0, NULL
},
125 { &MSNET32_Descriptor
, 0, 0, NULL
},
126 { &MSVFW32_Descriptor
, 0, 0, NULL
},
127 { &NTDLL_Descriptor
, 0, 0, NULL
},
128 { &OLE32_Descriptor
, 0, 0, NULL
},
129 { &OLEAUT32_Descriptor
, 0, 0, NULL
},
130 { &OLECLI32_Descriptor
, 0, 0, NULL
},
131 { &OLEDLG_Descriptor
, 0, 0, NULL
},
132 { &OLESVR32_Descriptor
, 0, 0, NULL
},
133 { &PSAPI_Descriptor
, 0, 0, NULL
},
134 { &RASAPI32_Descriptor
, 0, 0, NULL
},
135 { &SHELL32_Descriptor
, BI32_DANGER
, 0, &shell32_ResourceDescriptor
},
136 { &TAPI32_Descriptor
, 0, 0, NULL
},
137 { &USER32_Descriptor
, 0, 0, &user32_ResourceDescriptor
},
138 { &VERSION_Descriptor
, 0, 0, NULL
},
139 { &W32SKRNL_Descriptor
, 0, 0, NULL
},
140 { &WINMM_Descriptor
, BI32_DANGER
, 0, NULL
},
141 { &WINSPOOL_Descriptor
, 0, 0, NULL
},
142 { &WNASPI32_Descriptor
, 0, 0, NULL
},
143 { &WOW32_Descriptor
, 0, 0, NULL
},
144 { &WSOCK32_Descriptor
, 0, 0, NULL
},
149 extern void RELAY_CallFrom32();
150 extern void RELAY_CallFrom32Regs();
152 /***********************************************************************
153 * BUILTIN32_DoLoadImage
155 * Load a built-in Win32 module. Helper function for BUILTIN32_LoadImage.
157 static HMODULE
BUILTIN32_DoLoadImage( BUILTIN32_DLL
*dll
)
160 IMAGE_DATA_DIRECTORY
*dir
;
161 IMAGE_DOS_HEADER
*dos
;
162 IMAGE_NT_HEADERS
*nt
;
163 IMAGE_SECTION_HEADER
*sec
;
164 IMAGE_EXPORT_DIRECTORY
*exp
;
165 IMAGE_IMPORT_DESCRIPTOR
*imp
;
169 DEBUG_ENTRY_POINT
*debug
;
170 INT i
, size
, nb_sections
;
173 /* Allocate the module */
175 nb_sections
= 2; /* exports + code */
176 if (dll
->descr
->nb_imports
) nb_sections
++;
177 size
= (sizeof(IMAGE_DOS_HEADER
)
178 + sizeof(IMAGE_NT_HEADERS
)
179 + nb_sections
* sizeof(IMAGE_SECTION_HEADER
)
180 + (dll
->descr
->nb_imports
+1) * sizeof(IMAGE_IMPORT_DESCRIPTOR
)
181 + sizeof(IMAGE_EXPORT_DIRECTORY
)
182 + dll
->descr
->nb_funcs
* sizeof(LPVOID
)
183 + dll
->descr
->nb_names
* sizeof(LPSTR
)
184 + dll
->descr
->fwd_size
);
186 if (WARN_ON(relay
) || TRACE_ON(relay
))
187 size
+= dll
->descr
->nb_funcs
* sizeof(DEBUG_ENTRY_POINT
);
189 addr
= VirtualAlloc( NULL
, size
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
191 dos
= (IMAGE_DOS_HEADER
*)addr
;
192 nt
= (IMAGE_NT_HEADERS
*)(dos
+ 1);
193 sec
= (IMAGE_SECTION_HEADER
*)(nt
+ 1);
194 imp
= (IMAGE_IMPORT_DESCRIPTOR
*)(sec
+ nb_sections
);
195 exp
= (IMAGE_EXPORT_DIRECTORY
*)(imp
+ dll
->descr
->nb_imports
+ 1);
196 funcs
= (LPVOID
*)(exp
+ 1);
197 names
= (LPSTR
*)(funcs
+ dll
->descr
->nb_funcs
);
198 pfwd
= (LPSTR
)(names
+ dll
->descr
->nb_names
);
199 debug
= (DEBUG_ENTRY_POINT
*)(pfwd
+ dll
->descr
->fwd_size
);
201 /* Build the DOS and NT headers */
203 dos
->e_magic
= IMAGE_DOS_SIGNATURE
;
204 dos
->e_lfanew
= sizeof(*dos
);
206 nt
->Signature
= IMAGE_NT_SIGNATURE
;
207 nt
->FileHeader
.Machine
= IMAGE_FILE_MACHINE_I386
;
208 nt
->FileHeader
.NumberOfSections
= nb_sections
;
209 nt
->FileHeader
.SizeOfOptionalHeader
= sizeof(nt
->OptionalHeader
);
210 nt
->FileHeader
.Characteristics
= IMAGE_FILE_DLL
;
212 nt
->OptionalHeader
.Magic
= IMAGE_NT_OPTIONAL_HDR_MAGIC
;
213 nt
->OptionalHeader
.SizeOfCode
= 0x1000;
214 nt
->OptionalHeader
.SizeOfInitializedData
= 0;
215 nt
->OptionalHeader
.SizeOfUninitializedData
= 0;
216 nt
->OptionalHeader
.ImageBase
= (DWORD
)addr
;
217 nt
->OptionalHeader
.SectionAlignment
= 0x1000;
218 nt
->OptionalHeader
.FileAlignment
= 0x1000;
219 nt
->OptionalHeader
.MajorOperatingSystemVersion
= 1;
220 nt
->OptionalHeader
.MinorOperatingSystemVersion
= 0;
221 nt
->OptionalHeader
.MajorSubsystemVersion
= 4;
222 nt
->OptionalHeader
.MinorSubsystemVersion
= 0;
223 nt
->OptionalHeader
.SizeOfImage
= size
;
224 nt
->OptionalHeader
.SizeOfHeaders
= (BYTE
*)exp
- addr
;
225 nt
->OptionalHeader
.NumberOfRvaAndSizes
= IMAGE_NUMBEROF_DIRECTORY_ENTRIES
;
226 if (dll
->descr
->dllentrypoint
)
227 nt
->OptionalHeader
.AddressOfEntryPoint
= (DWORD
)dll
->descr
->dllentrypoint
- (DWORD
)addr
;
229 /* Build the code section */
231 strcpy( sec
->Name
, ".code" );
232 sec
->SizeOfRawData
= 0;
234 if (WARN_ON(relay
) || TRACE_ON(relay
))
235 sec
->SizeOfRawData
+= dll
->descr
->nb_funcs
* sizeof(DEBUG_ENTRY_POINT
);
237 sec
->Misc
.VirtualSize
= sec
->SizeOfRawData
;
238 sec
->VirtualAddress
= (BYTE
*)debug
- addr
;
239 sec
->PointerToRawData
= (BYTE
*)debug
- addr
;
240 sec
->Characteristics
= (IMAGE_SCN_CNT_INITIALIZED_DATA
|
241 IMAGE_SCN_MEM_EXECUTE
| IMAGE_SCN_MEM_READ
);
244 /* Build the import directory */
246 if (dll
->descr
->nb_imports
)
248 dir
= &nt
->OptionalHeader
.DataDirectory
[IMAGE_FILE_IMPORT_DIRECTORY
];
249 dir
->VirtualAddress
= (BYTE
*)imp
- addr
;
250 dir
->Size
= sizeof(*imp
) * (dll
->descr
->nb_imports
+ 1);
252 /* Build the imports section */
253 strcpy( sec
->Name
, ".idata" );
254 sec
->Misc
.VirtualSize
= dir
->Size
;
255 sec
->VirtualAddress
= (BYTE
*)imp
- addr
;
256 sec
->SizeOfRawData
= dir
->Size
;
257 sec
->PointerToRawData
= (BYTE
*)imp
- addr
;
258 sec
->Characteristics
= (IMAGE_SCN_CNT_INITIALIZED_DATA
|
259 IMAGE_SCN_MEM_EXECUTE
| IMAGE_SCN_MEM_READ
|
260 IMAGE_SCN_MEM_WRITE
);
263 /* Build the imports */
264 for (i
= 0; i
< dll
->descr
->nb_imports
; i
++)
266 imp
[i
].u
.Characteristics
= 0;
267 imp
[i
].ForwarderChain
= -1;
268 imp
[i
].Name
= (BYTE
*)dll
->descr
->imports
[i
] - addr
;
269 /* hack: make first thunk point to some zero value */
270 imp
[i
].FirstThunk
= (PIMAGE_THUNK_DATA
)((BYTE
*)&imp
[i
].u
.Characteristics
- addr
);
274 /* Build the export directory */
276 dir
= &nt
->OptionalHeader
.DataDirectory
[IMAGE_FILE_EXPORT_DIRECTORY
];
277 dir
->VirtualAddress
= (BYTE
*)exp
- addr
;
278 dir
->Size
= sizeof(*exp
)
279 + dll
->descr
->nb_funcs
* sizeof(LPVOID
)
280 + dll
->descr
->nb_names
* sizeof(LPSTR
)
281 + dll
->descr
->fwd_size
;
283 /* Build the exports section */
285 strcpy( sec
->Name
, ".edata" );
286 sec
->Misc
.VirtualSize
= dir
->Size
;
287 sec
->VirtualAddress
= (BYTE
*)exp
- addr
;
288 sec
->SizeOfRawData
= dir
->Size
;
289 sec
->PointerToRawData
= (BYTE
*)exp
- addr
;
290 sec
->Characteristics
= (IMAGE_SCN_CNT_INITIALIZED_DATA
|
291 IMAGE_SCN_MEM_EXECUTE
| IMAGE_SCN_MEM_READ
|
292 IMAGE_SCN_MEM_WRITE
);
295 /* Build the resource directory */
300 IMAGE_RESOURCE_DATA_ENTRY
*rdep
;
302 rtab
= HeapAlloc(GetProcessHeap(), 0, dll
->rsc
->restabsize
);
305 ERR_(module
)("Failed to get memory for resource directory\n");
306 VirtualFree(addr
, size
, MEM_RELEASE
);
311 * The resource directory has to be copied because it contains
312 * RVAs. These would be invalid if the dll is instantiated twice.
314 memcpy(rtab
, dll
->rsc
->restab
, dll
->rsc
->restabsize
);
316 dir
= &nt
->OptionalHeader
.DataDirectory
[IMAGE_FILE_RESOURCE_DIRECTORY
];
317 dir
->VirtualAddress
= (DWORD
)rtab
- (DWORD
)addr
;
318 dir
->Size
= dll
->rsc
->restabsize
;
319 rdep
= (IMAGE_RESOURCE_DATA_ENTRY
*)((DWORD
)rtab
+ (DWORD
)dll
->rsc
->entries
- (DWORD
)dll
->rsc
->restab
);
320 for(i
= 0; i
< dll
->rsc
->nresources
; i
++)
322 rdep
[i
].OffsetToData
+= (DWORD
)dll
->rsc
->restab
- (DWORD
)addr
;
326 /* Build the exports section data */
328 exp
->Name
= ((BYTE
*)dll
->descr
->name
) - addr
; /*??*/
329 exp
->Base
= dll
->descr
->base
;
330 exp
->NumberOfFunctions
= dll
->descr
->nb_funcs
;
331 exp
->NumberOfNames
= dll
->descr
->nb_names
;
332 exp
->AddressOfFunctions
= (LPDWORD
*)((BYTE
*)funcs
- addr
);
333 exp
->AddressOfNames
= (LPDWORD
*)((BYTE
*)names
- addr
);
334 exp
->AddressOfNameOrdinals
= (LPWORD
*)((BYTE
*)dll
->descr
->ordinals
- addr
);
336 /* Build the funcs table */
338 for (i
= 0; i
< dll
->descr
->nb_funcs
; i
++, funcs
++, debug
++)
340 BYTE args
= dll
->descr
->args
[i
];
343 if (!dll
->descr
->functions
[i
]) continue;
345 if (args
== 0xfd) /* forward func */
347 strcpy( pfwd
, (LPSTR
)dll
->descr
->functions
[i
] );
348 *funcs
= (LPVOID
)((BYTE
*)pfwd
- addr
);
349 pfwd
+= strlen(pfwd
) + 1;
351 else *funcs
= (LPVOID
)((BYTE
*)dll
->descr
->functions
[i
] - addr
);
354 if (!(WARN_ON(relay
) || TRACE_ON(relay
))) continue;
355 for (j
=0;j
<dll
->descr
->nb_names
;j
++)
356 if (dll
->descr
->ordinals
[j
] == i
)
358 if (j
<dll
->descr
->nb_names
) {
359 if (dll
->descr
->names
[j
]) {
361 sprintf(buffer
,"%s.%d: %s",dll
->descr
->name
,i
,dll
->descr
->names
[j
]);
362 if (!RELAY_ShowDebugmsgRelay(buffer
))
368 case 0xfd: /* forward */
369 case 0xff: /* stub or extern */
371 default: /* normal function (stdcall or cdecl or register) */
372 if (TRACE_ON(relay
)) {
373 debug
->call
= 0xe8; /* lcall relative */
374 if (args
& 0x40) /* register func */
375 debug
->callfrom32
= (DWORD
)RELAY_CallFrom32Regs
-
378 debug
->callfrom32
= (DWORD
)RELAY_CallFrom32
-
381 debug
->call
= 0xe9; /* ljmp relative */
382 debug
->callfrom32
= (DWORD
)dll
->descr
->functions
[i
] -
385 debug
->ret
= (args
& 0x80) ? 0xc3 : 0xc2; /*ret/ret $n*/
386 debug
->args
= (args
& 0x3f) * sizeof(int);
387 *funcs
= (LPVOID
)((BYTE
*)debug
- addr
);
390 #endif /* __i386__ */
393 /* Build the names table */
395 for (i
= 0; i
< exp
->NumberOfNames
; i
++, names
++)
396 if (dll
->descr
->names
[i
])
397 *names
= (LPSTR
)((BYTE
*)dll
->descr
->names
[i
] - addr
);
399 return (HMODULE
)addr
;
402 /***********************************************************************
403 * BUILTIN32_LoadImage
405 * Load a built-in module.
407 HMODULE
BUILTIN32_LoadImage( LPCSTR name
, OFSTRUCT
*ofs
)
409 BUILTIN32_DLL
*table
;
410 char dllname
[16], *p
;
412 /* Fix the name in case we have a full path and extension */
414 if ((p
= strrchr( name
, '\\' ))) name
= p
+ 1;
415 lstrcpynA( dllname
, name
, sizeof(dllname
) );
416 if ((p
= strrchr( dllname
, '.' ))) *p
= '\0';
418 for (table
= BuiltinDLLs
; table
->descr
; table
++)
419 if (!lstrcmpiA( table
->descr
->name
, dllname
)) break;
420 if (!table
->descr
) return 0;
422 if ( (table
->flags
& BI32_INSTANTIATED
) && (table
->flags
& BI32_DANGER
) )
424 ERR_(module
)("Attemp to instantiate built-in dll '%s' twice in the same address-space. Expect trouble!\n",
428 sprintf( ofs
->szPathName
, "%s.DLL", table
->descr
->name
);
430 if ( !table
->hModule
)
431 table
->hModule
= BUILTIN32_DoLoadImage( table
);
433 if ( table
->hModule
)
434 table
->flags
|= BI32_INSTANTIATED
;
436 return table
->hModule
;
440 /***********************************************************************
441 * BUILTIN32_LoadLibraryExA
443 * Partly copied from the original PE_ version.
445 * Note: This implementation is not very nice and should be one with
446 * the BUILTIN32_LoadImage function. But, we don't care too much
447 * because this code will obsolete itself shortly when we get the
448 * modularization of wine implemented (BS 05-Mar-1999).
450 WINE_MODREF
*BUILTIN32_LoadLibraryExA(LPCSTR path
, DWORD flags
, DWORD
*err
)
452 LPCSTR modName
= NULL
;
458 char dllname
[256], *p
;
460 /* Append .DLL to name if no extension present */
461 strcpy( dllname
, path
);
462 if (!(p
= strrchr( dllname
, '.')) || strchr( p
, '/' ) || strchr( p
, '\\'))
463 strcat( dllname
, ".DLL" );
465 hModule32
= BUILTIN32_LoadImage(path
, &ofs
);
468 *err
= ERROR_FILE_NOT_FOUND
;
472 /* Create 16-bit dummy module */
473 if ((hModule16
= MODULE_CreateDummyModule( &ofs
, modName
)) < 32)
475 *err
= (DWORD
)hModule16
;
476 return NULL
; /* FIXME: Should unload the builtin module */
479 pModule
= (NE_MODULE
*)GlobalLock16( hModule16
);
480 pModule
->flags
= NE_FFLAGS_LIBMODULE
| NE_FFLAGS_SINGLEDATA
| NE_FFLAGS_WIN32
| NE_FFLAGS_BUILTIN
;
481 pModule
->module32
= hModule32
;
483 /* Create 32-bit MODREF */
484 if ( !(wm
= PE_CreateModule( hModule32
, &ofs
, flags
, TRUE
)) )
486 ERR_(win32
)("can't load %s\n",ofs
.szPathName
);
487 FreeLibrary16( hModule16
); /* FIXME: Should unload the builtin module */
488 *err
= ERROR_OUTOFMEMORY
;
492 if (wm
->binfmt
.pe
.pe_export
)
493 SNOOP_RegisterDLL(wm
->module
,wm
->modname
,wm
->binfmt
.pe
.pe_export
->NumberOfFunctions
);
500 /***********************************************************************
501 * BUILTIN32_UnloadLibrary
503 * Unload the built-in library and free the modref.
505 void BUILTIN32_UnloadLibrary(WINE_MODREF
*wm
)
507 /* FIXME: do something here */
511 /***********************************************************************
512 * BUILTIN32_GetEntryPoint
514 * Return the name of the DLL entry point corresponding
515 * to a relay entry point address. This is used only by relay debugging.
517 * This function _must_ return the real entry point to call
518 * after the debug info is printed.
520 ENTRYPOINT32
BUILTIN32_GetEntryPoint( char *buffer
, void *relay
,
521 unsigned int *typemask
)
526 /* First find the module */
528 for (dll
= BuiltinDLLs
; dll
->descr
; dll
++)
529 if ( dll
->flags
& BI32_INSTANTIATED
)
531 IMAGE_SECTION_HEADER
*sec
= PE_SECTIONS(dll
->hModule
);
532 DEBUG_ENTRY_POINT
*debug
=
533 (DEBUG_ENTRY_POINT
*)((DWORD
)dll
->hModule
+ sec
[0].VirtualAddress
);
534 DEBUG_ENTRY_POINT
*func
= (DEBUG_ENTRY_POINT
*)relay
;
536 if (debug
<= func
&& func
< debug
+ dll
->descr
->nb_funcs
)
538 ordinal
= func
- debug
;
544 return (ENTRYPOINT32
)NULL
;
546 /* Now find the function */
548 for (i
= 0; i
< dll
->descr
->nb_names
; i
++)
549 if (dll
->descr
->ordinals
[i
] == ordinal
) break;
550 assert( i
< dll
->descr
->nb_names
);
552 sprintf( buffer
, "%s.%d: %s", dll
->descr
->name
, ordinal
+ dll
->descr
->base
,
553 dll
->descr
->names
[i
] );
554 *typemask
= dll
->descr
->argtypes
[ordinal
];
555 return dll
->descr
->functions
[ordinal
];
558 /***********************************************************************
559 * BUILTIN32_SwitchRelayDebug
561 * FIXME: enhance to do it module relative.
563 void BUILTIN32_SwitchRelayDebug(BOOL onoff
) {
568 if (!(TRACE_ON(relay
) || WARN_ON(relay
)))
570 for (dll
= BuiltinDLLs
; dll
->descr
; dll
++) {
571 IMAGE_SECTION_HEADER
*sec
;
572 DEBUG_ENTRY_POINT
*debug
;
573 if (!(dll
->flags
& BI32_INSTANTIATED
))
576 sec
= PE_SECTIONS(dll
->hModule
);
577 debug
= (DEBUG_ENTRY_POINT
*)((DWORD
)dll
->hModule
+ sec
[1].VirtualAddress
);
578 for (i
= 0; i
< dll
->descr
->nb_funcs
; i
++,debug
++) {
579 if (!dll
->descr
->functions
[i
]) continue;
580 if ((dll
->descr
->args
[i
]==0xff) || (dll
->descr
->args
[i
]==0xfe))
583 debug
->call
= 0xe8; /* lcall relative */
584 debug
->callfrom32
= (DWORD
)RELAY_CallFrom32
-
587 debug
->call
= 0xe9; /* ljmp relative */
588 debug
->callfrom32
= (DWORD
)dll
->descr
->functions
[i
] -
593 #endif /* __i386__ */
597 /***********************************************************************
598 * BUILTIN32_Unimplemented
600 * This function is called for unimplemented 32-bit entry points (declared
601 * as 'stub' in the spec file).
603 void BUILTIN32_Unimplemented( const BUILTIN32_DESCRIPTOR
*descr
, int ordinal
)
605 const char *func_name
= "???";
608 __RESTORE_ES
; /* Just in case */
610 for (i
= 0; i
< descr
->nb_names
; i
++)
611 if (descr
->ordinals
[i
] + descr
->base
== ordinal
) break;
612 if (i
< descr
->nb_names
) func_name
= descr
->names
[i
];
614 MESSAGE( "No handler for Win32 routine %s.%d: %s",
615 descr
->name
, ordinal
, func_name
);
617 MESSAGE( " (called from %p)", __builtin_return_address(1) );