Add LanguageGroup/GeoID enumeration fns.
[wine/hacks.git] / dlls / kernel / wowthunk.c
blob1dc70ad90c26adf596a36d48340898bdecee2499
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 static SEGPTR call16_ret_addr; /* segptr to CallTo16_Ret routine */
93 /***********************************************************************
94 * WOWTHUNK_Init
96 BOOL WOWTHUNK_Init(void)
98 /* allocate the code selector for CallTo16 routines */
99 WORD codesel = SELECTOR_AllocBlock( (void *)Call16_Ret_Start,
100 (char *)Call16_Ret_End - (char *)Call16_Ret_Start,
101 WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
102 if (!codesel) return FALSE;
104 /* Patch the return addresses for CallTo16 routines */
106 CallTo16_DataSelector = wine_get_ds();
107 call16_ret_addr = MAKESEGPTR( codesel, (char*)CallTo16_Ret - (char*)Call16_Ret_Start );
108 CALL32_CBClient_RetAddr =
109 MAKESEGPTR( codesel, (char*)CALL32_CBClient_Ret - (char*)Call16_Ret_Start );
110 CALL32_CBClientEx_RetAddr =
111 MAKESEGPTR( codesel, (char*)CALL32_CBClientEx_Ret - (char*)Call16_Ret_Start );
112 return TRUE;
116 /*************************************************************
117 * fix_selector
119 * Fix a selector load that caused an exception if it's in the
120 * 16-bit relay code.
122 static BOOL fix_selector( CONTEXT *context )
124 WORD *stack;
125 BYTE *instr = (BYTE *)context->Eip;
127 if (instr < &Call16_Start || instr >= &Call16_End) return FALSE;
129 /* skip prefixes */
130 while (*instr == 0x66 || *instr == 0x67) instr++;
132 switch(instr[0])
134 case 0x07: /* pop es */
135 case 0x17: /* pop ss */
136 case 0x1f: /* pop ds */
137 break;
138 case 0x0f: /* extended instruction */
139 switch(instr[1])
141 case 0xa1: /* pop fs */
142 case 0xa9: /* pop gs */
143 break;
144 default:
145 return FALSE;
147 break;
148 default:
149 return FALSE;
151 stack = wine_ldt_get_ptr( context->SegSs, context->Esp );
152 TRACE( "fixing up selector %x for pop instruction\n", *stack );
153 *stack = 0;
154 return TRUE;
158 /*************************************************************
159 * call16_handler
161 * Handler for exceptions occurring in 16-bit code.
163 static DWORD call16_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
164 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **pdispatcher )
166 if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
168 /* unwinding: restore the stack pointer in the TEB, and leave the Win16 mutex */
169 STACK32FRAME *frame32 = (STACK32FRAME *)((char *)frame - offsetof(STACK32FRAME,frame));
170 NtCurrentTeb()->cur_stack = frame32->frame16;
171 _LeaveWin16Lock();
173 else if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
174 record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)
176 if (IS_SELECTOR_SYSTEM(context->SegCs))
178 if (fix_selector( context )) return ExceptionContinueExecution;
180 else
182 SEGPTR gpHandler;
183 DWORD ret = INSTR_EmulateInstruction( record, context );
185 if (ret != ExceptionContinueSearch) return ret;
187 /* check for Win16 __GP handler */
188 if ((gpHandler = HasGPHandler16( MAKESEGPTR( context->SegCs, context->Eip ) )))
190 WORD *stack = wine_ldt_get_ptr( context->SegSs, context->Esp );
191 *--stack = context->SegCs;
192 *--stack = context->Eip;
194 if (!IS_SELECTOR_32BIT(context->SegSs))
195 context->Esp = MAKELONG( LOWORD(context->Esp - 2*sizeof(WORD)),
196 HIWORD(context->Esp) );
197 else
198 context->Esp -= 2*sizeof(WORD);
200 context->SegCs = SELECTOROF( gpHandler );
201 context->Eip = OFFSETOF( gpHandler );
202 return ExceptionContinueExecution;
206 return ExceptionContinueSearch;
210 /*************************************************************
211 * vm86_handler
213 * Handler for exceptions occurring in vm86 code.
215 static DWORD vm86_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
216 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **pdispatcher )
218 if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
219 return ExceptionContinueSearch;
221 if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
222 record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION)
224 return INSTR_EmulateInstruction( record, context );
227 return ExceptionContinueSearch;
231 #else /* __i386__ */
233 BOOL WOWTHUNK_Init(void)
235 return TRUE;
238 #endif /* __i386__ */
242 * 32-bit WOW routines (in WOW32, but actually forwarded to KERNEL32)
245 /**********************************************************************
246 * K32WOWGetDescriptor (KERNEL32.70)
248 BOOL WINAPI K32WOWGetDescriptor( SEGPTR segptr, LPLDT_ENTRY ldtent )
250 return GetThreadSelectorEntry( GetCurrentThread(),
251 segptr >> 16, ldtent );
254 /**********************************************************************
255 * K32WOWGetVDMPointer (KERNEL32.56)
257 LPVOID WINAPI K32WOWGetVDMPointer( DWORD vp, DWORD dwBytes, BOOL fProtectedMode )
259 /* FIXME: add size check too */
261 if ( fProtectedMode )
262 return MapSL( vp );
263 else
264 return DOSMEM_MapRealToLinear( vp );
267 /**********************************************************************
268 * K32WOWGetVDMPointerFix (KERNEL32.68)
270 LPVOID WINAPI K32WOWGetVDMPointerFix( DWORD vp, DWORD dwBytes, BOOL fProtectedMode )
273 * Hmmm. According to the docu, we should call:
275 * GlobalFix16( SELECTOROF(vp) );
277 * But this is unnecessary under Wine, as we never move global
278 * memory segments in linear memory anyway.
280 * (I'm not so sure what we are *supposed* to do if
281 * fProtectedMode is TRUE, anyway ...)
284 return K32WOWGetVDMPointer( vp, dwBytes, fProtectedMode );
287 /**********************************************************************
288 * K32WOWGetVDMPointerUnfix (KERNEL32.69)
290 VOID WINAPI K32WOWGetVDMPointerUnfix( DWORD vp )
293 * See above why we don't call:
295 * GlobalUnfix16( SELECTOROF(vp) );
300 /**********************************************************************
301 * K32WOWGlobalAlloc16 (KERNEL32.59)
303 WORD WINAPI K32WOWGlobalAlloc16( WORD wFlags, DWORD cb )
305 return (WORD)GlobalAlloc16( wFlags, cb );
308 /**********************************************************************
309 * K32WOWGlobalFree16 (KERNEL32.62)
311 WORD WINAPI K32WOWGlobalFree16( WORD hMem )
313 return (WORD)GlobalFree16( (HGLOBAL16)hMem );
316 /**********************************************************************
317 * K32WOWGlobalUnlock16 (KERNEL32.61)
319 BOOL WINAPI K32WOWGlobalUnlock16( WORD hMem )
321 return (BOOL)GlobalUnlock16( (HGLOBAL16)hMem );
324 /**********************************************************************
325 * K32WOWGlobalAllocLock16 (KERNEL32.63)
327 DWORD WINAPI K32WOWGlobalAllocLock16( WORD wFlags, DWORD cb, WORD *phMem )
329 WORD hMem = K32WOWGlobalAlloc16( wFlags, cb );
330 if (phMem) *phMem = hMem;
332 return K32WOWGlobalLock16( hMem );
335 /**********************************************************************
336 * K32WOWGlobalLockSize16 (KERNEL32.65)
338 DWORD WINAPI K32WOWGlobalLockSize16( WORD hMem, PDWORD pcb )
340 if ( pcb )
341 *pcb = GlobalSize16( (HGLOBAL16)hMem );
343 return K32WOWGlobalLock16( hMem );
346 /**********************************************************************
347 * K32WOWGlobalUnlockFree16 (KERNEL32.64)
349 WORD WINAPI K32WOWGlobalUnlockFree16( DWORD vpMem )
351 if ( !K32WOWGlobalUnlock16( HIWORD(vpMem) ) )
352 return FALSE;
354 return K32WOWGlobalFree16( HIWORD(vpMem) );
358 /**********************************************************************
359 * K32WOWYield16 (KERNEL32.66)
361 VOID WINAPI K32WOWYield16( void )
364 * This does the right thing for both Win16 and Win32 tasks.
365 * More or less, at least :-/
367 Yield16();
370 /**********************************************************************
371 * K32WOWDirectedYield16 (KERNEL32.67)
373 VOID WINAPI K32WOWDirectedYield16( WORD htask16 )
376 * Argh. Our scheduler doesn't like DirectedYield by Win32
377 * tasks at all. So we do hope that this routine is indeed
378 * only ever called by Win16 tasks that have thunked up ...
380 DirectedYield16( (HTASK16)htask16 );
384 /***********************************************************************
385 * K32WOWHandle32 (KERNEL32.57)
387 HANDLE WINAPI K32WOWHandle32( WORD handle, WOW_HANDLE_TYPE type )
389 switch ( type )
391 case WOW_TYPE_HWND:
392 case WOW_TYPE_HMENU:
393 case WOW_TYPE_HDWP:
394 case WOW_TYPE_HDROP:
395 case WOW_TYPE_HDC:
396 case WOW_TYPE_HFONT:
397 case WOW_TYPE_HRGN:
398 case WOW_TYPE_HBITMAP:
399 case WOW_TYPE_HBRUSH:
400 case WOW_TYPE_HPALETTE:
401 case WOW_TYPE_HPEN:
402 case WOW_TYPE_HACCEL:
403 return (HANDLE)(ULONG_PTR)handle;
405 case WOW_TYPE_HMETAFILE:
406 FIXME( "conversion of metafile handles not supported yet\n" );
407 return (HANDLE)(ULONG_PTR)handle;
409 case WOW_TYPE_HTASK:
410 return ((TDB *)GlobalLock16(handle))->teb->ClientId.UniqueThread;
412 case WOW_TYPE_FULLHWND:
413 FIXME( "conversion of full window handles not supported yet\n" );
414 return (HANDLE)(ULONG_PTR)handle;
416 default:
417 ERR( "handle 0x%04x of unknown type %d\n", handle, type );
418 return (HANDLE)(ULONG_PTR)handle;
422 /***********************************************************************
423 * K32WOWHandle16 (KERNEL32.58)
425 WORD WINAPI K32WOWHandle16( HANDLE handle, WOW_HANDLE_TYPE type )
427 switch ( type )
429 case WOW_TYPE_HWND:
430 case WOW_TYPE_HMENU:
431 case WOW_TYPE_HDWP:
432 case WOW_TYPE_HDROP:
433 case WOW_TYPE_HDC:
434 case WOW_TYPE_HFONT:
435 case WOW_TYPE_HRGN:
436 case WOW_TYPE_HBITMAP:
437 case WOW_TYPE_HBRUSH:
438 case WOW_TYPE_HPALETTE:
439 case WOW_TYPE_HPEN:
440 case WOW_TYPE_HACCEL:
441 case WOW_TYPE_FULLHWND:
442 if ( HIWORD(handle ) )
443 ERR( "handle %p of type %d has non-zero HIWORD\n", handle, type );
444 return LOWORD(handle);
446 case WOW_TYPE_HMETAFILE:
447 FIXME( "conversion of metafile handles not supported yet\n" );
448 return LOWORD(handle);
450 case WOW_TYPE_HTASK:
451 return TASK_GetTaskFromThread( (DWORD)handle );
453 default:
454 ERR( "handle %p of unknown type %d\n", handle, type );
455 return LOWORD(handle);
459 /**********************************************************************
460 * K32WOWCallback16Ex (KERNEL32.55)
462 BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
463 DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode )
465 #ifdef __i386__
467 * Arguments must be prepared in the correct order by the caller
468 * (both for PASCAL and CDECL calling convention), so we simply
469 * copy them to the 16-bit stack ...
471 WORD *stack = (WORD *)CURRENT_STACK16 - cbArgs / sizeof(WORD);
473 memcpy( stack, pArgs, cbArgs );
475 if (dwFlags & (WCB16_REGS|WCB16_REGS_LONG))
477 CONTEXT *context = (CONTEXT *)pdwRetCode;
479 if (TRACE_ON(relay))
481 DWORD count = cbArgs / sizeof(WORD);
483 DPRINTF("%04lx:CallTo16(func=%04lx:%04x,ds=%04lx",
484 GetCurrentThreadId(),
485 context->SegCs, LOWORD(context->Eip), context->SegDs );
486 while (count) DPRINTF( ",%04x", stack[--count] );
487 DPRINTF(") ss:sp=%04x:%04x",
488 SELECTOROF(NtCurrentTeb()->cur_stack), OFFSETOF(NtCurrentTeb()->cur_stack) );
489 DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x bp=%04x es=%04x fs=%04x\n",
490 (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
491 (WORD)context->Edx, (WORD)context->Esi, (WORD)context->Edi,
492 (WORD)context->Ebp, (WORD)context->SegEs, (WORD)context->SegFs );
493 SYSLEVEL_CheckNotLevel( 2 );
496 if (ISV86(context))
498 EXCEPTION_REGISTRATION_RECORD frame;
499 frame.Handler = vm86_handler;
500 __wine_push_frame( &frame );
501 __wine_enter_vm86( context );
502 __wine_pop_frame( &frame );
504 else
506 /* push return address */
507 if (dwFlags & WCB16_REGS_LONG)
509 *((DWORD *)stack - 1) = HIWORD(call16_ret_addr);
510 *((DWORD *)stack - 2) = LOWORD(call16_ret_addr);
511 cbArgs += 2 * sizeof(DWORD);
513 else
515 *((SEGPTR *)stack - 1) = call16_ret_addr;
516 cbArgs += sizeof(SEGPTR);
519 _EnterWin16Lock();
520 wine_call_to_16_regs( context, cbArgs, call16_handler );
521 _LeaveWin16Lock();
524 if (TRACE_ON(relay))
526 DPRINTF("%04lx:RetFrom16() ss:sp=%04x:%04x ",
527 GetCurrentThreadId(), SELECTOROF(NtCurrentTeb()->cur_stack),
528 OFFSETOF(NtCurrentTeb()->cur_stack));
529 DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x bp=%04x sp=%04x\n",
530 (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
531 (WORD)context->Edx, (WORD)context->Ebp, (WORD)context->Esp );
532 SYSLEVEL_CheckNotLevel( 2 );
535 else
537 DWORD ret;
539 if (TRACE_ON(relay))
541 DWORD count = cbArgs / sizeof(WORD);
543 DPRINTF("%04lx:CallTo16(func=%04x:%04x,ds=%04x",
544 GetCurrentThreadId(), HIWORD(vpfn16), LOWORD(vpfn16),
545 SELECTOROF(NtCurrentTeb()->cur_stack) );
546 while (count) DPRINTF( ",%04x", stack[--count] );
547 DPRINTF(") ss:sp=%04x:%04x\n",
548 SELECTOROF(NtCurrentTeb()->cur_stack), OFFSETOF(NtCurrentTeb()->cur_stack) );
549 SYSLEVEL_CheckNotLevel( 2 );
552 /* push return address */
553 *((SEGPTR *)stack - 1) = call16_ret_addr;
554 cbArgs += sizeof(SEGPTR);
557 * Actually, we should take care whether the called routine cleans up
558 * its stack or not. Fortunately, our wine_call_to_16 core doesn't rely on
559 * the callee to do so; after the routine has returned, the 16-bit
560 * stack pointer is always reset to the position it had before.
562 _EnterWin16Lock();
563 ret = wine_call_to_16( (FARPROC16)vpfn16, cbArgs, call16_handler );
564 if (pdwRetCode) *pdwRetCode = ret;
565 _LeaveWin16Lock();
567 if (TRACE_ON(relay))
569 DPRINTF("%04lx:RetFrom16() ss:sp=%04x:%04x retval=%08lx\n",
570 GetCurrentThreadId(), SELECTOROF(NtCurrentTeb()->cur_stack),
571 OFFSETOF(NtCurrentTeb()->cur_stack), ret);
572 SYSLEVEL_CheckNotLevel( 2 );
575 #else
576 assert(0); /* cannot call to 16-bit on non-Intel architectures */
577 #endif /* __i386__ */
579 return TRUE; /* success */
582 /**********************************************************************
583 * K32WOWCallback16 (KERNEL32.54)
585 DWORD WINAPI K32WOWCallback16( DWORD vpfn16, DWORD dwParam )
587 DWORD ret;
589 if ( !K32WOWCallback16Ex( vpfn16, WCB16_PASCAL,
590 sizeof(DWORD), &dwParam, &ret ) )
591 ret = 0L;
593 return ret;
598 * 16-bit WOW routines (in KERNEL)
601 /**********************************************************************
602 * GetVDMPointer32W (KERNEL.516)
604 DWORD WINAPI GetVDMPointer32W16( SEGPTR vp, UINT16 fMode )
606 GlobalPageLock16(GlobalHandle16(SELECTOROF(vp)));
607 return (DWORD)K32WOWGetVDMPointer( vp, 0, (DWORD)fMode );
610 /***********************************************************************
611 * LoadLibraryEx32W (KERNEL.513)
613 DWORD WINAPI LoadLibraryEx32W16( LPCSTR lpszLibFile, DWORD hFile, DWORD dwFlags )
615 HMODULE hModule;
616 DOS_FULL_NAME full_name;
617 DWORD mutex_count;
618 UNICODE_STRING libfileW;
619 LPCWSTR filenameW;
620 static const WCHAR dllW[] = {'.','D','L','L',0};
622 if (!lpszLibFile)
624 SetLastError(ERROR_INVALID_PARAMETER);
625 return 0;
628 if (!RtlCreateUnicodeStringFromAsciiz(&libfileW, lpszLibFile))
630 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
631 return 0;
634 /* if the file can not be found, call LoadLibraryExA anyway, since it might be
635 a buildin module. This case is handled in MODULE_LoadLibraryExA */
637 filenameW = libfileW.Buffer;
638 if ( DIR_SearchPath( NULL, filenameW, dllW, &full_name, FALSE ) )
639 filenameW = full_name.short_name;
641 ReleaseThunkLock( &mutex_count );
642 hModule = LoadLibraryExW( filenameW, (HANDLE)hFile, dwFlags );
643 RestoreThunkLock( mutex_count );
645 RtlFreeUnicodeString(&libfileW);
647 return (DWORD)hModule;
650 /***********************************************************************
651 * GetProcAddress32W (KERNEL.515)
653 DWORD WINAPI GetProcAddress32W16( DWORD hModule, LPCSTR lpszProc )
655 return (DWORD)GetProcAddress( (HMODULE)hModule, lpszProc );
658 /***********************************************************************
659 * FreeLibrary32W (KERNEL.514)
661 DWORD WINAPI FreeLibrary32W16( DWORD hLibModule )
663 BOOL retv;
664 DWORD mutex_count;
666 ReleaseThunkLock( &mutex_count );
667 retv = FreeLibrary( (HMODULE)hLibModule );
668 RestoreThunkLock( mutex_count );
669 return (DWORD)retv;
673 /**********************************************************************
674 * WOW_CallProc32W
676 static DWORD WOW_CallProc32W16( FARPROC proc32, DWORD nrofargs, DWORD *args )
678 DWORD ret;
679 DWORD mutex_count;
681 ReleaseThunkLock( &mutex_count );
684 * FIXME: If ( nrofargs & CPEX_DEST_CDECL ) != 0, we should call a
685 * 32-bit CDECL routine ...
688 if (!proc32) ret = 0;
689 else switch (nrofargs)
691 case 0: ret = proc32();
692 break;
693 case 1: ret = proc32(args[0]);
694 break;
695 case 2: ret = proc32(args[0],args[1]);
696 break;
697 case 3: ret = proc32(args[0],args[1],args[2]);
698 break;
699 case 4: ret = proc32(args[0],args[1],args[2],args[3]);
700 break;
701 case 5: ret = proc32(args[0],args[1],args[2],args[3],args[4]);
702 break;
703 case 6: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5]);
704 break;
705 case 7: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
706 break;
707 case 8: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]);
708 break;
709 case 9: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]);
710 break;
711 case 10:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9]);
712 break;
713 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]);
714 break;
715 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]);
716 break;
717 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]);
718 break;
719 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]);
720 break;
721 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]);
722 break;
723 default:
724 /* FIXME: should go up to 32 arguments */
725 ERR("Unsupported number of arguments %ld, please report.\n",nrofargs);
726 ret = 0;
727 break;
730 RestoreThunkLock( mutex_count );
732 TRACE("returns %08lx\n",ret);
733 return ret;
736 /**********************************************************************
737 * CallProc32W (KERNEL.517)
739 DWORD WINAPIV CallProc32W16( DWORD nrofargs, DWORD argconvmask, FARPROC proc32, VA_LIST16 valist )
741 DWORD args[32];
742 unsigned int i;
744 TRACE("(%ld,%ld,%p args[",nrofargs,argconvmask,proc32);
746 for (i=0;i<nrofargs;i++)
748 if (argconvmask & (1<<i))
750 SEGPTR ptr = VA_ARG16( valist, SEGPTR );
751 /* pascal convention, have to reverse the arguments order */
752 args[nrofargs - i - 1] = (DWORD)MapSL(ptr);
753 TRACE("%08lx(%p),",ptr,MapSL(ptr));
755 else
757 DWORD arg = VA_ARG16( valist, DWORD );
758 /* pascal convention, have to reverse the arguments order */
759 args[nrofargs - i - 1] = arg;
760 TRACE("%ld,", arg);
763 TRACE("])\n");
765 /* POP nrofargs DWORD arguments and 3 DWORD parameters */
766 stack16_pop( (3 + nrofargs) * sizeof(DWORD) );
768 return WOW_CallProc32W16( proc32, nrofargs, args );
771 /**********************************************************************
772 * _CallProcEx32W (KERNEL.518)
774 DWORD WINAPIV CallProcEx32W16( DWORD nrofargs, DWORD argconvmask, FARPROC proc32, VA_LIST16 valist )
776 DWORD args[32];
777 unsigned int i;
779 TRACE("(%ld,%ld,%p args[",nrofargs,argconvmask,proc32);
781 for (i=0;i<nrofargs;i++)
783 if (argconvmask & (1<<i))
785 SEGPTR ptr = VA_ARG16( valist, SEGPTR );
786 args[i] = (DWORD)MapSL(ptr);
787 TRACE("%08lx(%p),",ptr,MapSL(ptr));
789 else
791 DWORD arg = VA_ARG16( valist, DWORD );
792 args[i] = arg;
793 TRACE("%ld,", arg);
796 TRACE("])\n");
797 return WOW_CallProc32W16( proc32, nrofargs, args );
801 /**********************************************************************
802 * WOW16Call (KERNEL.500)
804 * FIXME!!!
807 DWORD WINAPIV WOW16Call(WORD x, WORD y, WORD z, VA_LIST16 args)
809 int i;
810 DWORD calladdr;
811 FIXME("(0x%04x,0x%04x,%d),calling (",x,y,z);
813 for (i=0;i<x/2;i++) {
814 WORD a = VA_ARG16(args,WORD);
815 DPRINTF("%04x ",a);
817 calladdr = VA_ARG16(args,DWORD);
818 stack16_pop( 3*sizeof(WORD) + x + sizeof(DWORD) );
819 DPRINTF(") calling address was 0x%08lx\n",calladdr);
820 return 0;
824 /***********************************************************************
825 * CreateThread16 (KERNEL.441)
827 HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
828 FARPROC16 start, SEGPTR param,
829 DWORD flags, LPDWORD id )
831 struct thread_args *args = HeapAlloc( GetProcessHeap(), 0, sizeof(*args) );
832 if (!args) return INVALID_HANDLE_VALUE;
833 args->proc = start;
834 args->param = param;
835 return CreateThread( sa, stack, start_thread16, args, flags, id );