2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-12-20 16:51:50 -03:00
|
|
|
#include <AK/Types.h>
|
2019-02-22 05:21:54 -03:00
|
|
|
#include <assert.h>
|
2018-10-30 22:09:11 -03:00
|
|
|
#include <stdio.h>
|
2019-02-22 05:21:54 -03:00
|
|
|
#include <stdlib.h>
|
2020-08-11 20:58:50 -03:00
|
|
|
#include <sys/internals.h>
|
|
|
|
|
#include <unistd.h>
|
2018-10-22 09:06:22 -03:00
|
|
|
|
2021-04-17 13:38:32 -03:00
|
|
|
#ifndef _DYNAMIC_LOADER
|
2019-02-15 09:30:48 -02:00
|
|
|
extern "C" {
|
|
|
|
|
|
2021-07-16 18:30:01 -03:00
|
|
|
extern size_t __stack_chk_guard;
|
2021-01-02 09:27:35 -03:00
|
|
|
|
2019-09-12 16:43:32 -03:00
|
|
|
int main(int, char**, char**);
|
2018-10-22 09:06:22 -03:00
|
|
|
|
2020-08-11 19:07:34 -03:00
|
|
|
// Tell the compiler that this may be called from somewhere else.
|
2021-07-08 19:58:43 -03:00
|
|
|
int _entry(int argc, char** argv, char** env);
|
2021-07-11 10:57:56 -03:00
|
|
|
void _start(int, char**, char**);
|
2020-08-11 19:07:34 -03:00
|
|
|
|
2021-07-11 10:57:56 -03:00
|
|
|
NAKED void _start(int, char**, char**)
|
|
|
|
|
{
|
|
|
|
|
asm(
|
|
|
|
|
"push $0\n"
|
|
|
|
|
"jmp _entry@plt\n");
|
|
|
|
|
}
|
2021-07-08 19:58:43 -03:00
|
|
|
|
|
|
|
|
int _entry(int argc, char** argv, char** env)
|
2018-10-22 09:06:22 -03:00
|
|
|
{
|
2021-07-16 18:30:01 -03:00
|
|
|
size_t original_stack_chk = __stack_chk_guard;
|
2021-01-02 09:27:35 -03:00
|
|
|
arc4random_buf(&__stack_chk_guard, sizeof(__stack_chk_guard));
|
|
|
|
|
|
|
|
|
|
if (__stack_chk_guard == 0)
|
|
|
|
|
__stack_chk_guard = original_stack_chk;
|
|
|
|
|
|
2019-02-21 21:55:22 -03:00
|
|
|
environ = env;
|
2019-05-16 08:04:47 -03:00
|
|
|
__environ_is_malloced = false;
|
2018-10-30 22:09:11 -03:00
|
|
|
|
2019-03-27 08:48:21 -03:00
|
|
|
_init();
|
|
|
|
|
|
2019-09-12 16:43:32 -03:00
|
|
|
int status = main(argc, argv, environ);
|
2018-10-31 13:50:43 -03:00
|
|
|
|
2019-02-22 05:21:54 -03:00
|
|
|
exit(status);
|
2018-10-22 09:06:22 -03:00
|
|
|
|
2021-01-02 09:27:35 -03:00
|
|
|
// We should never get here, but if we ever do, make sure to
|
|
|
|
|
// restore the stack guard to the value we entered _start with.
|
|
|
|
|
// Then we won't trigger the stack canary check on the way out.
|
|
|
|
|
__stack_chk_guard = original_stack_chk;
|
|
|
|
|
|
2018-10-22 09:06:22 -03:00
|
|
|
return 20150614;
|
|
|
|
|
}
|
2019-02-15 09:30:48 -02:00
|
|
|
}
|
2021-04-17 13:38:32 -03:00
|
|
|
#endif
|