2 * 386-specific Win32 relay functions
4 * Copyright 1997 Alexandre Julliard
13 #include "builtin32.h"
14 #include "selectors.h"
18 char **debug_relay_excludelist
= NULL
, **debug_relay_includelist
= NULL
;
20 /***********************************************************************
21 * RELAY_ShowDebugmsgRelay
23 * Simple function to decide if a particular debugging message is
24 * wanted. Called from RELAY_CallFrom32 and from in if1632/relay.c
26 int RELAY_ShowDebugmsgRelay(const char *func
) {
28 if(debug_relay_excludelist
|| debug_relay_includelist
) {
29 const char *term
= strchr(func
, ':');
31 int len
, len2
, itemlen
, show
;
33 if(debug_relay_excludelist
) {
35 listitem
= debug_relay_excludelist
;
38 listitem
= debug_relay_includelist
;
41 assert(strlen(term
) > 2);
43 len2
= strchr(func
, '.') - func
;
44 assert(len2
&& len2
> 0 && len2
< 64);
46 for(; *listitem
; listitem
++) {
47 itemlen
= strlen(*listitem
);
48 if((itemlen
== len
&& !strncmp(*listitem
, func
, len
)) ||
49 (itemlen
== len2
&& !strncmp(*listitem
, func
, len2
)) ||
50 !strcmp(*listitem
, term
)) {
60 /***********************************************************************
63 * Stack layout on entry to this function:
68 * (esp) return addr to relay code
70 int RELAY_CallFrom32( int ret_addr
, ... )
75 unsigned int mask
, typemask
;
78 int *args
= &ret_addr
;
79 /* Relay addr is the return address for this function */
80 BYTE
*relay_addr
= (BYTE
*)args
[-1];
81 WORD nb_args
= *(WORD
*)(relay_addr
+ 1) / sizeof(int);
83 assert(TRACE_ON(relay
));
84 func
= (FARPROC32
)BUILTIN32_GetEntryPoint( buffer
, relay_addr
- 5,
86 DPRINTF( "Call %s(", buffer
);
88 for (i
= 0, mask
= 3; i
< nb_args
; i
++, mask
<<= 2)
90 if (i
) DPRINTF( "," );
91 if ((typemask
& mask
) && HIWORD(args
[i
]))
93 if (typemask
& (2<<(2*i
)))
94 DPRINTF( "%08x L%s", args
[i
], debugstr_w((LPWSTR
)args
[i
]) );
96 DPRINTF( "%08x %s", args
[i
], debugstr_a((LPCSTR
)args
[i
]) );
98 else DPRINTF( "%08x", args
[i
] );
101 DPRINTF( ") ret=%08x fs=%04x\n", ret_addr
, fs
);
103 if (*relay_addr
== 0xc3) /* cdecl */
105 LRESULT (*cfunc
)() = (LRESULT(*)())func
;
108 case 0: ret
= cfunc(); break;
109 case 1: ret
= cfunc(args
[0]); break;
110 case 2: ret
= cfunc(args
[0],args
[1]); break;
111 case 3: ret
= cfunc(args
[0],args
[1],args
[2]); break;
112 case 4: ret
= cfunc(args
[0],args
[1],args
[2],args
[3]); break;
113 case 5: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4]); break;
114 case 6: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],
116 case 7: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
118 case 8: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
119 args
[6],args
[7]); break;
120 case 9: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
121 args
[6],args
[7],args
[8]); break;
122 case 10: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
123 args
[6],args
[7],args
[8],args
[9]); break;
124 case 11: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
125 args
[6],args
[7],args
[8],args
[9],args
[10]); break;
126 case 12: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
127 args
[6],args
[7],args
[8],args
[9],args
[10],
129 case 13: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
130 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
132 case 14: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
133 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
134 args
[12],args
[13]); break;
135 case 15: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
136 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
137 args
[12],args
[13],args
[14]); break;
139 ERR(relay
, "Unsupported nb args %d\n",
148 case 0: ret
= func(); break;
149 case 1: ret
= func(args
[0]); break;
150 case 2: ret
= func(args
[0],args
[1]); break;
151 case 3: ret
= func(args
[0],args
[1],args
[2]); break;
152 case 4: ret
= func(args
[0],args
[1],args
[2],args
[3]); break;
153 case 5: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4]); break;
154 case 6: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],
156 case 7: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
158 case 8: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
159 args
[6],args
[7]); break;
160 case 9: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
161 args
[6],args
[7],args
[8]); break;
162 case 10: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
163 args
[6],args
[7],args
[8],args
[9]); break;
164 case 11: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
165 args
[6],args
[7],args
[8],args
[9],args
[10]); break;
166 case 12: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
167 args
[6],args
[7],args
[8],args
[9],args
[10],
169 case 13: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
170 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
172 case 14: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
173 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
174 args
[12],args
[13]); break;
175 case 15: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
176 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
177 args
[12],args
[13],args
[14]); break;
179 ERR(relay
, "Unsupported nb args %d\n",nb_args
);
183 DPRINTF( "Ret %s() retval=%08x ret=%08x fs=%04x\n",
184 buffer
, ret
, ret_addr
, fs
);
189 /***********************************************************************
190 * RELAY_CallFrom32Regs
192 * 'context' contains the register contents at the point of call of
193 * the REG_ENTRY_POINT. The stack layout of the stack pointed to by
194 * ESP_reg(&context) is as follows:
196 * If debugmsg(relay) is OFF:
199 * (esp) return addr to caller
200 * (esp-4) function entry point
202 * If debugmsg(relay) is ON:
205 * (esp+4) return addr to caller
206 * (esp) return addr to DEBUG_ENTRY_POINT
207 * (esp-4) function entry point
209 * As the called function might change the stack layout
210 * (e.g. FT_Prolog, FT_ExitNN), we remove all modifications to the stack,
211 * so that the called function sees (in both cases):
215 * (esp) return addr to caller
216 * ... >128 bytes space free to be modified (ensured by the assembly glue)
218 * NOTE: This routine makes no assumption about the relative position of
219 * its own stack to the stack pointed to by ESP_reg(&context),
220 * except that the latter must have >128 bytes space to grow.
221 * This means the assembly glue could even switch stacks completely
222 * (e.g. to allow for large stacks).
226 void RELAY_CallFrom32Regs( CONTEXT context
)
228 typedef void (CALLBACK
*entry_point_t
)(CONTEXT
*);
229 entry_point_t entry_point
= *(entry_point_t
*) (ESP_reg(&context
) - 4);
233 if (!TRACE_ON(relay
))
235 /* Simply call the entry point */
236 entry_point( &context
);
241 unsigned int typemask
;
245 * Fixup the context structure because of the extra parameter
246 * pushed by the relay debugging code.
247 * Note that this implicitly does a RET on the CALL from the
248 * DEBUG_ENTRY_POINT to the REG_ENTRY_POINT; setting the EIP register
249 * ensures that the assembly glue will directly return to the
250 * caller, just as in the non-debugging case.
253 relay_addr
= *(BYTE
**) ESP_reg(&context
);
254 if (BUILTIN32_GetEntryPoint( buffer
, relay_addr
- 5, &typemask
)) {
255 /* correct win32 spec generated register function found.
256 * remove extra call stuff from stack
258 ESP_reg(&context
) += sizeof(BYTE
*);
259 EIP_reg(&context
) = *(DWORD
*)ESP_reg(&context
);
260 DPRINTF("Call %s(regs) ret=%08x\n", buffer
, *(int *)ESP_reg(&context
) );
261 DPRINTF(" EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx ESI=%08lx EDI=%08lx\n",
262 EAX_reg(&context
), EBX_reg(&context
), ECX_reg(&context
),
263 EDX_reg(&context
), ESI_reg(&context
), EDI_reg(&context
) );
264 DPRINTF(" EBP=%08lx ESP=%08lx EIP=%08lx DS=%04lx ES=%04lx FS=%04lx GS=%04lx EFL=%08lx\n",
265 EBP_reg(&context
), ESP_reg(&context
), EIP_reg(&context
),
266 DS_reg(&context
), ES_reg(&context
), FS_reg(&context
),
267 GS_reg(&context
), EFL_reg(&context
) );
269 /* Now call the real function */
270 entry_point( &context
);
273 DPRINTF("Ret %s() retval=regs ret=%08x\n", buffer
, *(int *)ESP_reg(&context
) );
274 DPRINTF(" EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx ESI=%08lx EDI=%08lx\n",
275 EAX_reg(&context
), EBX_reg(&context
), ECX_reg(&context
),
276 EDX_reg(&context
), ESI_reg(&context
), EDI_reg(&context
) );
277 DPRINTF(" EBP=%08lx ESP=%08lx EIP=%08lx DS=%04lx ES=%04lx FS=%04lx GS=%04lx EFL=%08lx\n",
278 EBP_reg(&context
), ESP_reg(&context
), EIP_reg(&context
),
279 DS_reg(&context
), ES_reg(&context
), FS_reg(&context
),
280 GS_reg(&context
), EFL_reg(&context
) );
282 /* WINE internal register function found. Do not remove anything.
283 * Do not print any debuginfo (it is not a normal relayed one).
284 * Currently only used for snooping.
286 entry_point( &context
);
289 #endif /* __i386__ */