ssp.cpp 859 B

123456789101112131415161718192021222324252627282930313233343536
  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 u32 __stack_chk_guard;
  17. u32 __stack_chk_guard = (u32)0xc6c7c8c9;
  18. __attribute__((noreturn)) void __stack_chk_fail()
  19. {
  20. dbgln("Error: USERSPACE({}) Stack protector failure, stack smashing detected!", getpid());
  21. if (__stdio_is_initialized)
  22. warnln("Error: Stack protector failure, stack smashing detected!");
  23. abort();
  24. }
  25. __attribute__((noreturn)) void __stack_chk_fail_local()
  26. {
  27. __stack_chk_fail();
  28. }
  29. } // extern "C"