Serenity Operating System
1/*
2 * Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <AK/Format.h>
8#include <AK/Types.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <sys/internals.h>
12#include <unistd.h>
13
14#if defined __SSP__ || defined __SSP_ALL__
15# error "file must not be compiled with stack protection enabled on it. Use -fno-stack-protector"
16#endif
17
18extern "C" {
19
20extern uintptr_t __stack_chk_guard;
21// Initialized in `initialize_libc` (we leave a placeholder value here before initialization).
22__attribute__((used)) uintptr_t __stack_chk_guard = (uintptr_t)0xc6c7c8c9;
23
24__attribute__((noreturn)) void __stack_chk_fail()
25{
26 dbgln("Error: USERSPACE({}) Stack protector failure, stack smashing detected!", getpid());
27 if (__stdio_is_initialized)
28 warnln("Error: Stack protector failure, stack smashing detected!");
29 abort();
30}
31
32} // extern "C"