aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/generic/libc-start.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/generic/libc-start.c')
-rw-r--r--sysdeps/generic/libc-start.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/sysdeps/generic/libc-start.c b/sysdeps/generic/libc-start.c
index 12419887a1..d6fd3d3581 100644
--- a/sysdeps/generic/libc-start.c
+++ b/sysdeps/generic/libc-start.c
@@ -16,9 +16,29 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include <stdlib.h>
+#include <unistd.h>
+
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))
{
- return (*main) (argc, argv, envp);
+ /* Register the destructor of the dynamic linker if there is any. */
+ if (rtld_fini != NULL)
+ atexit (rtld_fini);
+
+ /* Call the initializer of the libc. */
+ __libc_init_first ();
+
+ /* Set the global _environ variable correctly. */
+ __environ = &argv[argc + 1];
+
+ /* Call the initializer of the program. */
+ (*init) ();
+
+ /* Register the destructor of the program. */
+ atexit (fini);
+
+ exit ((*main) (argc, argv, envp));
}