1 /* ptrace.c: FRV specific parts of process tracing
3 * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from arch/m68k/kernel/ptrace.c
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
16 #include <linux/smp.h>
17 #include <linux/errno.h>
18 #include <linux/ptrace.h>
19 #include <linux/user.h>
20 #include <linux/security.h>
21 #include <linux/signal.h>
23 #include <asm/uaccess.h>
25 #include <asm/pgtable.h>
26 #include <asm/system.h>
27 #include <asm/processor.h>
28 #include <asm/unistd.h>
31 * does not yet catch signals sent when the child dies.
32 * in exit.c or in signal.c.
36 * Get contents of register REGNO in task TASK.
38 static inline long get_reg(struct task_struct *task, int regno)
40 struct user_context *user = task->thread.user;
42 if (regno < 0 || regno >= PT__END)
45 return ((unsigned long *) user)[regno];
49 * Write contents of register REGNO in task TASK.
51 static inline int put_reg(struct task_struct *task, int regno,
54 struct user_context *user = task->thread.user;
56 if (regno < 0 || regno >= PT__END)
66 ((unsigned long *) user)[regno] = data;
72 * check that an address falls within the bounds of the target process's memory mappings
74 static inline int is_user_addr_valid(struct task_struct *child,
75 unsigned long start, unsigned long len)
78 if (start >= PAGE_OFFSET || len > PAGE_OFFSET - start)
82 struct vm_list_struct *vml;
84 for (vml = child->mm->context.vmlist; vml; vml = vml->next)
85 if (start >= vml->vma->vm_start && start + len <= vml->vma->vm_end)
93 * Called by kernel/ptrace.c when detaching..
95 * Control h/w single stepping
97 void ptrace_disable(struct task_struct *child)
99 child->thread.frame0->__status &= ~REG__STATUS_STEP;
102 void ptrace_enable(struct task_struct *child)
104 child->thread.frame0->__status |= REG__STATUS_STEP;
107 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
113 /* when I and D space are separate, these will need to be fixed. */
114 case PTRACE_PEEKTEXT: /* read word at location addr. */
115 case PTRACE_PEEKDATA:
117 if (is_user_addr_valid(child, addr, sizeof(tmp)) < 0)
119 ret = generic_ptrace_peekdata(child, addr, data);
122 /* read the word at location addr in the USER area. */
123 case PTRACE_PEEKUSR: {
126 if ((addr & 3) || addr < 0)
131 case 0 ... PT__END - 1:
132 tmp = get_reg(child, addr >> 2);
136 tmp = child->mm->end_code - child->mm->start_code;
140 tmp = child->mm->end_data - child->mm->start_data;
144 tmp = child->mm->start_stack - child->mm->start_brk;
148 tmp = child->mm->start_code;
152 tmp = child->mm->start_stack;
161 ret = put_user(tmp, (unsigned long *) data);
165 /* when I and D space are separate, this will have to be fixed. */
166 case PTRACE_POKETEXT: /* write the word at location addr. */
167 case PTRACE_POKEDATA:
169 if (is_user_addr_valid(child, addr, sizeof(tmp)) < 0)
171 ret = generic_ptrace_pokedata(child, addr, data);
174 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
176 if ((addr & 3) || addr < 0)
181 case 0 ... PT__END-1:
182 ret = put_reg(child, addr >> 2, data);
191 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
192 case PTRACE_CONT: /* restart after signal. */
194 if (!valid_signal(data))
196 if (request == PTRACE_SYSCALL)
197 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
199 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
200 child->exit_code = data;
201 ptrace_disable(child);
202 wake_up_process(child);
206 /* make the child exit. Best I can do is send it a sigkill.
207 * perhaps it should be put in the status that it wants to
212 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
214 child->exit_code = SIGKILL;
215 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
216 ptrace_disable(child);
217 wake_up_process(child);
220 case PTRACE_SINGLESTEP: /* set the trap flag. */
222 if (!valid_signal(data))
224 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
225 ptrace_enable(child);
226 child->exit_code = data;
227 wake_up_process(child);
231 case PTRACE_DETACH: /* detach a process that was attached. */
232 ret = ptrace_detach(child, data);
235 case PTRACE_GETREGS: { /* Get all integer regs from the child. */
237 for (i = 0; i < PT__GPEND; i++) {
238 tmp = get_reg(child, i);
239 if (put_user(tmp, (unsigned long *) data)) {
243 data += sizeof(long);
249 case PTRACE_SETREGS: { /* Set all integer regs in the child. */
251 for (i = 0; i < PT__GPEND; i++) {
252 if (get_user(tmp, (unsigned long *) data)) {
256 put_reg(child, i, tmp);
257 data += sizeof(long);
263 case PTRACE_GETFPREGS: { /* Get the child FP/Media state. */
265 if (copy_to_user((void *) data,
266 &child->thread.user->f,
267 sizeof(child->thread.user->f)))
272 case PTRACE_SETFPREGS: { /* Set the child FP/Media state. */
274 if (copy_from_user(&child->thread.user->f,
276 sizeof(child->thread.user->f)))
281 case PTRACE_GETFDPIC:
284 case PTRACE_GETFDPIC_EXEC:
285 tmp = child->mm->context.exec_fdpic_loadmap;
287 case PTRACE_GETFDPIC_INTERP:
288 tmp = child->mm->context.interp_fdpic_loadmap;
295 if (put_user(tmp, (unsigned long *) data)) {
308 int __nongprelbss kstrace;
310 static const struct {
313 } __syscall_name_table[NR_syscalls] = {
314 [0] = { "restart_syscall" },
315 [1] = { "exit", 0x000001 },
316 [2] = { "fork", 0xffffff },
317 [3] = { "read", 0x000141 },
318 [4] = { "write", 0x000141 },
319 [5] = { "open", 0x000235 },
320 [6] = { "close", 0x000001 },
321 [7] = { "waitpid", 0x000141 },
322 [8] = { "creat", 0x000025 },
323 [9] = { "link", 0x000055 },
324 [10] = { "unlink", 0x000005 },
325 [11] = { "execve", 0x000445 },
326 [12] = { "chdir", 0x000005 },
327 [13] = { "time", 0x000004 },
328 [14] = { "mknod", 0x000325 },
329 [15] = { "chmod", 0x000025 },
330 [16] = { "lchown", 0x000025 },
332 [18] = { "oldstat", 0x000045 },
333 [19] = { "lseek", 0x000131 },
334 [20] = { "getpid", 0xffffff },
335 [21] = { "mount", 0x043555 },
336 [22] = { "umount", 0x000005 },
337 [23] = { "setuid", 0x000001 },
338 [24] = { "getuid", 0xffffff },
339 [25] = { "stime", 0x000004 },
340 [26] = { "ptrace", 0x004413 },
341 [27] = { "alarm", 0x000001 },
342 [28] = { "oldfstat", 0x000041 },
343 [29] = { "pause", 0xffffff },
344 [30] = { "utime", 0x000045 },
347 [33] = { "access", 0x000025 },
348 [34] = { "nice", 0x000001 },
350 [36] = { "sync", 0xffffff },
351 [37] = { "kill", 0x000011 },
352 [38] = { "rename", 0x000055 },
353 [39] = { "mkdir", 0x000025 },
354 [40] = { "rmdir", 0x000005 },
355 [41] = { "dup", 0x000001 },
356 [42] = { "pipe", 0x000004 },
357 [43] = { "times", 0x000004 },
359 [45] = { "brk", 0x000004 },
360 [46] = { "setgid", 0x000001 },
361 [47] = { "getgid", 0xffffff },
362 [48] = { "signal", 0x000041 },
363 [49] = { "geteuid", 0xffffff },
364 [50] = { "getegid", 0xffffff },
365 [51] = { "acct", 0x000005 },
366 [52] = { "umount2", 0x000035 },
368 [54] = { "ioctl", 0x000331 },
369 [55] = { "fcntl", 0x000331 },
371 [57] = { "setpgid", 0x000011 },
373 [60] = { "umask", 0x000002 },
374 [61] = { "chroot", 0x000005 },
375 [62] = { "ustat", 0x000043 },
376 [63] = { "dup2", 0x000011 },
377 [64] = { "getppid", 0xffffff },
378 [65] = { "getpgrp", 0xffffff },
379 [66] = { "setsid", 0xffffff },
380 [67] = { "sigaction" },
381 [68] = { "sgetmask" },
382 [69] = { "ssetmask" },
383 [70] = { "setreuid" },
384 [71] = { "setregid" },
385 [72] = { "sigsuspend" },
386 [73] = { "sigpending" },
387 [74] = { "sethostname" },
388 [75] = { "setrlimit" },
389 [76] = { "getrlimit" },
390 [77] = { "getrusage" },
391 [78] = { "gettimeofday" },
392 [79] = { "settimeofday" },
393 [80] = { "getgroups" },
394 [81] = { "setgroups" },
396 [83] = { "symlink" },
397 [84] = { "oldlstat" },
398 [85] = { "readlink" },
402 [89] = { "readdir" },
403 [91] = { "munmap", 0x000034 },
404 [92] = { "truncate" },
405 [93] = { "ftruncate" },
408 [96] = { "getpriority" },
409 [97] = { "setpriority" },
411 [100] = { "fstatfs" },
412 [102] = { "socketcall" },
413 [103] = { "syslog" },
414 [104] = { "setitimer" },
415 [105] = { "getitimer" },
419 [111] = { "vhangup" },
421 [115] = { "swapoff" },
422 [116] = { "sysinfo" },
425 [119] = { "sigreturn" },
427 [121] = { "setdomainname" },
429 [123] = { "modify_ldt" },
430 [123] = { "cacheflush" },
431 [124] = { "adjtimex" },
432 [125] = { "mprotect" },
433 [126] = { "sigprocmask" },
434 [127] = { "create_module" },
435 [128] = { "init_module" },
436 [129] = { "delete_module" },
437 [130] = { "get_kernel_syms" },
438 [131] = { "quotactl" },
439 [132] = { "getpgid" },
440 [133] = { "fchdir" },
441 [134] = { "bdflush" },
443 [136] = { "personality" },
444 [137] = { "afs_syscall" },
445 [138] = { "setfsuid" },
446 [139] = { "setfsgid" },
447 [140] = { "_llseek", 0x014331 },
448 [141] = { "getdents" },
449 [142] = { "_newselect", 0x000141 },
453 [146] = { "writev" },
454 [147] = { "getsid", 0x000001 },
455 [148] = { "fdatasync", 0x000001 },
456 [149] = { "_sysctl", 0x000004 },
458 [151] = { "munlock" },
459 [152] = { "mlockall" },
460 [153] = { "munlockall" },
461 [154] = { "sched_setparam" },
462 [155] = { "sched_getparam" },
463 [156] = { "sched_setscheduler" },
464 [157] = { "sched_getscheduler" },
465 [158] = { "sched_yield" },
466 [159] = { "sched_get_priority_max" },
467 [160] = { "sched_get_priority_min" },
468 [161] = { "sched_rr_get_interval" },
469 [162] = { "nanosleep", 0x000044 },
470 [163] = { "mremap" },
471 [164] = { "setresuid" },
472 [165] = { "getresuid" },
474 [167] = { "query_module" },
476 [169] = { "nfsservctl" },
477 [170] = { "setresgid" },
478 [171] = { "getresgid" },
479 [172] = { "prctl", 0x333331 },
480 [173] = { "rt_sigreturn", 0xffffff },
481 [174] = { "rt_sigaction", 0x001441 },
482 [175] = { "rt_sigprocmask", 0x001441 },
483 [176] = { "rt_sigpending", 0x000014 },
484 [177] = { "rt_sigtimedwait", 0x001444 },
485 [178] = { "rt_sigqueueinfo", 0x000411 },
486 [179] = { "rt_sigsuspend", 0x000014 },
487 [180] = { "pread", 0x003341 },
488 [181] = { "pwrite", 0x003341 },
489 [182] = { "chown", 0x000115 },
490 [183] = { "getcwd" },
491 [184] = { "capget" },
492 [185] = { "capset" },
493 [186] = { "sigaltstack" },
494 [187] = { "sendfile" },
495 [188] = { "getpmsg" },
496 [189] = { "putpmsg" },
497 [190] = { "vfork", 0xffffff },
498 [191] = { "ugetrlimit" },
499 [192] = { "mmap2", 0x313314 },
500 [193] = { "truncate64" },
501 [194] = { "ftruncate64" },
502 [195] = { "stat64", 0x000045 },
503 [196] = { "lstat64", 0x000045 },
504 [197] = { "fstat64", 0x000041 },
505 [198] = { "lchown32" },
506 [199] = { "getuid32", 0xffffff },
507 [200] = { "getgid32", 0xffffff },
508 [201] = { "geteuid32", 0xffffff },
509 [202] = { "getegid32", 0xffffff },
510 [203] = { "setreuid32" },
511 [204] = { "setregid32" },
512 [205] = { "getgroups32" },
513 [206] = { "setgroups32" },
514 [207] = { "fchown32" },
515 [208] = { "setresuid32" },
516 [209] = { "getresuid32" },
517 [210] = { "setresgid32" },
518 [211] = { "getresgid32" },
519 [212] = { "chown32" },
520 [213] = { "setuid32" },
521 [214] = { "setgid32" },
522 [215] = { "setfsuid32" },
523 [216] = { "setfsgid32" },
524 [217] = { "pivot_root" },
525 [218] = { "mincore" },
526 [219] = { "madvise" },
527 [220] = { "getdents64" },
528 [221] = { "fcntl64" },
529 [223] = { "security" },
530 [224] = { "gettid" },
531 [225] = { "readahead" },
532 [226] = { "setxattr" },
533 [227] = { "lsetxattr" },
534 [228] = { "fsetxattr" },
535 [229] = { "getxattr" },
536 [230] = { "lgetxattr" },
537 [231] = { "fgetxattr" },
538 [232] = { "listxattr" },
539 [233] = { "llistxattr" },
540 [234] = { "flistxattr" },
541 [235] = { "removexattr" },
542 [236] = { "lremovexattr" },
543 [237] = { "fremovexattr" },
545 [239] = { "sendfile64" },
547 [241] = { "sched_setaffinity" },
548 [242] = { "sched_getaffinity" },
549 [243] = { "set_thread_area" },
550 [244] = { "get_thread_area" },
551 [245] = { "io_setup" },
552 [246] = { "io_destroy" },
553 [247] = { "io_getevents" },
554 [248] = { "io_submit" },
555 [249] = { "io_cancel" },
556 [250] = { "fadvise64" },
557 [252] = { "exit_group", 0x000001 },
558 [253] = { "lookup_dcookie" },
559 [254] = { "epoll_create" },
560 [255] = { "epoll_ctl" },
561 [256] = { "epoll_wait" },
562 [257] = { "remap_file_pages" },
563 [258] = { "set_tid_address" },
564 [259] = { "timer_create" },
565 [260] = { "timer_settime" },
566 [261] = { "timer_gettime" },
567 [262] = { "timer_getoverrun" },
568 [263] = { "timer_delete" },
569 [264] = { "clock_settime" },
570 [265] = { "clock_gettime" },
571 [266] = { "clock_getres" },
572 [267] = { "clock_nanosleep" },
573 [268] = { "statfs64" },
574 [269] = { "fstatfs64" },
575 [270] = { "tgkill" },
576 [271] = { "utimes" },
577 [272] = { "fadvise64_64" },
578 [273] = { "vserver" },
580 [275] = { "get_mempolicy" },
581 [276] = { "set_mempolicy" },
582 [277] = { "mq_open" },
583 [278] = { "mq_unlink" },
584 [279] = { "mq_timedsend" },
585 [280] = { "mq_timedreceive" },
586 [281] = { "mq_notify" },
587 [282] = { "mq_getsetattr" },
588 [283] = { "sys_kexec_load" },
591 asmlinkage void do_syscall_trace(int leaving)
605 if (__frame->gr7 == __NR_close)
609 if (__frame->gr7 != __NR_mmap2 &&
610 __frame->gr7 != __NR_vfork &&
611 __frame->gr7 != __NR_execve &&
612 __frame->gr7 != __NR_exit)
618 if (__frame->gr7 < NR_syscalls) {
619 name = __syscall_name_table[__frame->gr7].name;
620 argmask = __syscall_name_table[__frame->gr7].argmask;
623 sprintf(buffer, "sys_%lx", __frame->gr7);
629 printk(KERN_CRIT "[%d] %s(%lx,%lx,%lx,%lx,%lx,%lx)\n",
639 else if (argmask == 0xffffff) {
640 printk(KERN_CRIT "[%d] %s()\n",
645 printk(KERN_CRIT "[%d] %s(",
649 argp = &__frame->gr8;
652 switch (argmask & 0xf) {
654 printk("%ld", (long) *argp);
657 printk("%lo", *argp);
660 printk("%lx", *argp);
663 printk("%p", (void *) *argp);
666 printk("\"%s\"", (char *) *argp);
681 if ((int)__frame->gr8 > -4096 && (int)__frame->gr8 < 4096)
682 printk(KERN_CRIT "[%d] %s() = %ld\n", current->pid, name, __frame->gr8);
684 printk(KERN_CRIT "[%d] %s() = %lx\n", current->pid, name, __frame->gr8);
689 if (!test_thread_flag(TIF_SYSCALL_TRACE))
692 if (!(current->ptrace & PT_PTRACED))
695 /* we need to indicate entry or exit to strace */
697 __frame->__status |= REG__STATUS_SYSC_EXIT;
699 __frame->__status |= REG__STATUS_SYSC_ENTRY;
701 ptrace_notify(SIGTRAP);
704 * this isn't the same as continuing with a signal, but it will do
705 * for normal use. strace only continues with a signal if the
706 * stopping signal is not SIGTRAP. -brl
708 if (current->exit_code) {
709 send_sig(current->exit_code, current, 1);
710 current->exit_code = 0;