schk.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of XNIX. */
  3. /*
  4. XNIX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) and later version.
  8. */
  9. /*
  10. XNIX 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. /*
  16. You should have received a copy of the GNU General Public License
  17. along with XNIX. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _SCHK_H
  20. #define _SCHK_H
  21. #include <kernel/types.h>
  22. #include <kernel/errno.h>
  23. #include <kernel/panic.h>
  24. #include <kernel/graphic.h>
  25. #include <arch/sys.h>
  26. void __stack_chk_fail(void);
  27. #define schk_init() \
  28. __uint64_t old_sp = get_rsp(); \
  29. syslog(" entering function "); \
  30. syslog(__FUNCTION__); \
  31. if (old_sp < 0x3000) { \
  32. syslog("#1#PANIC: SP < 0x3000\n"); \
  33. __stack_chk_fail(); \
  34. } \
  35. if (old_sp < 0x4000) \
  36. syslog("#2#WARNING: SP < 0x4000 now"); \
  37. else if (old_sp < 0x5000) \
  38. syslog("#3#WARNING: SP < 0x5000 now"); \
  39. else if (old_sp < 0x6000) \
  40. syslog("#4#WARNING: SP < 0x6000 now");
  41. #define schk_leave() \
  42. if (old_sp != get_rsp()) \
  43. __stack_chk_fail();
  44. #endif