2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2019-12-20 19:51:50 +00:00
|
|
|
#include <AK/Types.h>
|
2019-02-22 08:21:54 +00:00
|
|
|
#include <assert.h>
|
2018-10-31 01:09:11 +00:00
|
|
|
#include <stdio.h>
|
2019-02-22 08:21:54 +00:00
|
|
|
#include <stdlib.h>
|
2020-08-11 23:58:50 +00:00
|
|
|
#include <sys/internals.h>
|
|
|
|
#include <unistd.h>
|
2018-10-22 12:06:22 +00:00
|
|
|
|
2021-04-17 16:38:32 +00:00
|
|
|
#ifndef _DYNAMIC_LOADER
|
2019-02-15 11:30:48 +00:00
|
|
|
extern "C" {
|
|
|
|
|
2022-11-26 18:17:32 +00:00
|
|
|
extern uintptr_t __stack_chk_guard;
|
2022-01-23 13:47:10 +00:00
|
|
|
extern bool s_global_initializers_ran;
|
2021-01-02 12:27:35 +00:00
|
|
|
|
2019-09-12 19:43:32 +00:00
|
|
|
int main(int, char**, char**);
|
2018-10-22 12:06:22 +00:00
|
|
|
|
2020-08-11 22:07:34 +00:00
|
|
|
// Tell the compiler that this may be called from somewhere else.
|
2021-09-05 14:08:13 +00:00
|
|
|
int _entry(int argc, char** argv, char** env) __attribute__((used));
|
|
|
|
void _start(int, char**, char**) __attribute__((used));
|
2020-08-11 22:07:34 +00:00
|
|
|
|
2021-07-11 13:57:56 +00:00
|
|
|
NAKED void _start(int, char**, char**)
|
|
|
|
{
|
2022-10-12 20:18:24 +00:00
|
|
|
# ifdef AK_ARCH_AARCH64
|
|
|
|
asm(
|
|
|
|
"bl _entry\n");
|
|
|
|
# else
|
2021-07-11 13:57:56 +00:00
|
|
|
asm(
|
|
|
|
"push $0\n"
|
|
|
|
"jmp _entry@plt\n");
|
2022-10-12 20:18:24 +00:00
|
|
|
# endif
|
2021-07-11 13:57:56 +00:00
|
|
|
}
|
2021-07-08 22:58:43 +00:00
|
|
|
|
|
|
|
int _entry(int argc, char** argv, char** env)
|
2018-10-22 12:06:22 +00:00
|
|
|
{
|
2019-02-22 00:55:22 +00:00
|
|
|
environ = env;
|
2019-05-16 11:04:47 +00:00
|
|
|
__environ_is_malloced = false;
|
2021-11-06 11:49:26 +00:00
|
|
|
__begin_atexit_locking();
|
2018-10-31 01:09:11 +00:00
|
|
|
|
2022-01-23 13:47:10 +00:00
|
|
|
s_global_initializers_ran = true;
|
|
|
|
|
2019-03-27 11:48:21 +00:00
|
|
|
_init();
|
|
|
|
|
2019-09-12 19:43:32 +00:00
|
|
|
int status = main(argc, argv, environ);
|
2018-10-31 16:50:43 +00:00
|
|
|
|
2019-02-22 08:21:54 +00:00
|
|
|
exit(status);
|
2018-10-22 12:06:22 +00:00
|
|
|
|
|
|
|
return 20150614;
|
|
|
|
}
|
2019-02-15 11:30:48 +00:00
|
|
|
}
|
2021-04-17 16:38:32 +00:00
|
|
|
#endif
|