Linux 3.16-rc2
[linux/fpc-iii.git] / arch / um / kernel / ptrace.c
blob694d551c88996dbee7c974487b9299c9f1efc8fe
1 /*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
6 #include <linux/audit.h>
7 #include <linux/ptrace.h>
8 #include <linux/sched.h>
9 #include <linux/tracehook.h>
10 #include <asm/uaccess.h>
11 #include <skas_ptrace.h>
15 void user_enable_single_step(struct task_struct *child)
17 child->ptrace |= PT_DTRACE;
18 child->thread.singlestep_syscall = 0;
20 #ifdef SUBARCH_SET_SINGLESTEPPING
21 SUBARCH_SET_SINGLESTEPPING(child, 1);
22 #endif
25 void user_disable_single_step(struct task_struct *child)
27 child->ptrace &= ~PT_DTRACE;
28 child->thread.singlestep_syscall = 0;
30 #ifdef SUBARCH_SET_SINGLESTEPPING
31 SUBARCH_SET_SINGLESTEPPING(child, 0);
32 #endif
36 * Called by kernel/ptrace.c when detaching..
38 void ptrace_disable(struct task_struct *child)
40 user_disable_single_step(child);
43 extern int peek_user(struct task_struct * child, long addr, long data);
44 extern int poke_user(struct task_struct * child, long addr, long data);
46 long arch_ptrace(struct task_struct *child, long request,
47 unsigned long addr, unsigned long data)
49 int i, ret;
50 unsigned long __user *p = (void __user *)data;
51 void __user *vp = p;
53 switch (request) {
54 /* read the word at location addr in the USER area. */
55 case PTRACE_PEEKUSR:
56 ret = peek_user(child, addr, data);
57 break;
59 /* write the word at location addr in the USER area */
60 case PTRACE_POKEUSR:
61 ret = poke_user(child, addr, data);
62 break;
64 case PTRACE_SYSEMU:
65 case PTRACE_SYSEMU_SINGLESTEP:
66 ret = -EIO;
67 break;
69 #ifdef PTRACE_GETREGS
70 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
71 if (!access_ok(VERIFY_WRITE, p, MAX_REG_OFFSET)) {
72 ret = -EIO;
73 break;
75 for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
76 __put_user(getreg(child, i), p);
77 p++;
79 ret = 0;
80 break;
82 #endif
83 #ifdef PTRACE_SETREGS
84 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
85 unsigned long tmp = 0;
86 if (!access_ok(VERIFY_READ, p, MAX_REG_OFFSET)) {
87 ret = -EIO;
88 break;
90 for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
91 __get_user(tmp, p);
92 putreg(child, i, tmp);
93 p++;
95 ret = 0;
96 break;
98 #endif
99 case PTRACE_GET_THREAD_AREA:
100 ret = ptrace_get_thread_area(child, addr, vp);
101 break;
103 case PTRACE_SET_THREAD_AREA:
104 ret = ptrace_set_thread_area(child, addr, vp);
105 break;
107 case PTRACE_FAULTINFO: {
109 * Take the info from thread->arch->faultinfo,
110 * but transfer max. sizeof(struct ptrace_faultinfo).
111 * On i386, ptrace_faultinfo is smaller!
113 ret = copy_to_user(p, &child->thread.arch.faultinfo,
114 sizeof(struct ptrace_faultinfo)) ?
115 -EIO : 0;
116 break;
119 #ifdef PTRACE_LDT
120 case PTRACE_LDT: {
121 struct ptrace_ldt ldt;
123 if (copy_from_user(&ldt, p, sizeof(ldt))) {
124 ret = -EIO;
125 break;
129 * This one is confusing, so just punt and return -EIO for
130 * now
132 ret = -EIO;
133 break;
135 #endif
136 default:
137 ret = ptrace_request(child, request, addr, data);
138 if (ret == -EIO)
139 ret = subarch_ptrace(child, request, addr, data);
140 break;
143 return ret;
146 static void send_sigtrap(struct task_struct *tsk, struct uml_pt_regs *regs,
147 int error_code)
149 struct siginfo info;
151 memset(&info, 0, sizeof(info));
152 info.si_signo = SIGTRAP;
153 info.si_code = TRAP_BRKPT;
155 /* User-mode eip? */
156 info.si_addr = UPT_IS_USER(regs) ? (void __user *) UPT_IP(regs) : NULL;
158 /* Send us the fake SIGTRAP */
159 force_sig_info(SIGTRAP, &info, tsk);
163 * XXX Check PT_DTRACE vs TIF_SINGLESTEP for singlestepping check and
164 * PT_PTRACED vs TIF_SYSCALL_TRACE for syscall tracing check
166 void syscall_trace_enter(struct pt_regs *regs)
168 audit_syscall_entry(HOST_AUDIT_ARCH,
169 UPT_SYSCALL_NR(&regs->regs),
170 UPT_SYSCALL_ARG1(&regs->regs),
171 UPT_SYSCALL_ARG2(&regs->regs),
172 UPT_SYSCALL_ARG3(&regs->regs),
173 UPT_SYSCALL_ARG4(&regs->regs));
175 if (!test_thread_flag(TIF_SYSCALL_TRACE))
176 return;
178 tracehook_report_syscall_entry(regs);
181 void syscall_trace_leave(struct pt_regs *regs)
183 int ptraced = current->ptrace;
185 audit_syscall_exit(regs);
187 /* Fake a debug trap */
188 if (ptraced & PT_DTRACE)
189 send_sigtrap(current, &regs->regs, 0);
191 if (!test_thread_flag(TIF_SYSCALL_TRACE))
192 return;
194 tracehook_report_syscall_exit(regs, 0);
195 /* force do_signal() --> is_syscall() */
196 if (ptraced & PT_PTRACED)
197 set_thread_flag(TIF_SIGPENDING);