gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
syscall_emul.cc File Reference
#include "sim/syscall_emul.hh"
#include <fcntl.h>
#include <unistd.h>
#include <csignal>
#include <iostream>
#include <string>
#include "arch/utility.hh"
#include "base/chunk_generator.hh"
#include "base/trace.hh"
#include "config/the_isa.hh"
#include "cpu/thread_context.hh"
#include "mem/page_table.hh"
#include "sim/process.hh"
#include "sim/sim_exit.hh"
#include "sim/syscall_debug_macros.hh"
#include "sim/syscall_desc.hh"
#include "sim/system.hh"

Go to the source code of this file.

Functions

SyscallReturn unimplementedFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Handler for unimplemented syscalls that we haven't thought about. More...
 
SyscallReturn ignoreFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Handler for unimplemented syscalls that we never intend to implement (signal handling, etc.) and should not affect the correct behavior of the program. More...
 
static void exitFutexWake (ThreadContext *tc, Addr addr, uint64_t tgid)
 
static SyscallReturn exitImpl (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, bool group)
 
SyscallReturn exitFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 Target exit() handler: terminate current context. More...
 
SyscallReturn exitGroupFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 Target exit_group() handler: terminate simulation. (exit all threads) More...
 
SyscallReturn getpagesizeFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target getpagesize() handler. More...
 
SyscallReturn brkFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target brk() handler: set brk address. More...
 
SyscallReturn setTidAddressFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target set_tid_address() handler. More...
 
SyscallReturn closeFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target close() handler. More...
 
SyscallReturn readFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 
SyscallReturn writeFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target write() handler. More...
 
SyscallReturn lseekFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target lseek() handler. More...
 
SyscallReturn _llseekFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target _llseek() handler. More...
 
SyscallReturn munmapFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target munmap() handler. More...
 
SyscallReturn gethostnameFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target gethostname() handler. More...
 
SyscallReturn getcwdFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target getcwd() handler. More...
 
SyscallReturn readlinkFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 
SyscallReturn readlinkFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc, int index)
 Target readlink() handler. More...
 
SyscallReturn unlinkFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 
SyscallReturn unlinkHelper (SyscallDesc *desc, int num, Process *p, ThreadContext *tc, int index)
 Target unlink() handler. More...
 
SyscallReturn mkdirFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target mkdir() handler. More...
 
SyscallReturn renameFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target rename() handler. More...
 
SyscallReturn truncateFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target truncate() handler. More...
 
SyscallReturn ftruncateFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target ftruncate() handler. More...
 
SyscallReturn truncate64Func (SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
 Target truncate64() handler. More...
 
SyscallReturn ftruncate64Func (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target ftruncate64() handler. More...
 
SyscallReturn umaskFunc (SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
 Target umask() handler. More...
 
SyscallReturn chownFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target chown() handler. More...
 
SyscallReturn fchownFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target fchown() handler. More...
 
SyscallReturn dupFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 FIXME: The file description is not shared among file descriptors created with dup. More...
 
SyscallReturn dup2Func (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target dup2() handler. More...
 
SyscallReturn fcntlFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target fcntl() handler. More...
 
SyscallReturn fcntl64Func (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target fcntl64() handler. More...
 
SyscallReturn pipeImpl (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, bool pseudoPipe)
 Internal pipe() handler. More...
 
SyscallReturn pipePseudoFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Pseudo Funcs - These functions use a different return convension, returning a second value in a register other than the normal return register. More...
 
SyscallReturn pipeFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target pipe() handler. More...
 
SyscallReturn setpgidFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target setpgid() handler. More...
 
SyscallReturn getpidPseudoFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target getpidPseudo() handler. More...
 
SyscallReturn getuidPseudoFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target getuidPseudo() handler. More...
 
SyscallReturn getgidPseudoFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target getgidPseudo() handler. More...
 
SyscallReturn setuidFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target setuid() handler. More...
 
SyscallReturn getpidFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target getpid() handler. More...
 
SyscallReturn gettidFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target gettid() handler. More...
 
SyscallReturn getppidFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target getppid() handler. More...
 
SyscallReturn getuidFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target getuid() handler. More...
 
SyscallReturn geteuidFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target geteuid() handler. More...
 
SyscallReturn getgidFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target getgid() handler. More...
 
SyscallReturn getegidFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target getegid() handler. More...
 
SyscallReturn fallocateFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 
SyscallReturn accessFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, int index)
 
SyscallReturn accessFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 Target access() handler. More...
 

Variables

const char * hostname = "m5.eecs.umich.edu"
 

Function Documentation

SyscallReturn _llseekFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn accessFunc ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc,
int  index 
)
SyscallReturn accessFunc ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc 
)

Target access() handler.

Definition at line 1049 of file syscall_emul.cc.

References accessFunc().

Referenced by faccessatFunc().

SyscallReturn brkFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn chownFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn closeFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target close() handler.

Definition at line 256 of file syscall_emul.cc.

References Process::fds, Process::getSyscallArg(), and MipsISA::index.

SyscallReturn dup2Func ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target dup2() handler.

We need a valid host file descriptor number to be able to pass into the second parameter for dup2 (newfd), but we don't know what the viable numbers are; we execute the open call to retrieve one.

Definition at line 707 of file syscall_emul.cc.

References Process::fds, Process::getSyscallArg(), and MipsISA::index.

SyscallReturn dupFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

FIXME: The file description is not shared among file descriptors created with dup.

Target dup() handler.

Really, it's difficult to maintain fields like file offset or flags since an update to such a field won't be reflected in the metadata for the fd entries that we maintain for checkpoint restoration.

Definition at line 686 of file syscall_emul.cc.

References Process::fds, Process::getSyscallArg(), and MipsISA::index.

SyscallReturn exitFunc ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc 
)

Target exit() handler: terminate current context.

Definition at line 178 of file syscall_emul.cc.

References exitImpl().

static void exitFutexWake ( ThreadContext tc,
Addr  addr,
uint64_t  tgid 
)
static
SyscallReturn exitGroupFunc ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc 
)

