b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef _ASM_SCS_H |
| 3 | #define _ASM_SCS_H |
| 4 | |
| 5 | #ifndef __ASSEMBLY__ |
| 6 | |
| 7 | #include <linux/scs.h> |
| 8 | |
| 9 | #ifdef CONFIG_SHADOW_CALL_STACK |
| 10 | |
| 11 | extern void scs_init_irq(void); |
| 12 | |
| 13 | static __always_inline void scs_save(struct task_struct *tsk) |
| 14 | { |
| 15 | void *s; |
| 16 | |
| 17 | asm volatile("mov %0, x18" : "=r" (s)); |
| 18 | task_set_scs(tsk, s); |
| 19 | } |
| 20 | |
| 21 | static inline void scs_overflow_check(struct task_struct *tsk) |
| 22 | { |
| 23 | if (unlikely(scs_corrupted(tsk))) |
| 24 | panic("corrupted shadow stack detected inside scheduler\n"); |
| 25 | } |
| 26 | |
| 27 | #else /* CONFIG_SHADOW_CALL_STACK */ |
| 28 | |
| 29 | static inline void scs_init_irq(void) {} |
| 30 | static inline void scs_save(struct task_struct *tsk) {} |
| 31 | static inline void scs_overflow_check(struct task_struct *tsk) {} |
| 32 | |
| 33 | #endif /* CONFIG_SHADOW_CALL_STACK */ |
| 34 | |
| 35 | #endif /* __ASSEMBLY __ */ |
| 36 | |
| 37 | #endif /* _ASM_SCS_H */ |