Duplicate parts of the relay debugging init code into kernel to avoid
[wine/multimedia.git] / dlls / kernel / wowthunk.c
blob0aeeeac0eb36bab93485fbee8b3934a533a902d3
1 /*
2 * Win32 WOW Generic Thunk API
4 * Copyright 1999 Ulrich Weigand
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <stdarg.h>
27 #include "wine/winbase16.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winerror.h"
31 #include "wownt32.h"
32 #include "excpt.h"
33 #include "winreg.h"
34 #include "winternl.h"
35 #include "file.h"
36 #include "task.h"
37 #include "miscemu.h"
38 #include "stackframe.h"
39 #include "kernel_private.h"
40 #include "wine/exception.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(thunk);
44 WINE_DECLARE_DEBUG_CHANNEL(relay);
47 * These are the 16-bit side WOW routines. They reside in wownt16.h
48 * in the SDK; since we don't support Win16 source code anyway, I've
49 * placed them here for compilation with Wine ...
52 DWORD WINAPI GetVDMPointer32W16(SEGPTR,UINT16);
54 DWORD WINAPI LoadLibraryEx32W16(LPCSTR,DWORD,DWORD);
55 DWORD WINAPI GetProcAddress32W16(DWORD,LPCSTR);
56 DWORD WINAPI FreeLibrary32W16(DWORD);
58 #define CPEX_DEST_STDCALL 0x00000000L
59 #define CPEX_DEST_CDECL 0x80000000L
61 /* thunk for 16-bit CreateThread */
62 struct thread_args
64 FARPROC16 proc;
65 DWORD param;
68 static DWORD CALLBACK start_thread16( LPVOID threadArgs )
70 struct thread_args args = *(struct thread_args *)threadArgs;
71 HeapFree( GetProcessHeap(), 0, threadArgs );
72 return K32WOWCallback16( (DWORD)args.proc, args.param );
76 #ifdef __i386__
78 /* symbols exported from relay16.s */
79 extern DWORD WINAPI wine_call_to_16( FARPROC16 target, DWORD cbArgs, PEXCEPTION_HANDLER handler );
80 extern void WINAPI wine_call_to_16_regs( CONTEXT86 *context, DWORD cbArgs, PEXCEPTION_HANDLER handler );
81 extern void Call16_Ret_Start(), Call16_Ret_End();
82 extern void CallTo16_Ret();
83 extern void CALL32_CBClient_Ret();
84 extern void CALL32_CBClientEx_Ret();
85 extern DWORD CallTo16_DataSelector;
86 extern SEGPTR CALL32_CBClient_RetAddr;
87 extern SEGPTR CALL32_CBClientEx_RetAddr;
88 extern BYTE Call16_Start;
89 extern BYTE Call16_End;
91 extern void RELAY16_InitDebugLists(void);
93 static SEGPTR call16_ret_addr; /* segptr to CallTo16_Ret routine */
95 /***********************************************************************
96 * WOWTHUNK_Init
98 BOOL WOWTHUNK_Init(void)
100 /* allocate the code selector for CallTo16 routines */
101 WORD codesel = SELECTOR_AllocBlock( (void *)Call16_Ret_Start,
102 (char *)Call16_Ret_End - (char *)Call16_Ret_Start,
103 WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
104 if (!codesel) return FALSE;
106 /* Patch the return addresses for CallTo16 routines */
108 CallTo16_DataSelector = wine_get_ds();
109 call16_ret_addr = MAKESEGPTR( codesel, (char*)CallTo16_Ret - (char*)Call16_Ret_Start );
110 CALL32_CBClient_RetAddr =
111 MAKESEGPTR( codesel, (char*)CALL32_CBClient_Ret - (char*)Call16_Ret_Start );
112 CALL32_CBClientEx_RetAddr =
113 MAKESEGPTR( codesel, (char*)CALL32_CBClientEx_Ret - (char*)Call16_Ret_Start );
115 if (TRACE_ON(relay)) RELAY16_InitDebugLists();
116 return TRUE;
120 /*************************************************************
121 * fix_selector
123 * Fix a selector load that caused an exception if it's in the
124 * 16-bit relay code.
126 static BOOL fix_selector( CONTEXT *context )
128 WORD *stack;
129 BYTE *instr = (BYTE *)context->Eip;
131 if (instr < &Call16_Start || instr >= &Call16_End) return FALSE;
133 /* skip prefixes */
134 while (*instr == 0x66 || *instr == 0x67) instr++;
136 switch(instr[0])
138 case 0x07: /* pop es */
139 case 0x17: /* pop ss */
140 case 0x1f: /* pop ds */
141 break;
142 case 0x0f: /* extended instruction */
143 switch(instr[1])
145 case 0xa1: /* pop fs */
146 case 0xa9: /* pop gs */
147 break;
148 default:
149 return FALSE;
151 break;
152 default:
153 return FALSE;
155 stack = wine_ldt_get_ptr( context->SegSs, context->Esp );
156 TRACE( "fixing up selector %x for pop instruction\n", *stack );
157 *stack = 0;
158 return TRUE;
162 /*************************************************************
163 * call16_handler
165 * Handler for exceptions occurring in 16-bit code.
167 static DWORD call16_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
168 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **pdispatcher )
170 if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
172 /* unwinding: restore the stack pointer in the TEB, and leave the Win16 mutex */
173 STACK32FRAME *frame32 = (STACK32FRAME *)((char *)frame - offsetof(STACK32FRAME,frame));
174 NtCurrentTeb()->cur_stack = frame32->frame16;
175 _LeaveWin16Lock();
177 else if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
178 record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)
180 if (IS_SELECTOR_SYSTEM(context->SegCs))
182 if (fix_selector( context )) return ExceptionContinueExecution;
184 else
186 SEGPTR gpHandler;
187 DWORD ret = INSTR_EmulateInstruction( record, context );
189 if (ret != ExceptionContinueSearch) return ret;
191 /* check for Win16 __GP handler */
192 if ((gpHandler = HasGPHandler16( MAKESEGPTR( context->SegCs, context->Eip ) )))
194 WORD *stack = wine_ldt_get_ptr( context->SegSs, context->Esp );
195 *--stack = context->SegCs;
196 *--stack = context->Eip;
198 if (!IS_SELECTOR_32BIT(context->SegSs))
199 context->Esp = MAKELONG( LOWORD(context->Esp - 2*sizeof(WORD)),
200 HIWORD(context->Esp) );
201 else
202 context->Esp -= 2*sizeof(WORD);
204 context->SegCs = SELECTOROF( gpHandler );
205 context->Eip = OFFSETOF( gpHandler );
206 return ExceptionContinueExecution;
210 return ExceptionContinueSearch;
214 /*************************************************************
215 * vm86_handler
217 * Handler for exceptions occurring in vm86 code.
219 static DWORD vm86_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
220 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **pdispatcher )
222 if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
223 return ExceptionContinueSearch;
225 if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
226 record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)
228 return INSTR_EmulateInstruction( record, context );
231 return ExceptionContinueSearch;
235 #else /* __i386__ */
237 BOOL WOWTHUNK_Init(void)
239 return TRUE;
242 #endif /* __i386__ */
246 * 32-bit WOW routines (in WOW32, but actually forwarded to KERNEL32)
249 /**********************************************************************
250 * K32WOWGetDescriptor (KERNEL32.70)
252 BOOL WINAPI K32WOWGetDescriptor( SEGPTR segptr, LPLDT_ENTRY ldtent )
254 return GetThreadSelectorEntry( GetCurrentThread(),
255 segptr >> 16, ldtent );
258 /**********************************************************************
259 * K32WOWGetVDMPointer (KERNEL32.56)
261 LPVOID WINAPI K32WOWGetVDMPointer( DWORD vp, DWORD dwBytes, BOOL fProtectedMode )
263 /* FIXME: add size check too */
265 if ( fProtectedMode )
266 return MapSL( vp );
267 else
268 return DOSMEM_MapRealToLinear( vp );
271 /**********************************************************************
272 * K32WOWGetVDMPointerFix (KERNEL32.68)
274 LPVOID WINAPI K32WOWGetVDMPointerFix( DWORD vp, DWORD dwBytes, BOOL fProtectedMode )
277 * Hmmm. According to the docu, we should call:
279 * GlobalFix16( SELECTOROF(vp) );
281 * But this is unnecessary under Wine, as we never move global
282 * memory segments in linear memory anyway.
284 * (I'm not so sure what we are *supposed* to do if
285 * fProtectedMode is TRUE, anyway ...)
288 return K32WOWGetVDMPointer( vp, dwBytes, fProtectedMode );
291 /**********************************************************************
292 * K32WOWGetVDMPointerUnfix (KERNEL32.69)
294 VOID WINAPI K32WOWGetVDMPointerUnfix( DWORD vp )
297 * See above why we don't call:
299 * GlobalUnfix16( SELECTOROF(vp) );
304 /**********************************************************************
305 * K32WOWGlobalAlloc16 (KERNEL32.59)
307 WORD WINAPI K32WOWGlobalAlloc16( WORD wFlags, DWORD cb )
309 return (WORD)GlobalAlloc16( wFlags, cb );
312 /**********************************************************************
313 * K32WOWGlobalFree16 (KERNEL32.62)
315 WORD WINAPI K32WOWGlobalFree16( WORD hMem )
317 return (WORD)GlobalFree16( (HGLOBAL16)hMem );
320 /**********************************************************************
321 * K32WOWGlobalUnlock16 (KERNEL32.61)
323 BOOL WINAPI K32WOWGlobalUnlock16( WORD hMem )
325 return (BOOL)GlobalUnlock16( (HGLOBAL16)hMem );
328 /**********************************************************************
329 * K32WOWGlobalAllocLock16 (KERNEL32.63)
331 DWORD WINAPI K32WOWGlobalAllocLock16( WORD wFlags, DWORD cb, WORD *phMem )
333 WORD hMem = K32WOWGlobalAlloc16( wFlags, cb );
334 if (phMem) *phMem = hMem;
336 return K32WOWGlobalLock16( hMem );
339 /**********************************************************************
340 * K32WOWGlobalLockSize16 (KERNEL32.65)
342 DWORD WINAPI K32WOWGlobalLockSize16( WORD hMem, PDWORD pcb )
344 if ( pcb )
345 *pcb = GlobalSize16( (HGLOBAL16)hMem );
347 return K32WOWGlobalLock16( hMem );
350 /**********************************************************************
351 * K32WOWGlobalUnlockFree16 (KERNEL32.64)
353 WORD WINAPI K32WOWGlobalUnlockFree16( DWORD vpMem )
355 if ( !K32WOWGlobalUnlock16( HIWORD(vpMem) ) )
356 return FALSE;
358 return K32WOWGlobalFree16( HIWORD(vpMem) );
362 /**********************************************************************
363 * K32WOWYield16 (KERNEL32.66)
365 VOID WINAPI K32WOWYield16( void )
368 * This does the right thing for both Win16 and Win32 tasks.
369 * More or less, at least :-/
371 Yield16();
374 /**********************************************************************
375 * K32WOWDirectedYield16 (KERNEL32.67)
377 VOID WINAPI K32WOWDirectedYield16( WORD htask16 )
380 * Argh. Our scheduler doesn't like DirectedYield by Win32
381 * tasks at all. So we do hope that this routine is indeed
382 * only ever called by Win16 tasks that have thunked up ...
384 DirectedYield16( (HTASK16)htask16 );
388 /***********************************************************************
389 * K32WOWHandle32 (KERNEL32.57)
391 HANDLE WINAPI K32WOWHandle32( WORD handle, WOW_HANDLE_TYPE type )
393 switch ( type )
395 case WOW_TYPE_HWND:
396 case WOW_TYPE_HMENU:
397 case WOW_TYPE_HDWP:
398 case WOW_TYPE_HDROP:
399 case WOW_TYPE_HDC:
400 case WOW_TYPE_HFONT:
401 case WOW_TYPE_HRGN:
402 case WOW_TYPE_HBITMAP:
403 case WOW_TYPE_HBRUSH:
404 case WOW_TYPE_HPALETTE:
405 case WOW_TYPE_HPEN:
406 case WOW_TYPE_HACCEL:
407 return (HANDLE)(ULONG_PTR)handle;
409 case WOW_TYPE_HMETAFILE:
410 FIXME( "conversion of metafile handles not supported yet\n" );
411 return (HANDLE)(ULONG_PTR)handle;
413 case WOW_TYPE_HTASK:
414 return ((TDB *)GlobalLock16(handle))->teb->ClientId.UniqueThread;
416 case WOW_TYPE_FULLHWND:
417 FIXME( "conversion of full window handles not supported yet\n" );
418 return (HANDLE)(ULONG_PTR)handle;
420 default:
421 ERR( "handle 0x%04x of unknown type %d\n", handle, type );
422 return (HANDLE)(ULONG_PTR)handle;
426 /***********************************************************************
427 * K32WOWHandle16 (KERNEL32.58)
429 WORD WINAPI K32WOWHandle16( HANDLE handle, WOW_HANDLE_TYPE type )
431 switch ( type )
433 case WOW_TYPE_HWND:
434 case WOW_TYPE_HMENU:
435 case WOW_TYPE_HDWP:
436 case WOW_TYPE_HDROP:
437 case WOW_TYPE_HDC:
438 case WOW_TYPE_HFONT:
439 case WOW_TYPE_HRGN:
440 case WOW_TYPE_HBITMAP:
441 case WOW_TYPE_HBRUSH:
442 case WOW_TYPE_HPALETTE:
443 case WOW_TYPE_HPEN:
444 case WOW_TYPE_HACCEL:
445 case WOW_TYPE_FULLHWND:
446 if ( HIWORD(handle ) )
447 ERR( "handle %p of type %d has non-zero HIWORD\n", handle, type );
448 return LOWORD(handle);
450 case WOW_TYPE_HMETAFILE:
451 FIXME( "conversion of metafile handles not supported yet\n" );
452 return LOWORD(handle);
454 case WOW_TYPE_HTASK:
455 return TASK_GetTaskFromThread( (DWORD)handle );
457 default:
458 ERR( "handle %p of unknown type %d\n", handle, type );
459 return LOWORD(handle);
463 /**********************************************************************
464 * K32WOWCallback16Ex (KERNEL32.55)
466 BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
467 DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode )
469 #ifdef __i386__
471 * Arguments must be prepared in the correct order by the caller
472 * (both for PASCAL and CDECL calling convention), so we simply
473 * copy them to the 16-bit stack ...
475 WORD *stack = (WORD *)CURRENT_STACK16 - cbArgs / sizeof(WORD);
477 memcpy( stack, pArgs, cbArgs );
479 if (dwFlags & (WCB16_REGS|WCB16_REGS_LONG))
481 CONTEXT *context = (CONTEXT *)pdwRetCode;
483 if (TRACE_ON(relay))
485 DWORD count = cbArgs / sizeof(WORD);
487 DPRINTF("%04lx:CallTo16(func=%04lx:%04x,ds=%04lx",
488 GetCurrentThreadId(),
489 context->SegCs, LOWORD(context->Eip), context->SegDs );
490 while (count) DPRINTF( ",%04x", stack[--count] );
491 DPRINTF(") ss:sp=%04x:%04x",
492 SELECTOROF(NtCurrentTeb()->cur_stack), OFFSETOF(NtCurrentTeb()->cur_stack) );
493 DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x bp=%04x es=%04x fs=%04x\n",
494 (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
495 (WORD)context->Edx, (WORD)context->Esi, (WORD)context->Edi,
496 (WORD)context->Ebp, (WORD)context->SegEs, (WORD)context->SegFs );
497 SYSLEVEL_CheckNotLevel( 2 );
500 if (ISV86(context))
502 EXCEPTION_REGISTRATION_RECORD frame;
503 frame.Handler = vm86_handler;
504 __wine_push_frame( &frame );
505 __wine_enter_vm86( context );
506 __wine_pop_frame( &frame );
508 else
510 /* push return address */
511 if (dwFlags & WCB16_REGS_LONG)
513 *((DWORD *)stack - 1) = HIWORD(call16_ret_addr);
514 *((DWORD *)stack - 2) = LOWORD(call16_ret_addr);
515 cbArgs += 2 * sizeof(DWORD);
517 else
519 *((SEGPTR *)stack - 1) = call16_ret_addr;
520 cbArgs += sizeof(SEGPTR);
523 _EnterWin16Lock();
524 wine_call_to_16_regs( context, cbArgs, call16_handler );
525 _LeaveWin16Lock();
528 if (TRACE_ON(relay))
530 DPRINTF("%04lx:RetFrom16() ss:sp=%04x:%04x ",
531 GetCurrentThreadId(), SELECTOROF(NtCurrentTeb()->cur_stack),
532 OFFSETOF(NtCurrentTeb()->cur_stack));
533 DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x bp=%04x sp=%04x\n",
534 (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
535 (WORD)context->Edx, (WORD)context->Ebp, (WORD)context->Esp );
536 SYSLEVEL_CheckNotLevel( 2 );
539 else
541 DWORD ret;
543 if (TRACE_ON(relay))
545 DWORD count = cbArgs / sizeof(WORD);
547 DPRINTF("%04lx:CallTo16(func=%04x:%04x,ds=%04x",
548 GetCurrentThreadId(), HIWORD(vpfn16), LOWORD(vpfn16),
549 SELECTOROF(NtCurrentTeb()->cur_stack) );
550 while (count) DPRINTF( ",%04x", stack[--count] );
551 DPRINTF(") ss:sp=%04x:%04x\n",
552 SELECTOROF(NtCurrentTeb()->cur_stack), OFFSETOF(NtCurrentTeb()->cur_stack) );
553 SYSLEVEL_CheckNotLevel( 2 );
556 /* push return address */
557 *((SEGPTR *)stack - 1) = call16_ret_addr;
558 cbArgs += sizeof(SEGPTR);
561 * Actually, we should take care whether the called routine cleans up
562 * its stack or not. Fortunately, our wine_call_to_16 core doesn't rely on
563 * the callee to do so; after the routine has returned, the 16-bit
564 * stack pointer is always reset to the position it had before.
566 _EnterWin16Lock();
567 ret = wine_call_to_16( (FARPROC16)vpfn16, cbArgs, call16_handler );
568 if (pdwRetCode) *pdwRetCode = ret;
569 _LeaveWin16Lock();
571 if (TRACE_ON(relay))
573 DPRINTF("%04lx:RetFrom16() ss:sp=%04x:%04x retval=%08lx\n",
574 GetCurrentThreadId(), SELECTOROF(NtCurrentTeb()->cur_stack),
575 OFFSETOF(NtCurrentTeb()->cur_stack), ret);
576 SYSLEVEL_CheckNotLevel( 2 );
579 #else
580 assert(0); /* cannot call to 16-bit on non-Intel architectures */
581 #endif /* __i386__ */
583 return TRUE; /* success */
586 /**********************************************************************
587 * K32WOWCallback16 (KERNEL32.54)
589 DWORD WINAPI K32WOWCallback16( DWORD vpfn16, DWORD dwParam )
591 DWORD ret;
593 if ( !K32WOWCallback16Ex( vpfn16, WCB16_PASCAL,
594 sizeof(DWORD), &dwParam, &ret ) )
595 ret = 0L;
597 return ret;
602 * 16-bit WOW routines (in KERNEL)
605 /**********************************************************************
606 * GetVDMPointer32W (KERNEL.516)
608 DWORD WINAPI GetVDMPointer32W16( SEGPTR vp, UINT16 fMode )
610 GlobalPageLock16(GlobalHandle16(SELECTOROF(vp)));
611 return (DWORD)K32WOWGetVDMPointer( vp, 0, (DWORD)fMode );
614 /***********************************************************************
615 * LoadLibraryEx32W (KERNEL.513)
617 DWORD WINAPI LoadLibraryEx32W16( LPCSTR lpszLibFile, DWORD hFile, DWORD dwFlags )
619 HMODULE hModule;
620 DOS_FULL_NAME full_name;
621 DWORD mutex_count;
622 UNICODE_STRING libfileW;
623 LPCWSTR filenameW;
624 static const WCHAR dllW[] = {'.','D','L','L',0};
626 if (!lpszLibFile)
628 SetLastError(ERROR_INVALID_PARAMETER);
629 return 0;
632 if (!RtlCreateUnicodeStringFromAsciiz(&libfileW, lpszLibFile))
634 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
635 return 0;
638 /* if the file can not be found, call LoadLibraryExA anyway, since it might be
639 a buildin module. This case is handled in MODULE_LoadLibraryExA */
641 filenameW = libfileW.Buffer;
642 if ( DIR_SearchPath( NULL, filenameW, dllW, &full_name, FALSE ) )
643 filenameW = full_name.short_name;
645 ReleaseThunkLock( &mutex_count );
646 hModule = LoadLibraryExW( filenameW, (HANDLE)hFile, dwFlags );
647 RestoreThunkLock( mutex_count );
649 RtlFreeUnicodeString(&libfileW);
651 return (DWORD)hModule;
654 /***********************************************************************
655 * GetProcAddress32W (KERNEL.515)
657 DWORD WINAPI GetProcAddress32W16( DWORD hModule, LPCSTR lpszProc )
659 return (DWORD)GetProcAddress( (HMODULE)hModule, lpszProc );
662 /***********************************************************************
663 * FreeLibrary32W (KERNEL.514)
665 DWORD WINAPI FreeLibrary32W16( DWORD hLibModule )
667 BOOL retv;
668 DWORD mutex_count;
670 ReleaseThunkLock( &mutex_count );
671 retv = FreeLibrary( (HMODULE)hLibModule );
672 RestoreThunkLock( mutex_count );
673 return (DWORD)retv;
677 /**********************************************************************
678 * WOW_CallProc32W
680 static DWORD WOW_CallProc32W16( FARPROC proc32, DWORD nrofargs, DWORD *args )
682 DWORD ret;
683 DWORD mutex_count;
685 ReleaseThunkLock( &mutex_count );
688 * FIXME: If ( nrofargs & CPEX_DEST_CDECL ) != 0, we should call a
689 * 32-bit CDECL routine ...
692 if (!proc32) ret = 0;
693 else switch (nrofargs)
695 case 0: ret = proc32();
696 break;
697 case 1: ret = proc32(args[0]);
698 break;
699 case 2: ret = proc32(args[0],args[1]);
700 break;
701 case 3: ret = proc32(args[0],args[1],args[2]);
702 break;
703 case 4: ret = proc32(args[0],args[1],args[2],args[3]);
704 break;
705 case 5: ret = proc32(args[0],args[1],args[2],args[3],args[4]);
706 break;
707 case 6: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5]);
708 break;
709 case 7: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
710 break;
711 case 8: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]);
712 break;
713 case 9: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]);
714 break;
715 case 10:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9]);
716 break;
717 case 11:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10]);
718 break;
719 case 12:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11]);
720 break;
721 case 13:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12]);
722 break;
723 case 14:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12],args[13]);
724 break;
725 case 15:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12],args[13],args[14]);
726 break;
727 default:
728 /* FIXME: should go up to 32 arguments */
729 ERR("Unsupported number of arguments %ld, please report.\n",nrofargs);
730 ret = 0;
731 break;
734 RestoreThunkLock( mutex_count );
736 TRACE("returns %08lx\n",ret);
737 return ret;
740 /**********************************************************************
741 * CallProc32W (KERNEL.517)
743 DWORD WINAPIV CallProc32W16( DWORD nrofargs, DWORD argconvmask, FARPROC proc32, VA_LIST16 valist )
745 DWORD args[32];
746 unsigned int i;
748 TRACE("(%ld,%ld,%p args[",nrofargs,argconvmask,proc32);
750 for (i=0;i<nrofargs;i++)
752 if (argconvmask & (1<<i))
754 SEGPTR ptr = VA_ARG16( valist, SEGPTR );
755 /* pascal convention, have to reverse the arguments order */
756 args[nrofargs - i - 1] = (DWORD)MapSL(ptr);
757 TRACE("%08lx(%p),",ptr,MapSL(ptr));
759 else
761 DWORD arg = VA_ARG16( valist, DWORD );
762 /* pascal convention, have to reverse the arguments order */
763 args[nrofargs - i - 1] = arg;
764 TRACE("%ld,", arg);
767 TRACE("])\n");
769 /* POP nrofargs DWORD arguments and 3 DWORD parameters */
770 stack16_pop( (3 + nrofargs) * sizeof(DWORD) );
772 return WOW_CallProc32W16( proc32, nrofargs, args );
775 /**********************************************************************
776 * _CallProcEx32W (KERNEL.518)
778 DWORD WINAPIV CallProcEx32W16( DWORD nrofargs, DWORD argconvmask, FARPROC proc32, VA_LIST16 valist )
780 DWORD args[32];
781 unsigned int i;
783 TRACE("(%ld,%ld,%p args[",nrofargs,argconvmask,proc32);
785 for (i=0;i<nrofargs;i++)
787 if (argconvmask & (1<<i))
789 SEGPTR ptr = VA_ARG16( valist, SEGPTR );
790 args[i] = (DWORD)MapSL(ptr);
791 TRACE("%08lx(%p),",ptr,MapSL(ptr));
793 else
795 DWORD arg = VA_ARG16( valist, DWORD );
796 args[i] = arg;
797 TRACE("%ld,", arg);
800 TRACE("])\n");
801 return WOW_CallProc32W16( proc32, nrofargs, args );
805 /**********************************************************************
806 * WOW16Call (KERNEL.500)
808 * FIXME!!!
811 DWORD WINAPIV WOW16Call(WORD x, WORD y, WORD z, VA_LIST16 args)
813 int i;
814 DWORD calladdr;
815 FIXME("(0x%04x,0x%04x,%d),calling (",x,y,z);
817 for (i=0;i<x/2;i++) {
818 WORD a = VA_ARG16(args,WORD);
819 DPRINTF("%04x ",a);
821 calladdr = VA_ARG16(args,DWORD);
822 stack16_pop( 3*sizeof(WORD) + x + sizeof(DWORD) );
823 DPRINTF(") calling address was 0x%08lx\n",calladdr);
824 return 0;
828 /***********************************************************************
829 * CreateThread16 (KERNEL.441)
831 HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
832 FARPROC16 start, SEGPTR param,
833 DWORD flags, LPDWORD id )
835 struct thread_args *args = HeapAlloc( GetProcessHeap(), 0, sizeof(*args) );
836 if (!args) return INVALID_HANDLE_VALUE;
837 args->proc = start;
838 args->param = param;
839 return CreateThread( sa, stack, start_thread16, args, flags, id );