Back to index

glibc  2.9
libc-start.c
Go to the documentation of this file.
00001 /* Copyright (C) 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2007
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <stdlib.h>
00021 #include <unistd.h>
00022 #include <ldsodefs.h>
00023 #include <sysdep.h>
00024 #include <bp-start.h>
00025 #include <bp-sym.h>
00026 
00027 
00028 int __cache_line_size attribute_hidden;
00029 /* The main work is done in the generic function.  */
00030 #define LIBC_START_MAIN generic_start_main
00031 #define LIBC_START_DISABLE_INLINE
00032 #define LIBC_START_MAIN_AUXVEC_ARG
00033 #define MAIN_AUXVEC_ARG
00034 #define INIT_MAIN_ARGS
00035 #include <csu/libc-start.c>
00036 
00037 struct startup_info
00038   {
00039     void *__unbounded sda_base;
00040     int (*main) (int, char **, char **, void *);
00041     int (*init) (int, char **, char **, void *);
00042     void (*fini) (void);
00043   };
00044 
00045 int
00046 /* GKM FIXME: GCC: this should get __BP_ prefix by virtue of the
00047    BPs in the arglist of startup_info.main and startup_info.init. */
00048   BP_SYM (__libc_start_main) (int argc, char *__unbounded *__unbounded ubp_av,
00049                            char *__unbounded *__unbounded ubp_ev,
00050                            ElfW (auxv_t) * __unbounded auxvec,
00051                            void (*rtld_fini) (void),
00052                            struct startup_info *__unbounded stinfo,
00053                            char *__unbounded *__unbounded stack_on_entry)
00054 {
00055 #if __BOUNDED_POINTERS__
00056   char **argv;
00057 #else
00058 # define argv ubp_av
00059 #endif
00060 
00061   /* the PPC SVR4 ABI says that the top thing on the stack will
00062      be a NULL pointer, so if not we assume that we're being called
00063      as a statically-linked program by Linux...  */
00064   if (*stack_on_entry != NULL)
00065     {
00066       char *__unbounded * __unbounded temp;
00067       /* ...in which case, we have argc as the top thing on the
00068          stack, followed by argv (NULL-terminated), envp (likewise),
00069          and the auxilary vector.  */
00070       /* 32/64-bit agnostic load from stack */
00071       argc = *(long int *__unbounded) stack_on_entry;
00072       ubp_av = stack_on_entry + 1;
00073       ubp_ev = ubp_av + argc + 1;
00074 #ifdef HAVE_AUX_VECTOR
00075       temp = ubp_ev;
00076       while (*temp != NULL)
00077        ++temp;
00078       auxvec = (ElfW (auxv_t) *)++ temp;
00079 #endif
00080       rtld_fini = NULL;
00081     }
00082 
00083   /* Initialize the __cache_line_size variable from the aux vector.  */
00084   for (ElfW (auxv_t) * av = auxvec; av->a_type != AT_NULL; ++av)
00085     switch (av->a_type)
00086       {
00087       case AT_DCACHEBSIZE:
00088        __cache_line_size = av->a_un.a_val;
00089        break;
00090       }
00091 
00092   return generic_start_main (stinfo->main, argc, ubp_av, auxvec,
00093                           stinfo->init, stinfo->fini, rtld_fini,
00094                           stack_on_entry);
00095 }