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
22 #include "wine/port.h"
27 #ifdef HAVE_SYS_MMAN_H
28 # include <sys/mman.h>
30 #ifdef HAVE_SYS_RESOURCE_H
31 # include <sys/resource.h>
33 #ifdef HAVE_SYS_SYSCALL_H
34 # include <sys/syscall.h>
40 #include "wine/library.h"
43 /* the preloader will set this variable */
44 const struct wine_preload_info
*wine_main_preload_info
= NULL
;
46 /***********************************************************************
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";
60 fprintf( stderr
, "%s\n", usage
);
63 if (!strcmp( argv
[1], "--help" ))
65 printf( "%s\n", usage
);
68 if (!strcmp( argv
[1], "--version" ))
70 printf( "%s\n", wine_get_build_id() );
78 static int pre_exec(void)
80 #if defined(__i386__) || defined(__x86_64__)
81 return 1; /* we have a preloader */
83 return 0; /* no exec needed */
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
)
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)
116 check_vmsplit( &temp
);
117 set_max_limit( RLIMIT_AS
);
119 return 1; /* we have a preloader on x86 */
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)
145 rl
.rlim_cur
= 0x02000000;
146 rl
.rlim_max
= 0x02000000;
147 setrlimit( RLIMIT_DATA
, &rl
);
153 static int pre_exec(void)
155 return 0; /* no exec needed */
161 /**********************************************************************
164 int main( int argc
, char *argv
[] )
169 if (!getenv( "WINELOADERNOEXEC" )) /* first time around */
171 static char noexec
[] = "WINELOADERNOEXEC=1";
174 check_command_line( argc
, argv
);
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" );
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
);