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