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