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 show
= RELAY_ShowDebugmsgRelay(buffer
);
88 DPRINTF( "Call %s(", buffer
);
90 for (i
= 0, mask
= 3; i
< nb_args
; i
++, mask
<<= 2)
92 if (i
) DPRINTF( "," );
93 if ((typemask
& mask
) && HIWORD(args
[i
]))
95 if (typemask
& (2<<(2*i
)))
96 DPRINTF( "%08x L%s", args
[i
], debugstr_w((LPWSTR
)args
[i
]) );
98 DPRINTF( "%08x %s", args
[i
], debugstr_a((LPCSTR
)args
[i
]) );
100 else DPRINTF( "%08x", args
[i
] );
103 DPRINTF( ") ret=%08x fs=%04x\n", ret_addr
, fs
);
106 fs
= 0; /* quieten gcc */
108 if (*relay_addr
== 0xc3) /* cdecl */
110 LRESULT (*cfunc
)() = (LRESULT(*)())func
;
113 case 0: ret
= cfunc(); break;
114 case 1: ret
= cfunc(args
[0]); break;
115 case 2: ret
= cfunc(args
[0],args
[1]); break;
116 case 3: ret
= cfunc(args
[0],args
[1],args
[2]); break;
117 case 4: ret
= cfunc(args
[0],args
[1],args
[2],args
[3]); break;
118 case 5: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4]); break;
119 case 6: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],
121 case 7: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
123 case 8: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
124 args
[6],args
[7]); break;
125 case 9: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
126 args
[6],args
[7],args
[8]); break;
127 case 10: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
128 args
[6],args
[7],args
[8],args
[9]); break;
129 case 11: 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]); break;
131 case 12: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
132 args
[6],args
[7],args
[8],args
[9],args
[10],
134 case 13: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
135 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
137 case 14: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
138 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
139 args
[12],args
[13]); break;
140 case 15: ret
= cfunc(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
141 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
142 args
[12],args
[13],args
[14]); break;
144 ERR(relay
, "Unsupported nb args %d\n",
153 case 0: ret
= func(); break;
154 case 1: ret
= func(args
[0]); break;
155 case 2: ret
= func(args
[0],args
[1]); break;
156 case 3: ret
= func(args
[0],args
[1],args
[2]); break;
157 case 4: ret
= func(args
[0],args
[1],args
[2],args
[3]); break;
158 case 5: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4]); break;
159 case 6: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],
161 case 7: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
163 case 8: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
164 args
[6],args
[7]); break;
165 case 9: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
166 args
[6],args
[7],args
[8]); break;
167 case 10: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
168 args
[6],args
[7],args
[8],args
[9]); break;
169 case 11: 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]); break;
171 case 12: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
172 args
[6],args
[7],args
[8],args
[9],args
[10],
174 case 13: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
175 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
177 case 14: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
178 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
179 args
[12],args
[13]); break;
180 case 15: ret
= func(args
[0],args
[1],args
[2],args
[3],args
[4],args
[5],
181 args
[6],args
[7],args
[8],args
[9],args
[10],args
[11],
182 args
[12],args
[13],args
[14]); break;
184 ERR(relay
, "Unsupported nb args %d\n",nb_args
);
189 DPRINTF( "Ret %s() retval=%08x ret=%08x fs=%04x\n",
190 buffer
, ret
, ret_addr
, fs
);
195 /***********************************************************************
196 * RELAY_CallFrom32Regs
198 * 'context' contains the register contents at the point of call of
199 * the REG_ENTRY_POINT. The stack layout of the stack pointed to by
200 * ESP_reg(&context) is as follows:
202 * If debugmsg(relay) is OFF:
205 * (esp) return addr to caller
206 * (esp-4) function entry point
208 * If debugmsg(relay) is ON:
211 * (esp+4) return addr to caller
212 * (esp) return addr to DEBUG_ENTRY_POINT
213 * (esp-4) function entry point
215 * As the called function might change the stack layout
216 * (e.g. FT_Prolog, FT_ExitNN), we remove all modifications to the stack,
217 * so that the called function sees (in both cases):
221 * (esp) return addr to caller
222 * ... >128 bytes space free to be modified (ensured by the assembly glue)
224 * NOTE: This routine makes no assumption about the relative position of
225 * its own stack to the stack pointed to by ESP_reg(&context),
226 * except that the latter must have >128 bytes space to grow.
227 * This means the assembly glue could even switch stacks completely
228 * (e.g. to allow for large stacks).
232 void RELAY_CallFrom32Regs( CONTEXT context
)
234 typedef void (CALLBACK
*entry_point_t
)(CONTEXT
*);
235 entry_point_t entry_point
= *(entry_point_t
*) (ESP_reg(&context
) - 4);
239 if (!TRACE_ON(relay
))
241 /* Simply call the entry point */
242 entry_point( &context
);
247 unsigned int typemask
;
251 * Fixup the context structure because of the extra parameter
252 * pushed by the relay debugging code.
253 * Note that this implicitly does a RET on the CALL from the
254 * DEBUG_ENTRY_POINT to the REG_ENTRY_POINT; setting the EIP register
255 * ensures that the assembly glue will directly return to the
256 * caller, just as in the non-debugging case.
259 relay_addr
= *(BYTE
**) ESP_reg(&context
);
260 if (BUILTIN32_GetEntryPoint( buffer
, relay_addr
- 5, &typemask
)) {
261 /* correct win32 spec generated register function found.
262 * remove extra call stuff from stack
264 ESP_reg(&context
) += sizeof(BYTE
*);
265 EIP_reg(&context
) = *(DWORD
*)ESP_reg(&context
);
266 DPRINTF("Call %s(regs) ret=%08x\n", buffer
, *(int *)ESP_reg(&context
) );
267 DPRINTF(" EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx ESI=%08lx EDI=%08lx\n",
268 EAX_reg(&context
), EBX_reg(&context
), ECX_reg(&context
),
269 EDX_reg(&context
), ESI_reg(&context
), EDI_reg(&context
) );
270 DPRINTF(" EBP=%08lx ESP=%08lx EIP=%08lx DS=%04lx ES=%04lx FS=%04lx GS=%04lx EFL=%08lx\n",
271 EBP_reg(&context
), ESP_reg(&context
), EIP_reg(&context
),
272 DS_reg(&context
), ES_reg(&context
), FS_reg(&context
),
273 GS_reg(&context
), EFL_reg(&context
) );
275 /* Now call the real function */
276 entry_point( &context
);
279 DPRINTF("Ret %s() retval=regs ret=%08x\n", buffer
, *(int *)ESP_reg(&context
) );
280 DPRINTF(" EAX=%08lx EBX=%08lx ECX=%08lx EDX=%08lx ESI=%08lx EDI=%08lx\n",
281 EAX_reg(&context
), EBX_reg(&context
), ECX_reg(&context
),
282 EDX_reg(&context
), ESI_reg(&context
), EDI_reg(&context
) );
283 DPRINTF(" EBP=%08lx ESP=%08lx EIP=%08lx DS=%04lx ES=%04lx FS=%04lx GS=%04lx EFL=%08lx\n",
284 EBP_reg(&context
), ESP_reg(&context
), EIP_reg(&context
),
285 DS_reg(&context
), ES_reg(&context
), FS_reg(&context
),
286 GS_reg(&context
), EFL_reg(&context
) );
288 /* WINE internal register function found. Do not remove anything.
289 * Do not print any debuginfo (it is not a normal relayed one).
290 * Currently only used for snooping.
292 entry_point( &context
);
295 #endif /* __i386__ */