crt0.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Types.h>
  7. #include <assert.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <sys/internals.h>
  11. #include <unistd.h>
  12. #ifndef _DYNAMIC_LOADER
  13. extern "C" {
  14. extern uintptr_t __stack_chk_guard;
  15. extern bool s_global_initializers_ran;
  16. int main(int, char**, char**);
  17. // Tell the compiler that this may be called from somewhere else.
  18. int _entry(int argc, char** argv, char** env) __attribute__((used));
  19. void _start(int, char**, char**) __attribute__((used));
  20. NAKED void _start(int, char**, char**)
  21. {
  22. # if ARCH(AARCH64)
  23. asm(
  24. "bl _entry\n");
  25. # else
  26. asm(
  27. "push $0\n"
  28. "jmp _entry@plt\n");
  29. # endif
  30. }
  31. int _entry(int argc, char** argv, char** env)
  32. {
  33. environ = env;
  34. __environ_is_malloced = false;
  35. __begin_atexit_locking();
  36. s_global_initializers_ran = true;
  37. _init();
  38. int status = main(argc, argv, environ);
  39. exit(status);
  40. return 20150614;
  41. }
  42. }
  43. #endif