imagehlp: Use the IMAGE_FIRST_SECTION helper macro.
[wine.git] / dlls / krnl386.exe16 / kernel.c
blob5891c7e05880f99982a32f2089c51d7f6a4f78d1
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 CURRENT_SS = kernel_get_thread_data()->stack_sel = GlobalHandleToSel16( hstack );
50 CURRENT_SP = 0x10000 - sizeof(STACK16FRAME);
51 memset( (char *)GlobalLock16(hstack) + 0x10000 - sizeof(STACK16FRAME), 0, sizeof(STACK16FRAME) );
55 /***********************************************************************
56 * KERNEL thread finalisation routine
58 static void thread_detach(void)
60 /* free the 16-bit stack */
61 WOWGlobalFree16( kernel_get_thread_data()->stack_sel );
62 CURRENT_SS = CURRENT_SP = 0;
63 if (NtCurrentTeb()->Tib.SubSystemTib) TASK_ExitTask();
67 /**************************************************************************
68 * DllMain
70 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
72 switch(reason)
74 case DLL_PROCESS_ATTACH:
75 init_selectors();
76 if (LoadLibrary16( "krnl386.exe" ) < 32) return FALSE;
77 /* fall through */
78 case DLL_THREAD_ATTACH:
79 thread_attach();
80 break;
81 case DLL_THREAD_DETACH:
82 thread_detach();
83 break;
85 return TRUE;
89 /**************************************************************************
90 * DllEntryPoint (KERNEL.669)
92 BOOL WINAPI KERNEL_DllEntryPoint( DWORD reasion, HINSTANCE16 inst, WORD ds,
93 WORD heap, DWORD reserved1, WORD reserved2 )
95 static BOOL done;
97 /* the entry point can be called multiple times */
98 if (done) return TRUE;
99 done = TRUE;
101 /* create the shared heap for broken win95 native dlls */
102 HeapCreate( HEAP_SHARED, 0, 0 );
104 /* setup emulation of protected instructions from 32-bit code */
105 if (GetVersion() & 0x80000000) RtlAddVectoredExceptionHandler( TRUE, INSTR_vectored_handler );
107 /* Initialize 16-bit thunking entry points */
108 if (!WOWTHUNK_Init()) return FALSE;
110 /* Initialize DOS memory */
111 if (!DOSMEM_Init()) return FALSE;
113 /* Initialize special KERNEL entry points */
115 NE_SetEntryPoint( inst, 178, GetWinFlags16() );
117 NE_SetEntryPoint( inst, 454, get_cs() );
118 NE_SetEntryPoint( inst, 455, get_ds() );
120 NE_SetEntryPoint( inst, 183, DOSMEM_0000H ); /* KERNEL.183: __0000H */
121 NE_SetEntryPoint( inst, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
122 NE_SetEntryPoint( inst, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
123 NE_SetEntryPoint( inst, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
125 /* Initialize KERNEL.THHOOK */
126 TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( inst, (LPCSTR)332 )));
127 TASK_CreateMainTask();
129 /* Initialize the real-mode selector entry points */
130 #define SET_ENTRY_POINT( num, addr ) \
131 NE_SetEntryPoint( inst, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
132 DOSMEM_MapDosToLinear(addr), 0x10000, inst, \
133 LDT_FLAGS_DATA ))
135 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
136 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
137 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
138 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
139 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
140 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
141 #undef SET_ENTRY_POINT
143 /* Force loading of some dlls */
144 LoadLibrary16( "system.drv" );
145 LoadLibrary16( "comm.drv" );
147 return TRUE;
150 /***********************************************************************
151 * GetVersion (KERNEL.3)
153 DWORD WINAPI GetVersion16(void)
155 static WORD dosver, winver;
157 if (!dosver) /* not determined yet */
159 RTL_OSVERSIONINFOEXW info;
161 info.dwOSVersionInfoSize = sizeof(info);
162 if (RtlGetVersion( &info )) return 0;
164 if (info.dwMajorVersion <= 3)
165 winver = MAKEWORD( info.dwMajorVersion, info.dwMinorVersion );
166 else
167 winver = MAKEWORD( 3, 95 );
169 switch(info.dwPlatformId)
171 case VER_PLATFORM_WIN32s:
172 switch(MAKELONG( info.dwMinorVersion, info.dwMajorVersion ))
174 case 0x0200:
175 dosver = 0x0303; /* DOS 3.3 for Windows 2.0 */
176 break;
177 case 0x0300:
178 dosver = 0x0500; /* DOS 5.0 for Windows 3.0 */
179 break;
180 default:
181 dosver = 0x0616; /* DOS 6.22 for Windows 3.1 and later */
182 break;
184 break;
185 case VER_PLATFORM_WIN32_WINDOWS:
186 /* DOS 8.0 for WinME, 7.0 for Win95/98 */
187 if (info.dwMinorVersion >= 90) dosver = 0x0800;
188 else dosver = 0x0700;
189 break;
190 case VER_PLATFORM_WIN32_NT:
191 dosver = 0x0500; /* always DOS 5.0 for NT */
192 break;
194 TRACE( "DOS %d.%02d Win %d.%02d\n",
195 HIBYTE(dosver), LOBYTE(dosver), LOBYTE(winver), HIBYTE(winver) );
197 return MAKELONG( winver, dosver );
200 /***********************************************************************
201 * Reserved1 (KERNEL.77)
203 SEGPTR WINAPI KERNEL_AnsiNext16(SEGPTR current)
205 return (*(char *)MapSL(current)) ? current + 1 : current;
208 /***********************************************************************
209 * Reserved2(KERNEL.78)
211 SEGPTR WINAPI KERNEL_AnsiPrev16( SEGPTR start, SEGPTR current )
213 return (current==start)?start:current-1;
216 /***********************************************************************
217 * Reserved3 (KERNEL.79)
219 SEGPTR WINAPI KERNEL_AnsiUpper16( SEGPTR strOrChar )
221 /* uppercase only one char if strOrChar < 0x10000 */
222 if (HIWORD(strOrChar))
224 char *s = MapSL(strOrChar);
225 while (*s)
227 *s = toupper(*s);
228 s++;
230 return strOrChar;
232 else return toupper((char)strOrChar);
235 /***********************************************************************
236 * Reserved4 (KERNEL.80)
238 SEGPTR WINAPI KERNEL_AnsiLower16( SEGPTR strOrChar )
240 /* lowercase only one char if strOrChar < 0x10000 */
241 if (HIWORD(strOrChar))
243 char *s = MapSL(strOrChar);
244 while (*s)
246 *s = tolower(*s);
247 s++;
249 return strOrChar;
251 else return tolower((char)strOrChar);
254 /***********************************************************************
255 * Reserved5 (KERNEL.87)
257 INT16 WINAPI KERNEL_lstrcmp16( LPCSTR str1, LPCSTR str2 )
259 int ret = strcmp( str1, str2 );
261 /* Looks too complicated, but in optimized strcpy we might get
262 * a 32bit wide difference and would truncate it to 16 bit, so
263 * erroneously returning equality. */
264 if (ret < 0) return -1;
265 if (ret > 0) return 1;
266 return 0;
269 /***********************************************************************
270 * lstrcpy (KERNEL.88)
272 SEGPTR WINAPI lstrcpy16( SEGPTR dst, LPCSTR src )
274 if (!lstrcpyA( MapSL(dst), src )) dst = 0;
275 return dst;
278 /***********************************************************************
279 * lstrcat (KERNEL.89)
281 SEGPTR WINAPI lstrcat16( SEGPTR dst, LPCSTR src )
283 /* Windows does not check for NULL pointers here, so we don't either */
284 strcat( MapSL(dst), src );
285 return dst;
288 /***********************************************************************
289 * lstrlen (KERNEL.90)
291 INT16 WINAPI lstrlen16( LPCSTR str )
293 return (INT16)lstrlenA( str );
296 /***********************************************************************
297 * OutputDebugString (KERNEL.115)
299 void WINAPI OutputDebugString16( LPCSTR str )
301 OutputDebugStringA( str );
304 /***********************************************************************
305 * GetWinFlags (KERNEL.132)
307 DWORD WINAPI GetWinFlags16(void)
309 static const long cpuflags[5] = { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
310 SYSTEM_INFO si;
311 OSVERSIONINFOA ovi;
312 DWORD result;
314 GetSystemInfo(&si);
316 /* There doesn't seem to be any Pentium flag. */
317 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
318 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
319 ovi.dwOSVersionInfoSize = sizeof(ovi);
320 GetVersionExA(&ovi);
321 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
322 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
323 return result;
326 /***********************************************************************
327 * GetVersionEx (KERNEL.149)
329 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
331 OSVERSIONINFOA info;
333 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
335 WARN("wrong OSVERSIONINFO size from app\n");
336 return FALSE;
339 info.dwOSVersionInfoSize = sizeof(info);
340 if (!GetVersionExA( &info )) return FALSE;
342 v->dwMajorVersion = info.dwMajorVersion;
343 v->dwMinorVersion = info.dwMinorVersion;
344 v->dwBuildNumber = info.dwBuildNumber;
345 v->dwPlatformId = info.dwPlatformId;
346 strcpy( v->szCSDVersion, info.szCSDVersion );
347 return TRUE;
350 /***********************************************************************
351 * DebugBreak (KERNEL.203)
353 void WINAPI DebugBreak16( CONTEXT *context )
355 EXCEPTION_RECORD rec;
357 rec.ExceptionCode = EXCEPTION_BREAKPOINT;
358 rec.ExceptionFlags = 0;
359 rec.ExceptionRecord = NULL;
360 rec.ExceptionAddress = (LPVOID)context->Eip;
361 rec.NumberParameters = 0;
362 NtRaiseException( &rec, context, TRUE );
365 /***********************************************************************
366 * K329 (KERNEL.329)
368 * TODO:
369 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
371 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
373 memset(lpBuffer, 0xf9 /* DBGFILL_BUFFER */, wBytes);
376 /***********************************************************************
377 * DiagQuery (KERNEL.339)
379 * returns TRUE if Win called with "/b" (bootlog.txt)
381 BOOL16 WINAPI DiagQuery16(void)
383 return FALSE;
386 /***********************************************************************
387 * DiagOutput (KERNEL.340)
389 * writes a debug string into <windir>\bootlog.txt
391 void WINAPI DiagOutput16(LPCSTR str)
393 /* FIXME */
394 TRACE("DIAGOUTPUT:%s\n", debugstr_a(str));
397 /***********************************************************************
398 * hmemcpy (KERNEL.348)
400 void WINAPI hmemcpy16( LPVOID dst, LPCVOID src, LONG count )
402 memcpy( dst, src, count );
405 /***********************************************************************
406 * lstrcpyn (KERNEL.353)
408 SEGPTR WINAPI lstrcpyn16( SEGPTR dst, LPCSTR src, INT16 n )
410 if (!lstrcpynA( MapSL(dst), src, n )) return 0;
411 return dst;
414 /***********************************************************************
415 * lstrcatn (KERNEL.352)
417 SEGPTR WINAPI lstrcatn16( SEGPTR dst, LPCSTR src, INT16 n )
419 LPSTR p = MapSL(dst);
420 LPSTR start = p;
422 while (*p) p++;
423 if ((n -= (p - start)) <= 0) return dst;
424 lstrcpynA( p, src, n );
425 return dst;
428 #if 0 /* Not used at this time. This is here for documentation only */
430 /* WINDEBUGINFO flags values */
431 #define WDI_OPTIONS 0x0001
432 #define WDI_FILTER 0x0002
433 #define WDI_ALLOCBREAK 0x0004
435 /* dwOptions values */
436 #define DBO_CHECKHEAP 0x0001
437 #define DBO_BUFFERFILL 0x0004
438 #define DBO_DISABLEGPTRAPPING 0x0010
439 #define DBO_CHECKFREE 0x0020
441 #define DBO_SILENT 0x8000
443 #define DBO_TRACEBREAK 0x2000
444 #define DBO_WARNINGBREAK 0x1000
445 #define DBO_NOERRORBREAK 0x0800
446 #define DBO_NOFATALBREAK 0x0400
447 #define DBO_INT3BREAK 0x0100
449 /* DebugOutput flags values */
450 #define DBF_TRACE 0x0000
451 #define DBF_WARNING 0x4000
452 #define DBF_ERROR 0x8000
453 #define DBF_FATAL 0xc000
455 /* dwFilter values */
456 #define DBF_KERNEL 0x1000
457 #define DBF_KRN_MEMMAN 0x0001
458 #define DBF_KRN_LOADMODULE 0x0002
459 #define DBF_KRN_SEGMENTLOAD 0x0004
460 #define DBF_USER 0x0800
461 #define DBF_GDI 0x0400
462 #define DBF_MMSYSTEM 0x0040
463 #define DBF_PENWIN 0x0020
464 #define DBF_APPLICATION 0x0008
465 #define DBF_DRIVER 0x0010
467 #endif /* NOLOGERROR */
469 /***********************************************************************
470 * GetWinDebugInfo (KERNEL.355)
472 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
474 FIXME("(%p,%d): stub returning FALSE\n", lpwdi, flags);
475 /* FALSE means not in debugging mode/version */
476 /* Can this type of debugging be used in wine ? */
477 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
478 return FALSE;
481 /***********************************************************************
482 * SetWinDebugInfo (KERNEL.356)
484 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
486 FIXME("(%p): stub returning FALSE\n", lpwdi);
487 /* FALSE means not in debugging mode/version */
488 /* Can this type of debugging be used in wine ? */
489 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
490 return FALSE;
493 /***********************************************************************
494 * UnicodeToAnsi (KERNEL.434)
496 INT16 WINAPI UnicodeToAnsi16( LPCWSTR src, LPSTR dst, INT16 codepage )
498 if ( codepage == -1 ) codepage = CP_ACP;
499 return WideCharToMultiByte( codepage, 0, src, -1, dst, 0x7fffffff, NULL, NULL );
502 /***********************************************************************
503 * VWin32_EventCreate (KERNEL.442)
505 HANDLE WINAPI VWin32_EventCreate(VOID)
507 HANDLE hEvent = CreateEventW( NULL, FALSE, 0, NULL );
508 return ConvertToGlobalHandle( hEvent );
511 /***********************************************************************
512 * VWin32_EventDestroy (KERNEL.443)
514 VOID WINAPI VWin32_EventDestroy(HANDLE event)
516 CloseHandle( event );
519 /***********************************************************************
520 * VWin32_EventWait (KERNEL.450)
522 VOID WINAPI VWin32_EventWait(HANDLE event)
524 DWORD mutex_count;
526 ReleaseThunkLock( &mutex_count );
527 WaitForSingleObject( event, INFINITE );
528 RestoreThunkLock( mutex_count );
531 /***********************************************************************
532 * VWin32_EventSet (KERNEL.451)
533 * KERNEL_479 (KERNEL.479)
535 VOID WINAPI VWin32_EventSet(HANDLE event)
537 SetEvent( event );
540 /***********************************************************************
541 * GetProcAddress32 (KERNEL.453)
543 FARPROC WINAPI GetProcAddress32_16( HMODULE hModule, LPCSTR function )
545 /* FIXME: we used to disable snoop when returning proc for Win16 subsystem */
546 return GetProcAddress( hModule, function );
549 /***********************************************************************
550 * CreateW32Event (KERNEL.457)
552 HANDLE WINAPI CreateW32Event( BOOL manual_reset, BOOL initial_state )
554 return CreateEventW( NULL, manual_reset, initial_state, NULL );
557 /***********************************************************************
558 * SetW32Event (KERNEL.458)
560 BOOL WINAPI SetW32Event( HANDLE handle )
562 return SetEvent( handle );
565 /***********************************************************************
566 * ResetW32Event (KERNEL.459)
568 BOOL WINAPI ResetW32Event( HANDLE handle )
570 return ResetEvent( handle );
573 /***********************************************************************
574 * WaitForSingleObject (KERNEL.460)
576 DWORD WINAPI WaitForSingleObject16( HANDLE handle, DWORD timeout )
578 DWORD retval, mutex_count;
580 ReleaseThunkLock( &mutex_count );
581 retval = WaitForSingleObject( handle, timeout );
582 RestoreThunkLock( mutex_count );
583 return retval;
586 /***********************************************************************
587 * WaitForMultipleObjects (KERNEL.461)
589 DWORD WINAPI WaitForMultipleObjects16( DWORD count, const HANDLE *handles,
590 BOOL wait_all, DWORD timeout )
592 DWORD retval, mutex_count;
594 ReleaseThunkLock( &mutex_count );
595 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
596 RestoreThunkLock( mutex_count );
597 return retval;
600 /***********************************************************************
601 * GetCurrentThreadId (KERNEL.462)
603 DWORD WINAPI GetCurrentThreadId16(void)
605 return GetCurrentThreadId();
608 /***********************************************************************
609 * ExitProcess (KERNEL.466)
611 void WINAPI ExitProcess16( WORD status )
613 DWORD count;
614 ReleaseThunkLock( &count );
615 ExitProcess( status );
618 /***********************************************************************
619 * GetCurrentProcessId (KERNEL.471)
621 DWORD WINAPI GetCurrentProcessId16(void)
623 return GetCurrentProcessId();
626 /*********************************************************************
627 * CloseW32Handle (KERNEL.474)
629 BOOL WINAPI CloseW32Handle( HANDLE handle )
631 return CloseHandle( handle );
634 /***********************************************************************
635 * ConvertToGlobalHandle (KERNEL.476)
637 HANDLE WINAPI ConvertToGlobalHandle16( HANDLE handle )
639 return ConvertToGlobalHandle( handle );
642 /*********************************************************************
643 * MapProcessHandle (KERNEL.483)
645 DWORD WINAPI MapProcessHandle( HANDLE hProcess )
647 return GetProcessId( hProcess );
650 /***********************************************************************
651 * SetProcessDword (KERNEL.484)
652 * 'Of course you cannot directly access Windows internal structures'
654 void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
656 TRACE("(%ld, %d)\n", dwProcessID, offset );
658 if (dwProcessID && dwProcessID != GetCurrentProcessId())
660 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
661 return;
664 switch ( offset )
666 case GPD_APP_COMPAT_FLAGS:
667 case GPD_LOAD_DONE_EVENT:
668 case GPD_HINSTANCE16:
669 case GPD_WINDOWS_VERSION:
670 case GPD_THDB:
671 case GPD_PDB:
672 case GPD_STARTF_SHELLDATA:
673 case GPD_STARTF_HOTKEY:
674 case GPD_STARTF_SHOWWINDOW:
675 case GPD_STARTF_SIZE:
676 case GPD_STARTF_POSITION:
677 case GPD_STARTF_FLAGS:
678 case GPD_PARENT:
679 case GPD_FLAGS:
680 ERR("Not allowed to modify offset %d\n", offset );
681 break;
682 case GPD_USERDATA:
683 process_dword = value;
684 break;
685 default:
686 ERR("Unknown offset %d\n", offset );
687 break;
691 /***********************************************************************
692 * GetProcessDword (KERNEL.485)
693 * 'Of course you cannot directly access Windows internal structures'
695 DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
697 DWORD x, y;
698 STARTUPINFOW siw;
700 TRACE("(%ld, %d)\n", dwProcessID, offset );
702 if (dwProcessID && dwProcessID != GetCurrentProcessId())
704 ERR("%d: process %lx not accessible\n", offset, dwProcessID);
705 return 0;
708 switch ( offset )
710 case GPD_APP_COMPAT_FLAGS:
711 return GetAppCompatFlags16(0);
712 case GPD_LOAD_DONE_EVENT:
713 return 0;
714 case GPD_HINSTANCE16:
715 return GetTaskDS16();
716 case GPD_WINDOWS_VERSION:
717 return GetExeVersion16();
718 case GPD_THDB:
719 return (DWORD_PTR)NtCurrentTeb() - 0x10 /* FIXME */;
720 case GPD_PDB:
721 return (DWORD_PTR)NtCurrentTeb()->Peb; /* FIXME: truncating a pointer */
722 case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
723 GetStartupInfoW(&siw);
724 return HandleToULong(siw.hStdOutput);
725 case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
726 GetStartupInfoW(&siw);
727 return HandleToULong(siw.hStdInput);
728 case GPD_STARTF_SHOWWINDOW:
729 GetStartupInfoW(&siw);
730 return siw.wShowWindow;
731 case GPD_STARTF_SIZE:
732 GetStartupInfoW(&siw);
733 x = siw.dwXSize;
734 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
735 y = siw.dwYSize;
736 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
737 return MAKELONG( x, y );
738 case GPD_STARTF_POSITION:
739 GetStartupInfoW(&siw);
740 x = siw.dwX;
741 if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
742 y = siw.dwY;
743 if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
744 return MAKELONG( x, y );
745 case GPD_STARTF_FLAGS:
746 GetStartupInfoW(&siw);
747 return siw.dwFlags;
748 case GPD_PARENT:
749 return 0;
750 case GPD_FLAGS:
751 return GetProcessFlags(0);
752 case GPD_USERDATA:
753 return process_dword;
754 default:
755 ERR("Unknown offset %d\n", offset );
756 return 0;
760 /***********************************************************************
761 * FreeLibrary32 (KERNEL.486)
763 BOOL WINAPI FreeLibrary32_16( HINSTANCE module )
765 return FreeLibrary( module );
768 /***********************************************************************
769 * GetModuleFileName32 (KERNEL.487)
771 DWORD WINAPI GetModuleFileName32_16( HMODULE module, LPSTR buffer, DWORD size )
773 return GetModuleFileNameA( module, buffer, size );
776 /***********************************************************************
777 * GetModuleHandle32 (KERNEL.488)
779 HMODULE WINAPI GetModuleHandle32_16(LPCSTR module)
781 return GetModuleHandleA( module );
784 /***********************************************************************
785 * RegisterServiceProcess (KERNEL.491)
787 DWORD WINAPI RegisterServiceProcess16( DWORD dwProcessId, DWORD dwType )
789 return 1; /* success */
792 /***********************************************************************
793 * WaitForMultipleObjectsEx (KERNEL.495)
795 DWORD WINAPI WaitForMultipleObjectsEx16( DWORD count, const HANDLE *handles,
796 BOOL wait_all, DWORD timeout, BOOL alertable )
798 DWORD retval, mutex_count;
800 ReleaseThunkLock( &mutex_count );
801 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, alertable );
802 RestoreThunkLock( mutex_count );
803 return retval;
806 /**********************************************************************
807 * VWin32_BoostThreadGroup (KERNEL.535)
809 VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost )
811 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
815 /**********************************************************************
816 * VWin32_BoostThreadStatic (KERNEL.536)
818 VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost )
820 FIXME("(0x%08lx,%d): stub\n", threadId, boost);
823 /***********************************************************************
824 * EnableDos (KERNEL.41)
825 * DisableDos (KERNEL.42)
826 * GetLastDiskChange (KERNEL.98)
827 * ValidateCodeSegments (KERNEL.100)
828 * KbdRst (KERNEL.123)
829 * EnableKernel (KERNEL.124)
830 * DisableKernel (KERNEL.125)
831 * ValidateFreeSpaces (KERNEL.200)
832 * K237 (KERNEL.237)
833 * BUNNY_351 (KERNEL.351)
834 * PIGLET_361 (KERNEL.361)
836 * Entry point for kernel functions that do nothing.
838 LONG WINAPI KERNEL_nop(void)
840 return 0;
843 /***********************************************************************
844 * ToolHelpHook (KERNEL.341)
845 * see "Undocumented Windows"
847 FARPROC16 WINAPI ToolHelpHook16(FARPROC16 func)
849 static FARPROC16 hook;
851 FIXME("(%p), stub.\n", func);
852 return InterlockedExchangePointer( (void **)&hook, func );
855 /* thunk for 16-bit CreateThread */
856 struct thread_args
858 FARPROC16 proc;
859 DWORD param;
862 static DWORD CALLBACK start_thread16( LPVOID threadArgs )
864 struct thread_args args = *(struct thread_args *)threadArgs;
865 HeapFree( GetProcessHeap(), 0, threadArgs );
866 return K32WOWCallback16( (DWORD)args.proc, args.param );
869 /***********************************************************************
870 * CreateThread16 (KERNEL.441)
872 HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
873 FARPROC16 start, SEGPTR param,
874 DWORD flags, LPDWORD id )
876 struct thread_args *args = HeapAlloc( GetProcessHeap(), 0, sizeof(*args) );
877 if (!args) return INVALID_HANDLE_VALUE;
878 args->proc = start;
879 args->param = param;
880 return CreateThread( sa, stack, start_thread16, args, flags, id );
883 /***********************************************************************
884 * _DebugOutput (KERNEL.328)
886 void WINAPIV _DebugOutput( WORD flags, LPCSTR spec, VA_LIST16 valist )
888 char caller[101];
890 /* Decode caller address */
891 if (!GetModuleName16( GetExePtr(CURRENT_STACK16->cs), caller, sizeof(caller) ))
892 sprintf( caller, "%04X:%04X", CURRENT_STACK16->cs, CURRENT_STACK16->ip );
894 /* FIXME: cannot use wvsnprintf16 from kernel */
895 /* wvsnprintf16( temp, sizeof(temp), spec, valist ); */
897 /* Output */
898 FIXME("%s %04x %s\n", caller, flags, debugstr_a(spec) );