Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ptrace.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999, 2000 Niibe Yutaka
3  */
4 #ifndef __ASM_SH_PTRACE_H
5 #define __ASM_SH_PTRACE_H
6 
7 
8 #include <linux/stringify.h>
9 #include <linux/stddef.h>
10 #include <linux/thread_info.h>
11 #include <asm/addrspace.h>
12 #include <asm/page.h>
13 #include <uapi/asm/ptrace.h>
14 
15 #define user_mode(regs) (((regs)->sr & 0x40000000)==0)
16 #define kernel_stack_pointer(_regs) ((unsigned long)(_regs)->regs[15])
17 
18 #define GET_FP(regs) ((regs)->regs[14])
19 #define GET_USP(regs) ((regs)->regs[15])
20 
21 #define arch_has_single_step() (1)
22 
23 /*
24  * kprobe-based event tracer support
25  */
26 struct pt_regs_offset {
27  const char *name;
28  int offset;
29 };
30 
31 #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
32 #define REGS_OFFSET_NAME(num) \
33  {.name = __stringify(r##num), .offset = offsetof(struct pt_regs, regs[num])}
34 #define TREGS_OFFSET_NAME(num) \
35  {.name = __stringify(tr##num), .offset = offsetof(struct pt_regs, tregs[num])}
36 #define REG_OFFSET_END {.name = NULL, .offset = 0}
37 
38 /* Query offset/name of register from its name/offset */
39 extern int regs_query_register_offset(const char *name);
40 extern const char *regs_query_register_name(unsigned int offset);
41 
42 extern const struct pt_regs_offset regoffset_table[];
43 
53 static inline unsigned long regs_get_register(struct pt_regs *regs,
54  unsigned int offset)
55 {
56  if (unlikely(offset > MAX_REG_OFFSET))
57  return 0;
58  return *(unsigned long *)((unsigned long)regs + offset);
59 }
60 
69 static inline int regs_within_kernel_stack(struct pt_regs *regs,
70  unsigned long addr)
71 {
72  return ((addr & ~(THREAD_SIZE - 1)) ==
73  (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
74 }
75 
85 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
86  unsigned int n)
87 {
88  unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
89  addr += n;
90  if (regs_within_kernel_stack(regs, (unsigned long)addr))
91  return *addr;
92  else
93  return 0;
94 }
95 
96 struct perf_event;
97 struct perf_sample_data;
98 
99 extern void ptrace_triggered(struct perf_event *bp,
100  struct perf_sample_data *data, struct pt_regs *regs);
101 
102 #define task_pt_regs(task) \
103  ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1)
104 
105 static inline unsigned long profile_pc(struct pt_regs *regs)
106 {
107  unsigned long pc = regs->pc;
108 
109  if (virt_addr_uncached(pc))
110  return CAC_ADDR(pc);
111 
112  return pc;
113 }
114 #define profile_pc profile_pc
115 
116 #include <asm-generic/ptrace.h>
117 #endif /* __ASM_SH_PTRACE_H */