Don't fail in CoRegisterClassObject if the class already exists and
[wine] / dlls / kernel / kernel16.c
1 /*
2  * 16-bit kernel initialization code
3  *
4  * Copyright 2000 Alexandre Julliard
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winternl.h"
26 #include "wownt32.h"
27
28 #include "toolhelp.h"
29 #include "kernel_private.h"
30 #include "kernel16_private.h"
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(kernel);
34
35 /**************************************************************************
36  *              DllEntryPoint   (KERNEL.669)
37  */
38 BOOL WINAPI KERNEL_DllEntryPoint( DWORD reasion, HINSTANCE16 inst, WORD ds,
39                                   WORD heap, DWORD reserved1, WORD reserved2 )
40 {
41     static int done;
42
43     /* the entry point can be called multiple times */
44     if (done) return TRUE;
45     done = 1;
46
47     /* Initialize 16-bit thunking entry points */
48     if (!WOWTHUNK_Init()) return FALSE;
49
50     /* Initialize DOS memory */
51     if (!DOSMEM_Init()) return FALSE;
52
53     /* Initialize special KERNEL entry points */
54
55     NE_SetEntryPoint( inst, 178, GetWinFlags16() );
56
57     NE_SetEntryPoint( inst, 454, wine_get_cs() );
58     NE_SetEntryPoint( inst, 455, wine_get_ds() );
59
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 */
64
65     /* Initialize KERNEL.THHOOK */
66     TASK_InstallTHHook(MapSL((SEGPTR)GetProcAddress16( inst, (LPCSTR)332 )));
67
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 ))
73
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
81
82     /* Force loading of some dlls */
83     LoadLibrary16( "system.drv" );
84
85     return TRUE;
86 }
87
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)
100  *
101  * Entry point for kernel functions that do nothing.
102  */
103 LONG WINAPI KERNEL_nop(void)
104 {
105     return 0;
106 }
107
108
109 /* thunk for 16-bit CreateThread */
110 struct thread_args
111 {
112     FARPROC16 proc;
113     DWORD     param;
114 };
115
116 static DWORD CALLBACK start_thread16( LPVOID threadArgs )
117 {
118     struct thread_args args = *(struct thread_args *)threadArgs;
119     HeapFree( GetProcessHeap(), 0, threadArgs );
120     return K32WOWCallback16( (DWORD)args.proc, args.param );
121 }
122
123 /***********************************************************************
124  *           CreateThread16   (KERNEL.441)
125  */
126 HANDLE WINAPI CreateThread16( SECURITY_ATTRIBUTES *sa, DWORD stack,
127                               FARPROC16 start, SEGPTR param,
128                               DWORD flags, LPDWORD id )
129 {
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 );
135 }