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
22 #include "wine/port.h"
26 #include "wine/winbase16.h"
36 #include "stackframe.h"
37 #include "wine/exception.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(thunk);
41 WINE_DECLARE_DEBUG_CHANNEL(relay);
44 * These are the 16-bit side WOW routines. They reside in wownt16.h
45 * in the SDK; since we don't support Win16 source code anyway, I've
46 * placed them here for compilation with Wine ...
49 DWORD WINAPI GetVDMPointer32W16(SEGPTR,UINT16);
51 DWORD WINAPI LoadLibraryEx32W16(LPCSTR,DWORD,DWORD);
52 DWORD WINAPI GetProcAddress32W16(DWORD,LPCSTR);
53 DWORD WINAPI FreeLibrary32W16(DWORD);
55 #define CPEX_DEST_STDCALL 0x00000000L
56 #define CPEX_DEST_CDECL 0x80000000L
58 /* thunk for 16-bit CreateThread */
65 static DWORD CALLBACK start_thread16( LPVOID threadArgs )
67 struct thread_args args = *(struct thread_args *)threadArgs;
68 HeapFree( GetProcessHeap(), 0, threadArgs );
69 return K32WOWCallback16( (DWORD)args.proc, args.param );
75 /* symbols exported from relay16.s */
76 extern DWORD WINAPI wine_call_to_16( FARPROC16 target, DWORD cbArgs, PEXCEPTION_HANDLER handler );
77 extern void WINAPI wine_call_to_16_regs( CONTEXT86 *context, DWORD cbArgs, PEXCEPTION_HANDLER handler );
78 extern void Call16_Ret_Start(), Call16_Ret_End();
79 extern void CallTo16_Ret();
80 extern void CALL32_CBClient_Ret();
81 extern void CALL32_CBClientEx_Ret();
82 extern DWORD CallTo16_DataSelector;
83 extern SEGPTR CALL32_CBClient_RetAddr;
84 extern SEGPTR CALL32_CBClientEx_RetAddr;
85 extern BYTE Call16_Start;
86 extern BYTE Call16_End;
88 static SEGPTR call16_ret_addr; /* segptr to CallTo16_Ret routine */
90 /***********************************************************************
93 BOOL WOWTHUNK_Init(void)
95 /* allocate the code selector for CallTo16 routines */
96 WORD codesel = SELECTOR_AllocBlock( (void *)Call16_Ret_Start,
97 (char *)Call16_Ret_End - (char *)Call16_Ret_Start,
98 WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
99 if (!codesel) return FALSE;
101 /* Patch the return addresses for CallTo16 routines */
103 CallTo16_DataSelector = wine_get_ds();
104 call16_ret_addr = MAKESEGPTR( codesel, (char*)CallTo16_Ret - (char*)Call16_Ret_Start );
105 CALL32_CBClient_RetAddr =
106 MAKESEGPTR( codesel, (char*)CALL32_CBClient_Ret - (char*)Call16_Ret_Start );
107 CALL32_CBClientEx_RetAddr =
108 MAKESEGPTR( codesel, (char*)CALL32_CBClientEx_Ret - (char*)Call16_Ret_Start );
113 /*************************************************************
116 * Fix a selector load that caused an exception if it's in the
119 static BOOL fix_selector( CONTEXT *context )
122 BYTE *instr = (BYTE *)context->Eip;
124 if (instr < &Call16_Start || instr >= &Call16_End) return FALSE;
127 while (*instr == 0x66 || *instr == 0x67) instr++;
131 case 0x07: /* pop es */
132 case 0x17: /* pop ss */
133 case 0x1f: /* pop ds */
135 case 0x0f: /* extended instruction */
138 case 0xa1: /* pop fs */
139 case 0xa9: /* pop gs */
148 stack = wine_ldt_get_ptr( context->SegSs, context->Esp );
149 TRACE( "fixing up selector %x for pop instruction\n", *stack );
155 /*************************************************************
158 * Handler for exceptions occurring in 16-bit code.
160 static DWORD call16_handler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_RECORD *frame,
161 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **pdispatcher )
163 if (record->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
165 /* unwinding: restore the stack pointer in the TEB, and leave the Win16 mutex */
166 STACK32FRAME *frame32 = (STACK32FRAME *)((char *)frame - offsetof(STACK32FRAME,frame));
167 NtCurrentTeb()->cur_stack = frame32->frame16;
172 if (IS_SELECTOR_SYSTEM(context->SegCs))
174 if (fix_selector( context )) return ExceptionContinueExecution;
176 else /* check for Win16 __GP handler */
178 SEGPTR gpHandler = HasGPHandler16( MAKESEGPTR( context->SegCs, context->Eip ) );
181 WORD *stack = wine_ldt_get_ptr( context->SegSs, context->Esp );
182 *--stack = context->SegCs;
183 *--stack = context->Eip;
185 if (!IS_SELECTOR_32BIT(context->SegSs))
186 context->Esp = MAKELONG( LOWORD(context->Esp - 2*sizeof(WORD)),
187 HIWORD(context->Esp) );
189 context->Esp -= 2*sizeof(WORD);
191 context->SegCs = SELECTOROF( gpHandler );
192 context->Eip = OFFSETOF( gpHandler );
193 return ExceptionContinueExecution;
197 return ExceptionContinueSearch;
202 BOOL WOWTHUNK_Init(void)
207 #endif /* __i386__ */
211 * 32-bit WOW routines (in WOW32, but actually forwarded to KERNEL32)
214 /**********************************************************************
215 * K32WOWGetDescriptor (KERNEL32.70)
217 BOOL WINAPI K32WOWGetDescriptor( SEGPTR segptr, LPLDT_ENTRY ldtent )
219 return GetThreadSelectorEntry( GetCurrentThread(),
220 segptr >> 16, ldtent );
223 /**********************************************************************
224 * K32WOWGetVDMPointer (KERNEL32.56)
226 LPVOID WINAPI K32WOWGetVDMPointer( DWORD vp, DWORD dwBytes, BOOL fProtectedMode )
228 /* FIXME: add size check too */
230 if ( fProtectedMode )
233 return DOSMEM_MapRealToLinear( vp );
236 /**********************************************************************
237 * K32WOWGetVDMPointerFix (KERNEL32.68)
239 LPVOID WINAPI K32WOWGetVDMPointerFix( DWORD vp, DWORD dwBytes, BOOL fProtectedMode )
242 * Hmmm. According to the docu, we should call:
244 * GlobalFix16( SELECTOROF(vp) );
246 * But this is unnecessary under Wine, as we never move global
247 * memory segments in linear memory anyway.
249 * (I'm not so sure what we are *supposed* to do if
250 * fProtectedMode is TRUE, anyway ...)
253 return K32WOWGetVDMPointer( vp, dwBytes, fProtectedMode );
256 /**********************************************************************
257 * K32WOWGetVDMPointerUnfix (KERNEL32.69)
259 VOID WINAPI K32WOWGetVDMPointerUnfix( DWORD vp )
262 * See above why we don't call:
264 * GlobalUnfix16( SELECTOROF(vp) );
269 /**********************************************************************
270 * K32WOWGlobalAlloc16 (KERNEL32.59)
272 WORD WINAPI K32WOWGlobalAlloc16( WORD wFlags, DWORD cb )
274 return (WORD)GlobalAlloc16( wFlags, cb );
277 /**********************************************************************
278 * K32WOWGlobalFree16 (KERNEL32.62)
280 WORD WINAPI K32WOWGlobalFree16( WORD hMem )
282 return (WORD)GlobalFree16( (HGLOBAL16)hMem );
285 /**********************************************************************
286 * K32WOWGlobalUnlock16 (KERNEL32.61)
288 BOOL WINAPI K32WOWGlobalUnlock16( WORD hMem )
290 return (BOOL)GlobalUnlock16( (HGLOBAL16)hMem );
293 /**********************************************************************
294 * K32WOWGlobalAllocLock16 (KERNEL32.63)
296 DWORD WINAPI K32WOWGlobalAllocLock16( WORD wFlags, DWORD cb, WORD *phMem )
298 WORD hMem = K32WOWGlobalAlloc16( wFlags, cb );
299 if (phMem) *phMem = hMem;
301 return K32WOWGlobalLock16( hMem );
304 /**********************************************************************
305 * K32WOWGlobalLockSize16 (KERNEL32.65)
307 DWORD WINAPI K32WOWGlobalLockSize16( WORD hMem, PDWORD pcb )
310 *pcb = GlobalSize16( (HGLOBAL16)hMem );
312 return K32WOWGlobalLock16( hMem );
315 /**********************************************************************
316 * K32WOWGlobalUnlockFree16 (KERNEL32.64)
318 WORD WINAPI K32WOWGlobalUnlockFree16( DWORD vpMem )
320 if ( !K32WOWGlobalUnlock16( HIWORD(vpMem) ) )
323 return K32WOWGlobalFree16( HIWORD(vpMem) );
327 /**********************************************************************
328 * K32WOWYield16 (KERNEL32.66)
330 VOID WINAPI K32WOWYield16( void )
333 * This does the right thing for both Win16 and Win32 tasks.
334 * More or less, at least :-/
339 /**********************************************************************
340 * K32WOWDirectedYield16 (KERNEL32.67)
342 VOID WINAPI K32WOWDirectedYield16( WORD htask16 )
345 * Argh. Our scheduler doesn't like DirectedYield by Win32
346 * tasks at all. So we do hope that this routine is indeed
347 * only ever called by Win16 tasks that have thunked up ...
349 DirectedYield16( (HTASK16)htask16 );
353 /***********************************************************************
354 * K32WOWHandle32 (KERNEL32.57)
356 HANDLE WINAPI K32WOWHandle32( WORD handle, WOW_HANDLE_TYPE type )
367 case WOW_TYPE_HBITMAP:
368 case WOW_TYPE_HBRUSH:
369 case WOW_TYPE_HPALETTE:
371 case WOW_TYPE_HACCEL:
372 return (HANDLE)(ULONG_PTR)handle;
374 case WOW_TYPE_HMETAFILE:
375 FIXME( "conversion of metafile handles not supported yet\n" );
376 return (HANDLE)(ULONG_PTR)handle;
379 return ((TDB *)GlobalLock16(handle))->teb->ClientId.UniqueThread;
381 case WOW_TYPE_FULLHWND:
382 FIXME( "conversion of full window handles not supported yet\n" );
383 return (HANDLE)(ULONG_PTR)handle;
386 ERR( "handle 0x%04x of unknown type %d\n", handle, type );
387 return (HANDLE)(ULONG_PTR)handle;
391 /***********************************************************************
392 * K32WOWHandle16 (KERNEL32.58)
394 WORD WINAPI K32WOWHandle16( HANDLE handle, WOW_HANDLE_TYPE type )
405 case WOW_TYPE_HBITMAP:
406 case WOW_TYPE_HBRUSH:
407 case WOW_TYPE_HPALETTE:
409 case WOW_TYPE_HACCEL:
410 case WOW_TYPE_FULLHWND:
411 if ( HIWORD(handle ) )
412 ERR( "handle %p of type %d has non-zero HIWORD\n", handle, type );
413 return LOWORD(handle);
415 case WOW_TYPE_HMETAFILE:
416 FIXME( "conversion of metafile handles not supported yet\n" );
417 return LOWORD(handle);
420 return TASK_GetTaskFromThread( (DWORD)handle );
423 ERR( "handle %p of unknown type %d\n", handle, type );
424 return LOWORD(handle);
428 /**********************************************************************
429 * K32WOWCallback16Ex (KERNEL32.55)
431 BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
432 DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode )
436 * Arguments must be prepared in the correct order by the caller
437 * (both for PASCAL and CDECL calling convention), so we simply
438 * copy them to the 16-bit stack ...
440 WORD *stack = (WORD *)CURRENT_STACK16 - cbArgs / sizeof(WORD);
442 memcpy( stack, pArgs, cbArgs );
444 if (dwFlags & (WCB16_REGS|WCB16_REGS_LONG))
446 CONTEXT *context = (CONTEXT *)pdwRetCode;
450 DWORD count = cbArgs / sizeof(WORD);
452 DPRINTF("%04lx:CallTo16(func=%04lx:%04x,ds=%04lx",
453 GetCurrentThreadId(),
454 context->SegCs, LOWORD(context->Eip), context->SegDs );
455 while (count) DPRINTF( ",%04x", stack[--count] );
456 DPRINTF(") ss:sp=%04x:%04x",
457 SELECTOROF(NtCurrentTeb()->cur_stack), OFFSETOF(NtCurrentTeb()->cur_stack) );
458 DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x bp=%04x es=%04x fs=%04x\n",
459 (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
460 (WORD)context->Edx, (WORD)context->Esi, (WORD)context->Edi,
461 (WORD)context->Ebp, (WORD)context->SegEs, (WORD)context->SegFs );
462 SYSLEVEL_CheckNotLevel( 2 );
465 /* push return address */
466 if (dwFlags & WCB16_REGS_LONG)
468 *((DWORD *)stack - 1) = HIWORD(call16_ret_addr);
469 *((DWORD *)stack - 2) = LOWORD(call16_ret_addr);
470 cbArgs += 2 * sizeof(DWORD);
474 *((SEGPTR *)stack - 1) = call16_ret_addr;
475 cbArgs += sizeof(SEGPTR);
479 wine_call_to_16_regs( context, cbArgs, call16_handler );
484 DPRINTF("%04lx:RetFrom16() ss:sp=%04x:%04x ",
485 GetCurrentThreadId(), SELECTOROF(NtCurrentTeb()->cur_stack),
486 OFFSETOF(NtCurrentTeb()->cur_stack));
487 DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x bp=%04x sp=%04x\n",
488 (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
489 (WORD)context->Edx, (WORD)context->Ebp, (WORD)context->Esp );
490 SYSLEVEL_CheckNotLevel( 2 );
499 DWORD count = cbArgs / sizeof(WORD);
501 DPRINTF("%04lx:CallTo16(func=%04x:%04x,ds=%04x",
502 GetCurrentThreadId(), HIWORD(vpfn16), LOWORD(vpfn16),
503 SELECTOROF(NtCurrentTeb()->cur_stack) );
504 while (count) DPRINTF( ",%04x", stack[--count] );
505 DPRINTF(") ss:sp=%04x:%04x\n",
506 SELECTOROF(NtCurrentTeb()->cur_stack), OFFSETOF(NtCurrentTeb()->cur_stack) );
507 SYSLEVEL_CheckNotLevel( 2 );
510 /* push return address */
511 *((SEGPTR *)stack - 1) = call16_ret_addr;
512 cbArgs += sizeof(SEGPTR);
515 * Actually, we should take care whether the called routine cleans up
516 * its stack or not. Fortunately, our wine_call_to_16 core doesn't rely on
517 * the callee to do so; after the routine has returned, the 16-bit
518 * stack pointer is always reset to the position it had before.
521 ret = wine_call_to_16( (FARPROC16)vpfn16, cbArgs, call16_handler );
522 if (pdwRetCode) *pdwRetCode = ret;
527 DPRINTF("%04lx:RetFrom16() ss:sp=%04x:%04x retval=%08lx\n",
528 GetCurrentThreadId(), SELECTOROF(NtCurrentTeb()->cur_stack),
529 OFFSETOF(NtCurrentTeb()->cur_stack), ret);
530 SYSLEVEL_CheckNotLevel( 2 );
534 assert(0); /* cannot call to 16-bit on non-Intel architectures */
535 #endif /* __i386__ */
537 return TRUE; /* success */
540 /**********************************************************************
541 * K32WOWCallback16 (KERNEL32.54)
543 DWORD WINAPI K32WOWCallback16( DWORD vpfn16, DWORD dwParam )
547 if ( !K32WOWCallback16Ex( vpfn16, WCB16_PASCAL,
548 sizeof(DWORD), &dwParam, &ret ) )
556 * 16-bit WOW routines (in KERNEL)
559 /**********************************************************************
560 * GetVDMPointer32W (KERNEL.516)
562 DWORD WINAPI GetVDMPointer32W16( SEGPTR vp, UINT16 fMode )
564 GlobalPageLock16(GlobalHandle16(SELECTOROF(vp)));
565 return (DWORD)K32WOWGetVDMPointer( vp, 0, (DWORD)fMode );
568 /***********************************************************************
569 * LoadLibraryEx32W (KERNEL.513)
571 DWORD WINAPI LoadLibraryEx32W16( LPCSTR lpszLibFile, DWORD hFile, DWORD dwFlags )
574 DOS_FULL_NAME full_name;
576 UNICODE_STRING libfileW;
578 static const WCHAR dllW[] = {'.','D','L','L',0};
582 SetLastError(ERROR_INVALID_PARAMETER);
586 if (!RtlCreateUnicodeStringFromAsciiz(&libfileW, lpszLibFile))
588 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
592 /* if the file can not be found, call LoadLibraryExA anyway, since it might be
593 a buildin module. This case is handled in MODULE_LoadLibraryExA */
595 filenameW = libfileW.Buffer;
596 if ( DIR_SearchPath( NULL, filenameW, dllW, &full_name, FALSE ) )
597 filenameW = full_name.short_name;
599 ReleaseThunkLock( &mutex_count );
600 hModule = LoadLibraryExW( filenameW, (HANDLE)hFile, dwFlags );
601 RestoreThunkLock( mutex_count );
603 RtlFreeUnicodeString(&libfileW);
605 return (DWORD)hModule;
608 /***********************************************************************
609 * GetProcAddress32W (KERNEL.515)
611 DWORD WINAPI GetProcAddress32W16( DWORD hModule, LPCSTR lpszProc )
613 return (DWORD)GetProcAddress( (HMODULE)hModule, lpszProc );
616 /***********************************************************************
617 * FreeLibrary32W (KERNEL.514)
619 DWORD WINAPI FreeLibrary32W16( DWORD hLibModule )
624 ReleaseThunkLock( &mutex_count );
625 retv = FreeLibrary( (HMODULE)hLibModule );
626 RestoreThunkLock( mutex_count );
631 /**********************************************************************
634 static DWORD WOW_CallProc32W16( FARPROC proc32, DWORD nrofargs, DWORD *args )
639 ReleaseThunkLock( &mutex_count );
642 * FIXME: If ( nrofargs & CPEX_DEST_CDECL ) != 0, we should call a
643 * 32-bit CDECL routine ...
646 if (!proc32) ret = 0;
647 else switch (nrofargs)
649 case 0: ret = proc32();
651 case 1: ret = proc32(args[0]);
653 case 2: ret = proc32(args[0],args[1]);
655 case 3: ret = proc32(args[0],args[1],args[2]);
657 case 4: ret = proc32(args[0],args[1],args[2],args[3]);
659 case 5: ret = proc32(args[0],args[1],args[2],args[3],args[4]);
661 case 6: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5]);
663 case 7: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
665 case 8: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]);
667 case 9: ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]);
669 case 10:ret = proc32(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9]);
671 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]);
673 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]);
675 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]);
677 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]);
679 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]);
682 /* FIXME: should go up to 32 arguments */
683 ERR("Unsupported number of arguments %ld, please report.\n",nrofargs);
688 RestoreThunkLock( mutex_count );
690 TRACE("returns %08lx\n",ret);
694 /**********************************************************************
695 * CallProc32W (KERNEL.517)
697 DWORD WINAPIV CallProc32W16( DWORD nrofargs, DWORD argconvmask, FARPROC proc32, VA_LIST16 valist )
702 TRACE("(%ld,%ld,%p args[",nrofargs,argconvmask,proc32);
704 for (i=0;i<nrofargs;i++)
706 if (argconvmask & (1<<i))
708 SEGPTR ptr = VA_ARG16( valist, SEGPTR );
709 /* pascal convention, have to reverse the arguments order */
710 args[nrofargs - i - 1] = (DWORD)MapSL(ptr);
711 TRACE("%08lx(%p),",ptr,MapSL(ptr));
715 DWORD arg = VA_ARG16( valist, DWORD );
716 /* pascal convention, have to reverse the arguments order */
717 args[nrofargs - i - 1] = arg;
723 /* POP nrofargs DWORD arguments and 3 DWORD parameters */
724 stack16_pop( (3 + nrofargs) * sizeof(DWORD) );
726 return WOW_CallProc32W16( proc32, nrofargs, args );
729 /**********************************************************************
730 * _CallProcEx32W (KERNEL.518)
732 DWORD WINAPIV CallProcEx32W16( DWORD nrofargs, DWORD argconvmask, FARPROC proc32, VA_LIST16 valist )
737 TRACE("(%ld,%ld,%p args[",nrofargs,argconvmask,proc32);
739 for (i=0;i<nrofargs;i++)
741 if (argconvmask & (1<<i))
743 SEGPTR ptr = VA_ARG16( valist, SEGPTR );
744 args[i] = (DWORD)MapSL(ptr);
745 TRACE("%08lx(%p),",ptr,MapSL(ptr));
749 DWORD arg = VA_ARG16( valist, DWORD );
755 return WOW_CallProc32W16( proc32, nrofargs, args );
759 /**********************************************************************
760 * WOW16Call (KERNEL.500)
765 DWORD WINAPIV WOW16Call(WORD x, WORD y, WORD z, VA_LIST16 args)
769 FIXME("(0x%04x,0x%04x,%d),calling (",x,y,z);
771 for (i=0;i<x/2;i++) {
772 WORD a = VA_ARG16(args,WORD);
775 calladdr = VA_ARG16(args,DWORD);
776 stack16_pop( 3*sizeof(WORD) + x + sizeof(DWORD) );
777 DPRINTF(") calling address was 0x%08lx\n",calladdr);
782 /***********************************************************************
783 * CreateThread16 (KERNEL.441)
785 HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
786 FARPROC16 start, SEGPTR param,
787 DWORD flags, LPDWORD id )
789 struct thread_args *args = HeapAlloc( GetProcessHeap(), 0, sizeof(*args) );
790 if (!args) return INVALID_HANDLE_VALUE;
793 return CreateThread( sa, stack, start_thread16, args, flags, id );