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"
47 __asm__(".zerofill WINE_DOS, WINE_DOS, ___wine_dos, 0x40000000");
48 __asm__(".zerofill WINE_SHAREDHEAP, WINE_SHAREDHEAP, ___wine_shared_heap, 0x03000000");
49 extern char __wine_dos
[0x40000000], __wine_shared_heap
[0x03000000];
51 __asm__(".zerofill WINE_DOS, WINE_DOS");
52 __asm__(".zerofill WINE_SHAREDHEAP, WINE_SHAREDHEAP");
53 static char __wine_dos
[0x40000000] __attribute__((section("WINE_DOS, WINE_DOS")));
54 static char __wine_shared_heap
[0x03000000] __attribute__((section("WINE_SHAREDHEAP, WINE_SHAREDHEAP")));
57 static const struct wine_preload_info wine_main_preload_info
[] =
59 { __wine_dos
, sizeof(__wine_dos
) }, /* DOS area + PE exe */
60 { __wine_shared_heap
, sizeof(__wine_shared_heap
) }, /* shared user data + shared heap */
61 { 0, 0 } /* end of list */
64 static inline void reserve_area( void *addr
, size_t size
)
66 wine_anon_mmap( addr
, size
, PROT_NONE
, MAP_FIXED
| MAP_NORESERVE
);
67 wine_mmap_add_reserved_area( addr
, size
);
72 /* the preloader will set this variable */
73 const struct wine_preload_info
*wine_main_preload_info
= NULL
;
75 static inline void reserve_area( void *addr
, size_t size
)
77 wine_mmap_add_reserved_area( addr
, size
);
80 #endif /* __APPLE__ */
82 /***********************************************************************
85 * Check if command line is one that needs to be handled specially.
87 static void check_command_line( int argc
, char *argv
[] )
89 static const char usage
[] =
90 "Usage: wine PROGRAM [ARGUMENTS...] Run the specified program\n"
91 " wine --help Display this help and exit\n"
92 " wine --version Output version information and exit";
96 fprintf( stderr
, "%s\n", usage
);
99 if (!strcmp( argv
[1], "--help" ))
101 printf( "%s\n", usage
);
104 if (!strcmp( argv
[1], "--version" ))
106 printf( "%s\n", wine_get_build_id() );
112 #if defined(__linux__) && defined(__i386__)
114 /* separate thread to check for NPTL and TLS features */
115 static void *needs_pthread( void *arg
)
117 pid_t tid
= syscall( 224 /* SYS_gettid */ );
119 if (tid
!= -1 && tid
!= getpid()) return (void *)1;
120 /* check for TLS glibc */
121 if (wine_get_gs() != 0) return (void *)1;
122 /* check for exported epoll_create to detect new glibc versions without TLS */
123 if (wine_dlsym( RTLD_DEFAULT
, "epoll_create", NULL
, 0 ))
125 "wine: glibc >= 2.3 without NPTL or TLS is not a supported combination.\n"
126 " Please upgrade to a glibc with NPTL support.\n" );
129 "wine: Your C library is too old. You need at least glibc 2.3 with NPTL support.\n" );
133 /* check if we support the glibc threading model */
134 static void check_threading(void)
139 pthread_create( &id
, NULL
, needs_pthread
, NULL
);
140 pthread_join( id
, &ret
);
144 static void check_vmsplit( void *stack
)
146 if (stack
< (void *)0x80000000)
148 /* if the stack is below 0x80000000, assume we can safely try a munmap there */
149 if (munmap( (void *)0x80000000, 1 ) == -1 && errno
== EINVAL
)
151 "Warning: memory above 0x80000000 doesn't seem to be accessible.\n"
152 "Wine requires a 3G/1G user/kernel memory split to work properly.\n" );
156 static void set_max_limit( int limit
)
158 struct rlimit rlimit
;
160 if (!getrlimit( limit
, &rlimit
))
162 rlimit
.rlim_cur
= rlimit
.rlim_max
;
163 setrlimit( limit
, &rlimit
);
167 static int pre_exec(void)
172 check_vmsplit( &temp
);
173 set_max_limit( RLIMIT_AS
);
177 #elif defined(__linux__) && defined(__x86_64__)
179 static int pre_exec(void)
181 return 1; /* we have a preloader on x86-64 */
184 #elif (defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)) && defined(__i386__)
186 static int pre_exec(void)
190 rl
.rlim_cur
= 0x02000000;
191 rl
.rlim_max
= 0x02000000;
192 setrlimit( RLIMIT_DATA
, &rl
);
198 static int pre_exec(void)
200 return 0; /* no exec needed */
206 /**********************************************************************
209 int main( int argc
, char *argv
[] )
214 if (!getenv( "WINELOADERNOEXEC" )) /* first time around */
216 static char noexec
[] = "WINELOADERNOEXEC=1";
219 check_command_line( argc
, argv
);
222 wine_init_argv0_path( argv
[0] );
223 wine_exec_wine_binary( NULL
, argv
, getenv( "WINELOADER" ));
224 fprintf( stderr
, "wine: could not exec the wine loader\n" );
230 if (wine_main_preload_info
)
233 for (i
= 0; wine_main_preload_info
[i
].size
; i
++)
234 reserve_area( wine_main_preload_info
[i
].addr
, wine_main_preload_info
[i
].size
);
237 wine_init( argc
, argv
, error
, sizeof(error
) );
238 fprintf( stderr
, "wine: failed to initialize: %s\n", error
);