Wed May 29 12:53:10 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / sysdeps / mach / start.c
blobc2ea3e3b7bd2356c19f980afc9512d41554e5a94
1 /* Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
19 #include <stddef.h>
20 #include <stdlib.h>
21 #include <errno.h>
22 #include <unistd.h>
23 #include <sysdep.h>
25 #ifndef __GNUC__
26 #error This file uses GNU C extensions; you must compile with GCC.
27 #endif
29 /* The first piece of initialized data. */
30 int __data_start = 0;
32 volatile int errno;
34 extern void __mach_init (void);
35 extern void __libc_init (int argc, char **argv, char **envp);
36 extern int main (int argc, char **argv, char **envp);
38 /* These are uninitialized common definitions so they will be zero
39 by default. If the user links in C threads, that will provide initialized
40 definitions that override these. */
41 void *(*_cthread_init_routine) (void); /* Returns new SP to use. */
42 void (*_cthread_exit_routine) (int status);
45 /* These are for communication from _start to start1,
46 where we cannot use the stack for anything. */
47 static int start_argc;
48 static char **start_argv;
50 /* _start calls this on the new stack. */
51 static volatile void
52 start1 (void)
54 __libc_init (start_argc, start_argv, __environ);
56 (_cthread_exit_routine != NULL ? *_cthread_exit_routine : exit)
57 (main (start_argc, start_argv, __environ));
59 /* Should never get here. */
60 LOSE;
63 #ifndef START_ARGS
64 #define START_ARGS void
65 #ifdef START_MACHDEP
66 START_MACHDEP
67 #define _start _start0
68 #endif
70 void
71 _start (START_ARGS)
73 SNARF_ARGS (start_argc, start_argv, __environ);
75 __mach_init ();
77 if (_cthread_init_routine != NULL)
78 CALL_WITH_SP (start1, (*_cthread_init_routine) ());
79 else
80 start1 ();
82 /* Should never get here. */
83 LOSE;