fedora core 6 1.2949 + vserver 2.2.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             16
20 #define PTRACE_DETACH             17
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>             /* For unlikely.  */
53 #include <linux/sched.h>                /* For struct task_struct.  */
54 #include <linux/types.h>
55 #include <linux/errno.h>
56 struct siginfo;
57 struct rusage;
58
59
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 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 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 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 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  * if .offset is zero, and is skipped on read (user's buffer unchanged)
140  * if .offset is -1.
141  */
142 struct ptrace_layout_segment {
143         unsigned int start, end, regset, offset;
144 };
145
146 /*
147  * Convenience function for doing access to a ptrace compatibility layout.
148  * The offset and size are in bytes.
149  */
150 extern int ptrace_layout_access(struct task_struct *child,
151                                 struct utrace_attached_engine *engine,
152                                 const struct utrace_regset_view *view,
153                                 const struct ptrace_layout_segment layout[],
154                                 unsigned long offset, unsigned int size,
155                                 void __user *data, void *kdata, int write);
156
157
158 /* Convenience wrapper for the common PTRACE_PEEKUSR implementation.  */
159 static inline int ptrace_peekusr(struct task_struct *child,
160                                  struct utrace_attached_engine *engine,
161                                  const struct ptrace_layout_segment layout[],
162                                  unsigned long addr, long data)
163 {
164         return ptrace_layout_access(child, engine, utrace_native_view(current),
165                                     layout, addr, sizeof(long),
166                                     (unsigned long __user *)data, NULL, 0);
167 }
168
169 /* Convenience wrapper for the common PTRACE_PEEKUSR implementation.  */
170 static inline int ptrace_pokeusr(struct task_struct *child,
171                                  struct utrace_attached_engine *engine,
172                                  const struct ptrace_layout_segment layout[],
173                                  unsigned long addr, long data)
174 {
175         return ptrace_layout_access(child, engine, utrace_native_view(current),
176                                     layout, addr, sizeof(long),
177                                     NULL, &data, 1);
178 }
179
180 #ifdef CONFIG_COMPAT
181 /* Convenience wrapper for the common PTRACE_PEEKUSR implementation.  */
182 static inline int ptrace_compat_peekusr(
183         struct task_struct *child, struct utrace_attached_engine *engine,
184         const struct ptrace_layout_segment layout[],
185         compat_ulong_t addr, compat_ulong_t data)
186 {
187         compat_ulong_t *udata = (compat_ulong_t __user *) (unsigned long) data;
188         return ptrace_layout_access(child, engine, utrace_native_view(current),
189                                     layout, addr, sizeof(compat_ulong_t),
190                                     udata, NULL, 0);
191 }
192
193 /* Convenience wrapper for the common PTRACE_PEEKUSR implementation.  */
194 static inline int ptrace_compat_pokeusr(
195         struct task_struct *child, struct utrace_attached_engine *engine,
196         const struct ptrace_layout_segment layout[],
197         compat_ulong_t addr, compat_ulong_t data)
198 {
199         return ptrace_layout_access(child, engine, utrace_native_view(current),
200                                     layout, addr, sizeof(compat_ulong_t),
201                                     NULL, &data, 1);
202 }
203 #endif
204
205
206 /*
207  * Called in copy_process.
208  */
209 static inline void ptrace_init_task(struct task_struct *tsk)
210 {
211         INIT_LIST_HEAD(&tsk->ptracees);
212 }
213
214 /*
215  * Called in do_exit, after setting PF_EXITING, no locks are held.
216  */
217 void ptrace_exit(struct task_struct *tsk);
218
219 /*
220  * Called in do_wait, with tasklist_lock held for reading.
221  * This reports any ptrace-child that is ready as do_wait would a normal child.
222  * If there are no ptrace children, returns -ECHILD.
223  * If there are some ptrace children but none reporting now, returns 0.
224  * In those cases the tasklist_lock is still held so next_thread(tsk) works.
225  * For any other return value, tasklist_lock is released before return.
226  */
227 int ptrace_do_wait(struct task_struct *tsk,
228                    pid_t pid, int options, struct siginfo __user *infop,
229                    int __user *stat_addr, struct rusage __user *rusagep);
230 #else
231 static inline void ptrace_init_task(struct task_struct *tsk) { }
232 static inline void ptrace_exit(struct task_struct *tsk) { }
233 static inline int ptrace_do_wait(struct task_struct *tsk,
234                                  pid_t pid, int options,
235                                  struct siginfo __user *infop,
236                                  int __user *stat_addr,
237                                  struct rusage __user *rusagep)
238 {
239         return -ECHILD;
240 }
241 #endif
242
243
244 #ifndef force_successful_syscall_return
245 /*
246  * System call handlers that, upon successful completion, need to return a
247  * negative value should call force_successful_syscall_return() right before
248  * returning.  On architectures where the syscall convention provides for a
249  * separate error flag (e.g., alpha, ia64, ppc{,64}, sparc{,64}, possibly
250  * others), this macro can be used to ensure that the error flag will not get
251  * set.  On architectures which do not support a separate error flag, the macro
252  * is a no-op and the spurious error condition needs to be filtered out by some
253  * other means (e.g., in user-level, by passing an extra argument to the
254  * syscall handler, or something along those lines).
255  */
256 #define force_successful_syscall_return() do { } while (0)
257 #endif
258
259 #endif
260
261 #endif