msxml3: Implement IXMLDOMCDATASection_substringData.
[wine/wine64.git] / dlls / kernel32 / kernel16.c
blob81c9bee88b609b9424a86396aceda81dd71c964c
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>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winternl.h"
26 #include "wownt32.h"
28 #include "toolhelp.h"
29 #include "kernel_private.h"
30 #include "kernel16_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(module);
35 /**************************************************************************
36 * DllEntryPoint (KERNEL.669)
38 BOOL WINAPI KERNEL_DllEntryPoint( DWORD reasion, HINSTANCE16 inst, WORD ds,
39 WORD heap, DWORD reserved1, WORD reserved2 )
41 static int done;
43 /* the entry point can be called multiple times */
44 if (done) return TRUE;
45 done = 1;
47 /* Initialize 16-bit thunking entry points */
48 if (!WOWTHUNK_Init()) return FALSE;
50 /* Initialize DOS memory */
51 if (!DOSMEM_Init()) return FALSE;
53 /* Initialize special KERNEL entry points */
55 NE_SetEntryPoint( inst, 178, GetWinFlags16() );
57 NE_SetEntryPoint( inst, 454, wine_get_cs() );
58 NE_SetEntryPoint( inst, 455, wine_get_ds() );
60 NE_SetEntryPoint( inst, 183, DOSMEM_0000H ); /* KERNEL.183: __0000H */
61 NE_SetEntryPoint( inst, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
62 NE_SetEntryPoint( inst, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
63 NE_SetEntryPoint( inst, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
65 /* Initialize KERNEL.THHOOK */
66 TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( inst, (LPCSTR)332 )));
68 /* Initialize the real-mode selector entry points */
69 #define SET_ENTRY_POINT( num, addr ) \
70 NE_SetEntryPoint( inst, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
71 DOSMEM_MapDosToLinear(addr), 0x10000, inst, \
72 WINE_LDT_FLAGS_DATA ))
74 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
75 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
76 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
77 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
78 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
79 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
80 #undef SET_ENTRY_POINT
82 /* Force loading of some dlls */
83 LoadLibrary16( "system.drv" );
85 return TRUE;
88 /***********************************************************************
89 * EnableDos (KERNEL.41)
90 * DisableDos (KERNEL.42)
91 * GetLastDiskChange (KERNEL.98)
92 * ValidateCodeSegments (KERNEL.100)
93 * KbdRst (KERNEL.123)
94 * EnableKernel (KERNEL.124)
95 * DisableKernel (KERNEL.125)
96 * ValidateFreeSpaces (KERNEL.200)
97 * K237 (KERNEL.237)
98 * BUNNY_351 (KERNEL.351)
99 * PIGLET_361 (KERNEL.361)
101 * Entry point for kernel functions that do nothing.
103 LONG WINAPI KERNEL_nop(void)
105 return 0;
109 /* thunk for 16-bit CreateThread */
110 struct thread_args
112 FARPROC16 proc;
113 DWORD param;
116 static DWORD CALLBACK start_thread16( LPVOID threadArgs )
118 struct thread_args args = *(struct thread_args *)threadArgs;
119 HeapFree( GetProcessHeap(), 0, threadArgs );
120 return K32WOWCallback16( (DWORD)args.proc, args.param );
123 /***********************************************************************
124 * CreateThread16 (KERNEL.441)
126 HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
127 FARPROC16 start, SEGPTR param,
128 DWORD flags, LPDWORD id )
130 struct thread_args *args = HeapAlloc( GetProcessHeap(), 0, sizeof(*args) );
131 if (!args) return INVALID_HANDLE_VALUE;
132 args->proc = start;
133 args->param = param;
134 return CreateThread( sa, stack, start_thread16, args, flags, id );
137 /**************************************************************************
138 * WINOLDAP entry point
140 void WINAPI WINOLDAP_EntryPoint( CONTEXT86 *context )
142 PDB16 *psp;
143 INT len;
144 LPSTR cmdline;
145 PROCESS_INFORMATION info;
146 STARTUPINFOA startup;
147 DWORD count, exit_code = 1;
149 InitTask16( context );
151 TRACE( "(ds=%x es=%x fs=%x gs=%x, bx=%04x cx=%04x di=%04x si=%x)\n",
152 context->SegDs, context->SegEs, context->SegFs, context->SegGs,
153 context->Ebx, context->Ecx, context->Edi, context->Esi );
155 psp = GlobalLock16( context->SegEs );
156 len = psp->cmdLine[0];
157 cmdline = HeapAlloc( GetProcessHeap(), 0, len + 1 );
158 memcpy( cmdline, psp->cmdLine + 1, len );
159 cmdline[len] = 0;
160 ReleaseThunkLock( &count );
162 memset( &startup, 0, sizeof(startup) );
163 startup.cb = sizeof(startup);
165 /* FIXME: Should this be WinExec instead of CreateProcess? */
166 if (CreateProcessA( NULL, cmdline, NULL, NULL, FALSE,
167 0, NULL, NULL, &startup, &info ))
169 WaitForSingleObject( info.hProcess, INFINITE );
170 GetExitCodeProcess( info.hProcess, &exit_code );
171 CloseHandle( info.hThread );
172 CloseHandle( info.hProcess );
174 HeapFree( GetProcessHeap(), 0, cmdline );
175 ExitThread( exit_code );