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>
41 #include "wine/library.h"
44 /* the preloader will set this variable */
45 const struct wine_preload_info
*wine_main_preload_info
= NULL
;
47 /***********************************************************************
50 * Check if command line is one that needs to be handled specially.
52 static void check_command_line( int argc
, char *argv
[] )
54 static const char usage
[] =
55 "Usage: wine PROGRAM [ARGUMENTS...] Run the specified program\n"
56 " wine --help Display this help and exit\n"
57 " wine --version Output version information and exit";
61 fprintf( stderr
, "%s\n", usage
);
64 if (!strcmp( argv
[1], "--help" ))
66 printf( "%s\n", usage
);
69 if (!strcmp( argv
[1], "--version" ))
71 printf( "%s\n", wine_get_build_id() );
79 static int pre_exec(void)
81 #if defined(__i386__) || defined(__x86_64__)
82 return 1; /* we have a preloader */
84 return 0; /* no exec needed */
88 #elif defined(__linux__) && (defined(__i386__) || defined(__arm__))
91 /* separate thread to check for NPTL and TLS features */
92 static void *needs_pthread( void *arg
)
94 pid_t tid
= syscall( 224 /* SYS_gettid */ );
96 if (tid
!= -1 && tid
!= getpid()) return (void *)1;
97 /* check for TLS glibc */
98 if (wine_get_gs() != 0) return (void *)1;
99 /* check for exported epoll_create to detect new glibc versions without TLS */
100 if (wine_dlsym( RTLD_DEFAULT
, "epoll_create", NULL
, 0 ))
102 "wine: glibc >= 2.3 without NPTL or TLS is not a supported combination.\n"
103 " Please upgrade to a glibc with NPTL support.\n" );
106 "wine: Your C library is too old. You need at least glibc 2.3 with NPTL support.\n" );
110 /* check if we support the glibc threading model */
111 static void check_threading(void)
116 pthread_create( &id
, NULL
, needs_pthread
, NULL
);
117 pthread_join( id
, &ret
);
121 static void check_threading(void)
126 static void check_vmsplit( void *stack
)
128 if (stack
< (void *)0x80000000)
130 /* if the stack is below 0x80000000, assume we can safely try a munmap there */
131 if (munmap( (void *)0x80000000, 1 ) == -1 && errno
== EINVAL
)
133 "Warning: memory above 0x80000000 doesn't seem to be accessible.\n"
134 "Wine requires a 3G/1G user/kernel memory split to work properly.\n" );
138 static void set_max_limit( int limit
)
140 struct rlimit rlimit
;
142 if (!getrlimit( limit
, &rlimit
))
144 rlimit
.rlim_cur
= rlimit
.rlim_max
;
145 setrlimit( limit
, &rlimit
);
149 static int pre_exec(void)
154 check_vmsplit( &temp
);
155 set_max_limit( RLIMIT_AS
);
157 return 1; /* we have a preloader on x86 */
163 #elif defined(__linux__) && (defined(__x86_64__) || defined(__aarch64__))
165 static int pre_exec(void)
167 return 1; /* we have a preloader on x86-64/arm64 */
170 #elif defined(__APPLE__) && (defined(__i386__) || defined(__x86_64__))
172 static int pre_exec(void)
174 return 1; /* we have a preloader */
177 #elif (defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__))
179 static int pre_exec(void)
183 rl
.rlim_cur
= 0x02000000;
184 rl
.rlim_max
= 0x02000000;
185 setrlimit( RLIMIT_DATA
, &rl
);
191 static int pre_exec(void)
193 return 0; /* no exec needed */
199 /**********************************************************************
202 int main( int argc
, char *argv
[] )
207 if (!getenv( "WINELOADERNOEXEC" )) /* first time around */
209 static char noexec
[] = "WINELOADERNOEXEC=1";
212 check_command_line( argc
, argv
);
215 wine_init_argv0_path( argv
[0] );
216 wine_exec_wine_binary( NULL
, argv
, getenv( "WINELOADER" ));
217 fprintf( stderr
, "wine: could not exec the wine loader\n" );
222 if (wine_main_preload_info
)
224 for (i
= 0; wine_main_preload_info
[i
].size
; i
++)
225 wine_mmap_add_reserved_area( wine_main_preload_info
[i
].addr
, wine_main_preload_info
[i
].size
);
228 wine_init( argc
, argv
, error
, sizeof(error
) );
229 fprintf( stderr
, "wine: failed to initialize: %s\n", error
);