Back to index

glibc  2.9
start.c
Go to the documentation of this file.
00001 /* Copyright (C) 1992, 1993, 1994, 1995, 1997 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    In addition to the permissions in the GNU Lesser General Public
00010    License, the Free Software Foundation gives you unlimited
00011    permission to link the compiled version of this file with other
00012    programs, and to distribute those programs without any restriction
00013    coming from the use of this file. (The GNU Lesser General Public
00014    License restrictions do apply in other respects; for example, they
00015    cover modification of the file, and distribution when not linked
00016    into another program.)
00017 
00018    Note that people who make modified versions of this file are not
00019    obligated to grant this special exception for their modified
00020    versions; it is their choice whether to do so. The GNU Lesser
00021    General Public License gives permission to release a modified
00022    version without this exception; this exception also makes it
00023    possible to release a modified version which carries forward this
00024    exception.
00025 
00026    The GNU C Library is distributed in the hope that it will be useful,
00027    but WITHOUT ANY WARRANTY; without even the implied warranty of
00028    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00029    Lesser General Public License for more details.
00030 
00031    You should have received a copy of the GNU Lesser General Public
00032    License along with the GNU C Library; if not, write to the Free
00033    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00034    02111-1307 USA.  */
00035 
00036 #include <stddef.h>
00037 #include <stdlib.h>
00038 #include <errno.h>
00039 #include <unistd.h>
00040 #include <sysdep.h>
00041 
00042 #ifndef       __GNUC__
00043   #error This file uses GNU C extensions; you must compile with GCC.
00044 #endif
00045 
00046 /* The first piece of initialized data.  */
00047 int __data_start = 0;
00048 
00049 #ifndef _HURD_THREADVAR_H
00050 volatile int errno;
00051 #endif
00052 
00053 extern void __mach_init (void);
00054 extern void __libc_init (int argc, char **argv, char **envp);
00055 extern int main (int argc, char **argv, char **envp);
00056 
00057 /* These are uninitialized common definitions so they will be zero
00058    by default.  If the user links in C threads, that will provide initialized
00059    definitions that override these.  */
00060 void *(*_cthread_init_routine) (void); /* Returns new SP to use.  */
00061 void (*_cthread_exit_routine) (int status);
00062 
00063 
00064 /* These are for communication from _start to start1,
00065    where we cannot use the stack for anything.  */
00066 static int start_argc;
00067 static char **start_argv;
00068 
00069 /* _start calls this on the new stack.  */
00070 static volatile void
00071 start1 (void)
00072 {
00073   __libc_init (start_argc, start_argv, __environ);
00074 
00075   (_cthread_exit_routine != NULL ? *_cthread_exit_routine : exit)
00076     (main (start_argc, start_argv, __environ));
00077 
00078   /* Should never get here.  */
00079   LOSE;
00080 }
00081 
00082 #ifndef START_ARGS
00083 #define START_ARGS void
00084 #endif
00085 #ifdef START_MACHDEP
00086 START_MACHDEP
00087 #define _start _start0
00088 #endif
00089 
00090 void
00091 _start (START_ARGS)
00092 {
00093   SNARF_ARGS (start_argc, start_argv, __environ);
00094 
00095   __mach_init ();
00096 
00097   if (_cthread_init_routine != NULL)
00098     CALL_WITH_SP (start1, (*_cthread_init_routine) ());
00099   else
00100     start1 ();
00101 
00102   /* Should never get here.  */
00103   LOSE;
00104 }