Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / include / linux / ptrace.h
1 #ifndef _LINUX_PTRACE_H
2 #define _LINUX_PTRACE_H
3 /* ptrace.h */
4 /* structs and defines to help the user use the ptrace system call. */
5
6 /* has the defines to get at the registers. */
7
8 #define PTRACE_TRACEME             0
9 #define PTRACE_PEEKTEXT            1
10 #define PTRACE_PEEKDATA            2
11 #define PTRACE_PEEKUSR             3
12 #define PTRACE_POKETEXT            4
13 #define PTRACE_POKEDATA            5
14 #define PTRACE_POKEUSR             6
15 #define PTRACE_CONT                7
16 #define PTRACE_KILL                8
17 #define PTRACE_SINGLESTEP          9
18
19 #define PTRACE_ATTACH           0x10
20 #define PTRACE_DETACH           0x11
21
22 #define PTRACE_SYSCALL            24
23
24 /* 0x4200-0x4300 are reserved for architecture-independent additions.  */
25 #define PTRACE_SETOPTIONS       0x4200
26 #define PTRACE_GETEVENTMSG      0x4201
27 #define PTRACE_GETSIGINFO       0x4202
28 #define PTRACE_SETSIGINFO       0x4203
29
30 /* options set using PTRACE_SETOPTIONS */
31 #define PTRACE_O_TRACESYSGOOD   0x00000001
32 #define PTRACE_O_TRACEFORK      0x00000002
33 #define PTRACE_O_TRACEVFORK     0x00000004
34 #define PTRACE_O_TRACECLONE     0x00000008
35 #define PTRACE_O_TRACEEXEC      0x00000010
36 #define PTRACE_O_TRACEVFORKDONE 0x00000020
37 #define PTRACE_O_TRACEEXIT      0x00000040
38
39 #define PTRACE_O_MASK           0x0000007f
40
41 /* Wait extended result codes for the above trace options.  */
42 #define PTRACE_EVENT_FORK       1
43 #define PTRACE_EVENT_VFORK      2
44 #define PTRACE_EVENT_CLONE      3
45 #define PTRACE_EVENT_EXEC       4
46 #define PTRACE_EVENT_VFORK_DONE 5
47 #define PTRACE_EVENT_EXIT       6
48
49 #include <asm/ptrace.h>
50
51 #ifdef __KERNEL__
52 #include <linux/compiler.h>
53 #include <linux/types.h>
54 struct task_struct;
55 struct siginfo;
56 struct rusage;
57
58
59 extern int ptrace_may_attach(struct task_struct *task);
60 extern int __ptrace_may_attach(struct task_struct *task);
61
62
63 #ifdef CONFIG_PTRACE
64 #include <asm/tracehook.h>
65 struct utrace_attached_engine;
66 struct utrace_regset_view;
67
68 /*
69  * These must be defined by arch code to handle machine-specific ptrace
70  * requests such as PTRACE_PEEKUSR and PTRACE_GETREGS.  Returns -ENOSYS for
71  * any request it does not handle, then handled by machine-independent code.
72  * This can change *request and then return -ENOSYS to handle a
73  * machine-specific alias for a generic request.
74  *
75  * This code should NOT access task machine state directly.  Instead it
76  * should use the utrace_regset accessors.  The functions below make this easy.
77  *
78  * Any nonzero return value should be for an error.  If the return value of
79  * the ptrace syscall should be a nonzero success value, this returns zero
80  * and sets *retval to the value--which might have any bit pattern at all,
81  * including one that looks like -ENOSYS or another error code.
82  */
83 extern fastcall int arch_ptrace(long *request, struct task_struct *child,
84                                 struct utrace_attached_engine *engine,
85                                 unsigned long addr, unsigned long data,
86                                 long *retval);
87 #ifdef CONFIG_COMPAT
88 #include <linux/compat.h>
89
90 extern fastcall int arch_compat_ptrace(compat_long_t *request,
91                                        struct task_struct *child,
92                                        struct utrace_attached_engine *engine,
93                                        compat_ulong_t a, compat_ulong_t d,
94                                        compat_long_t *retval);
95 #endif
96
97 /*
98  * Convenience function doing access to a single utrace_regset for ptrace.
99  * The offset and size are in bytes, giving the location in the regset data.
100  */
101 extern fastcall int ptrace_regset_access(struct task_struct *child,
102                                          struct utrace_attached_engine *engine,
103                                          const struct utrace_regset_view *view,
104                                          int setno, unsigned long offset,
105                                          unsigned int size, void __user *data,
106                                          int write);
107
108 /*
109  * Convenience wrapper for doing access to a whole utrace_regset for ptrace.
110  */
111 static inline int ptrace_whole_regset(struct task_struct *child,
112                                       struct utrace_attached_engine *engine,
113                                       long data, int setno, int write)
114 {
115         return ptrace_regset_access(child, engine, utrace_native_view(current),
116                                     setno, 0, -1, (void __user *)data, write);
117 }
118
119 /*
120  * Convenience function doing access to a single slot in a utrace_regset.
121  * The regno value gives a slot number plus regset->bias.
122  * The value accessed is regset->size bytes long.
123  */
124 extern fastcall int ptrace_onereg_access(struct task_struct *child,
125                                          struct utrace_attached_engine *engine,
126                                          const struct utrace_regset_view *view,
127                                          int setno, unsigned long regno,
128                                          void __user *data, int write);
129
130
131 /*
132  * An array of these describes the layout of the virtual struct user
133  * accessed by PEEKUSR/POKEUSR, or the structure used by GETREGS et al.
134  * The array is terminated by an element with .end of zero.
135  * An element describes the range [.start, .end) of struct user offsets,
136  * measured in bytes; it maps to the regset in the view's regsets array
137  * at the index given by .regset, at .offset bytes into that regset's data.
138  * If .regset is -1, then the [.start, .end) range reads as zero.
139  */
140 struct ptrace_layout_segment {
141         unsigned int start, end, regset, offset;
142 };
143
144 /*
145  * Convenience function for doing access to a ptrace compatibility layout.
146  * The offset and size are in bytes.
147  */
148 extern fastcall int ptrace_layout_access(
149         struct task_struct *child, struct utrace_attached_engine *engine,
150         const struct utrace_regset_view *view,
151         const struct ptrace_layout_segment layout[],
152         unsigned long offset, unsigned int size,
153         void __user *data, void *kdata, int write);
154
155
156 /* Convenience wrapper for the common PTRACE_PEEKUSR implementation.  */
157 static inline int ptrace_peekusr(struct task_struct *child,
158                                  struct utrace_attached_engine *engine,
159                                  const struct ptrace_layout_segment layout[],
160                                  unsigned long addr, long data)
161 {
162         return ptrace_layout_access(child, engine, utrace_native_view(current),
163                                     layout, addr, sizeof(long),
164                                     (unsigned long __user *)data, NULL, 0);
165 }
166
167 /* Convenience wrapper for the common PTRACE_PEEKUSR implementation.  */
168 static inline int ptrace_pokeusr(struct task_struct *child,
169                                  struct utrace_attached_engine *engine,
170                                  const struct ptrace_layout_segment layout[],
171                                  unsigned long addr, long data)
172 {
173         return ptrace_layout_access(child, engine, utrace_native_view(current),
174                                     layout, addr, sizeof(long),
175                                     NULL, &data, 1);
176 }
177
178 #ifdef CONFIG_COMPAT
179 /* Convenience wrapper for the common PTRACE_PEEKUSR implementation.  */
180 static inline int ptrace_compat_peekusr(
181         struct task_struct *child, struct utrace_attached_engine *engine,
182         const struct ptrace_layout_segment layout[],
183         compat_ulong_t addr, compat_ulong_t data)
184 {
185         compat_ulong_t *udata = (compat_ulong_t __user *) (unsigned long) data;
186         return ptrace_layout_access(child, engine, utrace_native_view(current),
187                                     layout, addr, sizeof(compat_ulong_t),
188                                     udata, NULL, 0);
189 }
190
191 /* Convenience wrapper for the common PTRACE_PEEKUSR implementation.  */
192 static inline int ptrace_compat_pokeusr(
193         struct task_struct *child, struct utrace_attached_engine *engine,
194         const struct ptrace_layout_segment layout[],
195         compat_ulong_t addr, compat_ulong_t data)
196 {
197         return ptrace_layout_access(child, engine, utrace_native_view(current),
198                                     layout, addr, sizeof(compat_ulong_t),
199                                     NULL, &data, 1);
200 }
201 #endif
202
203
204 /*
205  * Called in do_exit, after setting PF_EXITING, no locks are held.
206  */
207 void ptrace_exit(struct task_struct *tsk);
208
209 /*
210  * Called in do_wait, with tasklist_lock held for reading.
211  * This reports any ptrace-child that is ready as do_wait would a normal child.
212  * If there are no ptrace children, returns -ECHILD.
213  * If there are some ptrace children but none reporting now, returns 0.
214  * In those cases the tasklist_lock is still held so next_thread(tsk) works.
215  * For any other return value, tasklist_lock is released before return.
216  */
217 int ptrace_do_wait(struct task_struct *tsk,
218                    pid_t pid, int options, struct siginfo __user *infop,
219                    int __user *stat_addr, struct rusage __user *rusagep);
220 #else
221 static inline void ptrace_exit(struct task_struct *tsk) { }
222 static inline int ptrace_do_wait(struct task_struct *tsk,
223                                  pid_t pid, int options,
224                                  struct siginfo __user *infop,
225                                  int __user *stat_addr,
226                                  struct rusage __user *rusagep)
227 {
228         return -ECHILD;
229 }
230 #endif
231
232
233 #ifndef force_successful_syscall_return
234 /*
235  * System call handlers that, upon successful completion, need to return a
236  * negative value should call force_successful_syscall_return() right before
237  * returning.  On architectures where the syscall convention provides for a
238  * separate error flag (e.g., alpha, ia64, ppc{,64}, sparc{,64}, possibly
239  * others), this macro can be used to ensure that the error flag will not get
240  * set.  On architectures which do not support a separate error flag, the macro
241  * is a no-op and the spurious error condition needs to be filtered out by some
242  * other means (e.g., in user-level, by passing an extra argument to the
243  * syscall handler, or something along those lines).
244  */
245 #define force_successful_syscall_return() do { } while (0)
246 #endif
247
248 #endif
249
250 #endif