Target exit_group() handler: terminate simulation. (exit all threads)

Definition at line 184 of file syscall_emul.cc.

References exitImpl().

Referenced by tgkillFunc().

static SyscallReturn exitImpl ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc,
bool  group 
)
static

Threads in a thread group require special handing. For instance, we send the SIGCHLD signal so that it appears that it came from the head of the group. We also only delete file descriptors if we are the last thread in the thread group.

Check if we share thread group with the pointer; this denotes that we are not the last thread active in the thread group. Note that setting this to false also prevents further iterations of the loop.

A corner case exists which involves execve(). After execve(), the execve will enable SIGCHLD in the process. The problem occurs when the exiting process is the root process in the system; there is no parent to receive the signal. We obviate this problem by setting the root process' ppid to zero in the Python configuration files. We really should handle the root/execve specific case more gracefully.

Run though FD array of the exiting process and close all file descriptors except for the standard file descriptors. (The standard file descriptors are shared with gem5.)

Definition at line 93 of file syscall_emul.cc.

References Process::childClearTID, exitFutexWake(), Process::exitGroup, exitSimLoop(), Process::fds, Process::getSyscallArg(), ThreadContext::getSystemPtr(), ThreadContext::halt(), ThreadContext::Halted, ArmISA::i, MipsISA::index, System::numContexts(), Process::pid(), Process::ppid(), Process::sigchld, System::signalList, ArmISA::status, ArmISA::system, System::systemList, Process::tgid(), and System::threadContexts.

Referenced by exitFunc(), and exitGroupFunc().

SyscallReturn fallocateFunc ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc 
)
SyscallReturn fchownFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target fchown() handler.

Definition at line 659 of file syscall_emul.cc.

References Process::fds, Process::getSyscallArg(), and MipsISA::index.

SyscallReturn fcntl64Func ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target fcntl64() handler.

Definition at line 782 of file syscall_emul.cc.

References Process::fds, Process::getSyscallArg(), MipsISA::index, and warn.

SyscallReturn fcntlFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target fcntl() handler.

Definition at line 738 of file syscall_emul.cc.

References Process::fds, Process::getSyscallArg(), MipsISA::index, and warn.

SyscallReturn ftruncate64Func ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target ftruncate64() handler.

Definition at line 606 of file syscall_emul.cc.

References Process::fds, Process::getSyscallArg(), MipsISA::index, and length.

SyscallReturn ftruncateFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target ftruncate() handler.

Definition at line 567 of file syscall_emul.cc.

References Process::fds, Process::getSyscallArg(), MipsISA::index, and length.

SyscallReturn getcwdFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn getegidFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target getegid() handler.

Definition at line 1001 of file syscall_emul.cc.

References Process::egid().

SyscallReturn geteuidFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target geteuid() handler.

Definition at line 987 of file syscall_emul.cc.

References Process::euid().

SyscallReturn getgidFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target getgid() handler.

Definition at line 994 of file syscall_emul.cc.

References Process::gid().

SyscallReturn getgidPseudoFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target getgidPseudo() handler.

Definition at line 939 of file syscall_emul.cc.

References Process::egid(), Process::gid(), ThreadContext::setIntReg(), and AlphaISA::SyscallPseudoReturnReg.

