Partially implemented LdrLock/UnlockLoaderLock.
[wine] / loader / main.c
1 /*
2  * Main initialization code
3  *
4  * Copyright 1998 Ulrich Weigand
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 "config.h"
22 #include "wine/port.h"
23
24 #include <locale.h>
25 #include <stdlib.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
32 #include <stdio.h>
33 #include <string.h>
34 #ifdef MALLOC_DEBUGGING
35 # include <malloc.h>
36 #endif
37 #include "windef.h"
38 #include "wine/winbase16.h"
39 #include "drive.h"
40 #include "file.h"
41 #include "options.h"
42 #include "wine/debug.h"
43 #include "wine/server.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(server);
46
47 extern void SHELL_LoadRegistry(void);
48
49 /***********************************************************************
50  *           Main initialisation routine
51  */
52 BOOL MAIN_MainInit(void)
53 {
54 #ifdef MALLOC_DEBUGGING
55     char *trace;
56
57     mcheck(NULL);
58     if (!(trace = getenv("MALLOC_TRACE")))
59         MESSAGE( "MALLOC_TRACE not set. No trace generated\n" );
60     else
61     {
62         MESSAGE( "malloc trace goes to %s\n", trace );
63         mtrace();
64     }
65 #endif
66     setbuf(stdout,NULL);
67     setbuf(stderr,NULL);
68     setlocale(LC_CTYPE,"");
69
70     /* Initialise DOS drives */
71     if (!DRIVE_Init()) return FALSE;
72
73     /* Initialise DOS directories */
74     if (!DIR_Init()) return FALSE;
75
76     /* Registry initialisation */
77     SHELL_LoadRegistry();
78
79     /* Global boot finished, the rest is process-local */
80     CLIENT_BootDone( TRACE_ON(server) );
81
82     return TRUE;
83 }
84
85
86 /***********************************************************************
87  *           ExitKernel (KERNEL.2)
88  *
89  * Clean-up everything and exit the Wine process.
90  *
91  */
92 void WINAPI ExitKernel16( void )
93 {
94     /* Do the clean-up stuff */
95
96     WriteOutProfiles16();
97     TerminateProcess( GetCurrentProcess(), 0 );
98 }