syscall.tcl 6.9 KB
#
# Copyright (C) 1996-1998 by the Board of Trustees
#    of Leland Stanford Junior University.
# 
# This file is part of the SimOS distribution. 
# See LICENSE file for terms of the license. 


# Write a trace of Linux system calls to the SimOS log.
#
# Warning: This currently only works on the X86 Linux
# 
# Usage:
#       source "syscall.tcl"
#
#       traceSyscall $SYSCALL_TRACE_ON    # Turns syscall tracing on
#       traceSyscall $SYSCALL_TRACE_OFF   # Turns syscall tracing off
#


set SYSCALL_VEC  "int128"

set SYSCALL_NAME(0) "setup"
set SYSCALL_NAME(1) "exit"
set SYSCALL_NAME(2) "fork"
set SYSCALL_NAME(3) "read"
set SYSCALL_NAME(4) "write"
set SYSCALL_NAME(5) "open"
set SYSCALL_NAME(6) "close"
set SYSCALL_NAME(7) "waitpid"
set SYSCALL_NAME(8) "creat"
set SYSCALL_NAME(9) "link"
set SYSCALL_NAME(10) "unlink"
set SYSCALL_NAME(11) "execve"
set SYSCALL_NAME(12) "chdir"
set SYSCALL_NAME(13) "time"
set SYSCALL_NAME(14) "prev_mknod"
set SYSCALL_NAME(15) "chmod"
set SYSCALL_NAME(16) "chown"
set SYSCALL_NAME(17) "break"
set SYSCALL_NAME(18) "oldstat"
set SYSCALL_NAME(19) "lseek"
set SYSCALL_NAME(20) "getpid"
set SYSCALL_NAME(21) "mount"
set SYSCALL_NAME(22) "umount"
set SYSCALL_NAME(23) "setuid"
set SYSCALL_NAME(24) "getuid"
set SYSCALL_NAME(25) "stime"
set SYSCALL_NAME(26) "ptrace"
set SYSCALL_NAME(27) "alarm"
set SYSCALL_NAME(28) "oldfstat"
set SYSCALL_NAME(29) "pause"
set SYSCALL_NAME(30) "utime"
set SYSCALL_NAME(31) "stty"
set SYSCALL_NAME(32) "gtty"
set SYSCALL_NAME(33) "access"
set SYSCALL_NAME(34) "nice"
set SYSCALL_NAME(35) "ftime"
set SYSCALL_NAME(36) "sync"
set SYSCALL_NAME(37) "kill"
set SYSCALL_NAME(38) "rename"
set SYSCALL_NAME(39) "mkdir"
set SYSCALL_NAME(40) "rmdir"
set SYSCALL_NAME(41) "dup"
set SYSCALL_NAME(42) "pipe"
set SYSCALL_NAME(43) "times"
set SYSCALL_NAME(44) "prof"
set SYSCALL_NAME(45) "brk"
set SYSCALL_NAME(46) "setgid"
set SYSCALL_NAME(47) "getgid"
set SYSCALL_NAME(48) "signal"
set SYSCALL_NAME(49) "geteuid"
set SYSCALL_NAME(50) "getegid"
set SYSCALL_NAME(51) "acct"
set SYSCALL_NAME(52) "phys"
set SYSCALL_NAME(53) "lock"
set SYSCALL_NAME(54) "ioctl"
set SYSCALL_NAME(55) "fcntl"
set SYSCALL_NAME(56) "mpx"
set SYSCALL_NAME(57) "setpgid"
set SYSCALL_NAME(58) "ulimit"
set SYSCALL_NAME(59) "oldolduname"
set SYSCALL_NAME(60) "umask"
set SYSCALL_NAME(61) "chroot"
set SYSCALL_NAME(62) "prev_ustat"
set SYSCALL_NAME(63) "dup2"
set SYSCALL_NAME(64) "getppid"
set SYSCALL_NAME(65) "getpgrp"
set SYSCALL_NAME(66) "setsid"
set SYSCALL_NAME(67) "sigaction"
set SYSCALL_NAME(68) "siggetmask"
set SYSCALL_NAME(69) "sigsetmask"
set SYSCALL_NAME(70) "setreuid"
set SYSCALL_NAME(71) "setregid"
set SYSCALL_NAME(72) "sigsuspend"
set SYSCALL_NAME(73) "sigpending"
set SYSCALL_NAME(74) "sethostname"
set SYSCALL_NAME(75) "setrlimit"
set SYSCALL_NAME(76) "getrlimit"
set SYSCALL_NAME(77) "getrusage"
set SYSCALL_NAME(78) "gettimeofday"
set SYSCALL_NAME(79) "settimeofday"
set SYSCALL_NAME(80) "getgroups"
set SYSCALL_NAME(81) "setgroups"
set SYSCALL_NAME(82) "select"
set SYSCALL_NAME(83) "symlink"
set SYSCALL_NAME(84) "oldlstat"
set SYSCALL_NAME(85) "readlink"
set SYSCALL_NAME(86) "uselib"
set SYSCALL_NAME(87) "swapon"
set SYSCALL_NAME(88) "reboot"
set SYSCALL_NAME(89) "readdir"
set SYSCALL_NAME(90) "mmap"
set SYSCALL_NAME(91) "munmap"
set SYSCALL_NAME(92) "truncate"
set SYSCALL_NAME(93) "ftruncate"
set SYSCALL_NAME(94) "fchmod"
set SYSCALL_NAME(95) "fchown"
set SYSCALL_NAME(96) "getpriority"
set SYSCALL_NAME(97) "setpriority"
set SYSCALL_NAME(98) "profil"
set SYSCALL_NAME(99) "statfs"
set SYSCALL_NAME(100) "fstatfs"
set SYSCALL_NAME(101) "ioperm"
set SYSCALL_NAME(102) "socketcall"
set SYSCALL_NAME(103) "klog"
set SYSCALL_NAME(104) "setitimer"
set SYSCALL_NAME(105) "getitimer"
set SYSCALL_NAME(106) "prev_stat"
set SYSCALL_NAME(107) "prev_lstat"
set SYSCALL_NAME(108) "prev_fstat"
set SYSCALL_NAME(109) "olduname"
set SYSCALL_NAME(110) "iopl"
set SYSCALL_NAME(111) "vhangup"
set SYSCALL_NAME(112) "idle"
set SYSCALL_NAME(113) "vm86old"
set SYSCALL_NAME(114) "wait4"
set SYSCALL_NAME(115) "swapoff"
set SYSCALL_NAME(116) "sysinfo"
set SYSCALL_NAME(117) "ipc"
set SYSCALL_NAME(118) "fsync"
set SYSCALL_NAME(119) "sigreturn"
set SYSCALL_NAME(120) "clone"
set SYSCALL_NAME(121) "setdomainname"
set SYSCALL_NAME(122) "uname"
set SYSCALL_NAME(123) "modify_ldt"
set SYSCALL_NAME(124) "adjtimex"
set SYSCALL_NAME(125) "mprotect"
set SYSCALL_NAME(126) "sigprocmask"
set SYSCALL_NAME(127) "create_module"
set SYSCALL_NAME(128) "init_module"
set SYSCALL_NAME(129) "delete_module"
set SYSCALL_NAME(130) "get_kernel_syms"
set SYSCALL_NAME(131) "quotactl"
set SYSCALL_NAME(132) "getpgid"
set SYSCALL_NAME(133) "fchdir"
set SYSCALL_NAME(134) "bdflush"
set SYSCALL_NAME(135) "sysfs"
set SYSCALL_NAME(136) "personality"
set SYSCALL_NAME(137) "afs_syscall"
set SYSCALL_NAME(138) "setfsuid"
set SYSCALL_NAME(139) "setfsgid"
set SYSCALL_NAME(140) "_llseek"
set SYSCALL_NAME(141) "getdents"
set SYSCALL_NAME(142) "_newselect"
set SYSCALL_NAME(143) "flock"
set SYSCALL_NAME(144) "msync"
set SYSCALL_NAME(145) "readv"
set SYSCALL_NAME(146) "writev"
set SYSCALL_NAME(147) "getsid"
set SYSCALL_NAME(148) "fdatasync"
set SYSCALL_NAME(149) "_sysctl"
set SYSCALL_NAME(150) "mlock"
set SYSCALL_NAME(151) "munlock"
set SYSCALL_NAME(152) "mlockall"
set SYSCALL_NAME(153) "munlockall"
set SYSCALL_NAME(154) "sched_setparam"
set SYSCALL_NAME(155) "sched_getparam"
set SYSCALL_NAME(156) "sched_setscheduler"
set SYSCALL_NAME(157) "sched_getscheduler"
set SYSCALL_NAME(158) "sched_yield"
set SYSCALL_NAME(159) "sched_get_priority_max"
set SYSCALL_NAME(160) "sched_get_priority_min"
set SYSCALL_NAME(161) "sched_rr_get_interval"
set SYSCALL_NAME(162) "nanosleep"
set SYSCALL_NAME(163) "mremap"
set SYSCALL_NAME(164) "setresuid"
set SYSCALL_NAME(165) "getresuid"
set SYSCALL_NAME(166) "vm86"
set SYSCALL_NAME(167) "query_module"
set SYSCALL_NAME(168) "poll"

