msvcrt: Use the public standard type definitions where possible in msvcrt.h.
[wine.git] / dlls / krnl386.exe16 / kernel.c
blob07a57d0d9372e8aab71fef102844a9274cf92fc8
1 /*
2 * 16-bit kernel initialization code
4 * Copyright 2000 Alexandre Julliard
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define WINE_NO_INLINE_STRING
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winternl.h"
28 #include "wownt32.h"
29 #include "wine/winuser16.h"
31 #include "kernel16_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(module);
36 extern DWORD WINAPI GetProcessFlags( DWORD processid );
38 void *dummy = RaiseException; /* force importing it from kernel32 */
40 static DWORD process_dword;
42 /***********************************************************************
43 * KERNEL thread initialisation routine
45 static void thread_attach(void)
47 /* allocate the 16-bit stack (FIXME: should be done lazily) */
48 HGLOBAL16 hstack = WOWGlobalAlloc16( GMEM_FIXED, 0x10000 );
49 kernel_get_thread_data()->stack_sel = GlobalHandleToSel16( hstack );
50 NtCurrentTeb()->WOW32Reserved = (void *)MAKESEGPTR( kernel_get_thread_data()->stack_sel,
51 0x10000 - sizeof(STACK16FRAME) );
52 memset( (char *)GlobalLock16(hstack) + 0x10000 - sizeof(STACK16FRAME), 0, sizeof(STACK16FRAME) );
56 /***********************************************************************
57 * KERNEL thread finalisation routine
59 static void thread_detach(void)
61 /* free the 16-bit stack */
62 WOWGlobalFree16( kernel_get_thread_data()->stack_sel );
63 NtCurrentTeb()->WOW32Reserved = 0;
64 if (NtCurrentTeb()->Tib.SubSystemTib) TASK_ExitTask();
68 /**************************************************************************
69 * DllMain
71 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
73 switch(reason)
75 case DLL_PROCESS_ATTACH:
76 init_selectors();
77 if (LoadLibrary16( "krnl386.exe" ) < 32) return FALSE;
78 /* fall through */
79 case DLL_THREAD_ATTACH:
80 thread_attach();
81 break;
82 case DLL_THREAD_DETACH:
83 thread_detach();
84 break;
86 return TRUE;
90 /**************************************************************************
91 * DllEntryPoint (KERNEL.669)
93 BOOL WINAPI KERNEL_DllEntryPoint( DWORD reasion, HINSTANCE16 inst, WORD ds,
94 WORD heap, DWORD reserved1, WORD reserved2 )
96 static BOOL done;
98 /* the entry point can be called multiple times */
99 if (done) return TRUE;
100 done = TRUE;
102 /* create the shared heap for broken win95 native dlls */
103 HeapCreate( HEAP_SHARED, 0, 0 );
105 /* setup emulation of protected instructions from 32-bit code */
106 if (GetVersion() & 0x80000000) RtlAddVectoredExceptionHandler( TRUE, INSTR_vectored_handler );
108 /* Initialize 16-bit thunking entry points */
109 if (!WOWTHUNK_Init()) return FALSE;
111 /* Initialize DOS memory */
112 if (!DOSMEM_Init()) return FALSE;
114 /* Initialize special KERNEL entry points */
116 NE_SetEntryPoint( inst, 178, GetWinFlags16() );
118 NE_SetEntryPoint( inst, 454, get_cs() );
119 NE_SetEntryPoint( inst, 455, get_ds() );
121 NE_SetEntryPoint( inst, 183, DOSMEM_0000H ); /* KERNEL.183: __0000H */
122 NE_SetEntryPoint( inst, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
123 NE_SetEntryPoint( inst, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
124 NE_SetEntryPoint( inst, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
126 /* Initialize KERNEL.THHOOK */
127 TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( inst, (LPCSTR)332 )));
128 TASK_CreateMainTask();
130 /* Initialize the real-mode selector entry points */
131 #define SET_ENTRY_POINT( num, addr ) \
132 NE_SetEntryPoint( inst, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
133 DOSMEM_MapDosToLinear(addr), 0x10000, inst, \
134 LDT_FLAGS_DATA ))
136 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
137 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
138 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
139 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
140 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
141 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
142 #undef SET_ENTRY_POINT
144 /* Force loading of some dlls */
145 LoadLibrary16( "system.drv" );
146 LoadLibrary16( "comm.drv" );
148 return TRUE;
151 /***********************************************************************
152 * GetVersion (KERNEL.3)
154 DWORD WINAPI GetVersion16(void)
156 static WORD dosver, winver;
158 if (!dosver) /* not determined yet */
160 RTL_OSVERSIONINFOEXW info;
162 info.dwOSVersionInfoSize = sizeof(info);
163 if (RtlGetVersion( &info )) return 0;
165 if (info.dwMajorVersion <= 3)
166 winver = MAKEWORD( info.dwMajorVersion, info.dwMinorVersion );
167 else
168 winver = MAKEWORD( 3, 95 );
170 switch(info.dwPlatformId)
172 case VER_PLATFORM_WIN32s:
173 switch(MAKELONG( info.dwMinorVersion, info.dwMajorVersion ))
175 case 0x0200:
176 dosver = 0x0303; /* DOS 3.3 for Windows 2.0 */
177 break;
178 case 0x0300:
179 dosver = 0x0500; /* DOS 5.0 for Windows 3.0 */
180 break;
181 default:
182 dosver = 0x0616; /* DOS 6.22 for Windows 3.1 and later */
183 break;
185 break;
186 case VER_PLATFORM_WIN32_WINDOWS:
187 /* DOS 8.0 for WinME, 7.0 for Win95/98 */
188 if (info.dwMinorVersion >= 90) dosver = 0x0800;
189 else dosver = 0x0700;
190 break;
191 case VER_PLATFORM_WIN32_NT:
192 dosver = 0x0500; /* always DOS 5.0 for NT */
193 break;
195 TRACE( "DOS %d.%02d Win %d.%02d\n",
196 HIBYTE(dosver), LOBYTE(dosver), LOBYTE(winver), HIBYTE(winver) );
198 return MAKELONG( winver, dosver );
201 /***********************************************************************
202 * Reserved1 (KERNEL.77)
204 SEGPTR WINAPI KERNEL_AnsiNext16(SEGPTR current)
206 return (*(char *)MapSL(current)) ? current + 1 : current;
209 /***********************************************************************
210 * Reserved2(KERNEL.78)
212 SEGPTR WINAPI KERNEL_AnsiPrev16( SEGPTR start, SEGPTR current )
214 return (current==start)?start:current-1;
217 /***********************************************************************
218 * Reserved3 (KERNEL.79)
220 SEGPTR WINAPI KERNEL_AnsiUpper16( SEGPTR strOrChar )
222 /* uppercase only one char if strOrChar < 0x10000 */
223 if (HIWORD(strOrChar))
225 char *s = MapSL(strOrChar);
226 while (*s)
228 *s = toupper(*s);
229 s++;
231 return strOrChar;
233 else return toupper((char)strOrChar);
236 /***********************************************************************
237 * Reserved4 (KERNEL.80)
239 SEGPTR WINAPI KERNEL_AnsiLower16( SEGPTR strOrChar )
241 /* lowercase only one char if strOrChar < 0x10000 */
242 if (HIWORD(strOrChar))
244 char *s = MapSL(strOrChar);
245 while (*s)
247 *s = tolower(*s);
248 s++;
250 return strOrChar;
252 else return tolower((char)strOrChar);
255 /***********************************************************************
256 * Reserved5 (KERNEL.87)
258 INT16 WINAPI KERNEL_lstrcmp16( LPCSTR str1, LPCSTR str2 )
260 int ret = strcmp( str1, str2 );
262 /* Looks too complicated, but in optimized strcpy we might get
263 * a 32bit wide difference and would truncate it to 16 bit, so
264 * erroneously returning equality. */
265 if (ret < 0) return -1;
266 if (ret > 0) return 1;
267 return 0;
270 /***********************************************************************
271 * lstrcpy (KERNEL.88)
273 SEGPTR WINAPI lstrcpy16( SEGPTR dst, LPCSTR src )
275 if (!lstrcpyA( MapSL(dst), src )) dst = 0;
276 return dst;
279 /***********************************************************************
280 * lstrcat (KERNEL.89)
282 SEGPTR WINAPI lstrcat16( SEGPTR dst, LPCSTR src )
284 /* Windows does not check for NULL pointers here, so we don't either */
285 strcat( MapSL(dst), src );
286 return dst;
289 /***********************************************************************
290 * lstrlen (KERNEL.90)
292 INT16 WINAPI lstrlen16( LPCSTR str )
294 return (INT16)lstrlenA( str );
297 /***********************************************************************
298 * OutputDebugString (KERNEL.115)
300 void WINAPI OutputDebugString16( LPCSTR str )
302 OutputDebugStringA( str );
305 /***********************************************************************
306 * GetWinFlags (KERNEL.132)
308 DWORD WINAPI GetWinFlags16(void)
310 static const long cpuflags[5] = { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
311 SYSTEM_INFO si;
312 OSVERSIONINFOA ovi;
313 DWORD result;
315 GetSystemInfo(&si);
317 /* There doesn't seem to be any Pentium flag. */
318 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
319 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
320 ovi.dwOSVersionInfoSize = sizeof(ovi);
321 GetVersionExA(&ovi);
322 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
323 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
324 return result;
327 /***********************************************************************
328 * GetVersionEx (KERNEL.149)
330 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
332 OSVERSIONINFOA info;
334 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
336 WARN("wrong OSVERSIONINFO size from app\n");
337 return FALSE;
340 info.dwOSVersionInfoSize = sizeof(info);
341 if (!GetVersionExA( &info )) return FALSE;
343 v->dwMajorVersion = info.dwMajorVersion;
344 v->dwMinorVersion = info.dwMinorVersion;
345 v->dwBuildNumber = info.dwBuildNumber;
346 v->dwPlatformId = info.dwPlatformId;
347 strcpy( v->szCSDVersion, info.szCSDVersion );
348 return TRUE;
351 /***********************************************************************
352 * DebugBreak (KERNEL.203)
354 void WINAPI DebugBreak16( CONTEXT *context )
356 EXCEPTION_RECORD rec;
358 rec.ExceptionCode = EXCEPTION_BREAKPOINT;
359 rec.ExceptionFlags = 0;
360 rec.ExceptionRecord = NULL;
361 rec.ExceptionAddress = (LPVOID)context->Eip;
362 rec.NumberParameters = 0;
363 NtRaiseException( &rec, context, TRUE );
366 /***********************************************************************
367 * K329 (KERNEL.329)
369 * TODO:
370 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
372 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
374 memset(lpBuffer, 0xf9 /* DBGFILL_BUFFER */, wBytes);
377 /***********************************************************************
378 * DiagQuery (KERNEL.339)
380 * returns TRUE if Win called with "/b" (bootlog.txt)
382 BOOL16 WINAPI DiagQuery16(void)
384 return FALSE;
387 /***********************************************************************
388 * DiagOutput (KERNEL.340)
390 * writes a debug string into <windir>\bootlog.txt
392 void WINAPI DiagOutput16(LPCSTR str)
394 /* FIXME */
395 TRACE("DIAGOUTPUT:%s\n", debugstr_a(str));
398 /***********************************************************************
399 * hmemcpy (KERNEL.348)
401 void WINAPI hmemcpy16( LPVOID dst, LPCVOID src, LONG count )
403 memcpy( dst, src, count );
406 /***********************************************************************
407 * lstrcpyn (KERNEL.353)
409 SEGPTR WINAPI lstrcpyn16( SEGPTR dst, LPCSTR src, INT16 n )
411 if (!lstrcpynA( MapSL(dst), src, n )) return 0;
412 return dst;
415 /***********************************************************************
416 * lstrcatn (KERNEL.352)
418 SEGPTR WINAPI lstrcatn16( SEGPTR dst, LPCSTR src, INT16 n )
420 LPSTR p = MapSL(dst);
421 LPSTR start = p;
423 while (*p) p++;
424 if ((n -= (p - start)) <= 0) return dst;
425 lstrcpynA( p, src, n );
426 return dst;
429 #if 0 /* Not used at this time. This is here for documentation only */
431 /* WINDEBUGINFO flags values */
432 #define WDI_OPTIONS 0x0001
433 #define WDI_FILTER 0x0002
434 #define WDI_ALLOCBREAK 0x0004
436 /* dwOptions values */
437 #define DBO_CHECKHEAP 0x0001
438 #define DBO_BUFFERFILL 0x0004
439 #define DBO_DISABLEGPTRAPPING 0x0010
440 #define DBO_CHECKFREE 0x0020
442 #define DBO_SILENT 0x8000
444 #define DBO_TRACEBREAK 0x2000
445 #define DBO_WARNINGBREAK 0x1000
446 #define DBO_NOERRORBREAK 0x0800
447 #define DBO_NOFATALBREAK 0x0400
448 #define DBO_INT3BREAK 0x0100
450 /* DebugOutput flags values */
451 #define DBF_TRACE 0x0000
452 #define DBF_WARNING 0x4000
453 #define DBF_ERROR 0x8000
454 #define DBF_FATAL 0xc000
456 /* dwFilter values */
457 #define DBF_KERNEL 0x1000
458 #define DBF_KRN_MEMMAN 0x0001
459 #define DBF_KRN_LOADMODULE 0x0002
460 #define DBF_KRN_SEGMENTLOAD 0x0004
461 #define DBF_USER 0x0800
462 #define DBF_GDI 0x0400
463 #define DBF_MMSYSTEM 0x0040
464 #define DBF_PENWIN 0x0020
465 #define DBF_APPLICATION 0x0008
466 #define DBF_DRIVER 0x0010
468 #endif /* NOLOGERROR */
470 /***********************************************************************
471 * GetWinDebugInfo (KERNEL.355)
473 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
475 FIXME("(%p,%d): stub returning FALSE\n", lpwdi, flags);
476 /* FALSE means not in debugging mode/version */
477 /* Can this type of debugging be used in wine ? */
478 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
479 return FALSE;
482 /***********************************************************************
483 * SetWinDebugInfo (KERNEL.356)
485 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
487 FIXME("(%p): stub returning FALSE\n", lpwdi);
488 /* FALSE means not in debugging mode/version */
489 /* Can this type of debugging be used in wine ? */
490 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
491 return FALSE;
494 /***********************************************************************
495 * UnicodeToAnsi (KERNEL.434)
497 INT16 WINAPI UnicodeToAnsi16( LPCWSTR src, LPSTR dst, INT16 codepage )
499 if ( codepage == -1 ) codepage = CP_ACP;
500 return WideCharToMultiByte( codepage, 0, src, -1, dst, 0x7fffffff, NULL, NULL );
503 /***********************************************************************
504 * VWin32_EventCreate (KERNEL.442)
506 HANDLE WINAPI VWin32_EventCreate(VOID)
508 HANDLE hEvent = CreateEventW( NULL, FALSE, 0, NULL );
509 return ConvertToGlobalHandle( hEvent );
512 /***********************************************************************
513 * VWin32_EventDestroy (KERNEL.443)
515 VOID WINAPI VWin32_EventDestroy(HANDLE event)
517 CloseHandle( event );
520 /***********************************************************************
521 * VWin32_EventWait (KERNEL.450)
523 VOID WINAPI VWin32_EventWait(HANDLE event)
525 DWORD mutex_count;
527 ReleaseThunkLock( &mutex_count );
528 WaitForSingleObject( event, INFINITE );
529 RestoreThunkLock( mutex_count );
532 /***********************************************************************
533 * VWin32_EventSet (KERNEL.451)
534 * KERNEL_479 (KERNEL.479)
536 VOID WINAPI VWin32_EventSet(HANDLE event)
538 SetEvent( event );
541 /***********************************************************************
542 * GetProcAddress32 (KERNEL.453)
544 FARPROC WINAPI GetProcAddress32_16( HMODULE hModule, LPCSTR function )
546 /* FIXME: we used to disable snoop when returning proc for Win16 subsystem */
547 return GetProcAddress( hModule, function );
550 /***********************************************************************
551 * CreateW32Event (KERNEL.457)
553 HANDLE WINAPI CreateW32Event( BOOL manual_reset, BOOL initial_state )
555 return CreateEventW( NULL, manual_reset, initial_state, NULL );
558 /***********************************************************************
559 * SetW32Event (KERNEL.458)
561 BOOL WINAPI SetW32Event( HANDLE handle )
563 return SetEvent( handle );
566 /***********************************************************************
567 * ResetW32Event (KERNEL.459)
569 BOOL WINAPI ResetW32Event( HANDLE handle )
571 return ResetEvent( handle );
574 /***********************************************************************
575 * WaitForSingleObject (KERNEL.460)
577 DWORD WINAPI WaitForSingleObject16( HANDLE handle, DWORD timeout )
579 DWORD retval, mutex_count;
581 ReleaseThunkLock( &mutex_count );
582 retval = WaitForSingleObject( handle, timeout );
583 RestoreThunkLock( mutex_count );
584 return retval;
587 /***********************************************************************
588 * WaitForMultipleObjects (KERNEL.461)
590 DWORD WINAPI WaitForMultipleObjects16( DWORD count, const HANDLE *handles,
591 BOOL wait_all, DWORD timeout )
593 DWORD retval, mutex_count;
595 ReleaseThunkLock( &mutex_count );
596 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
597 RestoreThunkLock( mutex_count );
598 return retval;
601 /***********************************************************************
602 * GetCurrentThreadId (KERNEL.462)
604 DWORD WINAPI GetCurrentThreadId16(void)
606 return GetCurrentThreadId();
609 /***********************************************************************
610 * ExitProcess (KERNEL.466)
612 void WINAPI ExitProcess16( WORD status )
614 DWORD count;
615 ReleaseThunkLock( &count );
616 ExitProcess( status );
619 /***********************************************************************
620 * GetCurrentProcessId (KERNEL.471)
622 DWORD WINAPI GetCurrentProcessId16(void)
624 return GetCurrentProcessId();
627 /*********************************************************************
628 * CloseW32Handle (KERNEL.474)
630 BOOL WINAPI CloseW32Handle( HANDLE handle )
632 return CloseHandle( handle );
635 /***********************************************************************
636 * ConvertToGlobalHandle (KERNEL.476)
638 HANDLE WINAPI ConvertToGlobalHandle16( HANDLE handle )
640 return ConvertToGlobalHandle( handle );
643 /*********************************************************************
644 * MapProcessHandle (KERNEL.483)
646 DWORD WINAPI MapProcessHandle( HANDLE hProcess )
648 return GetProcessId( hProcess );
651 /***********************************************************************
652 * SetProcessDword (KERNEL.484)
653 * 'Of course you cannot directly access Windows internal structures'
655 void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
657 TRACE("(%d, %d)\n", dwProcessID, offset );
659 if (dwProcessID && dwProcessID != GetCurrentProcessId())
661 ERR("%d: process %x not accessible\n", offset, dwProcessID);
662 return;
665 switch ( offset )
667 case GPD_APP_COMPAT_FLAGS:
668 case GPD_LOAD_DONE_EVENT:
669 case GPD_HINSTANCE16:
670 case GPD_WINDOWS_VERSION:
671 case GPD_THDB:
672 case GPD_PDB:
673 case GPD_STARTF_SHELLDATA:
674 case GPD_STARTF_HOTKEY:
675 case GPD_STARTF_SHOWWINDOW:
676 case GPD_STARTF_SIZE:
677 case GPD_STARTF_POSITION:
678 case GPD_STARTF_FLAGS:
679 case GPD_PARENT:
680 case GPD_FLAGS:
681 ERR("Not allowed to modify offset %d\n", offset );
682 break;
683 case GPD_USERDATA:
684 process_dword = value;
685 break;
686 default:
687 ERR("Unknown offset %d\n", offset );
688 break;
692 /***********************************************************************
693 * GetProcessDword (KERNEL.485)
694 * 'Of course you cannot directly access Windows internal structures'
696 DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
698 DWORD x, y;
699 STARTUPINFOW siw;
701 TRACE("(%d, %d)\n", dwProcessID, offset );
703 if (dwProcessID && dwProcessID != GetCurrentProcessId())
705 ERR("%d: process %x not accessible\n", offset, dwProcessID);
706 return 0;
709 switch ( offset )
711 case GPD_APP_COMPAT_FLAGS:
712 return GetAppCompatFlags16(0);
713 case GPD_LOAD_DONE_EVENT:
714 return 0;
715 case GPD_HINSTANCE16:
716 return GetTaskDS16();
717 case GPD_WINDOWS_VERSION:
718 return GetExeVersion16();
719 case GPD_THDB:
720 return (DWORD_PTR)NtCurrentTeb() - 0x10 /* FIXME */;
721 case GPD_PDB:
722 return (DWORD_PTR)NtCurrentTeb()->Peb; /* FIXME: truncating a pointer */
723 case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
724 GetStartupInfoW(&siw);
725 return HandleToULong(siw.hStdOutput);
726 case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
727 GetStartupInfoW(&siw);
728 return HandleToULong(siw.hStdInput);
729 case GPD_STARTF_SHOWWINDOW:
730 GetStartupInfoW(&siw);
731 return siw.wShowWindow;
732 case GPD_STARTF_SIZE:
733 GetStartupInfoW(&siw);
734 x = siw.dwXSize;
735 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
736 y = siw.dwYSize;
737 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
738 return MAKELONG( x, y );
739 case GPD_STARTF_POSITION:
740 GetStartupInfoW(&siw);
741 x = siw.dwX;
742 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
743 y = siw.dwY;
744 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
745 return MAKELONG( x, y );
746 case GPD_STARTF_FLAGS:
747 GetStartupInfoW(&siw);
748 return siw.dwFlags;
749 case GPD_PARENT:
750 return 0;
751 case GPD_FLAGS:
752 return GetProcessFlags(0);
753 case GPD_USERDATA:
754 return process_dword;
755 default:
756 ERR("Unknown offset %d\n", offset );
757 return 0;
761 /***********************************************************************
762 * FreeLibrary32 (KERNEL.486)
764 BOOL WINAPI FreeLibrary32_16( HINSTANCE module )
766 return FreeLibrary( module );
769 /***********************************************************************
770 * GetModuleFileName32 (KERNEL.487)
772 DWORD WINAPI GetModuleFileName32_16( HMODULE module, LPSTR buffer, DWORD size )
774 return GetModuleFileNameA( module, buffer, size );
777 /***********************************************************************
778 * GetModuleHandle32 (KERNEL.488)
780 HMODULE WINAPI GetModuleHandle32_16(LPCSTR module)
782 return GetModuleHandleA( module );
785 /***********************************************************************
786 * RegisterServiceProcess (KERNEL.491)
788 DWORD WINAPI RegisterServiceProcess16( DWORD dwProcessId, DWORD dwType )
790 return 1; /* success */
793 /***********************************************************************
794 * WaitForMultipleObjectsEx (KERNEL.495)
796 DWORD WINAPI WaitForMultipleObjectsEx16( DWORD count, const HANDLE *handles,
797 BOOL wait_all, DWORD timeout, BOOL alertable )
799 DWORD retval, mutex_count;
801 ReleaseThunkLock( &mutex_count );
802 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, alertable );
803 RestoreThunkLock( mutex_count );
804 return retval;
807 /**********************************************************************
808 * VWin32_BoostThreadGroup (KERNEL.535)
810 VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost )
812 FIXME("(0x%08x,%d): stub\n", threadId, boost);
816 /**********************************************************************
817 * VWin32_BoostThreadStatic (KERNEL.536)
819 VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost )
821 FIXME("(0x%08x,%d): stub\n", threadId, boost);
824 /***********************************************************************
825 * EnableDos (KERNEL.41)
826 * DisableDos (KERNEL.42)
827 * GetLastDiskChange (KERNEL.98)
828 * ValidateCodeSegments (KERNEL.100)
829 * KbdRst (KERNEL.123)
830 * EnableKernel (KERNEL.124)
831 * DisableKernel (KERNEL.125)
832 * ValidateFreeSpaces (KERNEL.200)
833 * K237 (KERNEL.237)
834 * BUNNY_351 (KERNEL.351)
835 * PIGLET_361 (KERNEL.361)
837 * Entry point for kernel functions that do nothing.
839 LONG WINAPI KERNEL_nop(void)
841 return 0;
844 /***********************************************************************
845 * ToolHelpHook (KERNEL.341)
846 * see "Undocumented Windows"
848 FARPROC16 WINAPI ToolHelpHook16(FARPROC16 func)
850 static FARPROC16 hook;
852 FIXME("(%p), stub.\n", func);
853 return InterlockedExchangePointer( (void **)&hook, func );
856 /* thunk for 16-bit CreateThread */
857 struct thread_args
859 FARPROC16 proc;
860 DWORD param;
863 static DWORD CALLBACK start_thread16( LPVOID threadArgs )
865 struct thread_args args = *(struct thread_args *)threadArgs;
866 HeapFree( GetProcessHeap(), 0, threadArgs );
867 return K32WOWCallback16( (DWORD)args.proc, args.param );
870 /***********************************************************************
871 * CreateThread16 (KERNEL.441)
873 HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
874 FARPROC16 start, SEGPTR param,
875 DWORD flags, LPDWORD id )
877 struct thread_args *args = HeapAlloc( GetProcessHeap(), 0, sizeof(*args) );
878 if (!args) return INVALID_HANDLE_VALUE;
879 args->proc = start;
880 args->param = param;
881 return CreateThread( sa, stack, start_thread16, args, flags, id );
884 /***********************************************************************
885 * _DebugOutput (KERNEL.328)
887 void WINAPIV _DebugOutput( WORD flags, LPCSTR spec, VA_LIST16 valist )
889 char caller[101];
891 /* Decode caller address */
892 if (!GetModuleName16( GetExePtr(CURRENT_STACK16->cs), caller, sizeof(caller) ))
893 sprintf( caller, "%04X:%04X", CURRENT_STACK16->cs, CURRENT_STACK16->ip );
895 /* FIXME: cannot use wvsnprintf16 from kernel */
896 /* wvsnprintf16( temp, sizeof(temp), spec, valist ); */
898 /* Output */
899 FIXME("%s %04x %s\n", caller, flags, debugstr_a(spec) );