4 * Copyright 1995 Alexandre Julliard
12 #include "wine/winbase16.h"
27 #include "selectors.h"
28 #include "stackframe.h"
36 #include "debugtools.h"
42 DECLARE_DEBUG_CHANNEL(relay)
43 DECLARE_DEBUG_CHANNEL(task)
44 DECLARE_DEBUG_CHANNEL(toolhelp)
46 /* Min. number of thunks allocated when creating a new segment */
49 /* Pointer to function to switch to a larger stack */
50 int (*IF1632_CallLargeStack)( int (*func)(), void *arg ) = NULL;
52 /* Pointer to debugger callback routine */
53 void (*TASK_AddTaskEntryBreakpoint)( HTASK16 hTask ) = NULL;
55 static THHOOK DefaultThhook = { 0 };
56 THHOOK *pThhook = &DefaultThhook;
58 #define hCurrentTask (pThhook->CurTDB)
59 #define hFirstTask (pThhook->HeadTDB)
60 #define hLockedTask (pThhook->LockTDB)
62 static UINT16 nTaskCount = 0;
65 /***********************************************************************
68 void TASK_InstallTHHook( THHOOK *pNewThhook )
70 THHOOK *pOldThhook = pThhook;
72 pThhook = pNewThhook? pNewThhook : &DefaultThhook;
74 *pThhook = *pOldThhook;
77 /***********************************************************************
80 HTASK16 TASK_GetNextTask( HTASK16 hTask )
82 TDB* pTask = (TDB*)GlobalLock16(hTask);
84 if (pTask->hNext) return pTask->hNext;
85 return (hFirstTask != hTask) ? hFirstTask : 0;
88 /***********************************************************************
91 static void TASK_LinkTask( HTASK16 hTask )
96 if (!(pTask = (TDB *)GlobalLock16( hTask ))) return;
97 prevTask = &hFirstTask;
100 TDB *prevTaskPtr = (TDB *)GlobalLock16( *prevTask );
101 if (prevTaskPtr->priority >= pTask->priority) break;
102 prevTask = &prevTaskPtr->hNext;
104 pTask->hNext = *prevTask;
110 /***********************************************************************
113 static void TASK_UnlinkTask( HTASK16 hTask )
118 prevTask = &hFirstTask;
119 while (*prevTask && (*prevTask != hTask))
121 pTask = (TDB *)GlobalLock16( *prevTask );
122 prevTask = &pTask->hNext;
126 pTask = (TDB *)GlobalLock16( *prevTask );
127 *prevTask = pTask->hNext;
134 /***********************************************************************
137 * Create a thunk free-list in segment 'handle', starting from offset 'offset'
138 * and containing 'count' entries.
140 static void TASK_CreateThunks( HGLOBAL16 handle, WORD offset, WORD count )
146 pThunk = (THUNKS *)((BYTE *)GlobalLock16( handle ) + offset);
148 pThunk->magic = THUNK_MAGIC;
149 pThunk->free = (int)&pThunk->thunks - (int)pThunk;
151 for (i = 0; i < count-1; i++)
153 free += 8; /* Offset of next thunk */
154 pThunk->thunks[4*i] = free;
156 pThunk->thunks[4*i] = 0; /* Last thunk */
160 /***********************************************************************
163 * Allocate a thunk for MakeProcInstance().
165 static SEGPTR TASK_AllocThunk( HTASK16 hTask )
171 if (!(pTask = (TDB *)GlobalLock16( hTask ))) return 0;
172 sel = pTask->hCSAlias;
173 pThunk = &pTask->thunks;
174 base = (int)pThunk - (int)pTask;
175 while (!pThunk->free)
178 if (!sel) /* Allocate a new segment */
180 sel = GLOBAL_Alloc( GMEM_FIXED, sizeof(THUNKS) + (MIN_THUNKS-1)*8,
181 pTask->hPDB, TRUE, FALSE, FALSE );
182 if (!sel) return (SEGPTR)0;
183 TASK_CreateThunks( sel, 0, MIN_THUNKS );
186 pThunk = (THUNKS *)GlobalLock16( sel );
189 base += pThunk->free;
190 pThunk->free = *(WORD *)((BYTE *)pThunk + pThunk->free);
191 return PTR_SEG_OFF_TO_SEGPTR( sel, base );
195 /***********************************************************************
198 * Free a MakeProcInstance() thunk.
200 static BOOL TASK_FreeThunk( HTASK16 hTask, SEGPTR thunk )
206 if (!(pTask = (TDB *)GlobalLock16( hTask ))) return 0;
207 sel = pTask->hCSAlias;
208 pThunk = &pTask->thunks;
209 base = (int)pThunk - (int)pTask;
210 while (sel && (sel != HIWORD(thunk)))
213 pThunk = (THUNKS *)GlobalLock16( sel );
216 if (!sel) return FALSE;
217 *(WORD *)((BYTE *)pThunk + LOWORD(thunk) - base) = pThunk->free;
218 pThunk->free = LOWORD(thunk) - base;
223 /***********************************************************************
226 * 32-bit entry point for a new task. This function is responsible for
227 * setting up the registers and jumping to the 16-bit entry point.
229 void TASK_CallToStart(void)
231 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
232 NE_MODULE *pModule = NE_GetPtr( pTask->hModule );
233 SEGTABLEENTRY *pSegTable = NE_SEG_TABLE( pModule );
236 /* Add task to 16-bit scheduler pool */
239 /* Registers at initialization must be:
241 * bx stack size in bytes
242 * cx heap size in bytes
243 * si previous app instance
244 * di current app instance
246 * es selector to the PSP
247 * ds dgroup of the application
249 * sp top of the stack
252 memset( &context, 0, sizeof(context) );
253 CS_reg(&context) = GlobalHandleToSel16(pSegTable[pModule->cs - 1].hSeg);
254 DS_reg(&context) = GlobalHandleToSel16(pSegTable[pModule->dgroup - 1].hSeg);
255 ES_reg(&context) = pTask->hPDB;
256 EIP_reg(&context) = pModule->ip;
257 EBX_reg(&context) = pModule->stack_size;
258 ECX_reg(&context) = pModule->heap_size;
259 EDI_reg(&context) = context.SegDs;
261 TRACE_(task)("Starting main program: cs:ip=%04lx:%04x ds=%04lx ss:sp=%04x:%04x\n",
262 CS_reg(&context), IP_reg(&context), DS_reg(&context),
263 SELECTOROF(pTask->thdb->cur_stack),
264 OFFSETOF(pTask->thdb->cur_stack) );
266 Callbacks->CallRegisterShortProc( &context, 0 );
270 /***********************************************************************
273 * NOTE: This routine might be called by a Win32 thread. Thus, we need
274 * to be careful to protect global data structures. We do this
275 * by entering the Win16Lock while linking the task into the
278 BOOL TASK_Create( THDB *thdb, NE_MODULE *pModule, HINSTANCE16 hInstance,
279 HINSTANCE16 hPrevInstance, UINT16 cmdShow)
286 PDB *pdb32 = thdb->process;
287 SEGTABLEENTRY *pSegTable = NE_SEG_TABLE( pModule );
289 /* Allocate the task structure */
291 hTask = GLOBAL_Alloc( GMEM_FIXED | GMEM_ZEROINIT, sizeof(TDB),
292 pModule->self, FALSE, FALSE, FALSE );
293 if (!hTask) return FALSE;
294 pTask = (TDB *)GlobalLock16( hTask );
296 /* Fill the task structure */
299 pTask->hSelf = hTask;
302 if (pModule->flags & NE_FFLAGS_WIN32)
303 pTask->flags |= TDBF_WIN32;
304 if (pModule->lpDosTask)
305 pTask->flags |= TDBF_WINOLDAP;
307 pTask->version = pModule->expected_version;
308 pTask->hInstance = hInstance? hInstance : pModule->self;
309 pTask->hPrevInstance = hPrevInstance;
310 pTask->hModule = pModule->self;
311 pTask->hParent = GetCurrentTask();
312 pTask->magic = TDB_MAGIC;
313 pTask->nCmdShow = cmdShow;
315 pTask->curdrive = DRIVE_GetCurrentDrive() | 0x80;
316 strcpy( pTask->curdir, "\\" );
317 lstrcpynA( pTask->curdir + 1, DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() ),
318 sizeof(pTask->curdir) - 1 );
320 /* Create the thunks block */
322 TASK_CreateThunks( hTask, (int)&pTask->thunks - (int)pTask, 7 );
324 /* Copy the module name */
326 GetModuleName16( pModule->self, name, sizeof(name) );
327 strncpy( pTask->module_name, name, sizeof(pTask->module_name) );
329 /* Allocate a selector for the PDB */
331 pTask->hPDB = GLOBAL_CreateBlock( GMEM_FIXED, &pTask->pdb, sizeof(PDB16),
332 pModule->self, FALSE, FALSE, FALSE, NULL );
336 pTask->pdb.int20 = 0x20cd;
337 pTask->pdb.dispatcher[0] = 0x9a; /* ljmp */
338 PUT_DWORD(&pTask->pdb.dispatcher[1], (DWORD)NE_GetEntryPoint(
339 GetModuleHandle16("KERNEL"), 102 )); /* KERNEL.102 is DOS3Call() */
340 pTask->pdb.savedint22 = INT_GetPMHandler( 0x22 );
341 pTask->pdb.savedint23 = INT_GetPMHandler( 0x23 );
342 pTask->pdb.savedint24 = INT_GetPMHandler( 0x24 );
343 pTask->pdb.fileHandlesPtr =
344 PTR_SEG_OFF_TO_SEGPTR( GlobalHandleToSel16(pTask->hPDB),
345 (int)&((PDB16 *)0)->fileHandles );
346 pTask->pdb.hFileHandles = 0;
347 memset( pTask->pdb.fileHandles, 0xff, sizeof(pTask->pdb.fileHandles) );
348 pTask->pdb.environment = pdb32->env_db->env_sel;
349 pTask->pdb.nbFiles = 20;
351 /* Fill the command line */
353 cmd_line = pdb32->env_db->cmd_line;
354 while (*cmd_line && (*cmd_line != ' ') && (*cmd_line != '\t')) cmd_line++;
355 while ((*cmd_line == ' ') || (*cmd_line == '\t')) cmd_line++;
356 lstrcpynA( pTask->pdb.cmdLine+1, cmd_line, sizeof(pTask->pdb.cmdLine)-1);
357 pTask->pdb.cmdLine[0] = strlen( pTask->pdb.cmdLine + 1 );
359 /* Get the compatibility flags */
361 pTask->compat_flags = GetProfileIntA( "Compatibility", name, 0 );
363 /* Allocate a code segment alias for the TDB */
365 pTask->hCSAlias = GLOBAL_CreateBlock( GMEM_FIXED, (void *)pTask,
366 sizeof(TDB), pTask->hPDB, TRUE,
367 FALSE, FALSE, NULL );
369 /* Set the owner of the environment block */
371 FarSetOwner16( pTask->pdb.environment, pTask->hPDB );
373 /* Default DTA overwrites command-line */
375 pTask->dta = PTR_SEG_OFF_TO_SEGPTR( pTask->hPDB,
376 (int)&pTask->pdb.cmdLine - (int)&pTask->pdb );
378 /* Create scheduler event for 16-bit tasks */
380 if ( !(pTask->flags & TDBF_WIN32) )
382 pTask->hEvent = CreateEventA( NULL, TRUE, FALSE, NULL );
383 pTask->hEvent = ConvertToGlobalHandle( pTask->hEvent );
386 /* Enter task handle into thread and process */
388 pTask->thdb->teb.htask16 = pTask->thdb->process->task = hTask;
389 TRACE_(task)("module='%s' cmdline='%s' task=%04x\n", name, cmd_line, hTask );
391 /* If we have a DGROUP/hInstance, use it for 16-bit stack */
395 if (!(sp = pModule->sp))
396 sp = pSegTable[pModule->ss-1].minsize + pModule->stack_size;
397 sp &= ~1; sp -= sizeof(STACK16FRAME);
398 pTask->thdb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( hInstance, sp );
401 /* If requested, add entry point breakpoint */
403 if ( TASK_AddTaskEntryBreakpoint )
404 TASK_AddTaskEntryBreakpoint( hTask );
406 /* Add the task to the linked list */
408 SYSLEVEL_EnterWin16Lock();
409 TASK_LinkTask( hTask );
410 SYSLEVEL_LeaveWin16Lock();
415 /***********************************************************************
418 static void TASK_DeleteTask( HTASK16 hTask )
423 if (!(pTask = (TDB *)GlobalLock16( hTask ))) return;
426 pTask->magic = 0xdead; /* invalidate signature */
428 /* Delete the Win32 part of the task */
430 /* PROCESS_FreePDB( pTask->thdb->process ); FIXME */
431 /* K32OBJ_DecCount( &pTask->thdb->header ); FIXME */
433 /* Free the selector aliases */
435 GLOBAL_FreeBlock( pTask->hCSAlias );
436 GLOBAL_FreeBlock( pTask->hPDB );
438 /* Free the task module */
440 FreeModule16( pTask->hModule );
442 /* Free the task structure itself */
444 GlobalFree16( hTask );
446 /* Free all memory used by this task (including the 32-bit stack, */
447 /* the environment block and the thunk segments). */
449 GlobalFreeAll16( hPDB );
452 /***********************************************************************
455 void TASK_KillTask( HTASK16 hTask )
459 /* Enter the Win16Lock to protect global data structures */
460 SYSLEVEL_EnterWin16Lock();
462 if ( !hTask ) hTask = GetCurrentTask();
463 pTask = (TDB *)GlobalLock16( hTask );
466 SYSLEVEL_LeaveWin16Lock();
470 TRACE_(task)("Killing task %04x\n", hTask );
472 /* Delete active sockets */
475 WINSOCK_DeleteTaskWSI( pTask, pTask->pwsi );
479 /* Kill DOS VM task */
480 NE_MODULE *pModule = NE_GetPtr( pTask->hModule );
481 if ( pModule->lpDosTask )
482 MZ_KillModule( pModule->lpDosTask );
486 /* Perform USER cleanup */
488 if (pTask->userhandler)
489 pTask->userhandler( hTask, USIG16_TERMINATION, 0,
490 pTask->hInstance, pTask->hQueue );
492 PROCESS_CallUserSignalProc( USIG_PROCESS_EXIT, 0 );
493 PROCESS_CallUserSignalProc( USIG_THREAD_EXIT, 0 ); /* FIXME */
494 PROCESS_CallUserSignalProc( USIG_PROCESS_DESTROY, 0 );
498 TRACE_(task)("this is the last task, exiting\n" );
502 /* FIXME: Hack! Send a message to the initial task so that
503 * the GetMessage wakes up and the initial task can check whether
504 * it is the only remaining one and terminate itself ...
505 * The initial task should probably install hooks or something
506 * to get informed about task termination :-/
508 Callout.PostAppMessage16( PROCESS_Initial()->task, WM_NULL, 0, 0 );
510 /* Remove the task from the list to be sure we never switch back to it */
511 TASK_UnlinkTask( hTask );
514 TDB* p = (TDB *)GlobalLock16( hFirstTask );
517 if( p->hYieldTo == hTask ) p->hYieldTo = 0;
518 p = (TDB *)GlobalLock16( p->hNext );
524 if ( hLockedTask == hTask )
527 TASK_DeleteTask( hTask );
529 /* When deleting the current task ... */
530 if ( hTask == hCurrentTask )
534 /* ... schedule another one ... */
537 /* ... and completely release the Win16Lock, just in case. */
538 ReleaseThunkLock( &lockCount );
543 SYSLEVEL_LeaveWin16Lock();
546 /***********************************************************************
549 * This is where all the magic of task-switching happens!
551 * 16-bit Windows performs non-preemptive (cooperative) multitasking.
552 * This means that each 16-bit task runs until it voluntarily yields
553 * control, at which point the scheduler gets active and selects the
556 * In Wine, all processes, even 16-bit ones, are scheduled preemptively
557 * by the standard scheduler of the underlying OS. As many 16-bit apps
558 * *rely* on the behaviour of the Windows scheduler, however, we have
559 * to simulate that behaviour.
561 * This is achieved as follows: every 16-bit task is at time (except
562 * during task creation and deletion) in one of two states: either it
563 * is the one currently running, then the global variable hCurrentTask
564 * contains its task handle, or it is not currently running, then it
565 * is blocked on a special scheduler event, a global handle to which
566 * is stored in the task struct.
568 * When the current task yields control, this routine gets called. Its
569 * purpose is to determine the next task to be active, signal the
570 * scheduler event of that task, and then put the current task to sleep
571 * waiting for *its* scheduler event to get signalled again.
573 * This routine can get called in a few other special situations as well:
575 * - On creation of a 16-bit task, the Unix process executing the task
576 * calls TASK_Reschedule once it has completed its initialization.
577 * At this point, the task needs to be blocked until its scheduler
578 * event is signalled the first time (this will be done by the parent
579 * process to get the task up and running).
581 * - When the task currently running terminates itself, this routine gets
582 * called and has to schedule another task, *without* blocking the
585 * - When a 32-bit thread posts an event for a 16-bit task, it might be
586 * the case that *no* 16-bit task is currently running. In this case
587 * the task that has now an event pending is to be scheduled.
590 void TASK_Reschedule(void)
592 TDB *pOldTask = NULL, *pNewTask = NULL;
593 HTASK16 hOldTask = 0, hNewTask = 0;
594 enum { MODE_YIELD, MODE_SLEEP, MODE_WAKEUP } mode;
597 SYSLEVEL_EnterWin16Lock();
599 /* Check what we need to do */
600 hOldTask = GetCurrentTask();
601 pOldTask = (TDB *)GlobalLock16( hOldTask );
602 TRACE_(task)( "entered with hCurrentTask %04x by hTask %04x (pid %d)\n",
603 hCurrentTask, hOldTask, getpid() );
605 if ( pOldTask && THREAD_IsWin16( THREAD_Current() ) )
607 /* We are called by an active (non-deleted) 16-bit task */
609 /* If we don't even have a current task, or else the current
610 task has yielded, we'll need to schedule a new task and
611 (possibly) put the calling task to sleep. Otherwise, we
612 only block the caller. */
614 if ( !hCurrentTask || hCurrentTask == hOldTask )
621 /* We are called by a deleted 16-bit task or a 32-bit thread */
623 /* The only situation where we need to do something is if we
624 now do not have a current task. Then, we'll need to wake up
625 some task that has events pending. */
627 if ( !hCurrentTask || hCurrentTask == hOldTask )
632 SYSLEVEL_LeaveWin16Lock();
637 /* Find a task to yield to: check for DirectedYield() */
638 if ( mode == MODE_YIELD && pOldTask && pOldTask->hYieldTo )
640 hNewTask = pOldTask->hYieldTo;
641 pNewTask = (TDB *)GlobalLock16( hNewTask );
642 if( !pNewTask || !pNewTask->nEvents) hNewTask = 0;
643 pOldTask->hYieldTo = 0;
646 /* Find a task to yield to: check for pending events */
647 if ( (mode == MODE_YIELD || mode == MODE_WAKEUP) && !hNewTask )
649 hNewTask = hFirstTask;
652 pNewTask = (TDB *)GlobalLock16( hNewTask );
654 TRACE_(task)( "\ttask = %04x, events = %i\n",
655 hNewTask, pNewTask->nEvents );
657 if (pNewTask->nEvents) break;
658 hNewTask = pNewTask->hNext;
660 if (hLockedTask && (hNewTask != hLockedTask)) hNewTask = 0;
663 /* If we are still the task with highest priority, just return ... */
664 if ( mode == MODE_YIELD && hNewTask == hCurrentTask )
666 TRACE_(task)("returning to the current task (%04x)\n", hCurrentTask );
667 SYSLEVEL_LeaveWin16Lock();
669 /* Allow Win32 threads to thunk down even while a Win16 task is
670 in a tight PeekMessage() or Yield() loop ... */
671 ReleaseThunkLock( &lockCount );
672 RestoreThunkLock( lockCount );
676 /* If no task to yield to found, suspend 16-bit scheduler ... */
677 if ( mode == MODE_YIELD && !hNewTask )
679 TRACE_(task)("No currently active task\n");
683 /* If we found a task to wake up, do it ... */
684 if ( (mode == MODE_YIELD || mode == MODE_WAKEUP) && hNewTask )
686 TRACE_(task)("Switching to task %04x (%.8s)\n",
687 hNewTask, pNewTask->module_name );
689 pNewTask->priority++;
690 TASK_UnlinkTask( hNewTask );
691 TASK_LinkTask( hNewTask );
692 pNewTask->priority--;
694 hCurrentTask = hNewTask;
695 SetEvent( pNewTask->hEvent );
697 /* This is set just in case some app reads it ... */
698 pNewTask->ss_sp = pNewTask->thdb->cur_stack;
701 /* If we need to put the current task to sleep, do it ... */
702 if ( (mode == MODE_YIELD || mode == MODE_SLEEP) && hOldTask != hCurrentTask )
704 ResetEvent( pOldTask->hEvent );
706 ReleaseThunkLock( &lockCount );
707 SYSLEVEL_CheckNotLevel( 1 );
708 WaitForSingleObject( pOldTask->hEvent, INFINITE );
709 RestoreThunkLock( lockCount );
712 SYSLEVEL_LeaveWin16Lock();
715 /***********************************************************************
716 * InitTask (KERNEL.91)
718 * Called by the application startup code.
720 void WINAPI InitTask16( CONTEXT *context )
724 SEGTABLEENTRY *pSegTable;
725 INSTANCEDATA *pinstance;
726 LONG stacklow, stackhi;
728 if (context) EAX_reg(context) = 0;
729 if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return;
730 if (!(pModule = NE_GetPtr( pTask->hModule ))) return;
732 /* Initialize implicitly loaded DLLs */
733 NE_InitializeDLLs( pTask->hModule );
737 /* Registers on return are:
738 * ax 1 if OK, 0 on error
739 * cx stack limit in bytes
740 * dx cmdShow parameter
741 * si instance handle of the previous instance
742 * di instance handle of the new task
743 * es:bx pointer to command-line inside PSP
745 * 0 (=%bp) is pushed on the stack
747 SEGPTR ptr = STACK16_PUSH( pTask->thdb, sizeof(WORD) );
748 *(WORD *)PTR_SEG_TO_LIN(ptr) = 0;
749 SP_reg(context) -= 2;
751 EAX_reg(context) = 1;
753 if (!pTask->pdb.cmdLine[0]) EBX_reg(context) = 0x80;
756 LPBYTE p = &pTask->pdb.cmdLine[1];
757 while ((*p == ' ') || (*p == '\t')) p++;
758 EBX_reg(context) = 0x80 + (p - pTask->pdb.cmdLine);
760 ECX_reg(context) = pModule->stack_size;
761 EDX_reg(context) = pTask->nCmdShow;
762 ESI_reg(context) = (DWORD)pTask->hPrevInstance;
763 EDI_reg(context) = (DWORD)pTask->hInstance;
764 ES_reg (context) = (WORD)pTask->hPDB;
767 /* Initialize the local heap */
768 if ( pModule->heap_size )
770 LocalInit16( pTask->hInstance, 0, pModule->heap_size );
773 /* Initialize the INSTANCEDATA structure */
774 pSegTable = NE_SEG_TABLE( pModule );
775 stacklow = pSegTable[pModule->ss - 1].minsize;
776 stackhi = stacklow + pModule->stack_size;
777 if (stackhi > 0xffff) stackhi = 0xffff;
778 pinstance = (INSTANCEDATA *)PTR_SEG_OFF_TO_LIN(CURRENT_DS, 0);
779 pinstance->stackbottom = stackhi; /* yup, that's right. Confused me too. */
780 pinstance->stacktop = stacklow;
781 pinstance->stackmin = OFFSETOF( pTask->thdb->cur_stack );
785 /***********************************************************************
786 * WaitEvent (KERNEL.30)
788 BOOL16 WINAPI WaitEvent16( HTASK16 hTask )
792 if (!hTask) hTask = GetCurrentTask();
793 pTask = (TDB *)GlobalLock16( hTask );
795 if ( !THREAD_IsWin16( THREAD_Current() ) )
797 FIXME_(task)("called for Win32 thread (%04x)!\n", THREAD_Current()->teb_sel);
801 if (pTask->nEvents > 0)
808 /* When we get back here, we have an event */
810 if (pTask->nEvents > 0) pTask->nEvents--;
815 /***********************************************************************
816 * PostEvent (KERNEL.31)
818 void WINAPI PostEvent16( HTASK16 hTask )
822 if (!hTask) hTask = GetCurrentTask();
823 if (!(pTask = (TDB *)GlobalLock16( hTask ))) return;
825 if ( !THREAD_IsWin16( pTask->thdb ) )
827 FIXME_(task)("called for Win32 thread (%04x)!\n", pTask->thdb->teb_sel );
833 /* If we are a 32-bit task, we might need to wake up the 16-bit scheduler */
834 if ( !THREAD_IsWin16( THREAD_Current() ) )
839 /***********************************************************************
840 * SetPriority (KERNEL.32)
842 void WINAPI SetPriority16( HTASK16 hTask, INT16 delta )
847 if (!hTask) hTask = GetCurrentTask();
848 if (!(pTask = (TDB *)GlobalLock16( hTask ))) return;
849 newpriority = pTask->priority + delta;
850 if (newpriority < -32) newpriority = -32;
851 else if (newpriority > 15) newpriority = 15;
853 pTask->priority = newpriority + 1;
854 TASK_UnlinkTask( hTask );
855 TASK_LinkTask( hTask );
860 /***********************************************************************
861 * LockCurrentTask (KERNEL.33)
863 HTASK16 WINAPI LockCurrentTask16( BOOL16 bLock )
865 if (bLock) hLockedTask = GetCurrentTask();
866 else hLockedTask = 0;
871 /***********************************************************************
872 * IsTaskLocked (KERNEL.122)
874 HTASK16 WINAPI IsTaskLocked16(void)
880 /***********************************************************************
881 * OldYield (KERNEL.117)
883 void WINAPI OldYield16(void)
885 TDB *pCurTask = (TDB *)GlobalLock16( GetCurrentTask() );
887 if ( !THREAD_IsWin16( THREAD_Current() ) )
889 FIXME_(task)("called for Win32 thread (%04x)!\n", THREAD_Current()->teb_sel);
893 if (pCurTask) pCurTask->nEvents++; /* Make sure we get back here */
895 if (pCurTask) pCurTask->nEvents--;
899 /***********************************************************************
900 * DirectedYield (KERNEL.150)
902 void WINAPI DirectedYield16( HTASK16 hTask )
904 TDB *pCurTask = (TDB *)GlobalLock16( GetCurrentTask() );
906 if ( !THREAD_IsWin16( THREAD_Current() ) )
908 FIXME_(task)("called for Win32 thread (%04x)!\n", THREAD_Current()->teb_sel);
912 TRACE_(task)("%04x: DirectedYield(%04x)\n", pCurTask->hSelf, hTask );
914 pCurTask->hYieldTo = hTask;
917 TRACE_(task)("%04x: back from DirectedYield(%04x)\n", pCurTask->hSelf, hTask );
920 /***********************************************************************
921 * Yield16 (KERNEL.29)
923 void WINAPI Yield16(void)
925 TDB *pCurTask = (TDB *)GlobalLock16( GetCurrentTask() );
927 if (pCurTask) pCurTask->hYieldTo = 0;
928 if (pCurTask && pCurTask->hQueue) Callout.UserYield16();
932 /***********************************************************************
933 * KERNEL_490 (KERNEL.490)
935 HTASK16 WINAPI KERNEL_490( HTASK16 someTask )
937 if ( !someTask ) return 0;
939 FIXME_(task)("(%04x): stub\n", someTask );
943 /***********************************************************************
944 * MakeProcInstance16 (KERNEL.51)
946 FARPROC16 WINAPI MakeProcInstance16( FARPROC16 func, HANDLE16 hInstance )
952 ERR_(task)("Ouch ! MakeProcInstance called with func == NULL !\n");
953 return (FARPROC16)0; /* Windows seems to do the same */
955 if (!hInstance) hInstance = CURRENT_DS;
956 thunkaddr = TASK_AllocThunk( GetCurrentTask() );
957 if (!thunkaddr) return (FARPROC16)0;
958 thunk = PTR_SEG_TO_LIN( thunkaddr );
959 lfunc = PTR_SEG_TO_LIN( func );
961 TRACE_(task)("(%08lx,%04x): got thunk %08lx\n",
962 (DWORD)func, hInstance, (DWORD)thunkaddr );
963 if (((lfunc[0]==0x8c) && (lfunc[1]==0xd8)) ||
964 ((lfunc[0]==0x1e) && (lfunc[1]==0x58))
966 FIXME_(task)("thunk would be useless for %p, overwriting with nop;nop;\n", func );
967 lfunc[0]=0x90; /* nop */
968 lfunc[1]=0x90; /* nop */
971 *thunk++ = 0xb8; /* movw instance, %ax */
972 *thunk++ = (BYTE)(hInstance & 0xff);
973 *thunk++ = (BYTE)(hInstance >> 8);
974 *thunk++ = 0xea; /* ljmp func */
975 *(DWORD *)thunk = (DWORD)func;
976 return (FARPROC16)thunkaddr;
980 /***********************************************************************
981 * FreeProcInstance16 (KERNEL.52)
983 void WINAPI FreeProcInstance16( FARPROC16 func )
985 TRACE_(task)("(%08lx)\n", (DWORD)func );
986 TASK_FreeThunk( GetCurrentTask(), (SEGPTR)func );
990 /**********************************************************************
991 * GetCodeHandle (KERNEL.93)
993 HANDLE16 WINAPI GetCodeHandle16( FARPROC16 proc )
996 BYTE *thunk = (BYTE *)PTR_SEG_TO_LIN( proc );
998 /* Return the code segment containing 'proc'. */
999 /* Not sure if this is really correct (shouldn't matter that much). */
1001 /* Check if it is really a thunk */
1002 if ((thunk[0] == 0xb8) && (thunk[3] == 0xea))
1003 handle = GlobalHandle16( thunk[6] + (thunk[7] << 8) );
1005 handle = GlobalHandle16( HIWORD(proc) );
1010 /**********************************************************************
1011 * GetCodeInfo (KERNEL.104)
1013 VOID WINAPI GetCodeInfo16( FARPROC16 proc, SEGINFO *segInfo )
1015 BYTE *thunk = (BYTE *)PTR_SEG_TO_LIN( proc );
1016 NE_MODULE *pModule = NULL;
1017 SEGTABLEENTRY *pSeg = NULL;
1020 /* proc is either a thunk, or else a pair of module handle
1021 and segment number. In the first case, we also need to
1022 extract module and segment number. */
1024 if ((thunk[0] == 0xb8) && (thunk[3] == 0xea))
1026 WORD selector = thunk[6] + (thunk[7] << 8);
1027 pModule = NE_GetPtr( GlobalHandle16( selector ) );
1028 pSeg = pModule? NE_SEG_TABLE( pModule ) : NULL;
1031 for ( segNr = 0; segNr < pModule->seg_count; segNr++, pSeg++ )
1032 if ( GlobalHandleToSel16(pSeg->hSeg) == selector )
1035 if ( pModule && segNr >= pModule->seg_count )
1040 pModule = NE_GetPtr( HIWORD( proc ) );
1041 segNr = LOWORD( proc );
1043 if ( pModule && segNr < pModule->seg_count )
1044 pSeg = NE_SEG_TABLE( pModule ) + segNr;
1047 /* fill in segment information */
1049 segInfo->offSegment = pSeg? pSeg->filepos : 0;
1050 segInfo->cbSegment = pSeg? pSeg->size : 0;
1051 segInfo->flags = pSeg? pSeg->flags : 0;
1052 segInfo->cbAlloc = pSeg? pSeg->minsize : 0;
1053 segInfo->h = pSeg? pSeg->hSeg : 0;
1054 segInfo->alignShift = pModule? pModule->alignment : 0;
1058 /**********************************************************************
1059 * DefineHandleTable16 (KERNEL.94)
1061 BOOL16 WINAPI DefineHandleTable16( WORD wOffset )
1063 return TRUE; /* FIXME */
1067 /***********************************************************************
1068 * SetTaskQueue (KERNEL.34)
1070 HQUEUE16 WINAPI SetTaskQueue16( HTASK16 hTask, HQUEUE16 hQueue )
1075 if (!hTask) hTask = GetCurrentTask();
1076 if (!(pTask = (TDB *)GlobalLock16( hTask ))) return 0;
1078 hPrev = pTask->hQueue;
1079 pTask->hQueue = hQueue;
1085 /***********************************************************************
1086 * GetTaskQueue (KERNEL.35)
1088 HQUEUE16 WINAPI GetTaskQueue16( HTASK16 hTask )
1092 if (!hTask) hTask = GetCurrentTask();
1093 if (!(pTask = (TDB *)GlobalLock16( hTask ))) return 0;
1094 return pTask->hQueue;
1097 /***********************************************************************
1098 * SetThreadQueue (KERNEL.463)
1100 HQUEUE16 WINAPI SetThreadQueue16( DWORD thread, HQUEUE16 hQueue )
1102 THDB *thdb = thread? THREAD_IdToTHDB( thread ) : THREAD_Current();
1103 HQUEUE16 oldQueue = thdb? thdb->teb.queue : 0;
1107 thdb->teb.queue = hQueue;
1109 if ( GetTaskQueue16( thdb->process->task ) == oldQueue )
1110 SetTaskQueue16( thdb->process->task, hQueue );
1116 /***********************************************************************
1117 * GetThreadQueue (KERNEL.464)
1119 HQUEUE16 WINAPI GetThreadQueue16( DWORD thread )
1123 thdb = THREAD_Current();
1124 else if ( HIWORD(thread) )
1125 thdb = THREAD_IdToTHDB( thread );
1126 else if ( IsTask16( (HTASK16)thread ) )
1127 thdb = ((TDB *)GlobalLock16( (HANDLE16)thread ))->thdb;
1129 return (HQUEUE16)(thdb? thdb->teb.queue : 0);
1132 /***********************************************************************
1133 * SetFastQueue (KERNEL.624)
1135 VOID WINAPI SetFastQueue16( DWORD thread, HANDLE hQueue )
1139 thdb = THREAD_Current();
1140 else if ( HIWORD(thread) )
1141 thdb = THREAD_IdToTHDB( thread );
1142 else if ( IsTask16( (HTASK16)thread ) )
1143 thdb = ((TDB *)GlobalLock16( (HANDLE16)thread ))->thdb;
1145 if ( thdb ) thdb->teb.queue = (HQUEUE16) hQueue;
1148 /***********************************************************************
1149 * GetFastQueue (KERNEL.625)
1151 HANDLE WINAPI GetFastQueue16( void )
1153 THDB *thdb = THREAD_Current();
1154 if (!thdb) return 0;
1156 if (!thdb->teb.queue)
1157 Callout.InitThreadInput16( 0, THREAD_IsWin16(thdb)? 4 : 5 );
1159 if (!thdb->teb.queue)
1160 FIXME_(task)("(): should initialize thread-local queue, expect failure!\n" );
1162 return (HANDLE)thdb->teb.queue;
1165 /***********************************************************************
1166 * SwitchStackTo (KERNEL.108)
1168 void WINAPI SwitchStackTo16( WORD seg, WORD ptr, WORD top )
1171 STACK16FRAME *oldFrame, *newFrame;
1172 INSTANCEDATA *pData;
1175 if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return;
1176 if (!(pData = (INSTANCEDATA *)GlobalLock16( seg ))) return;
1177 TRACE_(task)("old=%04x:%04x new=%04x:%04x\n",
1178 SELECTOROF( pTask->thdb->cur_stack ),
1179 OFFSETOF( pTask->thdb->cur_stack ), seg, ptr );
1181 /* Save the old stack */
1183 oldFrame = THREAD_STACK16( pTask->thdb );
1184 /* pop frame + args and push bp */
1185 pData->old_ss_sp = pTask->thdb->cur_stack + sizeof(STACK16FRAME)
1187 *(WORD *)PTR_SEG_TO_LIN(pData->old_ss_sp) = oldFrame->bp;
1188 pData->stacktop = top;
1189 pData->stackmin = ptr;
1190 pData->stackbottom = ptr;
1192 /* Switch to the new stack */
1194 /* Note: we need to take the 3 arguments into account; otherwise,
1195 * the stack will underflow upon return from this function.
1197 copySize = oldFrame->bp - OFFSETOF(pData->old_ss_sp);
1198 copySize += 3 * sizeof(WORD) + sizeof(STACK16FRAME);
1199 pTask->thdb->cur_stack = PTR_SEG_OFF_TO_SEGPTR( seg, ptr - copySize );
1200 newFrame = THREAD_STACK16( pTask->thdb );
1202 /* Copy the stack frame and the local variables to the new stack */
1204 memmove( newFrame, oldFrame, copySize );
1206 *(WORD *)PTR_SEG_OFF_TO_LIN( seg, ptr ) = 0; /* clear previous bp */
1210 /***********************************************************************
1211 * SwitchStackBack (KERNEL.109)
1213 void WINAPI SwitchStackBack16( CONTEXT *context )
1216 STACK16FRAME *oldFrame, *newFrame;
1217 INSTANCEDATA *pData;
1219 if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return;
1220 if (!(pData = (INSTANCEDATA *)GlobalLock16(SELECTOROF(pTask->thdb->cur_stack))))
1222 if (!pData->old_ss_sp)
1224 WARN_(task)("No previous SwitchStackTo\n" );
1227 TRACE_(task)("restoring stack %04x:%04x\n",
1228 SELECTOROF(pData->old_ss_sp), OFFSETOF(pData->old_ss_sp) );
1230 oldFrame = THREAD_STACK16( pTask->thdb );
1232 /* Pop bp from the previous stack */
1234 BP_reg(context) = *(WORD *)PTR_SEG_TO_LIN(pData->old_ss_sp);
1235 pData->old_ss_sp += sizeof(WORD);
1237 /* Switch back to the old stack */
1239 pTask->thdb->cur_stack = pData->old_ss_sp - sizeof(STACK16FRAME);
1240 SS_reg(context) = SELECTOROF(pData->old_ss_sp);
1241 ESP_reg(context) = OFFSETOF(pData->old_ss_sp) - sizeof(DWORD); /*ret addr*/
1242 pData->old_ss_sp = 0;
1244 /* Build a stack frame for the return */
1246 newFrame = THREAD_STACK16( pTask->thdb );
1247 newFrame->frame32 = oldFrame->frame32;
1248 if (TRACE_ON(relay))
1250 newFrame->entry_ip = oldFrame->entry_ip;
1251 newFrame->entry_cs = oldFrame->entry_cs;
1256 /***********************************************************************
1257 * GetTaskQueueDS (KERNEL.118)
1259 void WINAPI GetTaskQueueDS16( CONTEXT *context )
1261 DS_reg(context) = GlobalHandleToSel16( GetTaskQueue16(0) );
1265 /***********************************************************************
1266 * GetTaskQueueES (KERNEL.119)
1268 void WINAPI GetTaskQueueES16( CONTEXT *context )
1270 ES_reg(context) = GlobalHandleToSel16( GetTaskQueue16(0) );
1274 /***********************************************************************
1275 * GetCurrentTask (KERNEL.36)
1277 HTASK16 WINAPI GetCurrentTask(void)
1279 return PROCESS_Current()->task;
1282 DWORD WINAPI WIN16_GetCurrentTask(void)
1284 /* This is the version used by relay code; the first task is */
1285 /* returned in the high word of the result */
1286 return MAKELONG( GetCurrentTask(), hFirstTask );
1290 /***********************************************************************
1291 * GetCurrentPDB (KERNEL.37)
1293 * UNDOC: returns PSP of KERNEL in high word
1295 DWORD WINAPI GetCurrentPDB16(void)
1299 if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return 0;
1300 return MAKELONG(pTask->hPDB, 0); /* FIXME */
1304 /***********************************************************************
1305 * GetInstanceData (KERNEL.54)
1307 INT16 WINAPI GetInstanceData16( HINSTANCE16 instance, WORD buffer, INT16 len )
1309 char *ptr = (char *)GlobalLock16( instance );
1310 if (!ptr || !len) return 0;
1311 if ((int)buffer + len >= 0x10000) len = 0x10000 - buffer;
1312 memcpy( (char *)GlobalLock16(CURRENT_DS) + buffer, ptr + buffer, len );
1317 /***********************************************************************
1318 * GetExeVersion (KERNEL.105)
1320 WORD WINAPI GetExeVersion16(void)
1324 if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return 0;
1325 return pTask->version;
1329 /***********************************************************************
1330 * SetErrorMode16 (KERNEL.107)
1332 UINT16 WINAPI SetErrorMode16( UINT16 mode )
1337 if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return 0;
1338 oldMode = pTask->error_mode;
1339 pTask->error_mode = mode;
1340 pTask->thdb->process->error_mode = mode;
1345 /***********************************************************************
1346 * SetErrorMode32 (KERNEL32.486)
1348 UINT WINAPI SetErrorMode( UINT mode )
1350 return SetErrorMode16( (UINT16)mode );
1354 /***********************************************************************
1355 * GetDOSEnvironment (KERNEL.131)
1357 SEGPTR WINAPI GetDOSEnvironment16(void)
1361 if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return 0;
1362 return PTR_SEG_OFF_TO_SEGPTR( pTask->pdb.environment, 0 );
1366 /***********************************************************************
1367 * GetNumTasks (KERNEL.152)
1369 UINT16 WINAPI GetNumTasks16(void)
1375 /***********************************************************************
1376 * GetTaskDS (KERNEL.155)
1378 * Note: this function apparently returns a DWORD with LOWORD == HIWORD.
1379 * I don't think we need to bother with this.
1381 HINSTANCE16 WINAPI GetTaskDS16(void)
1385 if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return 0;
1386 return pTask->hInstance;
1389 /***********************************************************************
1390 * GetDummyModuleHandleDS (KERNEL.602)
1392 VOID WINAPI GetDummyModuleHandleDS16( CONTEXT *context )
1397 AX_reg( context ) = 0;
1398 if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return;
1399 if (!(pTask->flags & TDBF_WIN32)) return;
1401 selector = GlobalHandleToSel16( pTask->hModule );
1402 DS_reg( context ) = selector;
1403 AX_reg( context ) = selector;
1406 /***********************************************************************
1407 * IsTask (KERNEL.320)
1409 BOOL16 WINAPI IsTask16( HTASK16 hTask )
1413 if (!(pTask = (TDB *)GlobalLock16( hTask ))) return FALSE;
1414 if (GlobalSize16( hTask ) < sizeof(TDB)) return FALSE;
1415 return (pTask->magic == TDB_MAGIC);
1419 /***********************************************************************
1420 * SetTaskSignalProc (KERNEL.38)
1422 * Real 16-bit interface is provided by the THUNK_SetTaskSignalProc.
1424 FARPROC16 WINAPI SetTaskSignalProc( HTASK16 hTask, FARPROC16 proc )
1429 if (!hTask) hTask = GetCurrentTask();
1430 if (!(pTask = (TDB *)GlobalLock16( hTask ))) return NULL;
1431 oldProc = (FARPROC16)pTask->userhandler;
1432 pTask->userhandler = (USERSIGNALPROC)proc;
1437 /***********************************************************************
1438 * SetSigHandler (KERNEL.140)
1440 WORD WINAPI SetSigHandler16( FARPROC16 newhandler, FARPROC16* oldhandler,
1441 UINT16 *oldmode, UINT16 newmode, UINT16 flag )
1443 FIXME_(task)("(%p,%p,%p,%d,%d), unimplemented.\n",
1444 newhandler,oldhandler,oldmode,newmode,flag );
1446 if (flag != 1) return 0;
1447 if (!newmode) newhandler = NULL; /* Default handler */
1452 if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return 0;
1453 if (oldmode) *oldmode = pTask->signal_flags;
1454 pTask->signal_flags = newmode;
1455 if (oldhandler) *oldhandler = pTask->sighandler;
1456 pTask->sighandler = newhandler;
1462 /***********************************************************************
1463 * GlobalNotify (KERNEL.154)
1465 * Note that GlobalNotify does _not_ return the old NotifyProc
1466 * -- contrary to LocalNotify !!
1468 VOID WINAPI GlobalNotify16( FARPROC16 proc )
1472 if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return;
1473 pTask->discardhandler = proc;
1477 /***********************************************************************
1478 * GetExePtr (KERNEL.133)
1480 static HMODULE16 GetExePtrHelper( HANDLE16 handle, HTASK16 *hTask )
1485 /* Check for module handle */
1487 if (!(ptr = GlobalLock16( handle ))) return 0;
1488 if (((NE_MODULE *)ptr)->magic == IMAGE_OS2_SIGNATURE) return handle;
1490 /* Search for this handle inside all tasks */
1492 *hTask = hFirstTask;
1495 TDB *pTask = (TDB *)GlobalLock16( *hTask );
1496 if ((*hTask == handle) ||
1497 (pTask->hInstance == handle) ||
1498 (pTask->hQueue == handle) ||
1499 (pTask->hPDB == handle)) return pTask->hModule;
1500 *hTask = pTask->hNext;
1503 /* Check the owner for module handle */
1505 owner = FarGetOwner16( handle );
1506 if (!(ptr = GlobalLock16( owner ))) return 0;
1507 if (((NE_MODULE *)ptr)->magic == IMAGE_OS2_SIGNATURE) return owner;
1509 /* Search for the owner inside all tasks */
1511 *hTask = hFirstTask;
1514 TDB *pTask = (TDB *)GlobalLock16( *hTask );
1515 if ((*hTask == owner) ||
1516 (pTask->hInstance == owner) ||
1517 (pTask->hQueue == owner) ||
1518 (pTask->hPDB == owner)) return pTask->hModule;
1519 *hTask = pTask->hNext;
1525 HMODULE16 WINAPI GetExePtr( HANDLE16 handle )
1528 return GetExePtrHelper( handle, &dummy );
1531 void WINAPI WIN16_GetExePtr( CONTEXT *context )
1533 WORD *stack = PTR_SEG_OFF_TO_LIN(SS_reg(context), SP_reg(context));
1534 HANDLE16 handle = (HANDLE16)stack[2];
1538 hModule = GetExePtrHelper( handle, &hTask );
1540 AX_reg(context) = CX_reg(context) = hModule;
1541 if (hTask) ES_reg(context) = hTask;
1544 /***********************************************************************
1545 * TaskFirst (TOOLHELP.63)
1547 BOOL16 WINAPI TaskFirst16( TASKENTRY *lpte )
1549 lpte->hNext = hFirstTask;
1550 return TaskNext16( lpte );
1554 /***********************************************************************
1555 * TaskNext (TOOLHELP.64)
1557 BOOL16 WINAPI TaskNext16( TASKENTRY *lpte )
1560 INSTANCEDATA *pInstData;
1562 TRACE_(toolhelp)("(%p): task=%04x\n", lpte, lpte->hNext );
1563 if (!lpte->hNext) return FALSE;
1564 pTask = (TDB *)GlobalLock16( lpte->hNext );
1565 if (!pTask || pTask->magic != TDB_MAGIC) return FALSE;
1566 pInstData = (INSTANCEDATA *)PTR_SEG_OFF_TO_LIN( pTask->hInstance, 0 );
1567 lpte->hTask = lpte->hNext;
1568 lpte->hTaskParent = pTask->hParent;
1569 lpte->hInst = pTask->hInstance;
1570 lpte->hModule = pTask->hModule;
1571 lpte->wSS = SELECTOROF( pTask->thdb->cur_stack );
1572 lpte->wSP = OFFSETOF( pTask->thdb->cur_stack );
1573 lpte->wStackTop = pInstData->stacktop;
1574 lpte->wStackMinimum = pInstData->stackmin;
1575 lpte->wStackBottom = pInstData->stackbottom;
1576 lpte->wcEvents = pTask->nEvents;
1577 lpte->hQueue = pTask->hQueue;
1578 strncpy( lpte->szModule, pTask->module_name, 8 );
1579 lpte->szModule[8] = '\0';
1580 lpte->wPSPOffset = 0x100; /*??*/
1581 lpte->hNext = pTask->hNext;
1586 /***********************************************************************
1587 * TaskFindHandle (TOOLHELP.65)
1589 BOOL16 WINAPI TaskFindHandle16( TASKENTRY *lpte, HTASK16 hTask )
1591 lpte->hNext = hTask;
1592 return TaskNext16( lpte );
1596 /***********************************************************************
1597 * GetAppCompatFlags16 (KERNEL.354)
1599 DWORD WINAPI GetAppCompatFlags16( HTASK16 hTask )
1601 return GetAppCompatFlags( hTask );
1605 /***********************************************************************
1606 * GetAppCompatFlags32 (USER32.206)
1608 DWORD WINAPI GetAppCompatFlags( HTASK hTask )
1612 if (!hTask) hTask = GetCurrentTask();
1613 if (!(pTask=(TDB *)GlobalLock16( (HTASK16)hTask ))) return 0;
1614 if (GlobalSize16(hTask) < sizeof(TDB)) return 0;
1615 return pTask->compat_flags;