| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /* Copyright (C) 2021 Rain */
- /* This file is part of XNIX. */
- /*
- XNIX is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) and later version.
- */
- /*
- XNIX is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- */
- /*
- You should have received a copy of the GNU General Public License
- along with XNIX. If not, see <https://www.gnu.org/licenses/>.
- */
- #ifndef _SCHK_H
- #define _SCHK_H
- #include <kernel/init.h>
- #include <kernel/types.h>
- #include <kernel/errno.h>
- #include <kernel/panic.h>
- #include <arch/sys.h>
- void __stack_chk_fail(void);
- #if DEBUG_LEVEL == TEST_DEBUG_LEVEL
- #define schk_init() \
- __uint64_t old_sp = get_rsp(); \
- syslog(" entering function "); \
- syslog(__FUNCTION__); \
- if (old_sp < 0x3000) { \
- syslog("#1#PANIC: SP < 0x3000\n"); \
- __stack_chk_fail(); \
- } \
- if (old_sp < 0x4000) \
- syslog("#2#WARNING: SP < 0x4000 now"); \
- else if (old_sp < 0x5000) \
- syslog("#3#WARNING: SP < 0x5000 now"); \
- else if (old_sp < 0x6000) \
- syslog("#4#WARNING: SP < 0x6000 now"); \
- #elif DEBUG_LEVEL == DEV_DEBUG_LEVEL
- #define schk_init() __uint64_t old_sp = get_rsp();
- #elif DEBUG_LEVEL == DEFAULT_DEBUG_LEVEL
- #define schk_init()
- #else
- #error "unknow debug level (in init.h)"
- #endif
- #if DEBUG_LEVEL == DEFAULT_DEBUG_LEVEL
- #define schk_leave()
- #else
- #define schk_leave() \
- if (old_sp != get_rsp()) \
- __stack_chk_fail()
- #endif
- #endif
|