blob: b964f0b2d8864ea091ecca93ab0cf14754aaac80 [file] [log] [blame]
Chris Zankel5a0015d2005-06-23 22:01:16 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
Chris Zankelc658eac2008-02-12 13:17:07 -08006 * Copyright (C) 2001 - 2007 Tensilica Inc.
Chris Zankel5a0015d2005-06-23 22:01:16 -07007 *
8 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
9 * Chris Zankel <chris@zankel.net>
10 * Scott Foehner<sfoehner@yahoo.com>,
11 * Kevin Chea
12 * Marc Gauthier<marc@tensilica.com> <marc@alumni.uwaterloo.ca>
13 */
14
Chris Zankel5a0015d2005-06-23 22:01:16 -070015#include <linux/errno.h>
Max Filippovc91e02b2016-01-24 10:32:10 +030016#include <linux/hw_breakpoint.h>
17#include <linux/kernel.h>
18#include <linux/mm.h>
19#include <linux/perf_event.h>
Chris Zankel5a0015d2005-06-23 22:01:16 -070020#include <linux/ptrace.h>
Max Filippov06fbac82018-11-09 19:32:06 -080021#include <linux/regset.h>
Max Filippovc91e02b2016-01-24 10:32:10 +030022#include <linux/sched.h>
Ingo Molnar68db0cf2017-02-08 18:51:37 +010023#include <linux/sched/task_stack.h>
Chris Zankel5a0015d2005-06-23 22:01:16 -070024#include <linux/security.h>
Jesper Juhl0ee23b52005-06-30 02:58:56 -070025#include <linux/signal.h>
Max Filippovc91e02b2016-01-24 10:32:10 +030026#include <linux/smp.h>
Max Filippovf984409a2015-03-16 14:40:14 +030027#include <linux/tracehook.h>
Max Filippov1b47a6832015-01-27 03:12:50 +030028#include <linux/uaccess.h>
Chris Zankel5a0015d2005-06-23 22:01:16 -070029
Max Filippovaf5395c2018-11-11 21:51:49 -080030#define CREATE_TRACE_POINTS
31#include <trace/events/syscalls.h>
32
Chris Zankelc658eac2008-02-12 13:17:07 -080033#include <asm/coprocessor.h>
Max Filippovc91e02b2016-01-24 10:32:10 +030034#include <asm/elf.h>
35#include <asm/page.h>
36#include <asm/pgtable.h>
37#include <asm/ptrace.h>
Chris Zankel5a0015d2005-06-23 22:01:16 -070038
Max Filippov06fbac82018-11-09 19:32:06 -080039static int gpr_get(struct task_struct *target,
40 const struct user_regset *regset,
41 unsigned int pos, unsigned int count,
42 void *kbuf, void __user *ubuf)
43{
44 struct pt_regs *regs = task_pt_regs(target);
45 struct user_pt_regs newregs = {
46 .pc = regs->pc,
47 .ps = regs->ps & ~(1 << PS_EXCM_BIT),
48 .lbeg = regs->lbeg,
49 .lend = regs->lend,
50 .lcount = regs->lcount,
51 .sar = regs->sar,
52 .threadptr = regs->threadptr,
53 .windowbase = regs->windowbase,
54 .windowstart = regs->windowstart,
55 };
56
57 memcpy(newregs.a,
58 regs->areg + XCHAL_NUM_AREGS - regs->windowbase * 4,
59 regs->windowbase * 16);
60 memcpy(newregs.a + regs->windowbase * 4,
61 regs->areg,
62 (WSBITS - regs->windowbase) * 16);
63
64 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
65 &newregs, 0, -1);
66}
67
68static int gpr_set(struct task_struct *target,
69 const struct user_regset *regset,
70 unsigned int pos, unsigned int count,
71 const void *kbuf, const void __user *ubuf)
72{
73 int ret;
74 struct user_pt_regs newregs = {0};
75 struct pt_regs *regs;
76 const u32 ps_mask = PS_CALLINC_MASK | PS_OWB_MASK;
77
78 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &newregs, 0, -1);
79 if (ret)
80 return ret;
81
82 if (newregs.windowbase >= XCHAL_NUM_AREGS / 4)
83 return -EINVAL;
84
85 regs = task_pt_regs(target);
86 regs->pc = newregs.pc;
87 regs->ps = (regs->ps & ~ps_mask) | (newregs.ps & ps_mask);
88 regs->lbeg = newregs.lbeg;
89 regs->lend = newregs.lend;
90 regs->lcount = newregs.lcount;
91 regs->sar = newregs.sar;
92 regs->threadptr = newregs.threadptr;
93
94 if (newregs.windowbase != regs->windowbase ||
95 newregs.windowstart != regs->windowstart) {
96 u32 rotws, wmask;
97
98 rotws = (((newregs.windowstart |
99 (newregs.windowstart << WSBITS)) >>
100 newregs.windowbase) &
101 ((1 << WSBITS) - 1)) & ~1;
102 wmask = ((rotws ? WSBITS + 1 - ffs(rotws) : 0) << 4) |
103 (rotws & 0xF) | 1;
104 regs->windowbase = newregs.windowbase;
105 regs->windowstart = newregs.windowstart;
106 regs->wmask = wmask;
107 }
108
109 memcpy(regs->areg + XCHAL_NUM_AREGS - newregs.windowbase * 4,
110 newregs.a, newregs.windowbase * 16);
111 memcpy(regs->areg, newregs.a + newregs.windowbase * 4,
112 (WSBITS - newregs.windowbase) * 16);
113
114 return 0;
115}
116
Max Filippov1819afc2018-11-24 21:36:11 -0800117static int tie_get(struct task_struct *target,
118 const struct user_regset *regset,
119 unsigned int pos, unsigned int count,
120 void *kbuf, void __user *ubuf)
121{
122 int ret;
123 struct pt_regs *regs = task_pt_regs(target);
124 struct thread_info *ti = task_thread_info(target);
125 elf_xtregs_t *newregs = kzalloc(sizeof(elf_xtregs_t), GFP_KERNEL);
126
127 if (!newregs)
128 return -ENOMEM;
129
130 newregs->opt = regs->xtregs_opt;
131 newregs->user = ti->xtregs_user;
132
133#if XTENSA_HAVE_COPROCESSORS
134 /* Flush all coprocessor registers to memory. */
135 coprocessor_flush_all(ti);
136 newregs->cp0 = ti->xtregs_cp.cp0;
137 newregs->cp1 = ti->xtregs_cp.cp1;
138 newregs->cp2 = ti->xtregs_cp.cp2;
139 newregs->cp3 = ti->xtregs_cp.cp3;
140 newregs->cp4 = ti->xtregs_cp.cp4;
141 newregs->cp5 = ti->xtregs_cp.cp5;
142 newregs->cp6 = ti->xtregs_cp.cp6;
143 newregs->cp7 = ti->xtregs_cp.cp7;
144#endif
145 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
146 newregs, 0, -1);
147 kfree(newregs);
148 return ret;
149}
150
151static int tie_set(struct task_struct *target,
152 const struct user_regset *regset,
153 unsigned int pos, unsigned int count,
154 const void *kbuf, const void __user *ubuf)
155{
156 int ret;
157 struct pt_regs *regs = task_pt_regs(target);
158 struct thread_info *ti = task_thread_info(target);
159 elf_xtregs_t *newregs = kzalloc(sizeof(elf_xtregs_t), GFP_KERNEL);
160
161 if (!newregs)
162 return -ENOMEM;
163
164 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
165 newregs, 0, -1);
166
167 if (ret)
168 goto exit;
169 regs->xtregs_opt = newregs->opt;
170 ti->xtregs_user = newregs->user;
171
172#if XTENSA_HAVE_COPROCESSORS
173 /* Flush all coprocessors before we overwrite them. */
174 coprocessor_flush_all(ti);
175 coprocessor_release_all(ti);
176 ti->xtregs_cp.cp0 = newregs->cp0;
177 ti->xtregs_cp.cp1 = newregs->cp1;
178 ti->xtregs_cp.cp2 = newregs->cp2;
179 ti->xtregs_cp.cp3 = newregs->cp3;
180 ti->xtregs_cp.cp4 = newregs->cp4;
181 ti->xtregs_cp.cp5 = newregs->cp5;
182 ti->xtregs_cp.cp6 = newregs->cp6;
183 ti->xtregs_cp.cp7 = newregs->cp7;
184#endif
185exit:
186 kfree(newregs);
187 return ret;
188}
189
Max Filippov06fbac82018-11-09 19:32:06 -0800190enum xtensa_regset {
191 REGSET_GPR,
Max Filippov1819afc2018-11-24 21:36:11 -0800192 REGSET_TIE,
Max Filippov06fbac82018-11-09 19:32:06 -0800193};
194
195static const struct user_regset xtensa_regsets[] = {
196 [REGSET_GPR] = {
197 .core_note_type = NT_PRSTATUS,
198 .n = sizeof(struct user_pt_regs) / sizeof(u32),
199 .size = sizeof(u32),
200 .align = sizeof(u32),
201 .get = gpr_get,
Max Filippov1819afc2018-11-24 21:36:11 -0800202 .set = gpr_set,
203 },
204 [REGSET_TIE] = {
205 .core_note_type = NT_PRFPREG,
206 .n = sizeof(elf_xtregs_t) / sizeof(u32),
207 .size = sizeof(u32),
208 .align = sizeof(u32),
209 .get = tie_get,
210 .set = tie_set,
Max Filippov06fbac82018-11-09 19:32:06 -0800211 },
212};
213
214static const struct user_regset_view user_xtensa_view = {
215 .name = "xtensa",
216 .e_machine = EM_XTENSA,
217 .regsets = xtensa_regsets,
218 .n = ARRAY_SIZE(xtensa_regsets)
219};
220
221const struct user_regset_view *task_user_regset_view(struct task_struct *task)
222{
223 return &user_xtensa_view;
224}
Christoph Hellwig6d75ca12010-03-10 15:22:57 -0800225
226void user_enable_single_step(struct task_struct *child)
227{
228 child->ptrace |= PT_SINGLESTEP;
229}
230
231void user_disable_single_step(struct task_struct *child)
232{
233 child->ptrace &= ~PT_SINGLESTEP;
234}
235
Chris Zankel5a0015d2005-06-23 22:01:16 -0700236/*
Chris Zankelc658eac2008-02-12 13:17:07 -0800237 * Called by kernel/ptrace.c when detaching to disable single stepping.
Chris Zankel5a0015d2005-06-23 22:01:16 -0700238 */
239
240void ptrace_disable(struct task_struct *child)
241{
242 /* Nothing to do.. */
243}
244
Max Filippov1b47a6832015-01-27 03:12:50 +0300245static int ptrace_getregs(struct task_struct *child, void __user *uregs)
Chris Zankel5a0015d2005-06-23 22:01:16 -0700246{
Max Filippov06fbac82018-11-09 19:32:06 -0800247 return copy_regset_to_user(child, &user_xtensa_view, REGSET_GPR,
248 0, sizeof(xtensa_gregset_t), uregs);
Chris Zankelc658eac2008-02-12 13:17:07 -0800249}
250
Max Filippov1b47a6832015-01-27 03:12:50 +0300251static int ptrace_setregs(struct task_struct *child, void __user *uregs)
Chris Zankelc658eac2008-02-12 13:17:07 -0800252{
Max Filippov06fbac82018-11-09 19:32:06 -0800253 return copy_regset_from_user(child, &user_xtensa_view, REGSET_GPR,
254 0, sizeof(xtensa_gregset_t), uregs);
Chris Zankelc658eac2008-02-12 13:17:07 -0800255}
256
Max Filippov1b47a6832015-01-27 03:12:50 +0300257static int ptrace_getxregs(struct task_struct *child, void __user *uregs)
Chris Zankelc658eac2008-02-12 13:17:07 -0800258{
Max Filippov1819afc2018-11-24 21:36:11 -0800259 return copy_regset_to_user(child, &user_xtensa_view, REGSET_TIE,
260 0, sizeof(elf_xtregs_t), uregs);
Chris Zankelc658eac2008-02-12 13:17:07 -0800261}
262
Max Filippov1b47a6832015-01-27 03:12:50 +0300263static int ptrace_setxregs(struct task_struct *child, void __user *uregs)
Chris Zankelc658eac2008-02-12 13:17:07 -0800264{
Max Filippov1819afc2018-11-24 21:36:11 -0800265 return copy_regset_from_user(child, &user_xtensa_view, REGSET_TIE,
266 0, sizeof(elf_xtregs_t), uregs);
Chris Zankelc658eac2008-02-12 13:17:07 -0800267}
268
Max Filippov1b47a6832015-01-27 03:12:50 +0300269static int ptrace_peekusr(struct task_struct *child, long regno,
270 long __user *ret)
Chris Zankelc658eac2008-02-12 13:17:07 -0800271{
272 struct pt_regs *regs;
273 unsigned long tmp;
274
275 regs = task_pt_regs(child);
276 tmp = 0; /* Default return value. */
277
278 switch(regno) {
Max Filippov1b47a6832015-01-27 03:12:50 +0300279 case REG_AR_BASE ... REG_AR_BASE + XCHAL_NUM_AREGS - 1:
280 tmp = regs->areg[regno - REG_AR_BASE];
281 break;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700282
Max Filippov1b47a6832015-01-27 03:12:50 +0300283 case REG_A_BASE ... REG_A_BASE + 15:
284 tmp = regs->areg[regno - REG_A_BASE];
285 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800286
Max Filippov1b47a6832015-01-27 03:12:50 +0300287 case REG_PC:
288 tmp = regs->pc;
289 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800290
Max Filippov1b47a6832015-01-27 03:12:50 +0300291 case REG_PS:
292 /* Note: PS.EXCM is not set while user task is running;
293 * its being set in regs is for exception handling
294 * convenience.
295 */
296 tmp = (regs->ps & ~(1 << PS_EXCM_BIT));
297 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800298
Max Filippov1b47a6832015-01-27 03:12:50 +0300299 case REG_WB:
300 break; /* tmp = 0 */
Chris Zankelc658eac2008-02-12 13:17:07 -0800301
Max Filippov1b47a6832015-01-27 03:12:50 +0300302 case REG_WS:
Chris Zankelc658eac2008-02-12 13:17:07 -0800303 {
304 unsigned long wb = regs->windowbase;
305 unsigned long ws = regs->windowstart;
Max Filippov1b47a6832015-01-27 03:12:50 +0300306 tmp = ((ws >> wb) | (ws << (WSBITS - wb))) &
307 ((1 << WSBITS) - 1);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700308 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800309 }
Max Filippov1b47a6832015-01-27 03:12:50 +0300310 case REG_LBEG:
311 tmp = regs->lbeg;
312 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800313
Max Filippov1b47a6832015-01-27 03:12:50 +0300314 case REG_LEND:
315 tmp = regs->lend;
316 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800317
Max Filippov1b47a6832015-01-27 03:12:50 +0300318 case REG_LCOUNT:
319 tmp = regs->lcount;
320 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800321
Max Filippov1b47a6832015-01-27 03:12:50 +0300322 case REG_SAR:
323 tmp = regs->sar;
324 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800325
Max Filippov1b47a6832015-01-27 03:12:50 +0300326 case SYSCALL_NR:
327 tmp = regs->syscall;
328 break;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700329
Max Filippov1b47a6832015-01-27 03:12:50 +0300330 default:
331 return -EIO;
Chris Zankelc658eac2008-02-12 13:17:07 -0800332 }
333 return put_user(tmp, ret);
334}
335
Max Filippov1b47a6832015-01-27 03:12:50 +0300336static int ptrace_pokeusr(struct task_struct *child, long regno, long val)
Chris Zankelc658eac2008-02-12 13:17:07 -0800337{
338 struct pt_regs *regs;
339 regs = task_pt_regs(child);
340
341 switch (regno) {
Max Filippov1b47a6832015-01-27 03:12:50 +0300342 case REG_AR_BASE ... REG_AR_BASE + XCHAL_NUM_AREGS - 1:
343 regs->areg[regno - REG_AR_BASE] = val;
344 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800345
Max Filippov1b47a6832015-01-27 03:12:50 +0300346 case REG_A_BASE ... REG_A_BASE + 15:
347 regs->areg[regno - REG_A_BASE] = val;
348 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800349
Max Filippov1b47a6832015-01-27 03:12:50 +0300350 case REG_PC:
351 regs->pc = val;
352 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800353
Max Filippov1b47a6832015-01-27 03:12:50 +0300354 case SYSCALL_NR:
355 regs->syscall = val;
356 break;
Chris Zankelc658eac2008-02-12 13:17:07 -0800357
Max Filippov1b47a6832015-01-27 03:12:50 +0300358 default:
359 return -EIO;
Chris Zankelc658eac2008-02-12 13:17:07 -0800360 }
361 return 0;
362}
363
Max Filippovc91e02b2016-01-24 10:32:10 +0300364#ifdef CONFIG_HAVE_HW_BREAKPOINT
365static void ptrace_hbptriggered(struct perf_event *bp,
366 struct perf_sample_data *data,
367 struct pt_regs *regs)
368{
369 int i;
Max Filippovc91e02b2016-01-24 10:32:10 +0300370 struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp);
371
372 if (bp->attr.bp_type & HW_BREAKPOINT_X) {
373 for (i = 0; i < XCHAL_NUM_IBREAK; ++i)
374 if (current->thread.ptrace_bp[i] == bp)
375 break;
376 i <<= 1;
377 } else {
378 for (i = 0; i < XCHAL_NUM_DBREAK; ++i)
379 if (current->thread.ptrace_wp[i] == bp)
380 break;
381 i = (i << 1) | 1;
382 }
383
Eric W. Biedermanf71dd7d2018-01-22 14:37:25 -0600384 force_sig_ptrace_errno_trap(i, (void __user *)bkpt->address);
Max Filippovc91e02b2016-01-24 10:32:10 +0300385}
386
387static struct perf_event *ptrace_hbp_create(struct task_struct *tsk, int type)
388{
389 struct perf_event_attr attr;
390
391 ptrace_breakpoint_init(&attr);
392
393 /* Initialise fields to sane defaults. */
394 attr.bp_addr = 0;
395 attr.bp_len = 1;
396 attr.bp_type = type;
397 attr.disabled = 1;
398
399 return register_user_hw_breakpoint(&attr, ptrace_hbptriggered, NULL,
400 tsk);
401}
402
403/*
404 * Address bit 0 choose instruction (0) or data (1) break register, bits
405 * 31..1 are the register number.
406 * Both PTRACE_GETHBPREGS and PTRACE_SETHBPREGS transfer two 32-bit words:
407 * address (0) and control (1).
408 * Instruction breakpoint contorl word is 0 to clear breakpoint, 1 to set.
409 * Data breakpoint control word bit 31 is 'trigger on store', bit 30 is
410 * 'trigger on load, bits 29..0 are length. Length 0 is used to clear a
411 * breakpoint. To set a breakpoint length must be a power of 2 in the range
412 * 1..64 and the address must be length-aligned.
413 */
414
415static long ptrace_gethbpregs(struct task_struct *child, long addr,
416 long __user *datap)
417{
418 struct perf_event *bp;
419 u32 user_data[2] = {0};
420 bool dbreak = addr & 1;
421 unsigned idx = addr >> 1;
422
423 if ((!dbreak && idx >= XCHAL_NUM_IBREAK) ||
424 (dbreak && idx >= XCHAL_NUM_DBREAK))
425 return -EINVAL;
426
427 if (dbreak)
428 bp = child->thread.ptrace_wp[idx];
429 else
430 bp = child->thread.ptrace_bp[idx];
431
432 if (bp) {
433 user_data[0] = bp->attr.bp_addr;
434 user_data[1] = bp->attr.disabled ? 0 : bp->attr.bp_len;
435 if (dbreak) {
436 if (bp->attr.bp_type & HW_BREAKPOINT_R)
437 user_data[1] |= DBREAKC_LOAD_MASK;
438 if (bp->attr.bp_type & HW_BREAKPOINT_W)
439 user_data[1] |= DBREAKC_STOR_MASK;
440 }
441 }
442
443 if (copy_to_user(datap, user_data, sizeof(user_data)))
444 return -EFAULT;
445
446 return 0;
447}
448
449static long ptrace_sethbpregs(struct task_struct *child, long addr,
450 long __user *datap)
451{
452 struct perf_event *bp;
453 struct perf_event_attr attr;
454 u32 user_data[2];
455 bool dbreak = addr & 1;
456 unsigned idx = addr >> 1;
457 int bp_type = 0;
458
459 if ((!dbreak && idx >= XCHAL_NUM_IBREAK) ||
460 (dbreak && idx >= XCHAL_NUM_DBREAK))
461 return -EINVAL;
462
463 if (copy_from_user(user_data, datap, sizeof(user_data)))
464 return -EFAULT;
465
466 if (dbreak) {
467 bp = child->thread.ptrace_wp[idx];
468 if (user_data[1] & DBREAKC_LOAD_MASK)
469 bp_type |= HW_BREAKPOINT_R;
470 if (user_data[1] & DBREAKC_STOR_MASK)
471 bp_type |= HW_BREAKPOINT_W;
472 } else {
473 bp = child->thread.ptrace_bp[idx];
474 bp_type = HW_BREAKPOINT_X;
475 }
476
477 if (!bp) {
478 bp = ptrace_hbp_create(child,
479 bp_type ? bp_type : HW_BREAKPOINT_RW);
480 if (IS_ERR(bp))
481 return PTR_ERR(bp);
482 if (dbreak)
483 child->thread.ptrace_wp[idx] = bp;
484 else
485 child->thread.ptrace_bp[idx] = bp;
486 }
487
488 attr = bp->attr;
489 attr.bp_addr = user_data[0];
490 attr.bp_len = user_data[1] & ~(DBREAKC_LOAD_MASK | DBREAKC_STOR_MASK);
491 attr.bp_type = bp_type;
492 attr.disabled = !attr.bp_len;
493
494 return modify_user_hw_breakpoint(bp, &attr);
495}
496#endif
497
Namhyung Kim9b05a692010-10-27 15:33:47 -0700498long arch_ptrace(struct task_struct *child, long request,
499 unsigned long addr, unsigned long data)
Chris Zankelc658eac2008-02-12 13:17:07 -0800500{
501 int ret = -EPERM;
Namhyung Kim5ef45072010-10-27 15:34:06 -0700502 void __user *datap = (void __user *) data;
Chris Zankelc658eac2008-02-12 13:17:07 -0800503
504 switch (request) {
Chris Zankelc658eac2008-02-12 13:17:07 -0800505 case PTRACE_PEEKUSR: /* read register specified by addr. */
Namhyung Kim5ef45072010-10-27 15:34:06 -0700506 ret = ptrace_peekusr(child, addr, datap);
Chris Zankelc658eac2008-02-12 13:17:07 -0800507 break;
508
Chris Zankelc658eac2008-02-12 13:17:07 -0800509 case PTRACE_POKEUSR: /* write register specified by addr. */
510 ret = ptrace_pokeusr(child, addr, data);
511 break;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700512
Chris Zankel5a0015d2005-06-23 22:01:16 -0700513 case PTRACE_GETREGS:
Namhyung Kim5ef45072010-10-27 15:34:06 -0700514 ret = ptrace_getregs(child, datap);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700515 break;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700516
517 case PTRACE_SETREGS:
Namhyung Kim5ef45072010-10-27 15:34:06 -0700518 ret = ptrace_setregs(child, datap);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700519 break;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700520
Chris Zankelc658eac2008-02-12 13:17:07 -0800521 case PTRACE_GETXTREGS:
Namhyung Kim5ef45072010-10-27 15:34:06 -0700522 ret = ptrace_getxregs(child, datap);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700523 break;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700524
Chris Zankelc658eac2008-02-12 13:17:07 -0800525 case PTRACE_SETXTREGS:
Namhyung Kim5ef45072010-10-27 15:34:06 -0700526 ret = ptrace_setxregs(child, datap);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700527 break;
Max Filippovc91e02b2016-01-24 10:32:10 +0300528#ifdef CONFIG_HAVE_HW_BREAKPOINT
529 case PTRACE_GETHBPREGS:
530 ret = ptrace_gethbpregs(child, addr, datap);
531 break;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700532
Max Filippovc91e02b2016-01-24 10:32:10 +0300533 case PTRACE_SETHBPREGS:
534 ret = ptrace_sethbpregs(child, addr, datap);
535 break;
536#endif
Chris Zankel5a0015d2005-06-23 22:01:16 -0700537 default:
538 ret = ptrace_request(child, request, addr, data);
Chris Zankelc658eac2008-02-12 13:17:07 -0800539 break;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700540 }
Chris Zankelc658eac2008-02-12 13:17:07 -0800541
Chris Zankel5a0015d2005-06-23 22:01:16 -0700542 return ret;
543}
544
Max Filippov3aee3e22018-11-15 19:33:47 -0800545void do_syscall_trace_enter(struct pt_regs *regs)
Chris Zankelfc4fb2a2006-12-10 02:18:52 -0800546{
Max Filippov1b47a6832015-01-27 03:12:50 +0300547 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
Max Filippovf984409a2015-03-16 14:40:14 +0300548 tracehook_report_syscall_entry(regs))
Max Filippov3aee3e22018-11-15 19:33:47 -0800549 regs->syscall = NO_SYSCALL;
Max Filippovf984409a2015-03-16 14:40:14 +0300550
Max Filippovaf5395c2018-11-11 21:51:49 -0800551 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
552 trace_sys_enter(regs, syscall_get_nr(current, regs));
Chris Zankelfc4fb2a2006-12-10 02:18:52 -0800553}
554
555void do_syscall_trace_leave(struct pt_regs *regs)
556{
Max Filippovf984409a2015-03-16 14:40:14 +0300557 int step;
558
Max Filippovaf5395c2018-11-11 21:51:49 -0800559 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
560 trace_sys_exit(regs, regs_return_value(regs));
561
Max Filippovf984409a2015-03-16 14:40:14 +0300562 step = test_thread_flag(TIF_SINGLESTEP);
563
564 if (step || test_thread_flag(TIF_SYSCALL_TRACE))
565 tracehook_report_syscall_exit(regs, step);
Chris Zankelfc4fb2a2006-12-10 02:18:52 -0800566}