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 OLE32_Descriptor
;
81 extern const BUILTIN32_DESCRIPTOR OLEAUT32_Descriptor
;
82 extern const BUILTIN32_DESCRIPTOR OLECLI32_Descriptor
;
83 extern const BUILTIN32_DESCRIPTOR OLEDLG_Descriptor
;
84 extern const BUILTIN32_DESCRIPTOR OLESVR32_Descriptor
;
85 extern const BUILTIN32_DESCRIPTOR PSAPI_Descriptor
;
86 extern const BUILTIN32_DESCRIPTOR RASAPI32_Descriptor
;
87 extern const BUILTIN32_DESCRIPTOR SHELL32_Descriptor
;
88 extern const BUILTIN32_DESCRIPTOR SHLWAPI_Descriptor
;
89 extern const BUILTIN32_DESCRIPTOR TAPI32_Descriptor
;
90 extern const BUILTIN32_DESCRIPTOR USER32_Descriptor
;
91 extern const BUILTIN32_DESCRIPTOR VERSION_Descriptor
;
92 extern const BUILTIN32_DESCRIPTOR W32SKRNL_Descriptor
;
93 extern const BUILTIN32_DESCRIPTOR WINEOSS_Descriptor
;
94 extern const BUILTIN32_DESCRIPTOR WINMM_Descriptor
;
95 extern const BUILTIN32_DESCRIPTOR WINSPOOL_Descriptor
;
96 extern const BUILTIN32_DESCRIPTOR WNASPI32_Descriptor
;
97 extern const BUILTIN32_DESCRIPTOR WOW32_Descriptor
;
98 extern const BUILTIN32_DESCRIPTOR WSOCK32_Descriptor
;
100 extern const BUILTIN32_RESOURCE comctl32_ResourceDescriptor
;
101 extern const BUILTIN32_RESOURCE comdlg32_ResourceDescriptor
;
102 extern const BUILTIN32_RESOURCE shell32_ResourceDescriptor
;
103 extern const BUILTIN32_RESOURCE user32_ResourceDescriptor
;
104 extern const BUILTIN32_RESOURCE winmm_ResourceDescriptor
;
106 static BUILTIN32_DLL BuiltinDLLs
[] =
108 { &ADVAPI32_Descriptor
, 0, 0, NULL
},
109 { &AVIFIL32_Descriptor
, 0, 0, NULL
},
110 { &COMCTL32_Descriptor
, BI32_DANGER
, 0, &comctl32_ResourceDescriptor
},
111 { &COMDLG32_Descriptor
, BI32_DANGER
, 0, &comdlg32_ResourceDescriptor
},
112 { &CRTDLL_Descriptor
, BI32_DANGER
, 0, NULL
},
113 { &DCIMAN32_Descriptor
, 0, 0, NULL
},
114 { &DDRAW_Descriptor
, 0, 0, NULL
},
115 { &DINPUT_Descriptor
, 0, 0, NULL
},
116 { &DPLAY_Descriptor
, 0, 0, NULL
},
117 { &DPLAYX_Descriptor
, 0, 0, NULL
},
118 { &DSOUND_Descriptor
, 0, 0, NULL
},
119 { &GDI32_Descriptor
, 0, 0, NULL
},
120 { &ICMP_Descriptor
, 0, 0, NULL
},
121 { &IMAGEHLP_Descriptor
, BI32_DANGER
, 0, NULL
},
122 { &IMM32_Descriptor
, 0, 0, NULL
},
123 { &KERNEL32_Descriptor
, 0, 0, NULL
},
124 { &LZ32_Descriptor
, 0, 0, NULL
},
125 { &MCIANIM_Descriptor
, 0, 0, NULL
},
126 { &MCIAVI_Descriptor
, 0, 0, NULL
},
127 { &MCICDA_Descriptor
, 0, 0, NULL
},
128 { &MCISEQ_Descriptor
, 0, 0, NULL
},
129 { &MCIWAVE_Descriptor
, 0, 0, NULL
},
130 { &MIDIMAP_Descriptor
, 0, 0, NULL
},
131 { &MPR_Descriptor
, 0, 0, NULL
},
132 { &MSACM32_Descriptor
, BI32_DANGER
, 0, NULL
},
133 { &MSACMMAP_Descriptor
, 0, 0, NULL
},
134 { &MSNET32_Descriptor
, 0, 0, NULL
},
135 { &MSVFW32_Descriptor
, 0, 0, NULL
},
136 { &NTDLL_Descriptor
, 0, 0, NULL
},
137 { &OLE32_Descriptor
, 0, 0, NULL
},
138 { &OLEAUT32_Descriptor
, 0, 0, NULL
},
139 { &OLECLI32_Descriptor
, 0, 0, NULL
},
140 { &OLEDLG_Descriptor
, 0, 0, NULL
},
141 { &OLESVR32_Descriptor
, 0, 0, NULL
},
142 { &PSAPI_Descriptor
, 0, 0, NULL
},
143 { &RASAPI32_Descriptor
, 0, 0, NULL
},
144 { &SHELL32_Descriptor
, BI32_DANGER
, 0, &shell32_ResourceDescriptor
},
145 { &SHLWAPI_Descriptor
, 0, 0, NULL
},
146 { &TAPI32_Descriptor
, 0, 0, NULL
},
147 { &USER32_Descriptor
, 0, 0, &user32_ResourceDescriptor
},
148 { &VERSION_Descriptor
, 0, 0, NULL
},
149 { &W32SKRNL_Descriptor
, 0, 0, NULL
},
150 { &WINMM_Descriptor
, 0, 0, &winmm_ResourceDescriptor
},
151 { &WINSPOOL_Descriptor
, 0, 0, NULL
},
152 { &WINEOSS_Descriptor
, 0, 0, NULL
},
153 { &WNASPI32_Descriptor
, 0, 0, NULL
},
154 { &WOW32_Descriptor
, 0, 0, NULL
},
155 { &WSOCK32_Descriptor
, 0, 0, NULL
},
160 extern void RELAY_CallFrom32();
161 extern void RELAY_CallFrom32Regs();
163 /***********************************************************************
164 * BUILTIN32_DoLoadImage
166 * Load a built-in Win32 module. Helper function for BUILTIN32_LoadImage.
168 static HMODULE
BUILTIN32_DoLoadImage( BUILTIN32_DLL
*dll
)
171 IMAGE_DATA_DIRECTORY
*dir
;
172 IMAGE_DOS_HEADER
*dos
;
173 IMAGE_NT_HEADERS
*nt
;
174 IMAGE_SECTION_HEADER
*sec
;
175 IMAGE_EXPORT_DIRECTORY
*exp
;
176 IMAGE_IMPORT_DESCRIPTOR
*imp
;
180 DEBUG_ENTRY_POINT
*debug
;
181 INT i
, size
, nb_sections
;
184 /* Allocate the module */
186 nb_sections
= 2; /* exports + code */
187 if (dll
->descr
->nb_imports
) nb_sections
++;
188 size
= (sizeof(IMAGE_DOS_HEADER
)
189 + sizeof(IMAGE_NT_HEADERS
)
190 + nb_sections
* sizeof(IMAGE_SECTION_HEADER
)
191 + (dll
->descr
->nb_imports
+1) * sizeof(IMAGE_IMPORT_DESCRIPTOR
)
192 + sizeof(IMAGE_EXPORT_DIRECTORY
)
193 + dll
->descr
->nb_funcs
* sizeof(LPVOID
)
194 + dll
->descr
->nb_names
* sizeof(LPSTR
)
195 + dll
->descr
->fwd_size
);
197 if (WARN_ON(relay
) || TRACE_ON(relay
))
198 size
+= dll
->descr
->nb_funcs
* sizeof(DEBUG_ENTRY_POINT
);
200 addr
= VirtualAlloc( NULL
, size
, MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
202 dos
= (IMAGE_DOS_HEADER
*)addr
;
203 nt
= (IMAGE_NT_HEADERS
*)(dos
+ 1);
204 sec
= (IMAGE_SECTION_HEADER
*)(nt
+ 1);
205 imp
= (IMAGE_IMPORT_DESCRIPTOR
*)(sec
+ nb_sections
);
206 exp
= (IMAGE_EXPORT_DIRECTORY
*)(imp
+ dll
->descr
->nb_imports
+ 1);
207 funcs
= (LPVOID
*)(exp
+ 1);
208 names
= (LPSTR
*)(funcs
+ dll
->descr
->nb_funcs
);
209 pfwd
= (LPSTR
)(names
+ dll
->descr
->nb_names
);
210 debug
= (DEBUG_ENTRY_POINT
*)(pfwd
+ dll
->descr
->fwd_size
);
212 /* Build the DOS and NT headers */
214 dos
->e_magic
= IMAGE_DOS_SIGNATURE
;
215 dos
->e_lfanew
= sizeof(*dos
);
217 nt
->Signature
= IMAGE_NT_SIGNATURE
;
218 nt
->FileHeader
.Machine
= IMAGE_FILE_MACHINE_I386
;
219 nt
->FileHeader
.NumberOfSections
= nb_sections
;
220 nt
->FileHeader
.SizeOfOptionalHeader
= sizeof(nt
->OptionalHeader
);
221 nt
->FileHeader
.Characteristics
= IMAGE_FILE_DLL
;
223 nt
->OptionalHeader
.Magic
= IMAGE_NT_OPTIONAL_HDR_MAGIC
;
224 nt
->OptionalHeader
.SizeOfCode
= 0x1000;
225 nt
->OptionalHeader
.SizeOfInitializedData
= 0;
226 nt
->OptionalHeader
.SizeOfUninitializedData
= 0;
227 nt
->OptionalHeader
.ImageBase
= (DWORD
)addr
;
228 nt
->OptionalHeader
.SectionAlignment
= 0x1000;
229 nt
->OptionalHeader
.FileAlignment
= 0x1000;
230 nt
->OptionalHeader
.MajorOperatingSystemVersion
= 1;
231 nt
->OptionalHeader
.MinorOperatingSystemVersion
= 0;
232 nt
->OptionalHeader
.MajorSubsystemVersion
= 4;
233 nt
->OptionalHeader
.MinorSubsystemVersion
= 0;
234 nt
->OptionalHeader
.SizeOfImage
= size
;
235 nt
->OptionalHeader
.SizeOfHeaders
= (BYTE
*)exp
- addr
;
236 nt
->OptionalHeader
.NumberOfRvaAndSizes
= IMAGE_NUMBEROF_DIRECTORY_ENTRIES
;
237 if (dll
->descr
->dllentrypoint
)
238 nt
->OptionalHeader
.AddressOfEntryPoint
= (DWORD
)dll
->descr
->dllentrypoint
- (DWORD
)addr
;
240 /* Build the code section */
242 strcpy( sec
->Name
, ".code" );
243 sec
->SizeOfRawData
= 0;
245 if (WARN_ON(relay
) || TRACE_ON(relay
))
246 sec
->SizeOfRawData
+= dll
->descr
->nb_funcs
* sizeof(DEBUG_ENTRY_POINT
);
248 sec
->Misc
.VirtualSize
= sec
->SizeOfRawData
;
249 sec
->VirtualAddress
= (BYTE
*)debug
- addr
;
250 sec
->PointerToRawData
= (BYTE
*)debug
- addr
;
251 sec
->Characteristics
= (IMAGE_SCN_CNT_INITIALIZED_DATA
|
252 IMAGE_SCN_MEM_EXECUTE
| IMAGE_SCN_MEM_READ
);
255 /* Build the import directory */
257 if (dll
->descr
->nb_imports
)
259 dir
= &nt
->OptionalHeader
.DataDirectory
[IMAGE_FILE_IMPORT_DIRECTORY
];
260 dir
->VirtualAddress
= (BYTE
*)imp
- addr
;
261 dir
->Size
= sizeof(*imp
) * (dll
->descr
->nb_imports
+ 1);
263 /* Build the imports section */
264 strcpy( sec
->Name
, ".idata" );
265 sec
->Misc
.VirtualSize
= dir
->Size
;
266 sec
->VirtualAddress
= (BYTE
*)imp
- addr
;
267 sec
->SizeOfRawData
= dir
->Size
;
268 sec
->PointerToRawData
= (BYTE
*)imp
- addr
;
269 sec
->Characteristics
= (IMAGE_SCN_CNT_INITIALIZED_DATA
|
270 IMAGE_SCN_MEM_EXECUTE
| IMAGE_SCN_MEM_READ
|
271 IMAGE_SCN_MEM_WRITE
);
274 /* Build the imports */
275 for (i
= 0; i
< dll
->descr
->nb_imports
; i
++)
277 imp
[i
].u
.Characteristics
= 0;
278 imp
[i
].ForwarderChain
= -1;
279 imp
[i
].Name
= (BYTE
*)dll
->descr
->imports
[i
] - addr
;
280 /* hack: make first thunk point to some zero value */
281 imp
[i
].FirstThunk
= (PIMAGE_THUNK_DATA
)((BYTE
*)&imp
[i
].u
.Characteristics
- addr
);
285 /* Build the export directory */
287 dir
= &nt
->OptionalHeader
.DataDirectory
[IMAGE_FILE_EXPORT_DIRECTORY
];
288 dir
->VirtualAddress
= (BYTE
*)exp
- addr
;
289 dir
->Size
= sizeof(*exp
)
290 + dll
->descr
->nb_funcs
* sizeof(LPVOID
)
291 + dll
->descr
->nb_names
* sizeof(LPSTR
)
292 + dll
->descr
->fwd_size
;
294 /* Build the exports section */
296 strcpy( sec
->Name
, ".edata" );
297 sec
->Misc
.VirtualSize
= dir
->Size
;
298 sec
->VirtualAddress
= (BYTE
*)exp
- addr
;
299 sec
->SizeOfRawData
= dir
->Size
;
300 sec
->PointerToRawData
= (BYTE
*)exp
- addr
;
301 sec
->Characteristics
= (IMAGE_SCN_CNT_INITIALIZED_DATA
|
302 IMAGE_SCN_MEM_EXECUTE
| IMAGE_SCN_MEM_READ
|
303 IMAGE_SCN_MEM_WRITE
);
306 /* Build the resource directory */
311 IMAGE_RESOURCE_DATA_ENTRY
*rdep
;
313 rtab
= HeapAlloc(GetProcessHeap(), 0, dll
->rsc
->restabsize
);
316 ERR_(module
)("Failed to get memory for resource directory\n");
317 VirtualFree(addr
, size
, MEM_RELEASE
);
322 * The resource directory has to be copied because it contains
323 * RVAs. These would be invalid if the dll is instantiated twice.
325 memcpy(rtab
, dll
->rsc
->restab
, dll
->rsc
->restabsize
);
327 dir
= &nt
->OptionalHeader
.DataDirectory
[IMAGE_FILE_RESOURCE_DIRECTORY
];
328 dir
->VirtualAddress
= (DWORD
)rtab
- (DWORD
)addr
;
329 dir
->Size
= dll
->rsc
->restabsize
;
330 rdep
= (IMAGE_RESOURCE_DATA_ENTRY
*)((DWORD
)rtab
+ (DWORD
)dll
->rsc
->entries
- (DWORD
)dll
->rsc
->restab
);
331 for(i
= 0; i
< dll
->rsc
->nresources
; i
++)
333 rdep
[i
].OffsetToData
+= (DWORD
)dll
->rsc
->restab
- (DWORD
)addr
;
337 /* Build the exports section data */
339 exp
->Name
= ((BYTE
*)dll
->descr
->name
) - addr
; /*??*/
340 exp
->Base
= dll
->descr
->base
;
341 exp
->NumberOfFunctions
= dll
->descr
->nb_funcs
;
342 exp
->NumberOfNames
= dll
->descr
->nb_names
;
343 exp
->AddressOfFunctions
= (LPDWORD
*)((BYTE
*)funcs
- addr
);
344 exp
->AddressOfNames
= (LPDWORD
*)((BYTE
*)names
- addr
);
345 exp
->AddressOfNameOrdinals
= (LPWORD
*)((BYTE
*)dll
->descr
->ordinals
- addr
);
347 /* Build the funcs table */
349 for (i
= 0; i
< dll
->descr
->nb_funcs
; i
++, funcs
++, debug
++)
351 BYTE args
= dll
->descr
->args
[i
];
354 if (!dll
->descr
->functions
[i
]) continue;
356 if (args
== 0xfd) /* forward func */
358 strcpy( pfwd
, (LPSTR
)dll
->descr
->functions
[i
] );
359 *funcs
= (LPVOID
)((BYTE
*)pfwd
- addr
);
360 pfwd
+= strlen(pfwd
) + 1;
362 else *funcs
= (LPVOID
)((BYTE
*)dll
->descr
->functions
[i
] - addr
);
365 if (!(WARN_ON(relay
) || TRACE_ON(relay
))) continue;
366 for (j
=0;j
<dll
->descr
->nb_names
;j
++)
367 if (dll
->descr
->ordinals
[j
] == i
)
369 if (j
<dll
->descr
->nb_names
) {
370 if (dll
->descr
->names
[j
]) {
372 sprintf(buffer
,"%s.%d: %s",dll
->descr
->name
,i
,dll
->descr
->names
[j
]);
373 if (!RELAY_ShowDebugmsgRelay(buffer
))
379 case 0xfd: /* forward */
380 case 0xff: /* stub or extern */
382 default: /* normal function (stdcall or cdecl or register) */
383 if (TRACE_ON(relay
)) {
384 debug
->call
= 0xe8; /* lcall relative */
385 if (args
& 0x40) /* register func */
386 debug
->callfrom32
= (DWORD
)RELAY_CallFrom32Regs
-
389 debug
->callfrom32
= (DWORD
)RELAY_CallFrom32
-
392 debug
->call
= 0xe9; /* ljmp relative */
393 debug
->callfrom32
= (DWORD
)dll
->descr
->functions
[i
] -
396 debug
->ret
= (args
& 0x80) ? 0xc3 : 0xc2; /*ret/ret $n*/
397 debug
->args
= (args
& 0x3f) * sizeof(int);
398 *funcs
= (LPVOID
)((BYTE
*)debug
- addr
);
401 #endif /* __i386__ */
404 /* Build the names table */
406 for (i
= 0; i
< exp
->NumberOfNames
; i
++, names
++)
407 if (dll
->descr
->names
[i
])
408 *names
= (LPSTR
)((BYTE
*)dll
->descr
->names
[i
] - addr
);
410 return (HMODULE
)addr
;
413 /***********************************************************************
414 * BUILTIN32_LoadLibraryExA
416 * Partly copied from the original PE_ version.
419 WINE_MODREF
*BUILTIN32_LoadLibraryExA(LPCSTR path
, DWORD flags
, DWORD
*err
)
421 BUILTIN32_DLL
*table
;
425 char dllname
[256], *p
;
427 /* Fix the name in case we have a full path and extension */
428 if ((p
= strrchr( path
, '\\' ))) path
= p
+ 1;
429 lstrcpynA( dllname
, path
, sizeof(dllname
) );
431 p
= strrchr( dllname
, '.' );
432 if (!p
) strcat( dllname
, ".dll" );
434 /* Search built-in descriptor */
435 for ( table
= BuiltinDLLs
; table
->descr
; table
++ )
436 if (!lstrcmpiA( table
->descr
->filename
, dllname
)) break;
440 *err
= ERROR_FILE_NOT_FOUND
;
444 /* Load built-in module */
445 if ( (table
->flags
& BI32_INSTANTIATED
) && (table
->flags
& BI32_DANGER
) )
446 ERR_(module
)( "Attempt to instantiate built-in dll '%s' twice "
447 "in the same address-space. Expect trouble!\n",
448 table
->descr
->name
);
450 if ( !table
->hModule
)
451 table
->hModule
= BUILTIN32_DoLoadImage( table
);
452 if ( table
->hModule
)
453 table
->flags
|= BI32_INSTANTIATED
;
456 *err
= ERROR_FILE_NOT_FOUND
;
460 /* Create 16-bit dummy module */
461 if ((hModule16
= MODULE_CreateDummyModule( dllname
, 0 )) < 32)
463 *err
= (DWORD
)hModule16
;
464 return NULL
; /* FIXME: Should unload the builtin module */
467 pModule
= (NE_MODULE
*)GlobalLock16( hModule16
);
468 pModule
->flags
= NE_FFLAGS_LIBMODULE
| NE_FFLAGS_SINGLEDATA
| NE_FFLAGS_WIN32
| NE_FFLAGS_BUILTIN
;
469 pModule
->module32
= table
->hModule
;
471 /* Create 32-bit MODREF */
472 if ( !(wm
= PE_CreateModule( table
->hModule
, dllname
, flags
, TRUE
)) )
474 ERR_(win32
)( "can't load %s\n", path
);
475 FreeLibrary16( hModule16
); /* FIXME: Should unload the builtin module */
476 *err
= ERROR_OUTOFMEMORY
;
480 if (wm
->binfmt
.pe
.pe_export
)
481 SNOOP_RegisterDLL(wm
->module
,wm
->modname
,wm
->binfmt
.pe
.pe_export
->NumberOfFunctions
);
488 /***********************************************************************
489 * BUILTIN32_UnloadLibrary
491 * Unload the built-in library and free the modref.
493 void BUILTIN32_UnloadLibrary(WINE_MODREF
*wm
)
495 /* FIXME: do something here */
499 /***********************************************************************
500 * BUILTIN32_GetEntryPoint
502 * Return the name of the DLL entry point corresponding
503 * to a relay entry point address. This is used only by relay debugging.
505 * This function _must_ return the real entry point to call
506 * after the debug info is printed.
508 ENTRYPOINT32
BUILTIN32_GetEntryPoint( char *buffer
, void *relay
,
509 unsigned int *typemask
)
514 /* First find the module */
516 for (dll
= BuiltinDLLs
; dll
->descr
; dll
++)
517 if ( dll
->flags
& BI32_INSTANTIATED
)
519 IMAGE_SECTION_HEADER
*sec
= PE_SECTIONS(dll
->hModule
);
520 DEBUG_ENTRY_POINT
*debug
=
521 (DEBUG_ENTRY_POINT
*)((DWORD
)dll
->hModule
+ sec
[0].VirtualAddress
);
522 DEBUG_ENTRY_POINT
*func
= (DEBUG_ENTRY_POINT
*)relay
;
524 if (debug
<= func
&& func
< debug
+ dll
->descr
->nb_funcs
)
526 ordinal
= func
- debug
;
532 return (ENTRYPOINT32
)NULL
;
534 /* Now find the function */
536 for (i
= 0; i
< dll
->descr
->nb_names
; i
++)
537 if (dll
->descr
->ordinals
[i
] == ordinal
) break;
538 assert( i
< dll
->descr
->nb_names
);
540 sprintf( buffer
, "%s.%d: %s", dll
->descr
->name
, ordinal
+ dll
->descr
->base
,
541 dll
->descr
->names
[i
] );
542 *typemask
= dll
->descr
->argtypes
[ordinal
];
543 return dll
->descr
->functions
[ordinal
];
546 /***********************************************************************
547 * BUILTIN32_SwitchRelayDebug
549 * FIXME: enhance to do it module relative.
551 void BUILTIN32_SwitchRelayDebug(BOOL onoff
) {
556 if (!(TRACE_ON(relay
) || WARN_ON(relay
)))
558 for (dll
= BuiltinDLLs
; dll
->descr
; dll
++) {
559 IMAGE_SECTION_HEADER
*sec
;
560 DEBUG_ENTRY_POINT
*debug
;
561 if (!(dll
->flags
& BI32_INSTANTIATED
))
564 sec
= PE_SECTIONS(dll
->hModule
);
565 debug
= (DEBUG_ENTRY_POINT
*)((DWORD
)dll
->hModule
+ sec
[1].VirtualAddress
);
566 for (i
= 0; i
< dll
->descr
->nb_funcs
; i
++,debug
++) {
567 if (!dll
->descr
->functions
[i
]) continue;
568 if ((dll
->descr
->args
[i
]==0xff) || (dll
->descr
->args
[i
]==0xfe))
571 debug
->call
= 0xe8; /* lcall relative */
572 debug
->callfrom32
= (DWORD
)RELAY_CallFrom32
-
575 debug
->call
= 0xe9; /* ljmp relative */
576 debug
->callfrom32
= (DWORD
)dll
->descr
->functions
[i
] -
581 #endif /* __i386__ */
585 /***********************************************************************
586 * BUILTIN32_Unimplemented
588 * This function is called for unimplemented 32-bit entry points (declared
589 * as 'stub' in the spec file).
591 void BUILTIN32_Unimplemented( const BUILTIN32_DESCRIPTOR
*descr
, int ordinal
)
593 const char *func_name
= "???";
596 __RESTORE_ES
; /* Just in case */
598 for (i
= 0; i
< descr
->nb_names
; i
++)
599 if (descr
->ordinals
[i
] + descr
->base
== ordinal
) break;
600 if (i
< descr
->nb_names
) func_name
= descr
->names
[i
];
602 MESSAGE( "No handler for Win32 routine %s.%d: %s",
603 descr
->name
, ordinal
, func_name
);
605 MESSAGE( " (called from %p)", __builtin_return_address(1) );