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