* sysdeps/m68k/dl-machine.h (_dl_start_user): Pass correct
[glibc.git] / sysdeps / generic / libc-start.c
bloba95ce56d2b1ef8ca0f740d0516ffcf8b0b17282c
1 /* Copyright (C) 1998, 1999, 2000 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 not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <ldsodefs.h>
22 #include <bp-start.h>
23 #include <bp-sym.h>
25 extern void __libc_init_first (int argc, char **argv, char **envp);
27 extern int _dl_starting_up;
28 weak_extern (_dl_starting_up)
29 extern int __libc_multiple_libcs;
30 extern void *__libc_stack_end;
32 #ifndef SHARED
33 extern void __pthread_initialize_minimal (void) __attribute__ ((weak));
34 #endif
36 /* Prototype for local function. */
37 extern void __libc_check_standard_fds (void);
39 int
40 /* GKM FIXME: GCC: this should get __BP_ prefix by virtue of the
41 BPs in the arglist of startup_info.main and startup_info.init. */
42 BP_SYM (__libc_start_main) (int (*main) (int, char **, char **),
43 int argc, char *__unbounded *__unbounded ubp_av,
44 void (*init) (void), void (*fini) (void),
45 void (*rtld_fini) (void), void *__unbounded stack_end)
47 char *__unbounded *__unbounded ubp_ev = &ubp_av[argc + 1];
48 #if __BOUNDED_POINTERS__
49 char **argv;
50 #else
51 # define argv ubp_av
52 #endif
54 #ifndef SHARED
55 /* The next variable is only here to work around a bug in gcc <= 2.7.2.2.
56 If the address would be taken inside the expression the optimizer
57 would try to be too smart and throws it away. Grrr. */
58 int *dummy_addr = &_dl_starting_up;
60 __libc_multiple_libcs = dummy_addr && !_dl_starting_up;
61 #endif
63 INIT_ARGV_and_ENVIRON;
65 /* Store the lowest stack address. */
66 __libc_stack_end = stack_end;
68 #ifndef SHARED
69 /* Initialize the thread library at least a bit since the libgcc
70 functions are using thread functions if these are available and
71 we need to setup errno. */
72 if (__pthread_initialize_minimal)
73 __pthread_initialize_minimal ();
75 /* Some security at this point. Prevent starting a SUID binary where
76 the standard file descriptors are not opened. We have to do this
77 only for statically linked applications since otherwise the dynamic
78 loader did the work already. */
79 if (__builtin_expect (__libc_enable_secure, 0))
80 __libc_check_standard_fds ();
81 #endif
83 /* Register the destructor of the dynamic linker if there is any. */
84 if (__builtin_expect (rtld_fini != NULL, 1))
85 atexit (rtld_fini);
87 /* Call the initializer of the libc. This is only needed here if we
88 are compiling for the static library in which case we haven't
89 run the constructors in `_dl_start_user'. */
90 #ifndef SHARED
91 __libc_init_first (argc, argv, __environ);
92 #endif
94 /* Register the destructor of the program, if any. */
95 if (fini)
96 atexit (fini);
98 /* Call the initializer of the program, if any. */
99 #ifdef SHARED
100 if (__builtin_expect (_dl_debug_impcalls, 0))
101 _dl_debug_message (1, "\ninitialize program: ", argv[0], "\n\n", NULL);
102 #endif
103 if (init)
104 (*init) ();
106 #ifdef SHARED
107 if (__builtin_expect (_dl_debug_impcalls, 0))
108 _dl_debug_message (1, "\ntransferring control: ", argv[0], "\n\n", NULL);
109 #endif
111 exit ((*main) (argc, argv, __environ));