__libc_start_main.c 784 B

1234567891011121314151617181920212223242526
  1. #include "libc.h"
  2. /* Any use of __environ/environ will override this symbol. */
  3. char **__dummy_environ = (void *)-1;
  4. weak_alias(__dummy_environ, ___environ);
  5. int __libc_start_main(
  6. int (*main)(int, char **, char **), int argc, char **argv,
  7. int (*init)(int, char **, char **), void (*fini)(void),
  8. void (*ldso_fini)(void))
  9. {
  10. /* Save the environment if it may be used by libc/application */
  11. char **envp = argv+argc+1;
  12. if (___environ != (void *)-1) ___environ = envp;
  13. /* Avoid writing 0 and triggering unnecessary COW */
  14. if (ldso_fini) libc.ldso_fini = ldso_fini;
  15. if (fini) libc.fini = fini;
  16. /* Execute constructors (static) linked into the application */
  17. if (init) init(argc, argv, envp);
  18. /* Pass control to to application */
  19. exit(main(argc, argv, envp));
  20. return 0;
  21. }