blob: ff89daa7f53a4d9efbd20b3a92fc06c595849b33 [file] [log] [blame]
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001/*
2 * 386-specific Win32 relay functions
3 *
4 * Copyright 1997 Alexandre Julliard
5 */
6
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00007
8#include <assert.h>
Alexandre Julliardf90efa91998-06-14 15:24:15 +00009#include <string.h>
Alexandre Julliard246c3602000-05-10 03:48:00 +000010#include <stdio.h>
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000011#include "winnt.h"
Alexandre Julliard02e90081998-01-04 17:49:09 +000012#include "selectors.h"
Alexandre Julliard06b97891999-05-13 16:13:17 +000013#include "stackframe.h"
Ulrich Weigand6cd829b1999-05-22 16:29:39 +000014#include "syslevel.h"
Alexandre Julliard638f1691999-01-17 16:32:32 +000015#include "main.h"
Alexandre Julliard246c3602000-05-10 03:48:00 +000016#include "module.h"
17#include "process.h"
Alexandre Julliard06b97891999-05-13 16:13:17 +000018#include "debugtools.h"
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000019
Alexandre Julliard0dd36552000-01-29 19:49:58 +000020DEFAULT_DEBUG_CHANNEL(relay);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000021
Alexandre Julliardf90efa91998-06-14 15:24:15 +000022char **debug_relay_excludelist = NULL, **debug_relay_includelist = NULL;
23
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000024/***********************************************************************
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +000025 * RELAY_ShowDebugmsgRelay
26 *
27 * Simple function to decide if a particular debugging message is
28 * wanted. Called from RELAY_CallFrom32 and from in if1632/relay.c
29 */
30int RELAY_ShowDebugmsgRelay(const char *func) {
31
32 if(debug_relay_excludelist || debug_relay_includelist) {
33 const char *term = strchr(func, ':');
34 char **listitem;
35 int len, len2, itemlen, show;
36
37 if(debug_relay_excludelist) {
38 show = 1;
39 listitem = debug_relay_excludelist;
40 } else {
41 show = 0;
42 listitem = debug_relay_includelist;
43 }
44 assert(term);
45 assert(strlen(term) > 2);
46 len = term - func;
47 len2 = strchr(func, '.') - func;
48 assert(len2 && len2 > 0 && len2 < 64);
49 term += 2;
50 for(; *listitem; listitem++) {
51 itemlen = strlen(*listitem);
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +000052 if((itemlen == len && !strncasecmp(*listitem, func, len)) ||
53 (itemlen == len2 && !strncasecmp(*listitem, func, len2)) ||
Alexandre Julliardcb10fda2000-08-06 02:41:16 +000054 !strcasecmp(*listitem, term)) {
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +000055 show = !show;
56 break;
57 }
58 }
59 return show;
60 }
61 return 1;
62}
63
Alexandre Julliard06b97891999-05-13 16:13:17 +000064
Ulrich Weigand6ca85a51999-11-14 21:28:57 +000065#ifdef __i386__
66
Alexandre Julliard246c3602000-05-10 03:48:00 +000067typedef struct
68{
69 BYTE call; /* 0xe8 call callfrom32 (relative) */
70 DWORD callfrom32 WINE_PACKED; /* RELAY_CallFrom32 relative addr */
71 BYTE ret; /* 0xc2 ret $n or 0xc3 ret */
72 WORD args; /* nb of args to remove from the stack */
Alexandre Julliarda8378492000-10-01 01:33:50 +000073 void *orig; /* original entry point */
Alexandre Julliard246c3602000-05-10 03:48:00 +000074 DWORD argtypes; /* argument types */
75} DEBUG_ENTRY_POINT;
76
77
78/***********************************************************************
79 * find_exported_name
80 *
81 * Find the name of an exported function.
82 */
83static const char *find_exported_name( const char *module,
84 IMAGE_EXPORT_DIRECTORY *exp, int ordinal )
85{
86 int i;
87 const char *ret = NULL;
88
89 WORD *ordptr = (WORD *)(module + exp->AddressOfNameOrdinals);
90 for (i = 0; i < exp->NumberOfNames; i++, ordptr++)
91 if (*ordptr + exp->Base == ordinal) break;
92 if (i < exp->NumberOfNames)
93 ret = module + ((DWORD*)(module + exp->AddressOfNames))[i];
94 return ret;
95}
96
97
98/***********************************************************************
99 * get_entry_point
100 *
101 * Get the name of the DLL entry point corresponding to a relay address.
102 */
103static void get_entry_point( char *buffer, DEBUG_ENTRY_POINT *relay )
104{
105 IMAGE_DATA_DIRECTORY *dir;
106 IMAGE_EXPORT_DIRECTORY *exp = NULL;
107 DEBUG_ENTRY_POINT *debug;
108 char *base = NULL;
109 const char *name;
110 int ordinal = 0;
111 WINE_MODREF *wm;
112
113 /* First find the module */
114
115 for (wm = PROCESS_Current()->modref_list; wm; wm = wm->next)
116 {
Alexandre Julliard246c3602000-05-10 03:48:00 +0000117 if (!(wm->flags & WINE_MODREF_INTERNAL)) continue;
118 base = (char *)wm->module;
119 dir = &PE_HEADER(base)->OptionalHeader.DataDirectory[IMAGE_FILE_EXPORT_DIRECTORY];
120 if (!dir->Size) continue;
121 exp = (IMAGE_EXPORT_DIRECTORY *)(base + dir->VirtualAddress);
122 debug = (DEBUG_ENTRY_POINT *)((char *)exp + dir->Size);
123 if (debug <= relay && relay < debug + exp->NumberOfFunctions)
124 {
125 ordinal = relay - debug;
126 break;
127 }
128 }
129
130 /* Now find the function */
131
132 name = find_exported_name( base, exp, ordinal + exp->Base );
133 sprintf( buffer, "%s.%ld: %s", base + exp->Name, ordinal + exp->Base, name ? name : "@" );
134}
135
136
Alexandre Julliard06b97891999-05-13 16:13:17 +0000137/***********************************************************************
138 * RELAY_PrintArgs
139 */
140static inline void RELAY_PrintArgs( int *args, int nb_args, unsigned int typemask )
141{
142 while (nb_args--)
143 {
144 if ((typemask & 3) && HIWORD(*args))
145 {
146 if (typemask & 2)
Francois Gougete73b8b81999-12-26 00:40:37 +0000147 DPRINTF( "%08x %s", *args, debugstr_w((LPWSTR)*args) );
Alexandre Julliard06b97891999-05-13 16:13:17 +0000148 else
149 DPRINTF( "%08x %s", *args, debugstr_a((LPCSTR)*args) );
150 }
151 else DPRINTF( "%08x", *args );
152 if (nb_args) DPRINTF( "," );
153 args++;
154 typemask >>= 2;
155 }
156}
157
158
Alexandre Julliard3f2b2d52000-10-12 20:55:26 +0000159typedef LONGLONG WINAPI (*LONGLONG_FARPROC)();
160
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000161/***********************************************************************
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000162 * RELAY_CallFrom32
163 *
164 * Stack layout on entry to this function:
165 * ... ...
166 * (esp+12) arg2
167 * (esp+8) arg1
168 * (esp+4) ret_addr
169 * (esp) return addr to relay code
170 */
Alexandre Julliarda8378492000-10-01 01:33:50 +0000171static LONGLONG RELAY_CallFrom32( int ret_addr, ... )
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000172{
Alexandre Julliarda8378492000-10-01 01:33:50 +0000173 LONGLONG ret;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000174 char buffer[80];
Alexandre Julliarda8378492000-10-01 01:33:50 +0000175 BOOL ret64;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000176
Alexandre Julliard06b97891999-05-13 16:13:17 +0000177 int *args = &ret_addr + 1;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000178 /* Relay addr is the return address for this function */
Alexandre Julliard06b97891999-05-13 16:13:17 +0000179 BYTE *relay_addr = (BYTE *)__builtin_return_address(0);
Alexandre Julliard246c3602000-05-10 03:48:00 +0000180 DEBUG_ENTRY_POINT *relay = (DEBUG_ENTRY_POINT *)(relay_addr - 5);
181 WORD nb_args = relay->args / sizeof(int);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000182
Alexandre Julliard246c3602000-05-10 03:48:00 +0000183 get_entry_point( buffer, relay );
184
Alexandre Julliard06b97891999-05-13 16:13:17 +0000185 DPRINTF( "Call %s(", buffer );
Alexandre Julliard246c3602000-05-10 03:48:00 +0000186 RELAY_PrintArgs( args, nb_args, relay->argtypes );
Alexandre Julliard916f9752000-02-26 16:51:13 +0000187 DPRINTF( ") ret=%08x fs=%04x\n", ret_addr, __get_fs() );
Alexandre Julliarda8378492000-10-01 01:33:50 +0000188 ret64 = (relay->argtypes & 0x80000000) && (nb_args < 16);
Marcus Meissner38980e41998-11-22 14:12:36 +0000189
Peter Ganten331f80e2000-08-11 12:52:56 +0000190 /* the user driver functions may be called with the window lock held */
191 if (memcmp( buffer, "x11drv.", 7 ) && memcmp( buffer, "ttydrv.", 7 ))
192 SYSLEVEL_CheckNotLevel( 2 );
Ulrich Weigand6cd829b1999-05-22 16:29:39 +0000193
Alexandre Julliard246c3602000-05-10 03:48:00 +0000194 if (relay->ret == 0xc3) /* cdecl */
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000195 {
Alexandre Julliarda8378492000-10-01 01:33:50 +0000196 LONGLONG (*cfunc)() = relay->orig;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000197 switch(nb_args)
198 {
199 case 0: ret = cfunc(); break;
200 case 1: ret = cfunc(args[0]); break;
201 case 2: ret = cfunc(args[0],args[1]); break;
202 case 3: ret = cfunc(args[0],args[1],args[2]); break;
203 case 4: ret = cfunc(args[0],args[1],args[2],args[3]); break;
204 case 5: ret = cfunc(args[0],args[1],args[2],args[3],args[4]); break;
205 case 6: ret = cfunc(args[0],args[1],args[2],args[3],args[4],
206 args[5]); break;
207 case 7: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
208 args[6]); break;
209 case 8: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
210 args[6],args[7]); break;
211 case 9: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
212 args[6],args[7],args[8]); break;
213 case 10: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
214 args[6],args[7],args[8],args[9]); break;
215 case 11: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
216 args[6],args[7],args[8],args[9],args[10]); break;
217 case 12: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
218 args[6],args[7],args[8],args[9],args[10],
219 args[11]); break;
220 case 13: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
221 args[6],args[7],args[8],args[9],args[10],args[11],
222 args[12]); break;
223 case 14: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
224 args[6],args[7],args[8],args[9],args[10],args[11],
225 args[12],args[13]); break;
226 case 15: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
227 args[6],args[7],args[8],args[9],args[10],args[11],
228 args[12],args[13],args[14]); break;
Marcus Meissner219cfd81999-02-24 13:05:13 +0000229 case 16: ret = cfunc(args[0],args[1],args[2],args[3],args[4],args[5],
230 args[6],args[7],args[8],args[9],args[10],args[11],
231 args[12],args[13],args[14],args[15]); break;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000232 default:
Alexandre Julliard06b97891999-05-13 16:13:17 +0000233 ERR( "Unsupported nb of args %d\n", nb_args );
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000234 assert(FALSE);
235 }
236 }
237 else /* stdcall */
238 {
Alexandre Julliard3f2b2d52000-10-12 20:55:26 +0000239 LONGLONG_FARPROC func = relay->orig;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000240 switch(nb_args)
241 {
242 case 0: ret = func(); break;
243 case 1: ret = func(args[0]); break;
244 case 2: ret = func(args[0],args[1]); break;
245 case 3: ret = func(args[0],args[1],args[2]); break;
246 case 4: ret = func(args[0],args[1],args[2],args[3]); break;
247 case 5: ret = func(args[0],args[1],args[2],args[3],args[4]); break;
248 case 6: ret = func(args[0],args[1],args[2],args[3],args[4],
249 args[5]); break;
250 case 7: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
251 args[6]); break;
252 case 8: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
253 args[6],args[7]); break;
254 case 9: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
255 args[6],args[7],args[8]); break;
256 case 10: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
257 args[6],args[7],args[8],args[9]); break;
258 case 11: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
259 args[6],args[7],args[8],args[9],args[10]); break;
260 case 12: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
261 args[6],args[7],args[8],args[9],args[10],
262 args[11]); break;
263 case 13: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
264 args[6],args[7],args[8],args[9],args[10],args[11],
265 args[12]); break;
266 case 14: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
267 args[6],args[7],args[8],args[9],args[10],args[11],
268 args[12],args[13]); break;
269 case 15: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
270 args[6],args[7],args[8],args[9],args[10],args[11],
271 args[12],args[13],args[14]); break;
Marcus Meissner219cfd81999-02-24 13:05:13 +0000272 case 16: ret = func(args[0],args[1],args[2],args[3],args[4],args[5],
273 args[6],args[7],args[8],args[9],args[10],args[11],
274 args[12],args[13],args[14],args[15]); break;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000275 default:
Alexandre Julliard06b97891999-05-13 16:13:17 +0000276 ERR( "Unsupported nb of args %d\n", nb_args );
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000277 assert(FALSE);
278 }
279 }
Alexandre Julliarda8378492000-10-01 01:33:50 +0000280 if (ret64)
281 DPRINTF( "Ret %s() retval=%08x%08x ret=%08x fs=%04x\n",
282 buffer, (UINT)(ret >> 32), (UINT)ret, ret_addr, __get_fs() );
283 else
284 DPRINTF( "Ret %s() retval=%08x ret=%08x fs=%04x\n",
285 buffer, (UINT)ret, ret_addr, __get_fs() );
Ulrich Weigand6cd829b1999-05-22 16:29:39 +0000286
Peter Ganten331f80e2000-08-11 12:52:56 +0000287 if (memcmp( buffer, "x11drv.", 7 ) && memcmp( buffer, "ttydrv.", 7 ))
288 SYSLEVEL_CheckNotLevel( 2 );
Ulrich Weigand6cd829b1999-05-22 16:29:39 +0000289
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000290 return ret;
291}
292
293
294/***********************************************************************
295 * RELAY_CallFrom32Regs
296 *
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000297 * Stack layout (esp is context->Esp, not the current %esp):
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000298 *
Alexandre Julliard06b97891999-05-13 16:13:17 +0000299 * ...
300 * (esp+4) first arg
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000301 * (esp) return addr to caller
Alexandre Julliard06b97891999-05-13 16:13:17 +0000302 * (esp-4) return addr to DEBUG_ENTRY_POINT
303 * (esp-8) ptr to relay entry code for RELAY_CallFrom32Regs
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000304 * ... >128 bytes space free to be modified (ensured by the assembly glue)
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000305 */
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000306
Ulrich Weigand6ca85a51999-11-14 21:28:57 +0000307void WINAPI RELAY_DoCallFrom32Regs( CONTEXT86 *context );
308DEFINE_REGS_ENTRYPOINT_0( RELAY_CallFrom32Regs, RELAY_DoCallFrom32Regs )
309void WINAPI RELAY_DoCallFrom32Regs( CONTEXT86 *context )
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000310{
Alexandre Julliard06b97891999-05-13 16:13:17 +0000311 char buffer[80];
312 int* args;
313 FARPROC func;
314 BYTE *entry_point;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000315
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000316 BYTE *relay_addr = *((BYTE **)context->Esp - 1);
Alexandre Julliard246c3602000-05-10 03:48:00 +0000317 DEBUG_ENTRY_POINT *relay = (DEBUG_ENTRY_POINT *)(relay_addr - 5);
318 WORD nb_args = (relay->args & ~0x8000) / sizeof(int);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000319
Alexandre Julliard06b97891999-05-13 16:13:17 +0000320 /* remove extra stuff from the stack */
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000321 context->Eip = stack32_pop(context);
322 args = (int *)context->Esp;
323 context->Esp += 4 * nb_args;
Alexandre Julliard06b97891999-05-13 16:13:17 +0000324
325 assert(TRACE_ON(relay));
326
Alexandre Julliard246c3602000-05-10 03:48:00 +0000327 entry_point = (BYTE *)relay->orig;
Alexandre Julliard06b97891999-05-13 16:13:17 +0000328 assert( *entry_point == 0xe8 /* lcall */ );
329 func = *(FARPROC *)(entry_point + 5);
330
Alexandre Julliard246c3602000-05-10 03:48:00 +0000331 get_entry_point( buffer, relay );
332
Alexandre Julliard06b97891999-05-13 16:13:17 +0000333 DPRINTF( "Call %s(", buffer );
Alexandre Julliard246c3602000-05-10 03:48:00 +0000334 RELAY_PrintArgs( args, nb_args, relay->argtypes );
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000335 DPRINTF( ") ret=%08lx fs=%04lx\n", context->Eip, context->SegFs );
Alexandre Julliard06b97891999-05-13 16:13:17 +0000336
337 DPRINTF(" eax=%08lx ebx=%08lx ecx=%08lx edx=%08lx esi=%08lx edi=%08lx\n",
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000338 context->Eax, context->Ebx, context->Ecx,
339 context->Edx, context->Esi, context->Edi );
Alexandre Julliard06b97891999-05-13 16:13:17 +0000340 DPRINTF(" ebp=%08lx esp=%08lx ds=%04lx es=%04lx gs=%04lx flags=%08lx\n",
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000341 context->Ebp, context->Esp, context->SegDs,
342 context->SegEs, context->SegGs, context->EFlags );
Alexandre Julliard06b97891999-05-13 16:13:17 +0000343
Ulrich Weigandac8cbe61999-05-23 09:17:48 +0000344 SYSLEVEL_CheckNotLevel( 2 );
Ulrich Weigand6cd829b1999-05-22 16:29:39 +0000345
Alexandre Julliard06b97891999-05-13 16:13:17 +0000346 /* Now call the real function */
347 switch(nb_args)
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000348 {
Alexandre Julliard06b97891999-05-13 16:13:17 +0000349 case 0: func(context); break;
350 case 1: func(args[0],context); break;
351 case 2: func(args[0],args[1],context); break;
352 case 3: func(args[0],args[1],args[2],context); break;
353 case 4: func(args[0],args[1],args[2],args[3],context); break;
354 case 5: func(args[0],args[1],args[2],args[3],args[4],context); break;
355 case 6: func(args[0],args[1],args[2],args[3],args[4],args[5],context); break;
356 case 7: func(args[0],args[1],args[2],args[3],args[4],args[5],args[6],context); break;
357 case 8: func(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],context); break;
358 case 9: func(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],
359 context); break;
360 case 10: func(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],
361 args[9],context); break;
362 case 11: func(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],
363 args[9],args[10],context); break;
364 case 12: func(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],
365 args[9],args[10],args[11],context); break;
366 case 13: func(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],
367 args[9],args[10],args[11],args[12],context); break;
368 case 14: func(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],
369 args[9],args[10],args[11],args[12],args[13],context); break;
370 case 15: func(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],
371 args[9],args[10],args[11],args[12],args[13],args[14],context); break;
372 case 16: func(args[0],args[1],args[2],args[3],args[4],args[5], args[6],args[7],args[8],
373 args[9],args[10],args[11],args[12],args[13],args[14],args[15],context); break;
374 default:
375 ERR( "Unsupported nb of args %d\n", nb_args );
376 assert(FALSE);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000377 }
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000378
Alexandre Julliard06b97891999-05-13 16:13:17 +0000379 DPRINTF( "Ret %s() retval=%08lx ret=%08lx fs=%04lx\n",
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000380 buffer, context->Eax, context->Eip, context->SegFs );
381
Alexandre Julliard06b97891999-05-13 16:13:17 +0000382 DPRINTF(" eax=%08lx ebx=%08lx ecx=%08lx edx=%08lx esi=%08lx edi=%08lx\n",
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000383 context->Eax, context->Ebx, context->Ecx,
384 context->Edx, context->Esi, context->Edi );
Alexandre Julliard06b97891999-05-13 16:13:17 +0000385 DPRINTF(" ebp=%08lx esp=%08lx ds=%04lx es=%04lx gs=%04lx flags=%08lx\n",
Alexandre Julliardd8fab2e2000-09-25 23:53:07 +0000386 context->Ebp, context->Esp, context->SegDs,
387 context->SegEs, context->SegGs, context->EFlags );
Ulrich Weigand6cd829b1999-05-22 16:29:39 +0000388
Ulrich Weigandac8cbe61999-05-23 09:17:48 +0000389 SYSLEVEL_CheckNotLevel( 2 );
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000390}
Alexandre Julliard06b97891999-05-13 16:13:17 +0000391
Alexandre Julliard246c3602000-05-10 03:48:00 +0000392
393/***********************************************************************
394 * RELAY_SetupDLL
395 *
396 * Setup relay debugging for a built-in dll.
397 */
398void RELAY_SetupDLL( const char *module )
399{
400 IMAGE_DATA_DIRECTORY *dir;
401 IMAGE_EXPORT_DIRECTORY *exports;
402 DEBUG_ENTRY_POINT *debug;
403 DWORD *funcs;
404 int i;
405 const char *name, *dllname;
406
407 dir = &PE_HEADER(module)->OptionalHeader.DataDirectory[IMAGE_FILE_EXPORT_DIRECTORY];
408 if (!dir->Size) return;
409 exports = (IMAGE_EXPORT_DIRECTORY *)(module + dir->VirtualAddress);
410 debug = (DEBUG_ENTRY_POINT *)((char *)exports + dir->Size);
411 funcs = (DWORD *)(module + exports->AddressOfFunctions);
412 dllname = module + exports->Name;
413
414 for (i = 0; i < exports->NumberOfFunctions; i++, funcs++, debug++)
415 {
416 int on = 1;
417
418 if (!debug->call) continue; /* not a normal function */
419
420 if ((name = find_exported_name( module, exports, i + exports->Base )))
421 {
422 char buffer[200];
423 sprintf( buffer, "%s.%d: %s", dllname, i, name );
424 on = RELAY_ShowDebugmsgRelay(buffer);
425 }
426
427 if (on)
428 {
429 debug->call = 0xe8; /* call relative */
430 if (debug->args & 0x8000) /* register func */
431 debug->callfrom32 = (char *)RELAY_CallFrom32Regs - (char *)&debug->ret;
432 else
433 debug->callfrom32 = (char *)RELAY_CallFrom32 - (char *)&debug->ret;
434 }
435 else
436 {
437 debug->call = 0xe9; /* jmp relative */
438 debug->callfrom32 = (char *)debug->orig - (char *)&debug->ret;
439 }
440
441 debug->orig = (FARPROC)(module + (DWORD)*funcs);
442 *funcs = (char *)debug - module;
443 }
444}
445
446#else /* __i386__ */
447
448void RELAY_SetupDLL( const char *module )
449{
450}
451
452#endif /* __i386__ */