main.c 3.34 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3
/*
 * Emulator initialisation code
 *
4 5 6 7 8 9 10 11 12 13 14 15 16 17
 * Copyright 2000 Alexandre Julliard
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
Alexandre Julliard's avatar
Alexandre Julliard committed
19 20
 */

21 22 23
#include "config.h"
#include "wine/port.h"

24
#include <stdio.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
25
#include <stdlib.h>
26 27 28 29
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif

30
#include "wine/library.h"
31 32
#include "main.h"

33
#ifdef __APPLE__
34

35 36 37
asm(".zerofill WINE_DOS, WINE_DOS, ___wine_dos, 0x60000000");
asm(".zerofill WINE_SHARED_HEAP, WINE_SHARED_HEAP, ___wine_shared_heap, 0x02000000");
extern char __wine_dos[0x60000000], __wine_shared_heap[0x02000000];
38 39 40 41 42 43 44

static const struct wine_preload_info wine_main_preload_info[] =
{
    { __wine_dos,         sizeof(__wine_dos) },          /* DOS area + PE exe */
    { __wine_shared_heap, sizeof(__wine_shared_heap) },  /* shared user data + shared heap */
    { 0, 0 }  /* end of list */
};
45 46 47 48 49 50 51 52 53

static inline void reserve_area( void *addr, size_t size )
{
    wine_anon_mmap( addr, size, PROT_NONE, MAP_FIXED | MAP_NORESERVE );
    wine_mmap_add_reserved_area( addr, size );
}

#else  /* __APPLE__ */

54 55
/* the preloader will set this variable */
const struct wine_preload_info *wine_main_preload_info = NULL;
56 57 58 59 60 61 62

static inline void reserve_area( void *addr, size_t size )
{
    wine_mmap_add_reserved_area( addr, size );
}

#endif  /* __APPLE__ */
Alexandre Julliard's avatar
Alexandre Julliard committed
63

64 65 66 67 68 69 70
/***********************************************************************
 *           check_command_line
 *
 * Check if command line is one that needs to be handled specially.
 */
static void check_command_line( int argc, char *argv[] )
{
71
    extern const char wine_version[];
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
    static const char usage[] =
        "Usage: wine PROGRAM [ARGUMENTS...]   Run the specified program\n"
        "       wine --help                   Display this help and exit\n"
        "       wine --version                Output version information and exit";

    if (argc <= 1)
    {
        fprintf( stderr, "%s\n", usage );
        exit(1);
    }
    if (!strcmp( argv[1], "--help" ))
    {
        printf( "%s\n", usage );
        exit(0);
    }
    if (!strcmp( argv[1], "--version" ))
    {
89
        printf( "%s\n", wine_version );
90 91 92 93 94
        exit(0);
    }
}


Alexandre Julliard's avatar
Alexandre Julliard committed
95 96 97 98 99
/**********************************************************************
 *           main
 */
int main( int argc, char *argv[] )
{
100
    char error[1024];
101 102
    int i;

103
    check_command_line( argc, argv );
104 105 106
    if (wine_main_preload_info)
    {
        for (i = 0; wine_main_preload_info[i].size; i++)
107
            reserve_area( wine_main_preload_info[i].addr, wine_main_preload_info[i].size );
108
    }
109

110
    wine_pthread_set_functions( &pthread_functions, sizeof(pthread_functions) );
111
    wine_init( argc, argv, error, sizeof(error) );
112 113
    fprintf( stderr, "wine: failed to initialize: %s\n", error );
    exit(1);
Alexandre Julliard's avatar
Alexandre Julliard committed
114
}