SyscallReturn gethostnameFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn getpagesizeFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target getpagesize() handler.

Definition at line 190 of file syscall_emul.cc.

References AlphaISA::PageBytes.

SyscallReturn getpidFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target getpid() handler.

Definition at line 959 of file syscall_emul.cc.

References Process::tgid().

SyscallReturn getpidPseudoFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target getpidPseudo() handler.

Definition at line 913 of file syscall_emul.cc.

References Process::pid(), Process::ppid(), ThreadContext::setIntReg(), and AlphaISA::SyscallPseudoReturnReg.

SyscallReturn getppidFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target getppid() handler.

Definition at line 973 of file syscall_emul.cc.

References Process::ppid().

SyscallReturn gettidFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target gettid() handler.

Definition at line 966 of file syscall_emul.cc.

References Process::pid().

SyscallReturn getuidFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target getuid() handler.

Definition at line 980 of file syscall_emul.cc.

References Process::uid().

SyscallReturn getuidPseudoFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target getuidPseudo() handler.

Definition at line 926 of file syscall_emul.cc.

References Process::euid(), ThreadContext::setIntReg(), AlphaISA::SyscallPseudoReturnReg, and Process::uid().

SyscallReturn ignoreFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Handler for unimplemented syscalls that we never intend to implement (signal handling, etc.) and should not affect the correct behavior of the program.

Print a warning only if the appropriate trace flag is enabled. Return success to the target program.

Definition at line 67 of file syscall_emul.cc.

References SyscallDesc::name(), SyscallDesc::needWarning(), warn, and SyscallDesc::warnOnce().

SyscallReturn lseekFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target lseek() handler.

Definition at line 312 of file syscall_emul.cc.

References Process::fds, Process::getSyscallArg(), and MipsISA::index.

SyscallReturn mkdirFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn munmapFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target munmap() handler.

Definition at line 361 of file syscall_emul.cc.

SyscallReturn pipeFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target pipe() handler.

Definition at line 871 of file syscall_emul.cc.

References pipeImpl().

SyscallReturn pipeImpl ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc,
bool  pseudoPipe 
)

Internal pipe() handler.

Now patch the read object to record the target file descriptor chosen as the write end of the pipe.

Alpha Linux convention for pipe() is that fd[0] is returned as the return value of the function, and fd[1] is returned in r20.

Copy the target file descriptors into buffer space and then copy the buffer space back into the target address space.

Definition at line 813 of file syscall_emul.cc.

References BufferArg::bufferPtr(), BaseBufferArg::copyOut(), Process::fds, ThreadContext::getMemProxy(), Process::getSyscallArg(), MipsISA::index, ThreadContext::setIntReg(), and AlphaISA::SyscallPseudoReturnReg.

Referenced by pipeFunc(), and pipePseudoFunc().

SyscallReturn pipePseudoFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Pseudo Funcs - These functions use a different return convension, returning a second value in a register other than the normal return register.

Definition at line 864 of file syscall_emul.cc.

References pipeImpl().

SyscallReturn readFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn readlinkFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Definition at line 419 of file syscall_emul.cc.

References readlinkFunc().

Referenced by readlinkFunc().

SyscallReturn readlinkFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc,
int  index 
)
SyscallReturn renameFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn setpgidFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
SyscallReturn setTidAddressFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target set_tid_address() handler.

Definition at line 245 of file syscall_emul.cc.

References Process::childClearTID, Process::getSyscallArg(), MipsISA::index, and Process::pid().

SyscallReturn setuidFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target setuid() handler.

Definition at line 949 of file syscall_emul.cc.

References Process::getSyscallArg(), MipsISA::index, and warn.

SyscallReturn truncate64Func ( SyscallDesc desc,
int  num,
Process process,
ThreadContext tc 
)
SyscallReturn truncateFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn umaskFunc ( SyscallDesc desc,
int  num,
Process process,
ThreadContext tc 
)

Target umask() handler.

Definition at line 626 of file syscall_emul.cc.

SyscallReturn unimplementedFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Handler for unimplemented syscalls that we haven't thought about.

Definition at line 57 of file syscall_emul.cc.

References fatal, and SyscallDesc::name().

SyscallReturn unlinkFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Definition at line 486 of file syscall_emul.cc.

References unlinkHelper().

SyscallReturn unlinkHelper ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc,
int  index 
)
SyscallReturn writeFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Variable Documentation

const char* hostname = "m5.eecs.umich.edu"

Definition at line 370 of file syscall_emul.cc.

Referenced by gethostnameFunc().


Generated on Fri Jun 9 2017 13:03:59 for gem5 by doxygen 1.8.6