stack_protector.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2021 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_STACK_PROTECTOR_H
  19. #define GRUB_STACK_PROTECTOR_H 1
  20. #include <grub/symbol.h>
  21. #include <grub/types.h>
  22. #ifdef GRUB_STACK_PROTECTOR
  23. extern grub_addr_t EXPORT_VAR (__stack_chk_guard);
  24. extern void __attribute__ ((noreturn)) EXPORT_FUNC (__stack_chk_fail) (void);
  25. #if defined(_WIN64) && !defined(__CYGWIN__) /* MinGW, Windows 64-bit target. */
  26. static grub_addr_t __attribute__ ((weakref("__stack_chk_guard"))) EXPORT_VAR (_stack_chk_guard);
  27. static void __attribute__ ((noreturn, weakref("__stack_chk_fail"))) EXPORT_FUNC (_stack_chk_fail) (void);
  28. #endif
  29. extern grub_addr_t grub_stack_protector_init (void);
  30. static inline __attribute__((__always_inline__))
  31. void grub_update_stack_guard (void)
  32. {
  33. grub_addr_t guard;
  34. guard = grub_stack_protector_init ();
  35. if (guard)
  36. __stack_chk_guard = guard;
  37. }
  38. #endif
  39. #endif /* GRUB_STACK_PROTECTOR_H */