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