configure: Allow specifying custom CFLAGS for LDAP.
[wine.git] / dlls / ntdll / relay.c
blob9ffe28a42198fcfcd5add5494f622075eff815e1
1 /*
2 * Win32 relay and snoop functions
4 * Copyright 1997 Alexandre Julliard
5 * Copyright 1998 Marcus Meissner
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdio.h>
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winternl.h"
34 #include "wine/exception.h"
35 #include "ntdll_misc.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(relay);
41 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
43 WINE_DECLARE_DEBUG_CHANNEL(timestamp);
44 WINE_DECLARE_DEBUG_CHANNEL(pid);
46 struct relay_descr /* descriptor for a module */
48 void *magic; /* signature */
49 void *relay_call; /* functions to call from relay thunks */
50 void *relay_call_regs;
51 void *private; /* reserved for the relay code private data */
52 const char *entry_point_base; /* base address of entry point thunks */
53 const unsigned int *entry_point_offsets; /* offsets of entry points thunks */
54 const unsigned int *arg_types; /* table of argument types for all entry points */
57 #define RELAY_DESCR_MAGIC ((void *)0xdeb90001)
58 #define IS_INTARG(x) (((ULONG_PTR)(x) >> 16) == 0)
60 /* private data built at dll load time */
62 struct relay_entry_point
64 void *orig_func; /* original entry point function */
65 const char *name; /* function name (if any) */
68 struct relay_private_data
70 HMODULE module; /* module handle of this dll */
71 unsigned int base; /* ordinal base */
72 char dllname[40]; /* dll name (without .dll extension) */
73 struct relay_entry_point entry_points[1]; /* list of dll entry points */
76 static const WCHAR **debug_relay_excludelist;
77 static const WCHAR **debug_relay_includelist;
78 static const WCHAR **debug_snoop_excludelist;
79 static const WCHAR **debug_snoop_includelist;
80 static const WCHAR **debug_from_relay_excludelist;
81 static const WCHAR **debug_from_relay_includelist;
82 static const WCHAR **debug_from_snoop_excludelist;
83 static const WCHAR **debug_from_snoop_includelist;
85 static RTL_RUN_ONCE init_once = RTL_RUN_ONCE_INIT;
87 /* compare an ASCII and a Unicode string without depending on the current codepage */
88 static inline int strcmpAW( const char *strA, const WCHAR *strW )
90 while (*strA && ((unsigned char)*strA == *strW)) { strA++; strW++; }
91 return (unsigned char)*strA - *strW;
94 /* compare an ASCII and a Unicode string without depending on the current codepage */
95 static inline int strncmpiAW( const char *strA, const WCHAR *strW, int n )
97 int ret = 0;
98 for ( ; n > 0; n--, strA++, strW++)
99 if ((ret = toupperW((unsigned char)*strA) - toupperW(*strW)) || !*strA) break;
100 return ret;
103 /***********************************************************************
104 * build_list
106 * Build a function list from a ';'-separated string.
108 static const WCHAR **build_list( const WCHAR *buffer )
110 int count = 1;
111 const WCHAR *p = buffer;
112 const WCHAR **ret;
114 while ((p = strchrW( p, ';' )))
116 count++;
117 p++;
119 /* allocate count+1 pointers, plus the space for a copy of the string */
120 if ((ret = RtlAllocateHeap( GetProcessHeap(), 0,
121 (count+1) * sizeof(WCHAR*) + (strlenW(buffer)+1) * sizeof(WCHAR) )))
123 WCHAR *str = (WCHAR *)(ret + count + 1);
124 WCHAR *q = str;
126 strcpyW( str, buffer );
127 count = 0;
128 for (;;)
130 ret[count++] = q;
131 if (!(q = strchrW( q, ';' ))) break;
132 *q++ = 0;
134 ret[count++] = NULL;
136 return ret;
139 /***********************************************************************
140 * load_list_value
142 * Load a function list from a registry value.
144 static const WCHAR **load_list( HKEY hkey, const WCHAR *value )
146 char initial_buffer[4096];
147 char *buffer = initial_buffer;
148 DWORD count;
149 NTSTATUS status;
150 UNICODE_STRING name;
151 const WCHAR **list = NULL;
153 RtlInitUnicodeString( &name, value );
154 status = NtQueryValueKey( hkey, &name, KeyValuePartialInformation, buffer, sizeof(initial_buffer), &count );
155 if (status == STATUS_BUFFER_OVERFLOW)
157 buffer = RtlAllocateHeap( GetProcessHeap(), 0, count );
158 status = NtQueryValueKey( hkey, &name, KeyValuePartialInformation, buffer, count, &count );
160 if (status == STATUS_SUCCESS)
162 WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)buffer)->Data;
163 list = build_list( str );
164 if (list) TRACE( "%s = %s\n", debugstr_w(value), debugstr_w(str) );
167 if (buffer != initial_buffer) RtlFreeHeap( GetProcessHeap(), 0, buffer );
168 return list;
171 /***********************************************************************
172 * init_debug_lists
174 * Build the relay include/exclude function lists.
176 static DWORD WINAPI init_debug_lists( RTL_RUN_ONCE *once, void *param, void **context )
178 OBJECT_ATTRIBUTES attr;
179 UNICODE_STRING name;
180 HANDLE root, hkey;
181 static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\',
182 'W','i','n','e','\\',
183 'D','e','b','u','g',0};
184 static const WCHAR RelayIncludeW[] = {'R','e','l','a','y','I','n','c','l','u','d','e',0};
185 static const WCHAR RelayExcludeW[] = {'R','e','l','a','y','E','x','c','l','u','d','e',0};
186 static const WCHAR SnoopIncludeW[] = {'S','n','o','o','p','I','n','c','l','u','d','e',0};
187 static const WCHAR SnoopExcludeW[] = {'S','n','o','o','p','E','x','c','l','u','d','e',0};
188 static const WCHAR RelayFromIncludeW[] = {'R','e','l','a','y','F','r','o','m','I','n','c','l','u','d','e',0};
189 static const WCHAR RelayFromExcludeW[] = {'R','e','l','a','y','F','r','o','m','E','x','c','l','u','d','e',0};
190 static const WCHAR SnoopFromIncludeW[] = {'S','n','o','o','p','F','r','o','m','I','n','c','l','u','d','e',0};
191 static const WCHAR SnoopFromExcludeW[] = {'S','n','o','o','p','F','r','o','m','E','x','c','l','u','d','e',0};
193 RtlOpenCurrentUser( KEY_ALL_ACCESS, &root );
194 attr.Length = sizeof(attr);
195 attr.RootDirectory = root;
196 attr.ObjectName = &name;
197 attr.Attributes = 0;
198 attr.SecurityDescriptor = NULL;
199 attr.SecurityQualityOfService = NULL;
200 RtlInitUnicodeString( &name, configW );
202 /* @@ Wine registry key: HKCU\Software\Wine\Debug */
203 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) hkey = 0;
204 NtClose( root );
205 if (!hkey) return TRUE;
207 debug_relay_includelist = load_list( hkey, RelayIncludeW );
208 debug_relay_excludelist = load_list( hkey, RelayExcludeW );
209 debug_snoop_includelist = load_list( hkey, SnoopIncludeW );
210 debug_snoop_excludelist = load_list( hkey, SnoopExcludeW );
211 debug_from_relay_includelist = load_list( hkey, RelayFromIncludeW );
212 debug_from_relay_excludelist = load_list( hkey, RelayFromExcludeW );
213 debug_from_snoop_includelist = load_list( hkey, SnoopFromIncludeW );
214 debug_from_snoop_excludelist = load_list( hkey, SnoopFromExcludeW );
216 NtClose( hkey );
217 return TRUE;
221 /***********************************************************************
222 * check_list
224 * Check if a given module and function is in the list.
226 static BOOL check_list( const char *module, int ordinal, const char *func, const WCHAR *const *list )
228 char ord_str[10];
230 sprintf( ord_str, "%d", ordinal );
231 for(; *list; list++)
233 const WCHAR *p = strrchrW( *list, '.' );
234 if (p && p > *list) /* check module and function */
236 int len = p - *list;
237 if (strncmpiAW( module, *list, len-1 ) || module[len]) continue;
238 if (p[1] == '*' && !p[2]) return TRUE;
239 if (!strcmpAW( ord_str, p + 1 )) return TRUE;
240 if (func && !strcmpAW( func, p + 1 )) return TRUE;
242 else /* function only */
244 if (func && !strcmpAW( func, *list )) return TRUE;
247 return FALSE;
251 /***********************************************************************
252 * check_relay_include
254 * Check if a given function must be included in the relay output.
256 static BOOL check_relay_include( const char *module, int ordinal, const char *func )
258 if (debug_relay_excludelist && check_list( module, ordinal, func, debug_relay_excludelist ))
259 return FALSE;
260 if (debug_relay_includelist && !check_list( module, ordinal, func, debug_relay_includelist ))
261 return FALSE;
262 return TRUE;
265 /***********************************************************************
266 * check_from_module
268 * Check if calls from a given module must be included in the relay/snoop output,
269 * given the exclusion and inclusion lists.
271 static BOOL check_from_module( const WCHAR **includelist, const WCHAR **excludelist, const WCHAR *module )
273 static const WCHAR dllW[] = {'.','d','l','l',0 };
274 const WCHAR **listitem;
275 BOOL show;
277 if (!module) return TRUE;
278 if (!includelist && !excludelist) return TRUE;
279 if (excludelist)
281 show = TRUE;
282 listitem = excludelist;
284 else
286 show = FALSE;
287 listitem = includelist;
289 for(; *listitem; listitem++)
291 int len;
293 if (!strcmpiW( *listitem, module )) return !show;
294 len = strlenW( *listitem );
295 if (!strncmpiW( *listitem, module, len ) && !strcmpiW( module + len, dllW ))
296 return !show;
298 return show;
301 /***********************************************************************
302 * RELAY_PrintArgs
304 static inline void RELAY_PrintArgs( const INT_PTR *args, int nb_args, unsigned int typemask )
306 while (nb_args--)
308 if ((typemask & 3) && !IS_INTARG(*args))
310 if (typemask & 2)
311 DPRINTF( "%08lx %s", *args, debugstr_w((LPCWSTR)*args) );
312 else
313 DPRINTF( "%08lx %s", *args, debugstr_a((LPCSTR)*args) );
315 else DPRINTF( "%08lx", *args );
316 if (nb_args) DPRINTF( "," );
317 args++;
318 typemask >>= 2;
322 static void print_timestamp(void)
324 ULONG ticks = NtGetTickCount();
325 DPRINTF( "%3u.%03u:", ticks / 1000, ticks % 1000 );
328 /***********************************************************************
329 * relay_trace_entry
331 * stack points to the return address, i.e. the first argument is stack[1].
333 void * WINAPI relay_trace_entry( struct relay_descr *descr, unsigned int idx, const INT_PTR *stack )
335 WORD ordinal = LOWORD(idx);
336 BYTE nb_args = LOBYTE(HIWORD(idx));
337 struct relay_private_data *data = descr->private;
338 struct relay_entry_point *entry_point = data->entry_points + ordinal;
340 if (TRACE_ON(relay))
342 if (TRACE_ON(timestamp)) print_timestamp();
344 if (TRACE_ON(pid))
345 DPRINTF( "%04x:", GetCurrentProcessId() );
347 if (entry_point->name)
348 DPRINTF( "%04x:Call %s.%s(", GetCurrentThreadId(), data->dllname, entry_point->name );
349 else
350 DPRINTF( "%04x:Call %s.%u(", GetCurrentThreadId(), data->dllname, data->base + ordinal );
351 RELAY_PrintArgs( stack + 1, nb_args, descr->arg_types[ordinal] );
352 DPRINTF( ") ret=%08lx\n", stack[0] );
354 return entry_point->orig_func;
357 /***********************************************************************
358 * relay_trace_exit
360 void WINAPI relay_trace_exit( struct relay_descr *descr, unsigned int idx,
361 const INT_PTR *stack, LONGLONG retval )
363 WORD ordinal = LOWORD(idx);
364 BYTE flags = HIBYTE(HIWORD(idx));
365 struct relay_private_data *data = descr->private;
366 struct relay_entry_point *entry_point = data->entry_points + ordinal;
368 if (!TRACE_ON(relay)) return;
370 if (TRACE_ON(timestamp)) print_timestamp();
372 if (TRACE_ON(pid))
373 DPRINTF( "%04x:", GetCurrentProcessId() );
375 if (entry_point->name)
376 DPRINTF( "%04x:Ret %s.%s()", GetCurrentThreadId(), data->dllname, entry_point->name );
377 else
378 DPRINTF( "%04x:Ret %s.%u()", GetCurrentThreadId(), data->dllname, data->base + ordinal );
380 if (flags & 1) /* 64-bit return value */
381 DPRINTF( " retval=%08x%08x ret=%08lx\n",
382 (UINT)(retval >> 32), (UINT)retval, stack[0] );
383 else
384 DPRINTF( " retval=%08lx ret=%08lx\n", (UINT_PTR)retval, stack[0] );
387 #ifdef __i386__
389 extern LONGLONG CDECL call_entry_point( void *func, int nb_args, const INT_PTR *args, int flags );
390 __ASM_GLOBAL_FUNC( call_entry_point,
391 "pushl %ebp\n\t"
392 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
393 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
394 "movl %esp,%ebp\n\t"
395 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
396 "pushl %esi\n\t"
397 __ASM_CFI(".cfi_rel_offset %esi,-4\n\t")
398 "pushl %edi\n\t"
399 __ASM_CFI(".cfi_rel_offset %edi,-8\n\t")
400 "movl 12(%ebp),%edx\n\t"
401 "shll $2,%edx\n\t"
402 "jz 1f\n\t"
403 "subl %edx,%esp\n\t"
404 "andl $~15,%esp\n\t"
405 "movl 12(%ebp),%ecx\n\t"
406 "movl 16(%ebp),%esi\n\t"
407 "movl %esp,%edi\n\t"
408 "cld\n\t"
409 "rep; movsl\n"
410 "testl $2,20(%ebp)\n\t" /* (flags & 2) -> thiscall */
411 "jz 1f\n\t"
412 "popl %ecx\n\t"
413 "1:\tcall *8(%ebp)\n\t"
414 "leal -8(%ebp),%esp\n\t"
415 "popl %edi\n\t"
416 __ASM_CFI(".cfi_same_value %edi\n\t")
417 "popl %esi\n\t"
418 __ASM_CFI(".cfi_same_value %esi\n\t")
419 "popl %ebp\n\t"
420 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
421 __ASM_CFI(".cfi_same_value %ebp\n\t")
422 "ret" )
424 extern LONGLONG WINAPI relay_call( struct relay_descr *descr, unsigned int idx, const INT_PTR *stack );
425 __ASM_GLOBAL_FUNC( relay_call,
426 "pushl %ebp\n\t"
427 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
428 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
429 "movl %esp,%ebp\n\t"
430 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
431 "pushl %esi\n\t"
432 __ASM_CFI(".cfi_rel_offset %esi,-4\n\t")
433 "pushl %edi\n\t"
434 __ASM_CFI(".cfi_rel_offset %edi,-8\n\t")
435 "pushl %ecx\n\t"
436 __ASM_CFI(".cfi_rel_offset %ecx,-12\n\t")
437 /* trace the parameters */
438 "pushl 16(%ebp)\n\t"
439 "pushl 12(%ebp)\n\t"
440 "pushl 8(%ebp)\n\t"
441 "call " __ASM_NAME("relay_trace_entry") "\n\t"
442 /* copy the arguments*/
443 "movzbl 14(%ebp),%ecx\n\t" /* number of args */
444 "jecxz 1f\n\t"
445 "leal 0(,%ecx,4),%edx\n\t"
446 "subl %edx,%esp\n\t"
447 "andl $~15,%esp\n\t"
448 "movl 16(%ebp),%esi\n\t"
449 "addl $4,%esi\n\t"
450 "movl %esp,%edi\n\t"
451 "cld\n\t"
452 "rep; movsl\n\t"
453 "testb $2,15(%ebp)\n\t" /* (flags & 2) -> thiscall */
454 "jz 1f\n\t"
455 "popl %ecx\n"
456 /* call the entry point */
457 "1:\tcall *%eax\n\t"
458 "movl %eax,%esi\n\t"
459 "movl %edx,%edi\n\t"
460 /* trace the return value */
461 "leal -20(%ebp),%esp\n\t"
462 "pushl %edx\n\t"
463 "pushl %eax\n\t"
464 "pushl 16(%ebp)\n\t"
465 "pushl 12(%ebp)\n\t"
466 "pushl 8(%ebp)\n\t"
467 "call " __ASM_NAME("relay_trace_exit") "\n\t"
468 /* restore return value and return */
469 "leal -12(%ebp),%esp\n\t"
470 "movl %esi,%eax\n\t"
471 "movl %edi,%edx\n\t"
472 "popl %ecx\n\t"
473 __ASM_CFI(".cfi_same_value %ecx\n\t")
474 "popl %edi\n\t"
475 __ASM_CFI(".cfi_same_value %edi\n\t")
476 "popl %esi\n\t"
477 __ASM_CFI(".cfi_same_value %esi\n\t")
478 "popl %ebp\n\t"
479 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
480 __ASM_CFI(".cfi_same_value %ebp\n\t")
481 "ret $12" )
483 void WINAPI __regs_relay_call_regs( struct relay_descr *descr, unsigned int idx,
484 unsigned int orig_eax, unsigned int ret_addr,
485 CONTEXT *context )
487 WORD ordinal = LOWORD(idx);
488 BYTE nb_args = LOBYTE(HIWORD(idx));
489 struct relay_private_data *data = descr->private;
490 struct relay_entry_point *entry_point = data->entry_points + ordinal;
491 BYTE *orig_func = entry_point->orig_func;
492 INT_PTR *args = (INT_PTR *)context->Esp;
493 INT_PTR args_copy[32];
495 /* restore the context to what it was before the relay thunk */
496 context->Eax = orig_eax;
497 context->Eip = ret_addr;
498 context->Esp += nb_args * sizeof(int);
500 if (TRACE_ON(relay))
502 if (entry_point->name)
503 DPRINTF( "%04x:Call %s.%s(", GetCurrentThreadId(), data->dllname, entry_point->name );
504 else
505 DPRINTF( "%04x:Call %s.%u(", GetCurrentThreadId(), data->dllname, data->base + ordinal );
506 RELAY_PrintArgs( args, nb_args, descr->arg_types[ordinal] );
507 DPRINTF( ") ret=%08x\n", ret_addr );
509 DPRINTF( "%04x: eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x "
510 "ebp=%08x esp=%08x ds=%04x es=%04x fs=%04x gs=%04x flags=%08x\n",
511 GetCurrentThreadId(), context->Eax, context->Ebx, context->Ecx,
512 context->Edx, context->Esi, context->Edi, context->Ebp, context->Esp,
513 context->SegDs, context->SegEs, context->SegFs, context->SegGs, context->EFlags );
515 assert( orig_func[0] == 0x68 /* pushl func */ );
516 assert( orig_func[5] == 0x6a /* pushl args */ );
517 assert( orig_func[7] == 0xe8 /* call */ );
520 /* now call the real function */
522 memcpy( args_copy, args, nb_args * sizeof(args[0]) );
523 args_copy[nb_args++] = (INT_PTR)context; /* append context argument */
525 call_entry_point( orig_func + 12 + *(int *)(orig_func + 1), nb_args, args_copy, 0 );
527 if (TRACE_ON(relay))
529 if (entry_point->name)
530 DPRINTF( "%04x:Ret %s.%s() retval=%08x ret=%08x\n",
531 GetCurrentThreadId(), data->dllname, entry_point->name,
532 context->Eax, context->Eip );
533 else
534 DPRINTF( "%04x:Ret %s.%u() retval=%08x ret=%08x\n",
535 GetCurrentThreadId(), data->dllname, data->base + ordinal,
536 context->Eax, context->Eip );
537 DPRINTF( "%04x: eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x "
538 "ebp=%08x esp=%08x ds=%04x es=%04x fs=%04x gs=%04x flags=%08x\n",
539 GetCurrentThreadId(), context->Eax, context->Ebx, context->Ecx,
540 context->Edx, context->Esi, context->Edi, context->Ebp, context->Esp,
541 context->SegDs, context->SegEs, context->SegFs, context->SegGs, context->EFlags );
544 extern void WINAPI relay_call_regs(void);
545 DEFINE_REGS_ENTRYPOINT( relay_call_regs, 4 )
547 #elif defined(__arm__)
549 extern LONGLONG CDECL call_entry_point( void *func, int nb_args, const INT_PTR *args, int flags );
550 __ASM_GLOBAL_FUNC( call_entry_point,
551 ".arm\n\t"
552 "push {r4, r5, LR}\n\t"
553 "mov r4, r0\n\t"
554 "mov r5, SP\n\t"
555 "lsl r3, r1, #2\n\t"
556 "cmp r3, #0\n\t"
557 "beq 5f\n\t"
558 "sub SP, SP, r3\n\t"
559 "tst r1, #1\n\t"
560 "subeq SP, SP, #4\n\t"
561 "1:\tsub r3, r3, #4\n\t"
562 "ldr r0, [r2, r3]\n\t"
563 "str r0, [SP, r3]\n\t"
564 "cmp r3, #0\n\t"
565 "bgt 1b\n\t"
566 "cmp r1, #1\n\t"
567 "bgt 2f\n\t"
568 "pop {r0}\n\t"
569 "b 5f\n\t"
570 "2:\tcmp r1, #2\n\t"
571 "bgt 3f\n\t"
572 "pop {r0-r1}\n\t"
573 "b 5f\n\t"
574 "3:\tcmp r1, #3\n\t"
575 "bgt 4f\n\t"
576 "pop {r0-r2}\n\t"
577 "b 5f\n\t"
578 "4:\tpop {r0-r3}\n\t"
579 "5:\tblx r4\n\t"
580 "mov SP, r5\n\t"
581 "pop {r4, r5, PC}" )
583 static LONGLONG WINAPI relay_call( struct relay_descr *descr, unsigned int idx, const INT_PTR *stack )
585 BYTE nb_args = LOBYTE(HIWORD(idx));
586 BYTE flags = HIBYTE(HIWORD(idx));
587 void *func = relay_trace_entry( descr, idx, stack );
588 LONGLONG ret = call_entry_point( func, nb_args, stack + 1, flags );
589 relay_trace_exit( descr, idx, stack, ret );
590 return ret;
593 static void WINAPI relay_call_regs( struct relay_descr *descr, INT_PTR idx, INT_PTR *stack )
595 assert(0); /* should never be called */
597 #elif defined(__aarch64__)
599 extern LONGLONG CDECL call_entry_point( void *func, int nb_args, const INT_PTR *args, int flags );
600 __ASM_GLOBAL_FUNC( call_entry_point,
601 "stp x29, x30, [SP,#-16]!\n\t"
602 "stp x19, x20, [SP,#-16]!\n\t"
603 "mov x29, SP\n\t"
604 "mov x19, x2\n\t"
605 "ldp x8, x9, [x19, #-32]\n\t"
606 "mov x9, x0\n\t"
607 "cbz w1, 2f\n\t"
608 "mov w10, w1\n\t"
609 "mov x11, x2\n\t"
610 "mov x12, #0\n\t"
611 "ldp x0, x1, [x11], #16\n\t"
612 "add w12, w12, #2\n\t"
613 "cmp w12, w10\n\t"
614 "b.hs 2f\n\t"
615 "ldp x2, x3, [x11], #16\n\t"
616 "add w12, w12, #2\n\t"
617 "cmp w12, w10\n\t"
618 "b.hs 2f\n\t"
619 "ldp x4, x5, [x11], #16\n\t"
620 "add w12, w12, #2\n\t"
621 "cmp w12, w10\n\t"
622 "b.hs 2f\n\t"
623 "ldp x6, x7, [x11], #16\n\t"
624 "add w12, w12, #2\n\t"
625 "cmp w12, w10\n\t"
626 "b.hs 2f\n\t"
627 "sub w12, w10, #8\n\t"
628 "lsl w12, w12, #3\n\t"
629 "sub SP, SP, w12, uxtw\n\t"
630 "tbz w12, #3, 1f\n\t"
631 "sub SP, SP, #8\n\t"
632 "1: sub w12, w12, #8\n\t"
633 "ldr x13, [x11, x12]\n\t"
634 "str x13, [SP, x12]\n\t"
635 "cbnz w12, 1b\n\t"
636 "2: blr x9\n\t"
637 "mov SP, x29\n\t"
638 "ldp x19, x20, [SP], #16\n\t"
639 "ldp x29, x30, [SP], #16\n\t"
640 "ret\n" )
642 static LONGLONG WINAPI relay_call( struct relay_descr *descr, unsigned int idx, const INT_PTR *stack )
644 BYTE nb_args = LOBYTE(HIWORD(idx));
645 BYTE flags = HIBYTE(HIWORD(idx));
646 void *func = relay_trace_entry( descr, idx, stack + 3 );
647 LONGLONG ret = call_entry_point( func, nb_args, stack + 4, flags );
648 relay_trace_exit( descr, idx, stack + 3, ret );
649 return ret;
652 static void WINAPI relay_call_regs( struct relay_descr *descr, INT_PTR idx, INT_PTR *stack )
654 assert(0); /* should never be called */
657 #elif defined(__x86_64__)
659 extern void * WINAPI relay_call( struct relay_descr *descr, unsigned int idx, const INT_PTR *stack );
660 __ASM_GLOBAL_FUNC( relay_call,
661 "pushq %rbp\n\t"
662 __ASM_CFI(".cfi_adjust_cfa_offset 8\n\t")
663 __ASM_CFI(".cfi_rel_offset %rbp,0\n\t")
664 "movq %rsp,%rbp\n\t"
665 __ASM_CFI(".cfi_def_cfa_register %rbp\n\t")
666 "subq $0x30,%rsp\n\t"
667 "movq %rsi,0x20(%rsp)\n\t"
668 __ASM_CFI(".cfi_rel_offset %rsi,-16\n\t")
669 "movq %rdi,0x28(%rsp)\n\t"
670 __ASM_CFI(".cfi_rel_offset %rdi,-8\n\t")
671 /* trace the parameters */
672 "movq %rcx,0x10(%rbp)\n\t"
673 "movq %rdx,0x18(%rbp)\n\t"
674 "movq %r8,0x20(%rbp)\n\t"
675 "call " __ASM_NAME("relay_trace_entry") "\n\t"
676 /* copy the arguments */
677 "movzbq 0x1a(%rbp),%rdx\n\t" /* number of args */
678 "movq $4,%rcx\n\t"
679 "cmp %rcx,%rdx\n\t"
680 "cmovgq %rdx,%rcx\n\t"
681 "leaq -16(,%rcx,8),%rdx\n\t"
682 "andq $~15,%rdx\n\t"
683 "subq %rdx,%rsp\n\t"
684 "movq 0x20(%rbp),%r8\n\t" /* original stack */
685 "leaq 8(%r8),%rsi\n\t"
686 "movq %rsp,%rdi\n\t"
687 "rep; movsq\n\t"
688 /* call the entry point */
689 "movq 0(%rsp),%rcx\n\t"
690 "movq 8(%rsp),%rdx\n\t"
691 "movq 16(%rsp),%r8\n\t"
692 "movq 24(%rsp),%r9\n\t"
693 "movq 0(%rsp),%xmm0\n\t"
694 "movq 8(%rsp),%xmm1\n\t"
695 "movq 16(%rsp),%xmm2\n\t"
696 "movq 24(%rsp),%xmm3\n\t"
697 "callq *%rax\n\t"
698 /* trace the return value */
699 "leaq -0x30(%rbp),%rsp\n\t"
700 "movq 0x10(%rbp),%rcx\n\t"
701 "movq 0x18(%rbp),%rdx\n\t"
702 "movq 0x20(%rbp),%r8\n\t"
703 "movq %rax,%rsi\n\t"
704 "movaps %xmm0,0x10(%rbp)\n\t"
705 "movq %rax,%r9\n\t"
706 "call " __ASM_NAME("relay_trace_exit") "\n\t"
707 /* restore return value and return */
708 "movq %rsi,%rax\n\t"
709 "movaps 0x10(%rbp),%xmm0\n\t"
710 "movq 0x20(%rsp),%rsi\n\t"
711 __ASM_CFI(".cfi_same_value %rsi\n\t")
712 "movq 0x28(%rsp),%rdi\n\t"
713 __ASM_CFI(".cfi_same_value %rdi\n\t")
714 "movq %rbp,%rsp\n\t"
715 __ASM_CFI(".cfi_def_cfa_register %rsp\n\t")
716 "popq %rbp\n\t"
717 __ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
718 __ASM_CFI(".cfi_same_value %rbp\n\t")
719 "ret")
721 static void WINAPI relay_call_regs( struct relay_descr *descr, INT_PTR idx, INT_PTR *stack )
723 assert(0); /* should never be called */
726 #else
727 #error Not supported on this CPU
728 #endif
731 /***********************************************************************
732 * RELAY_GetProcAddress
734 * Return the proc address to use for a given function.
736 FARPROC RELAY_GetProcAddress( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
737 DWORD exp_size, FARPROC proc, DWORD ordinal, const WCHAR *user )
739 struct relay_private_data *data;
740 const struct relay_descr *descr = (const struct relay_descr *)((const char *)exports + exp_size);
742 if (descr->magic != RELAY_DESCR_MAGIC || !(data = descr->private)) return proc; /* no relay data */
743 if (!data->entry_points[ordinal].orig_func) return proc; /* not a relayed function */
744 if (check_from_module( debug_from_relay_includelist, debug_from_relay_excludelist, user ))
745 return proc; /* we want to relay it */
746 return data->entry_points[ordinal].orig_func;
750 /***********************************************************************
751 * RELAY_SetupDLL
753 * Setup relay debugging for a built-in dll.
755 void RELAY_SetupDLL( HMODULE module )
757 IMAGE_EXPORT_DIRECTORY *exports;
758 DWORD *funcs;
759 unsigned int i, len;
760 DWORD size, entry_point_rva;
761 struct relay_descr *descr;
762 struct relay_private_data *data;
763 const WORD *ordptr;
765 RtlRunOnceExecuteOnce( &init_once, init_debug_lists, NULL, NULL );
767 exports = RtlImageDirectoryEntryToData( module, TRUE, IMAGE_DIRECTORY_ENTRY_EXPORT, &size );
768 if (!exports) return;
770 descr = (struct relay_descr *)((char *)exports + size);
771 if (descr->magic != RELAY_DESCR_MAGIC) return;
773 if (!(data = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) +
774 (exports->NumberOfFunctions-1) * sizeof(data->entry_points) )))
775 return;
777 descr->relay_call = relay_call;
778 descr->relay_call_regs = relay_call_regs;
779 descr->private = data;
781 data->module = module;
782 data->base = exports->Base;
783 len = strlen( (char *)module + exports->Name );
784 if (len > 4 && !strcasecmp( (char *)module + exports->Name + len - 4, ".dll" )) len -= 4;
785 len = min( len, sizeof(data->dllname) - 1 );
786 memcpy( data->dllname, (char *)module + exports->Name, len );
787 data->dllname[len] = 0;
789 /* fetch name pointer for all entry points and store them in the private structure */
791 ordptr = (const WORD *)((char *)module + exports->AddressOfNameOrdinals);
792 for (i = 0; i < exports->NumberOfNames; i++, ordptr++)
794 DWORD name_rva = ((DWORD*)((char *)module + exports->AddressOfNames))[i];
795 data->entry_points[*ordptr].name = (const char *)module + name_rva;
798 /* patch the functions in the export table to point to the relay thunks */
800 funcs = (DWORD *)((char *)module + exports->AddressOfFunctions);
801 entry_point_rva = descr->entry_point_base - (const char *)module;
802 for (i = 0; i < exports->NumberOfFunctions; i++, funcs++)
804 if (!descr->entry_point_offsets[i]) continue; /* not a normal function */
805 if (!check_relay_include( data->dllname, i + exports->Base, data->entry_points[i].name ))
806 continue; /* don't include this entry point */
808 data->entry_points[i].orig_func = (char *)module + *funcs;
809 *funcs = entry_point_rva + descr->entry_point_offsets[i];
813 #else /* __i386__ || __x86_64__ || __arm__ || __aarch64__ */
815 FARPROC RELAY_GetProcAddress( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
816 DWORD exp_size, FARPROC proc, DWORD ordinal, const WCHAR *user )
818 return proc;
821 void RELAY_SetupDLL( HMODULE module )
825 #endif /* __i386__ || __x86_64__ || __arm__ || __aarch64__ */
828 /***********************************************************************/
829 /* snoop support */
830 /***********************************************************************/
832 #ifdef __i386__
834 WINE_DECLARE_DEBUG_CHANNEL(seh);
835 WINE_DECLARE_DEBUG_CHANNEL(snoop);
837 #include "pshpack1.h"
839 typedef struct
841 /* code part */
842 BYTE lcall; /* 0xe8 call snoopentry (relative) */
843 DWORD snoopentry; /* SNOOP_Entry relative */
844 /* unreached */
845 int nrofargs;
846 FARPROC origfun;
847 const char *name;
848 } SNOOP_FUN;
850 typedef struct tagSNOOP_DLL {
851 HMODULE hmod;
852 SNOOP_FUN *funs;
853 DWORD ordbase;
854 DWORD nrofordinals;
855 struct tagSNOOP_DLL *next;
856 char name[1];
857 } SNOOP_DLL;
859 typedef struct
861 /* code part */
862 BYTE lcall; /* 0xe8 call snoopret relative*/
863 DWORD snoopret; /* SNOOP_Ret relative */
864 /* unreached */
865 FARPROC origreturn;
866 SNOOP_DLL *dll;
867 DWORD ordinal;
868 void **origESP;
869 DWORD *args; /* saved args across a stdcall */
870 } SNOOP_RETURNENTRY;
872 typedef struct tagSNOOP_RETURNENTRIES {
873 SNOOP_RETURNENTRY entry[4092/sizeof(SNOOP_RETURNENTRY)];
874 struct tagSNOOP_RETURNENTRIES *next;
875 } SNOOP_RETURNENTRIES;
877 #include "poppack.h"
879 extern void WINAPI SNOOP_Entry(void);
880 extern void WINAPI SNOOP_Return(void);
882 static SNOOP_DLL *firstdll;
883 static SNOOP_RETURNENTRIES *firstrets;
886 /***********************************************************************
887 * SNOOP_ShowDebugmsgSnoop
889 * Simple function to decide if a particular debugging message is
890 * wanted.
892 static BOOL SNOOP_ShowDebugmsgSnoop(const char *module, int ordinal, const char *func)
894 if (debug_snoop_excludelist && check_list( module, ordinal, func, debug_snoop_excludelist ))
895 return FALSE;
896 if (debug_snoop_includelist && !check_list( module, ordinal, func, debug_snoop_includelist ))
897 return FALSE;
898 return TRUE;
902 /***********************************************************************
903 * SNOOP_SetupDLL
905 * Setup snoop debugging for a native dll.
907 void SNOOP_SetupDLL(HMODULE hmod)
909 SNOOP_DLL **dll = &firstdll;
910 char *p, *name;
911 void *addr;
912 SIZE_T size;
913 ULONG size32;
914 IMAGE_EXPORT_DIRECTORY *exports;
916 RtlRunOnceExecuteOnce( &init_once, init_debug_lists, NULL, NULL );
918 exports = RtlImageDirectoryEntryToData( hmod, TRUE, IMAGE_DIRECTORY_ENTRY_EXPORT, &size32 );
919 if (!exports || !exports->NumberOfFunctions) return;
920 name = (char *)hmod + exports->Name;
921 size = size32;
923 TRACE_(snoop)("hmod=%p, name=%s\n", hmod, name);
925 while (*dll) {
926 if ((*dll)->hmod == hmod)
928 /* another dll, loaded at the same address */
929 addr = (*dll)->funs;
930 size = (*dll)->nrofordinals * sizeof(SNOOP_FUN);
931 NtFreeVirtualMemory(NtCurrentProcess(), &addr, &size, MEM_RELEASE);
932 break;
934 dll = &((*dll)->next);
936 if (*dll)
937 *dll = RtlReAllocateHeap(GetProcessHeap(),
938 HEAP_ZERO_MEMORY, *dll,
939 sizeof(SNOOP_DLL) + strlen(name));
940 else
941 *dll = RtlAllocateHeap(GetProcessHeap(),
942 HEAP_ZERO_MEMORY,
943 sizeof(SNOOP_DLL) + strlen(name));
944 (*dll)->hmod = hmod;
945 (*dll)->ordbase = exports->Base;
946 (*dll)->nrofordinals = exports->NumberOfFunctions;
947 strcpy( (*dll)->name, name );
948 p = (*dll)->name + strlen((*dll)->name) - 4;
949 if (p > (*dll)->name && !strcasecmp( p, ".dll" )) *p = 0;
951 size = exports->NumberOfFunctions * sizeof(SNOOP_FUN);
952 addr = NULL;
953 NtAllocateVirtualMemory(NtCurrentProcess(), &addr, 0, &size,
954 MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
955 if (!addr) {
956 RtlFreeHeap(GetProcessHeap(),0,*dll);
957 FIXME("out of memory\n");
958 return;
960 (*dll)->funs = addr;
961 memset((*dll)->funs,0,size);
965 /***********************************************************************
966 * SNOOP_GetProcAddress
968 * Return the proc address to use for a given function.
970 FARPROC SNOOP_GetProcAddress( HMODULE hmod, const IMAGE_EXPORT_DIRECTORY *exports,
971 DWORD exp_size, FARPROC origfun, DWORD ordinal,
972 const WCHAR *user)
974 unsigned int i;
975 const char *ename;
976 const WORD *ordinals;
977 const DWORD *names;
978 SNOOP_DLL *dll = firstdll;
979 SNOOP_FUN *fun;
980 const IMAGE_SECTION_HEADER *sec;
982 if (!TRACE_ON(snoop)) return origfun;
983 if (!check_from_module( debug_from_snoop_includelist, debug_from_snoop_excludelist, user ))
984 return origfun; /* the calling module was explicitly excluded */
986 if (!*(LPBYTE)origfun) /* 0x00 is an impossible opcode, possible dataref. */
987 return origfun;
989 sec = RtlImageRvaToSection( RtlImageNtHeader(hmod), hmod, (char *)origfun - (char *)hmod );
991 if (!sec || !(sec->Characteristics & IMAGE_SCN_CNT_CODE))
992 return origfun; /* most likely a data reference */
994 while (dll) {
995 if (hmod == dll->hmod)
996 break;
997 dll = dll->next;
999 if (!dll) /* probably internal */
1000 return origfun;
1002 /* try to find a name for it */
1003 ename = NULL;
1004 names = (const DWORD *)((const char *)hmod + exports->AddressOfNames);
1005 ordinals = (const WORD *)((const char *)hmod + exports->AddressOfNameOrdinals);
1006 if (names) for (i = 0; i < exports->NumberOfNames; i++)
1008 if (ordinals[i] == ordinal)
1010 ename = (const char *)hmod + names[i];
1011 break;
1014 if (!SNOOP_ShowDebugmsgSnoop(dll->name,ordinal,ename))
1015 return origfun;
1016 assert(ordinal < dll->nrofordinals);
1017 fun = dll->funs + ordinal;
1018 if (!fun->name)
1020 fun->name = ename;
1021 fun->lcall = 0xe8;
1022 fun->snoopentry = (char *)SNOOP_Entry - (char *)(&fun->snoopentry + 1);
1023 fun->origfun = origfun;
1024 fun->nrofargs = -1;
1026 return (FARPROC)&(fun->lcall);
1029 static void SNOOP_PrintArg(DWORD x)
1031 int i,nostring;
1033 DPRINTF("%08x",x);
1034 if (IS_INTARG(x) || TRACE_ON(seh)) return; /* trivial reject to avoid faults */
1035 __TRY
1037 LPBYTE s=(LPBYTE)x;
1038 i=0;nostring=0;
1039 while (i<80) {
1040 if (s[i]==0) break;
1041 if (s[i]<0x20) {nostring=1;break;}
1042 if (s[i]>=0x80) {nostring=1;break;}
1043 i++;
1045 if (!nostring && i > 5)
1046 DPRINTF(" %s",debugstr_an((LPSTR)x,i));
1047 else /* try unicode */
1049 LPWSTR s=(LPWSTR)x;
1050 i=0;nostring=0;
1051 while (i<80) {
1052 if (s[i]==0) break;
1053 if (s[i]<0x20) {nostring=1;break;}
1054 if (s[i]>0x100) {nostring=1;break;}
1055 i++;
1057 if (!nostring && i > 5) DPRINTF(" %s",debugstr_wn((LPWSTR)x,i));
1060 __EXCEPT_PAGE_FAULT
1063 __ENDTRY
1066 void WINAPI __regs_SNOOP_Entry( void **stack )
1068 SNOOP_DLL *dll;
1069 SNOOP_FUN *fun = (SNOOP_FUN *)((char *)stack[0] - 5);
1070 SNOOP_RETURNENTRIES **rets = &firstrets;
1071 SNOOP_RETURNENTRY *ret;
1072 int i=0, max;
1074 for (dll = firstdll; dll; dll = dll->next )
1075 if (fun >= dll->funs && fun < dll->funs + dll->nrofordinals) break;
1077 if (!dll) {
1078 FIXME("entrypoint %p not found\n", fun);
1079 return; /* oops */
1081 /* guess cdecl ... */
1082 if (fun->nrofargs<0) {
1083 /* Typical cdecl return frame is:
1084 * add esp, xxxxxxxx
1085 * which has (for xxxxxxxx up to 255 the opcode "83 C4 xx".
1086 * (after that 81 C2 xx xx xx xx)
1088 LPBYTE reteip = stack[1];
1090 if (reteip) {
1091 if ((reteip[0]==0x83)&&(reteip[1]==0xc4))
1092 fun->nrofargs=reteip[2]/4;
1097 while (*rets) {
1098 for (i=0;i<sizeof((*rets)->entry)/sizeof((*rets)->entry[0]);i++)
1099 if (!(*rets)->entry[i].origreturn)
1100 break;
1101 if (i!=sizeof((*rets)->entry)/sizeof((*rets)->entry[0]))
1102 break;
1103 rets = &((*rets)->next);
1105 if (!*rets) {
1106 SIZE_T size = 4096;
1107 VOID* addr = NULL;
1109 NtAllocateVirtualMemory(NtCurrentProcess(), &addr, 0, &size,
1110 MEM_COMMIT | MEM_RESERVE,
1111 PAGE_EXECUTE_READWRITE);
1112 if (!addr) return;
1113 *rets = addr;
1114 i = 0; /* entry 0 is free */
1116 ret = &((*rets)->entry[i]);
1117 ret->lcall = 0xe8;
1118 ret->snoopret = (char *)SNOOP_Return - (char *)(&ret->snoopret + 1);
1119 ret->origreturn = stack[1];
1120 stack[1] = &ret->lcall;
1121 ret->dll = dll;
1122 ret->args = NULL;
1123 ret->ordinal = fun - dll->funs;
1124 ret->origESP = stack;
1126 stack[0] = fun->origfun;
1128 if (!TRACE_ON(snoop)) return;
1130 if (TRACE_ON(timestamp))
1131 print_timestamp();
1132 if (fun->name) DPRINTF("%04x:CALL %s.%s(",GetCurrentThreadId(),dll->name,fun->name);
1133 else DPRINTF("%04x:CALL %s.%d(",GetCurrentThreadId(),dll->name,dll->ordbase+ret->ordinal);
1134 if (fun->nrofargs>0) {
1135 max = fun->nrofargs; if (max>16) max=16;
1136 for (i=0;i<max;i++)
1138 SNOOP_PrintArg( (DWORD)stack[i + 2] );
1139 if (i<fun->nrofargs-1) DPRINTF(",");
1141 if (max!=fun->nrofargs)
1142 DPRINTF(" ...");
1143 } else if (fun->nrofargs<0) {
1144 DPRINTF("<unknown, check return>");
1145 ret->args = RtlAllocateHeap(GetProcessHeap(),
1146 0,16*sizeof(DWORD));
1147 memcpy(ret->args, stack + 2, sizeof(DWORD)*16);
1149 DPRINTF(") ret=%08x\n",(DWORD)ret->origreturn);
1152 void WINAPI __regs_SNOOP_Return( void **stack )
1154 SNOOP_RETURNENTRY *ret = (SNOOP_RETURNENTRY*)((char *)stack[0] - 5);
1155 SNOOP_FUN *fun = &ret->dll->funs[ret->ordinal];
1156 DWORD retval = (DWORD)stack[-1]; /* get saved %eax from the stack */
1158 /* We haven't found out the nrofargs yet. If we called a cdecl
1159 * function it is too late anyway and we can just set '0' (which
1160 * will be the difference between orig and current ESP
1161 * If stdcall -> everything ok.
1163 if (ret->dll->funs[ret->ordinal].nrofargs<0)
1164 ret->dll->funs[ret->ordinal].nrofargs = stack - ret->origESP - 1;
1165 stack[0] = ret->origreturn;
1167 if (!TRACE_ON(snoop)) {
1168 ret->origreturn = NULL; /* mark as empty */
1169 return;
1172 if (TRACE_ON(timestamp))
1173 print_timestamp();
1174 if (ret->args) {
1175 int i,max;
1177 if (fun->name)
1178 DPRINTF("%04x:RET %s.%s(", GetCurrentThreadId(), ret->dll->name, fun->name);
1179 else
1180 DPRINTF("%04x:RET %s.%d(", GetCurrentThreadId(),
1181 ret->dll->name,ret->dll->ordbase+ret->ordinal);
1183 max = fun->nrofargs;
1184 if (max>16) max=16;
1186 for (i=0;i<max;i++)
1188 SNOOP_PrintArg(ret->args[i]);
1189 if (i<max-1) DPRINTF(",");
1191 DPRINTF(") retval=%08x ret=%08x\n", retval, (DWORD)ret->origreturn );
1192 RtlFreeHeap(GetProcessHeap(),0,ret->args);
1193 ret->args = NULL;
1195 else
1197 if (fun->name)
1198 DPRINTF("%04x:RET %s.%s() retval=%08x ret=%08x\n",
1199 GetCurrentThreadId(),
1200 ret->dll->name, fun->name, retval, (DWORD)ret->origreturn);
1201 else
1202 DPRINTF("%04x:RET %s.%d() retval=%08x ret=%08x\n",
1203 GetCurrentThreadId(),
1204 ret->dll->name,ret->dll->ordbase+ret->ordinal,
1205 retval, (DWORD)ret->origreturn);
1207 ret->origreturn = NULL; /* mark as empty */
1210 /* small wrappers that save registers and get the stack pointer */
1211 #define SNOOP_WRAPPER(name) \
1212 __ASM_STDCALL_FUNC( name, 0, \
1213 "pushl %eax\n\t" \
1214 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") \
1215 "pushl %ecx\n\t" \
1216 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") \
1217 "pushl %edx\n\t" \
1218 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") \
1219 "leal 12(%esp),%eax\n\t" \
1220 "pushl %eax\n\t" \
1221 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") \
1222 "call " __ASM_NAME("__regs_" #name) __ASM_STDCALL(4) "\n\t" \
1223 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t") \
1224 "popl %edx\n\t" \
1225 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t") \
1226 "popl %ecx\n\t" \
1227 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t") \
1228 "popl %eax\n\t" \
1229 __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t") \
1230 "ret" )
1232 SNOOP_WRAPPER( SNOOP_Entry )
1233 SNOOP_WRAPPER( SNOOP_Return )
1235 #else /* __i386__ */
1237 FARPROC SNOOP_GetProcAddress( HMODULE hmod, const IMAGE_EXPORT_DIRECTORY *exports, DWORD exp_size,
1238 FARPROC origfun, DWORD ordinal, const WCHAR *user )
1240 return origfun;
1243 void SNOOP_SetupDLL( HMODULE hmod )
1245 FIXME("snooping works only on i386 for now.\n");
1248 #endif /* __i386__ */