aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/libc-start.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/sysv/linux/libc-start.c')
-rw-r--r--sysdeps/unix/sysv/linux/libc-start.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/sysdeps/unix/sysv/linux/libc-start.c b/sysdeps/unix/sysv/linux/libc-start.c
index f142195..e9d21a6 100644
--- a/sysdeps/unix/sysv/linux/libc-start.c
+++ b/sysdeps/unix/sysv/linux/libc-start.c
@@ -17,15 +17,44 @@
Boston, MA 02111-1307, USA. */
#include <link.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+extern void __libc_init_first (void);
int
__libc_start_main (int (*main) (int, char **, char **), int argc,
- char **argv, char **envp)
+ char **argv, void (*init) (void), void (*fini) (void),
+ void (*rtld_fini) (void))
{
+ /* Register the destructor of the dynamic linker if there is any. */
+ if (rtld_fini != NULL)
+ atexit (rtld_fini);
+
+ /* Call the initializer of the libc. */
+#ifdef PIC
+ if (_dl_debug_impcalls)
+ _dl_debug_message ("\tinitialize libc\n\n", NULL);
+#endif
+ __libc_init_first ();
+
+ /* Set the global _environ variable correctly. */
+ __environ = &argv[argc + 1];
+
+ /* Call the initializer of the program. */
+#ifdef PIC
+ if (_dl_debug_impcalls)
+ _dl_debug_message ("\tinitialize program: ", argv[0], "\n\n", NULL);
+#endif
+ (*init) ();
+
+ /* Register the destructor of the program. */
+ atexit (fini);
+
#ifdef PIC
if (_dl_debug_impcalls)
_dl_debug_message ("\ttransferring control: ", argv[0], "\n\n", NULL);
#endif
- return (*main) (argc, argv, envp);
+ exit ((*main) (argc, argv, __environ));
}