qcap/filewriter: Implement IFileSinkFilter::SetFileName().
[wine.git] / loader / main.c
blob407c897892dcaa35ca69a90ba2caf3b17fd2bf52
1 /*
2 * Emulator initialisation 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 "config.h"
22 #include "wine/port.h"
24 #include <errno.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #ifdef HAVE_SYS_MMAN_H
28 # include <sys/mman.h>
29 #endif
30 #ifdef HAVE_SYS_RESOURCE_H
31 # include <sys/resource.h>
32 #endif
33 #ifdef HAVE_SYS_SYSCALL_H
34 # include <sys/syscall.h>
35 #endif
36 #ifdef HAVE_UNISTD_H
37 # include <unistd.h>
38 #endif
40 #include "wine/library.h"
41 #include "main.h"
43 /* the preloader will set this variable */
44 const struct wine_preload_info *wine_main_preload_info = NULL;
46 /***********************************************************************
47 * check_command_line
49 * Check if command line is one that needs to be handled specially.
51 static void check_command_line( int argc, char *argv[] )
53 static const char usage[] =
54 "Usage: wine PROGRAM [ARGUMENTS...] Run the specified program\n"
55 " wine --help Display this help and exit\n"
56 " wine --version Output version information and exit";
58 if (argc <= 1)
60 fprintf( stderr, "%s\n", usage );
61 exit(1);
63 if (!strcmp( argv[1], "--help" ))
65 printf( "%s\n", usage );
66 exit(0);
68 if (!strcmp( argv[1], "--version" ))
70 printf( "%s\n", wine_get_build_id() );
71 exit(0);
76 #ifdef __ANDROID__
78 static int pre_exec(void)
80 #if defined(__i386__) || defined(__x86_64__)
81 return 1; /* we have a preloader */
82 #else
83 return 0; /* no exec needed */
84 #endif
87 #elif defined(__linux__) && (defined(__i386__) || defined(__arm__))
89 static void check_vmsplit( void *stack )
91 if (stack < (void *)0x80000000)
93 /* if the stack is below 0x80000000, assume we can safely try a munmap there */
94 if (munmap( (void *)0x80000000, 1 ) == -1 && errno == EINVAL)
95 fprintf( stderr,
96 "Warning: memory above 0x80000000 doesn't seem to be accessible.\n"
97 "Wine requires a 3G/1G user/kernel memory split to work properly.\n" );
101 static void set_max_limit( int limit )
103 struct rlimit rlimit;
105 if (!getrlimit( limit, &rlimit ))
107 rlimit.rlim_cur = rlimit.rlim_max;
108 setrlimit( limit, &rlimit );
112 static int pre_exec(void)
114 int temp;
116 check_vmsplit( &temp );
117 set_max_limit( RLIMIT_AS );
118 #ifdef __i386__
119 return 1; /* we have a preloader on x86 */
120 #else
121 return 0;
122 #endif
125 #elif defined(__linux__) && (defined(__x86_64__) || defined(__aarch64__))
127 static int pre_exec(void)
129 return 1; /* we have a preloader on x86-64/arm64 */
132 #elif defined(__APPLE__) && (defined(__i386__) || defined(__x86_64__))
134 static int pre_exec(void)
136 return 1; /* we have a preloader */
139 #elif (defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__))
141 static int pre_exec(void)
143 struct rlimit rl;
145 rl.rlim_cur = 0x02000000;
146 rl.rlim_max = 0x02000000;
147 setrlimit( RLIMIT_DATA, &rl );
148 return 1;
151 #else
153 static int pre_exec(void)
155 return 0; /* no exec needed */
158 #endif
161 /**********************************************************************
162 * main
164 int main( int argc, char *argv[] )
166 char error[1024];
167 int i;
169 if (!getenv( "WINELOADERNOEXEC" )) /* first time around */
171 static char noexec[] = "WINELOADERNOEXEC=1";
173 putenv( noexec );
174 check_command_line( argc, argv );
175 if (pre_exec())
177 wine_init_argv0_path( argv[0] );
178 wine_exec_wine_binary( NULL, argv, getenv( "WINELOADER" ));
179 fprintf( stderr, "wine: could not exec the wine loader\n" );
180 exit(1);
184 if (wine_main_preload_info)
186 for (i = 0; wine_main_preload_info[i].size; i++)
187 wine_mmap_add_reserved_area( wine_main_preload_info[i].addr, wine_main_preload_info[i].size );
190 wine_init( argc, argv, error, sizeof(error) );
191 fprintf( stderr, "wine: failed to initialize: %s\n", error );
192 exit(1);