~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/sparc/kernel/kstack.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _KSTACK_H
  3 #define _KSTACK_H
  4 
  5 #include <linux/thread_info.h>
  6 #include <linux/sched.h>
  7 #include <asm/ptrace.h>
  8 #include <asm/irq.h>
  9 
 10 /* SP must be STACK_BIAS adjusted already.  */
 11 static inline bool kstack_valid(struct thread_info *tp, unsigned long sp)
 12 {
 13         unsigned long base = (unsigned long) tp;
 14 
 15         /* Stack pointer must be 16-byte aligned.  */
 16         if (sp & (16UL - 1))
 17                 return false;
 18 
 19         if (sp >= (base + sizeof(struct thread_info)) &&
 20             sp <= (base + THREAD_SIZE - sizeof(struct sparc_stackf)))
 21                 return true;
 22 
 23         if (hardirq_stack[tp->cpu]) {
 24                 base = (unsigned long) hardirq_stack[tp->cpu];
 25                 if (sp >= base &&
 26                     sp <= (base + THREAD_SIZE - sizeof(struct sparc_stackf)))
 27                         return true;
 28                 base = (unsigned long) softirq_stack[tp->cpu];
 29                 if (sp >= base &&
 30                     sp <= (base + THREAD_SIZE - sizeof(struct sparc_stackf)))
 31                         return true;
 32         }
 33         return false;
 34 }
 35 
 36 /* Does "regs" point to a valid pt_regs trap frame?  */
 37 static inline bool kstack_is_trap_frame(struct thread_info *tp, struct pt_regs *regs)
 38 {
 39         unsigned long base = (unsigned long) tp;
 40         unsigned long addr = (unsigned long) regs;
 41 
 42         if (addr >= base &&
 43             addr <= (base + THREAD_SIZE - sizeof(*regs)))
 44                 goto check_magic;
 45 
 46         if (hardirq_stack[tp->cpu]) {
 47                 base = (unsigned long) hardirq_stack[tp->cpu];
 48                 if (addr >= base &&
 49                     addr <= (base + THREAD_SIZE - sizeof(*regs)))
 50                         goto check_magic;
 51                 base = (unsigned long) softirq_stack[tp->cpu];
 52                 if (addr >= base &&
 53                     addr <= (base + THREAD_SIZE - sizeof(*regs)))
 54                         goto check_magic;
 55         }
 56         return false;
 57 
 58 check_magic:
 59         if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC)
 60                 return true;
 61         return false;
 62 
 63 }
 64 
 65 static inline __attribute__((always_inline)) void *set_hardirq_stack(void)
 66 {
 67         void *orig_sp, *sp = hardirq_stack[smp_processor_id()];
 68 
 69         __asm__ __volatile__("mov %%sp, %0" : "=r" (orig_sp));
 70         if (orig_sp < sp ||
 71             orig_sp > (sp + THREAD_SIZE)) {
 72                 sp += THREAD_SIZE - 192 - STACK_BIAS;
 73                 __asm__ __volatile__("mov %0, %%sp" : : "r" (sp));
 74         }
 75 
 76         return orig_sp;
 77 }
 78 
 79 static inline __attribute__((always_inline)) void restore_hardirq_stack(void *orig_sp)
 80 {
 81         __asm__ __volatile__("mov %0, %%sp" : : "r" (orig_sp));
 82 }
 83 
 84 #endif /* _KSTACK_H */
 85 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php