]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/ptrace.c
Use <> for include of kernel-features.h.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / ptrace.c
CommitLineData
9c316a45 1/* Copyright (C) 1995-1998,2000,2003,2006 Free Software Foundation, Inc.
478b92f0
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
478b92f0
UD
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
478b92f0 13
41bdb6e2
AJ
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
93995795
RM
18
19#include <errno.h>
97aa195c 20#include <sys/types.h>
93995795 21#include <sys/ptrace.h>
4bbb61e4 22#include <sys/user.h>
97aa195c 23#include <stdarg.h>
9c316a45 24#include <signal.h>
97aa195c 25
0dee6738
UD
26#include <sysdep.h>
27#include <sys/syscall.h>
4bbb61e4 28#include <bp-checks.h>
0dee6738 29
4547c1a4 30long int
97aa195c 31ptrace (enum __ptrace_request request, ...)
93995795 32{
4547c1a4 33 long int res, ret;
97aa195c
RM
34 va_list ap;
35 pid_t pid;
36 void *addr, *data;
37
38 va_start (ap, request);
39 pid = va_arg (ap, pid_t);
40 addr = va_arg (ap, void *);
41 data = va_arg (ap, void *);
42 va_end (ap);
43
93995795 44 if (request > 0 && request < 4)
97aa195c 45 data = &ret;
93995795 46
4bbb61e4
GM
47#if __BOUNDED_POINTERS__
48 switch (request)
49 {
50 case PTRACE_PEEKTEXT:
51 case PTRACE_PEEKDATA:
52 case PTRACE_PEEKUSER:
53 case PTRACE_POKETEXT:
54 case PTRACE_POKEDATA:
55 case PTRACE_POKEUSER:
c62f5cab
GM
56 (void) CHECK_1 ((int *) addr);
57 (void) CHECK_1 ((int *) data);
4bbb61e4
GM
58 break;
59
60 case PTRACE_GETREGS:
61 case PTRACE_SETREGS:
62#ifdef __i386__
c62f5cab 63 (void) CHECK_1 ((struct user_regs_struct *) data);
4bbb61e4
GM
64#else
65 /* We don't know the size of data, so the best we can do is ensure
66 that `data' is valid for at least one word. */
c62f5cab 67 (void) CHECK_1 ((int *) data);
4bbb61e4
GM
68#endif
69 break;
70
71 case PTRACE_GETFPREGS:
72 case PTRACE_SETFPREGS:
73#ifdef __i386__
c62f5cab 74 (void) CHECK_1 ((struct user_fpregs_struct *) data);
4bbb61e4
GM
75#else
76 /* We don't know the size of data, so the best we can do is ensure
77 that `data' is valid for at least one word. */
c62f5cab 78 (void) CHECK_1 ((int *) data);
4bbb61e4
GM
79#endif
80 break;
81
82 case PTRACE_GETFPXREGS:
83 case PTRACE_SETFPXREGS:
84#ifdef __i386__
c62f5cab 85 (void) CHECK_1 ((struct user_fpxregs_struct *) data);
4bbb61e4
GM
86#else
87 /* We don't know the size of data, so the best we can do is ensure
88 that `data' is valid for at least one word. */
c62f5cab 89 (void) CHECK_1 ((int *) data);
4bbb61e4
GM
90#endif
91 break;
14fa17cc 92
9c316a45
UD
93 case PTRACE_GETSIGINFO:
94 case PTRACE_SETSIGINFO:
95 (void) CHECK_1 ((siginfo_t *) data);
96 break;
97
98 case PTRACE_GETEVENTMSG:
99 (void) CHECK_1 ((unsigned long *) data);
100 break;
101
102 case PTRACE_SETOPTIONS:
103 (void) CHECK_1 ((long *) data);
104 break;
105
14fa17cc
GM
106 case PTRACE_TRACEME:
107 case PTRACE_CONT:
108 case PTRACE_KILL:
109 case PTRACE_SINGLESTEP:
110 case PTRACE_ATTACH:
111 case PTRACE_DETACH:
112 case PTRACE_SYSCALL:
113 /* Neither `data' nor `addr' needs any checks. */
114 break;
4bbb61e4
GM
115 };
116#endif
117
118 res = INLINE_SYSCALL (ptrace, 4, request, pid,
119 __ptrvalue (addr), __ptrvalue (data));
0dee6738 120 if (res >= 0 && request > 0 && request < 4)
93995795 121 {
0dee6738
UD
122 __set_errno (0);
123 return ret;
93995795
RM
124 }
125
0dee6738 126 return res;
93995795 127}