blob: 5247283d1c03e57c94d40ebfea4074cdf7db3100 [file] [log] [blame]
David S. Miller4f70f7a2008-08-12 18:33:56 -07001#ifndef _KSTACK_H
2#define _KSTACK_H
3
4#include <linux/thread_info.h>
5#include <linux/sched.h>
6#include <asm/ptrace.h>
7#include <asm/irq.h>
8
9/* SP must be STACK_BIAS adjusted already. */
10static inline bool kstack_valid(struct thread_info *tp, unsigned long sp)
11{
12 unsigned long base = (unsigned long) tp;
13
David S. Miller232486e2010-02-12 12:03:45 -080014 /* Stack pointer must be 16-byte aligned. */
15 if (sp & (16UL - 1))
16 return false;
17
David S. Miller4f70f7a2008-08-12 18:33:56 -070018 if (sp >= (base + sizeof(struct thread_info)) &&
19 sp <= (base + THREAD_SIZE - sizeof(struct sparc_stackf)))
20 return true;
21
David S. Miller6f63e782008-08-13 17:17:52 -070022 if (hardirq_stack[tp->cpu]) {
23 base = (unsigned long) hardirq_stack[tp->cpu];
24 if (sp >= base &&
25 sp <= (base + THREAD_SIZE - sizeof(struct sparc_stackf)))
26 return true;
27 base = (unsigned long) softirq_stack[tp->cpu];
28 if (sp >= base &&
29 sp <= (base + THREAD_SIZE - sizeof(struct sparc_stackf)))
30 return true;
31 }
David S. Miller4f70f7a2008-08-12 18:33:56 -070032 return false;
33}
34
35/* Does "regs" point to a valid pt_regs trap frame? */
36static inline bool kstack_is_trap_frame(struct thread_info *tp, struct pt_regs *regs)
37{
38 unsigned long base = (unsigned long) tp;
39 unsigned long addr = (unsigned long) regs;
40
41 if (addr >= base &&
42 addr <= (base + THREAD_SIZE - sizeof(*regs)))
43 goto check_magic;
44
David S. Miller6f63e782008-08-13 17:17:52 -070045 if (hardirq_stack[tp->cpu]) {
46 base = (unsigned long) hardirq_stack[tp->cpu];
47 if (addr >= base &&
48 addr <= (base + THREAD_SIZE - sizeof(*regs)))
49 goto check_magic;
50 base = (unsigned long) softirq_stack[tp->cpu];
51 if (addr >= base &&
52 addr <= (base + THREAD_SIZE - sizeof(*regs)))
53 goto check_magic;
54 }
David S. Miller4f70f7a2008-08-12 18:33:56 -070055 return false;
56
57check_magic:
58 if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC)
59 return true;
60 return false;
61
62}
63
64#endif /* _KSTACK_H */