set traceSyscallHasDoneInit 0

proc traceSyscallInit {} {
    global SYSCALL_VEC SYSCALL_NAME
    global traceSyscallHasDoneInit
    global syscallReturnEIP
     annotation set vec $SYSCALL_VEC -tag SyscallTrace { 
        set _off 8
        catch { set _ra   $MEMORY([expr $esp + $_off]) } { set _ra
            "INV" }
         set _arg0 $ebx
         set _arg1 $ecx
         set _arg2 $edx
        catch { set _name $SYSCALL_NAME([format "%u" $eax]) } { set _name [format "SYS%u" $eax] }
        log "$CYCLES: SYSCALL @ $eip from $_ra : $_name ($_arg0, $_arg1, $_arg2)\n"
        set syscallReturnEIP $eip
    }
    annotation set inst rfe -tag SyscallTrace {
        if {$syscallReturnEIP == $eip} {
            log "$CYCLES: SYSCALL_RETURN @ $eip eax = $eax\n"
        }
        set syscallReturnEIP -1
    }
    set traceSyscallHasDoneInit 1
    set syscallReturnEIP -1
}

set SYSCALL_TRACE_ON  1
set SYSCALL_TRACE_OFF 0

proc traceSyscall {enableFlag} {
    global traceSyscallHasDoneInit
    if {$enableFlag} {
        if {$traceSyscallHasDoneInit == 0} traceSyscallInit
        annotation enable SyscallTrace
    } else  {
        annotation disable SyscallTrace
    }
}