~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/loader/main.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Emulator initialisation code
  3  *
  4  * Copyright 2000 Alexandre Julliard
  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include "config.h"
 22 #include "wine/port.h"
 23 
 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_UNISTD_H
 34 # include <unistd.h>
 35 #endif
 36 #ifdef HAVE_PTHREAD_H
 37 # include <pthread.h>
 38 #endif
 39 
 40 #include "wine/library.h"
 41 #include "main.h"
 42 
 43 #ifdef __APPLE__
 44 
 45 asm(".zerofill WINE_DOS, WINE_DOS, ___wine_dos, 0x60000000");
 46 asm(".zerofill WINE_SHARED_HEAP, WINE_SHARED_HEAP, ___wine_shared_heap, 0x03000000");
 47 extern char __wine_dos[0x60000000], __wine_shared_heap[0x03000000];
 48 
 49 static const struct wine_preload_info wine_main_preload_info[] =
 50 {
 51     { __wine_dos,         sizeof(__wine_dos) },          /* DOS area + PE exe */
 52     { __wine_shared_heap, sizeof(__wine_shared_heap) },  /* shared user data + shared heap */
 53     { 0, 0 }  /* end of list */
 54 };
 55 
 56 static inline void reserve_area( void *addr, size_t size )
 57 {
 58     wine_anon_mmap( addr, size, PROT_NONE, MAP_FIXED | MAP_NORESERVE );
 59     wine_mmap_add_reserved_area( addr, size );
 60 }
 61 
 62 #else  /* __APPLE__ */
 63 
 64 /* the preloader will set this variable */
 65 const struct wine_preload_info *wine_main_preload_info = NULL;
 66 
 67 static inline void reserve_area( void *addr, size_t size )
 68 {
 69     wine_mmap_add_reserved_area( addr, size );
 70 }
 71 
 72 #endif  /* __APPLE__ */
 73 
 74 /***********************************************************************
 75  *           check_command_line
 76  *
 77  * Check if command line is one that needs to be handled specially.
 78  */
 79 static void check_command_line( int argc, char *argv[] )
 80 {
 81     static const char usage[] =
 82         "Usage: wine PROGRAM [ARGUMENTS...]   Run the specified program\n"
 83         "       wine --help                   Display this help and exit\n"
 84         "       wine --version                Output version information and exit";
 85 
 86     if (argc <= 1)
 87     {
 88         fprintf( stderr, "%s\n", usage );
 89         exit(1);
 90     }
 91     if (!strcmp( argv[1], "--help" ))
 92     {
 93         printf( "%s\n", usage );
 94         exit(0);
 95     }
 96     if (!strcmp( argv[1], "--version" ))
 97     {
 98         printf( "%s\n", wine_get_build_id() );
 99         exit(0);
100     }
101 }
102 
103 
104 #if defined(__linux__) && defined(__i386__)
105 
106 /* separate thread to check for NPTL and TLS features */
107 static void *needs_pthread( void *arg )
108 {
109     pid_t tid = gettid();
110     /* check for NPTL */
111     if (tid != -1 && tid != getpid()) return (void *)1;
112     /* check for TLS glibc */
113     if (wine_get_gs() != 0) return (void *)1;
114     /* check for exported epoll_create to detect new glibc versions without TLS */
115     if (wine_dlsym( RTLD_DEFAULT, "epoll_create", NULL, 0 ))
116         fprintf( stderr,
117                  "wine: glibc >= 2.3 without NPTL or TLS is not a supported combination.\n"
118                  "      Please upgrade to a glibc with NPTL support.\n" );
119     else
120         fprintf( stderr,
121                  "wine: Your C library is too old. You need at least glibc 2.3 with NPTL support.\n" );
122     return 0;
123 }
124 
125 /* check if we support the glibc threading model */
126 static void check_threading(void)
127 {
128     pthread_t id;
129     void *ret;
130 
131     pthread_create( &id, NULL, needs_pthread, NULL );
132     pthread_join( id, &ret );
133     if (!ret) exit(1);
134 }
135 
136 static void check_vmsplit( void *stack )
137 {
138     if (stack < (void *)0x80000000)
139     {
140         /* if the stack is below 0x80000000, assume we can safely try a munmap there */
141         if (munmap( (void *)0x80000000, 1 ) == -1 && errno == EINVAL)
142             fprintf( stderr,
143                      "Warning: memory above 0x80000000 doesn't seem to be accessible.\n"
144                      "Wine requires a 3G/1G user/kernel memory split to work properly.\n" );
145     }
146 }
147 
148 static void set_max_limit( int limit )
149 {
150     struct rlimit rlimit;
151 
152     if (!getrlimit( limit, &rlimit ))
153     {
154         rlimit.rlim_cur = rlimit.rlim_max;
155         setrlimit( limit, &rlimit );
156     }
157 }
158 
159 static int pre_exec(void)
160 {
161     int temp;
162 
163     check_threading();
164     check_vmsplit( &temp );
165     set_max_limit( RLIMIT_AS );
166     return 1;
167 }
168 
169 #elif defined(__FreeBSD__) && defined(__i386__)
170 
171 static int pre_exec(void)
172 {
173     struct rlimit rl;
174 
175     rl.rlim_cur = 0x02000000;
176     rl.rlim_max = 0x02000000;
177     setrlimit( RLIMIT_DATA, &rl );
178     return 1;
179 }
180 
181 #else
182 
183 static int pre_exec(void)
184 {
185     return 0;  /* no exec needed */
186 }
187 
188 #endif
189 
190 
191 /**********************************************************************
192  *           main
193  */
194 int main( int argc, char *argv[] )
195 {
196     char error[1024];
197     int i;
198 
199     if (!getenv( "WINELOADERNOEXEC" ))  /* first time around */
200     {
201         static char noexec[] = "WINELOADERNOEXEC=1";
202 
203         putenv( noexec );
204         check_command_line( argc, argv );
205         if (pre_exec())
206         {
207             wine_init_argv0_path( argv[0] );
208             wine_exec_wine_binary( NULL, argv, getenv( "WINELOADER" ));
209             fprintf( stderr, "wine: could not exec the wine loader\n" );
210             exit(1);
211         }
212     }
213 
214     if (wine_main_preload_info)
215     {
216         for (i = 0; wine_main_preload_info[i].size; i++)
217             reserve_area( wine_main_preload_info[i].addr, wine_main_preload_info[i].size );
218     }
219 
220     init_pthread_functions();
221     wine_init( argc, argv, error, sizeof(error) );
222     fprintf( stderr, "wine: failed to initialize: %s\n", error );
223     exit(1);
224 }
225 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.