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