ssp.cpp 909 B

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