📄 syscall.c
字号:
/* syscall.c - proxy system call handler routines *//* SimpleScalar(TM) Tool Suite * Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC. * All Rights Reserved. * * THIS IS A LEGAL DOCUMENT, BY USING SIMPLESCALAR, * YOU ARE AGREEING TO THESE TERMS AND CONDITIONS. * * No portion of this work may be used by any commercial entity, or for any * commercial purpose, without the prior, written permission of SimpleScalar, * LLC (info@simplescalar.com). Nonprofit and noncommercial use is permitted * as described below. * * 1. SimpleScalar is provided AS IS, with no warranty of any kind, express * or implied. The user of the program accepts full responsibility for the * application of the program and the use of any results. * * 2. Nonprofit and noncommercial use is encouraged. SimpleScalar may be * downloaded, compiled, executed, copied, and modified solely for nonprofit, * educational, noncommercial research, and noncommercial scholarship * purposes provided that this notice in its entirety accompanies all copies. * Copies of the modified software can be delivered to persons who use it * solely for nonprofit, educational, noncommercial research, and * noncommercial scholarship purposes provided that this notice in its * entirety accompanies all copies. * * 3. ALL COMMERCIAL USE, AND ALL USE BY FOR PROFIT ENTITIES, IS EXPRESSLY * PROHIBITED WITHOUT A LICENSE FROM SIMPLESCALAR, LLC (info@simplescalar.com). * * 4. No nonprofit user may place any restrictions on the use of this software, * including as modified by the user, by any other authorized user. * * 5. Noncommercial and nonprofit users may distribute copies of SimpleScalar * in compiled or executable form as set forth in Section 2, provided that * either: (A) it is accompanied by the corresponding machine-readable source * code, or (B) it is accompanied by a written offer, with no time limit, to * give anyone a machine-readable copy of the corresponding source code in * return for reimbursement of the cost of distribution. This written offer * must permit verbatim duplication by anyone, or (C) it is distributed by * someone who received only the executable form, and is accompanied by a * copy of the written offer of source code. * * 6. SimpleScalar was developed by Todd M. Austin, Ph.D. The tool suite is * currently maintained by SimpleScalar LLC (info@simplescalar.com). US Mail: * 2395 Timbercrest Court, Ann Arbor, MI 48105. * * Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC. */#include <stdio.h>#include <stdlib.h>/* only enable a minimal set of systen call proxies if on limited hosts or if in cross endian live execution mode */#ifndef MIN_SYSCALL_MODE#if defined(_MSC_VER) || defined(__CYGWIN32__) || defined(MD_CROSS_ENDIAN)#define MIN_SYSCALL_MODE#endif#endif /* !MIN_SYSCALL_MODE *//* live execution only support on same-endian hosts... */#ifdef _MSC_VER#include <io.h>#else /* !_MSC_VER */#include <unistd.h>#endif#include <fcntl.h>#include <sys/types.h>#ifndef _MSC_VER#include <sys/param.h>#endif#include <errno.h>#include <time.h>#ifndef _MSC_VER#include <sys/time.h>#endif#ifndef _MSC_VER#include <sys/resource.h>#endif#include <signal.h>#ifndef _MSC_VER#include <sys/file.h>#endif#include <sys/stat.h>#ifndef _MSC_VER#include <sys/uio.h>#endif#include <setjmp.h>#ifndef _MSC_VER#include <sys/times.h>#endif#include <limits.h>#ifndef _MSC_VER#include <sys/ioctl.h>#endif#if defined(linux)#include <utime.h>#include <dirent.h>#include <sys/vfs.h>#endif#if defined(_AIX)#include <sys/statfs.h>#else /* !_AIX */#ifndef _MSC_VER#include <sys/mount.h>#endif#endif /* !_AIX */#if !defined(linux) && !defined(sparc) && !defined(hpux) && !defined(__hpux) && !defined(__CYGWIN32__) && !defined(ultrix)#ifndef _MSC_VER#include <sys/select.h>#endif#endif#ifdef linux#include <sgtty.h>#include <netinet/tcp.h>#include <netinet/udp.h>#include <netinet/in.h>#endif /* linux */#if defined(__svr4__)#include <sys/dirent.h>#include <sys/filio.h>#elif defined(__osf__)#include <dirent.h>/* -- For some weird reason, getdirentries() is not declared in any * -- header file under /usr/include on the Alpha boxen that I tried * -- SS-Alpha on. But the function exists in the libraries. */int getdirentries(int fd, char *buf, int nbytes, long *basep);#endif#if defined(__svr4__) || defined(__osf__)#include <sys/statvfs.h>#define statfs statvfs#include <sys/time.h>#include <utime.h>#include <sgtty.h>#include <netinet/in.h>#include <netinet/tcp.h>#endif#if defined(sparc) && defined(__unix__)#if defined(__svr4__) || defined(__USLC__)#include <dirent.h>#else#include <sys/dir.h>#endif/* dorks */#undef NL0#undef NL1#undef CR0#undef CR1#undef CR2#undef CR3#undef TAB0#undef TAB1#undef TAB2#undef XTABS#undef BS0#undef BS1#undef FF0#undef FF1#undef ECHO#undef NOFLSH#undef TOSTOP#undef FLUSHO#undef PENDIN#endif#if defined(hpux) || defined(__hpux)#undef CR0#endif#ifdef __FreeBSD__#include <sys/ioctl_compat.h>#else#ifndef _MSC_VER#include <termio.h>#endif#endif#if defined(hpux) || defined(__hpux)/* et tu, dorks! */#undef HUPCL#undef ECHO#undef B50#undef B75#undef B110#undef B134#undef B150#undef B200#undef B300#undef B600#undef B1200#undef B1800#undef B2400#undef B4800#undef B9600#undef B19200#undef B38400#undef NL0#undef NL1#undef CR0#undef CR1#undef CR2#undef CR3#undef TAB0#undef TAB1#undef BS0#undef BS1#undef FF0#undef FF1#undef EXTA#undef EXTB#undef B900#undef B3600#undef B7200#undef XTABS#include <sgtty.h>#include <utime.h>#endif#include <sys/socket.h>#include <sys/poll.h>#ifdef _MSC_VER#define access _access#define chmod _chmod#define chdir _chdir#define unlink _unlink#define open _open#define creat _creat#define pipe _pipe#define dup _dup#define dup2 _dup2#define stat _stat#define fstat _fstat#define lseek _lseek#define read _read#define write _write#define close _close#define getpid _getpid#define utime _utime#include <sys/utime.h>#endif /* _MSC_VER */#include "host.h"#include "misc.h"#include "machine.h"#include "regs.h"#include "memory.h"#include "loader.h"#include "sim.h"#include "endian.h"#include "eio.h"#include "syscall.h"#define OSF_SYS_syscall 0/* OSF_SYS_exit moved to alpha.h */#define OSF_SYS_fork 2#define OSF_SYS_read 3/* OSF_SYS_write moved to alpha.h */#define OSF_SYS_old_open 5 /* 5 is old open */#define OSF_SYS_close 6#define OSF_SYS_wait4 7#define OSF_SYS_old_creat 8 /* 8 is old creat */#define OSF_SYS_link 9#define OSF_SYS_unlink 10#define OSF_SYS_execv 11#define OSF_SYS_chdir 12#define OSF_SYS_fchdir 13#define OSF_SYS_mknod 14#define OSF_SYS_chmod 15#define OSF_SYS_chown 16#define OSF_SYS_obreak 17#define OSF_SYS_getfsstat 18#define OSF_SYS_lseek 19#define OSF_SYS_getpid 20#define OSF_SYS_mount 21#define OSF_SYS_unmount 22#define OSF_SYS_setuid 23#define OSF_SYS_getuid 24#define OSF_SYS_exec_with_loader 25#define OSF_SYS_ptrace 26#ifdef COMPAT_43#define OSF_SYS_nrecvmsg 27#define OSF_SYS_nsendmsg 28#define OSF_SYS_nrecvfrom 29#define OSF_SYS_naccept 30#define OSF_SYS_ngetpeername 31#define OSF_SYS_ngetsockname 32#else#define OSF_SYS_recvmsg 27#define OSF_SYS_sendmsg 28#define OSF_SYS_recvfrom 29#define OSF_SYS_accept 30#define OSF_SYS_getpeername 31#define OSF_SYS_getsockname 32#endif#define OSF_SYS_access 33#define OSF_SYS_chflags 34#define OSF_SYS_fchflags 35#define OSF_SYS_sync 36#define OSF_SYS_kill 37#define OSF_SYS_old_stat 38 /* 38 is old stat */#define OSF_SYS_setpgid 39#define OSF_SYS_old_lstat 40 /* 40 is old lstat */#define OSF_SYS_dup 41#define OSF_SYS_pipe 42#define OSF_SYS_set_program_attributes 43#define OSF_SYS_profil 44#define OSF_SYS_open 45 /* 46 is obsolete osigaction */#define OSF_SYS_getgid 47#define OSF_SYS_sigprocmask 48#define OSF_SYS_getlogin 49#define OSF_SYS_setlogin 50#define OSF_SYS_acct 51#define OSF_SYS_sigpending 52#define OSF_SYS_ioctl 54#define OSF_SYS_reboot 55#define OSF_SYS_revoke 56#define OSF_SYS_symlink 57#define OSF_SYS_readlink 58#define OSF_SYS_execve 59#define OSF_SYS_umask 60#define OSF_SYS_chroot 61#define OSF_SYS_old_fstat 62 /* 62 is old fstat */#define OSF_SYS_getpgrp 63#define OSF_SYS_getpagesize 64#define OSF_SYS_mremap 65#define OSF_SYS_vfork 66#define OSF_SYS_stat 67#define OSF_SYS_lstat 68#define OSF_SYS_sbrk 69#define OSF_SYS_sstk 70#define OSF_SYS_mmap 71#define OSF_SYS_ovadvise 72#define OSF_SYS_munmap 73#define OSF_SYS_mprotect 74#define OSF_SYS_madvise 75#define OSF_SYS_old_vhangup 76 /* 76 is old vhangup */#define OSF_SYS_kmodcall 77#define OSF_SYS_mincore 78#define OSF_SYS_getgroups 79#define OSF_SYS_setgroups 80#define OSF_SYS_old_getpgrp 81 /* 81 is old getpgrp */#define OSF_SYS_setpgrp 82#define OSF_SYS_setitimer 83#define OSF_SYS_old_wait 84 /* 84 is old wait */#define OSF_SYS_table 85#define OSF_SYS_getitimer 86#define OSF_SYS_gethostname 87#define OSF_SYS_sethostname 88#define OSF_SYS_getdtablesize 89#define OSF_SYS_dup2 90#define OSF_SYS_fstat 91#define OSF_SYS_fcntl 92#define OSF_SYS_select 93#define OSF_SYS_poll 94#define OSF_SYS_fsync 95#define OSF_SYS_setpriority 96#define OSF_SYS_socket 97#define OSF_SYS_connect 98#ifdef COMPAT_43#define OSF_SYS_accept 99#else#define OSF_SYS_old_accept 99 /* 99 is old accept */#endif#define OSF_SYS_getpriority 100#ifdef COMPAT_43#define OSF_SYS_send 101#define OSF_SYS_recv 102#else#define OSF_SYS_old_send 101 /* 101 is old send */#define OSF_SYS_old_recv 102 /* 102 is old recv */#endif#define OSF_SYS_sigreturn 103#define OSF_SYS_bind 104#define OSF_SYS_setsockopt 105#define OSF_SYS_listen 106#define OSF_SYS_plock 107#define OSF_SYS_old_sigvec 108 /* 108 is old sigvec */#define OSF_SYS_old_sigblock 109 /* 109 is old sigblock */#define OSF_SYS_old_sigsetmask 110 /* 110 is old sigsetmask */#define OSF_SYS_sigsuspend 111#define OSF_SYS_sigstack 112#ifdef COMPAT_43#define OSF_SYS_recvmsg 113#define OSF_SYS_sendmsg 114#else#define OSF_SYS_old_recvmsg 113 /* 113 is old recvmsg */#define OSF_SYS_old_sendmsg 114 /* 114 is old sendmsg */#endif /* 115 is obsolete vtrace */#define OSF_SYS_gettimeofday 116#define OSF_SYS_getrusage 117#define OSF_SYS_getsockopt 118#define OSF_SYS_readv 120#define OSF_SYS_writev 121#define OSF_SYS_settimeofday 122#define OSF_SYS_fchown 123#define OSF_SYS_fchmod 124#ifdef COMPAT_43#define OSF_SYS_recvfrom 125#else#define OSF_SYS_old_recvfrom 125 /* 125 is old recvfrom */#endif#define OSF_SYS_setreuid 126#define OSF_SYS_setregid 127#define OSF_SYS_rename 128#define OSF_SYS_truncate 129#define OSF_SYS_ftruncate 130#define OSF_SYS_flock 131#define OSF_SYS_setgid 132#define OSF_SYS_sendto 133#define OSF_SYS_shutdown 134#define OSF_SYS_socketpair 135#define OSF_SYS_mkdir 136#define OSF_SYS_rmdir 137#define OSF_SYS_utimes 138 /* 139 is obsolete 4.2 sigreturn */#define OSF_SYS_adjtime 140#ifdef COMPAT_43#define OSF_SYS_getpeername 141#else#define OSF_SYS_old_getpeername 141 /* 141 is old getpeername */#endif#define OSF_SYS_gethostid 142#define OSF_SYS_sethostid 143#define OSF_SYS_getrlimit 144#define OSF_SYS_setrlimit 145#define OSF_SYS_old_killpg 146 /* 146 is old killpg */#define OSF_SYS_setsid 147#define OSF_SYS_quotactl 148#define OSF_SYS_oldquota 149#ifdef COMPAT_43#define OSF_SYS_getsockname 150#else#define OSF_SYS_old_getsockname 150 /* 150 is old getsockname */#endif#define OSF_SYS_pid_block 153#define OSF_SYS_pid_unblock 154#define OSF_SYS_sigaction 156#define OSF_SYS_sigwaitprim 157#define OSF_SYS_nfssvc 158#define OSF_SYS_getdirentries 159#define OSF_SYS_statfs 160#define OSF_SYS_fstatfs 161#define OSF_SYS_async_daemon 163#define OSF_SYS_getfh 164#define OSF_SYS_getdomainname 165#define OSF_SYS_setdomainname 166#define OSF_SYS_exportfs 169#define OSF_SYS_alt_plock 181 /* 181 is alternate plock */#define OSF_SYS_getmnt 184#define OSF_SYS_alt_sigpending 187 /* 187 is alternate sigpending */#define OSF_SYS_alt_setsid 188 /* 188 is alternate setsid */#define OSF_SYS_swapon 199#define OSF_SYS_msgctl 200#define OSF_SYS_msgget 201#define OSF_SYS_msgrcv 202#define OSF_SYS_msgsnd 203#define OSF_SYS_semctl 204#define OSF_SYS_semget 205#define OSF_SYS_semop 206#define OSF_SYS_uname 207
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -