Test for stack alignment.
[glibc.git] / sysdeps / unix / sysv / linux / mips / ptrace.c
blob19d7c2d92783896fa7f848078897592bdc6d0b6d
1 /* Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2003, 2004
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <sgidefs.h>
22 #include <sys/types.h>
23 #include <sys/ptrace.h>
24 #include <sys/user.h>
25 #include <stdarg.h>
27 #include <sysdep.h>
28 #include <sys/syscall.h>
29 #include <bp-checks.h>
30 #include <sgidefs.h>
32 #if _MIPS_SIM == _ABIN32
33 __extension__ typedef long long int reg_type;
34 #else
35 typedef long int reg_type;
36 #endif
38 reg_type
39 ptrace (enum __ptrace_request request, ...)
41 reg_type res, ret;
42 va_list ap;
43 pid_t pid;
44 void *addr;
45 reg_type data;
47 va_start (ap, request);
48 pid = va_arg (ap, pid_t);
49 addr = va_arg (ap, void *);
50 data = va_arg (ap, reg_type);
51 va_end (ap);
53 if (request > 0 && request < 4)
54 data = &ret;
56 #if __BOUNDED_POINTERS__
57 switch (request)
59 case PTRACE_PEEKTEXT:
60 case PTRACE_PEEKDATA:
61 case PTRACE_PEEKUSER:
62 case PTRACE_POKETEXT:
63 case PTRACE_POKEDATA:
64 case PTRACE_POKEUSER:
65 (void) CHECK_1 ((int *) addr);
66 (void) CHECK_1 ((int *) data);
67 break;
69 case PTRACE_GETREGS:
70 case PTRACE_SETREGS:
71 /* We don't know the size of data, so the best we can do is ensure
72 that `data' is valid for at least one word. */
73 (void) CHECK_1 ((int *) data);
74 break;
76 case PTRACE_GETFPREGS:
77 case PTRACE_SETFPREGS:
78 /* We don't know the size of data, so the best we can do is ensure
79 that `data' is valid for at least one word. */
80 (void) CHECK_1 ((int *) data);
81 break;
83 case PTRACE_GETFPXREGS:
84 case PTRACE_SETFPXREGS:
85 /* We don't know the size of data, so the best we can do is ensure
86 that `data' is valid for at least one word. */
87 (void) CHECK_1 ((int *) data);
88 break;
90 case PTRACE_TRACEME:
91 case PTRACE_CONT:
92 case PTRACE_KILL:
93 case PTRACE_SINGLESTEP:
94 case PTRACE_ATTACH:
95 case PTRACE_DETACH:
96 case PTRACE_SYSCALL:
97 /* Neither `data' nor `addr' needs any checks. */
98 break;
100 #endif
102 res = INLINE_SYSCALL (ptrace, 4, request, pid,
103 __ptrvalue (addr), __ptrvalue (data));
104 if (res >= 0 && request > 0 && request < 4)
106 __set_errno (0);
107 return ret;
110 return res;