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