gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Typedefs | Functions | Variables
syscall_emul.hh File Reference

This file defines objects used to emulate syscalls from the target application on the host machine. More...

#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <unistd.h>
#include <cerrno>
#include <memory>
#include <string>
#include "arch/utility.hh"
#include "base/intmath.hh"
#include "base/loader/object_file.hh"
#include "base/misc.hh"
#include "base/trace.hh"
#include "base/types.hh"
#include "config/the_isa.hh"
#include "cpu/base.hh"
#include "cpu/thread_context.hh"
#include "mem/page_table.hh"
#include "params/Process.hh"
#include "sim/emul_driver.hh"
#include "sim/futex_map.hh"
#include "sim/process.hh"
#include "sim/syscall_debug_macros.hh"
#include "sim/syscall_desc.hh"
#include "sim/syscall_emul_buf.hh"
#include "sim/syscall_return.hh"

Go to the source code of this file.

Macros

#define NO_STAT64   0
 
#define NO_STATFS   0
 
#define NO_FALLOCATE   0
 

Typedefs

typedef struct statfs hst_statfs
 
typedef struct stat hst_stat
 
typedef struct stat64 hst_stat64
 

Functions

SyscallReturn unimplementedFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Handler for unimplemented syscalls that we haven't thought about. More...
 
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. More...
 
SyscallReturn fallocateFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 
SyscallReturn exitFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target exit() handler: terminate current context. More...
 
SyscallReturn exitGroupFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target exit_group() handler: terminate simulation. (exit all threads) More...
 
SyscallReturn setTidAddressFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target set_tid_address() handler. 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 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 num, Process *p, ThreadContext *tc, int index=0)
 Target readlink() handler. More...
 
SyscallReturn readlinkFunc (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 unlinkFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 
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 *p, 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 *p, ThreadContext *tc)
 Target umask() handler. More...
 
SyscallReturn gettidFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target gettid() handler. More...
 
SyscallReturn chownFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target chown() handler. More...
 
SyscallReturn setpgidFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target setpgid() handler. More...
 
SyscallReturn fchownFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target fchown() handler. More...
 
SyscallReturn dupFunc (SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
 Target dup() handler. More...
 
SyscallReturn dup2Func (SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
 Target dup2() handler. More...
 
SyscallReturn fcntlFunc (SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
 Target fcntl() handler. More...
 
SyscallReturn fcntl64Func (SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
 Target fcntl64() handler. More...
 
SyscallReturn setuidFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target setuid() handler. More...
 
SyscallReturn pipeFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target pipe() handler. More...
 
SyscallReturn pipeImpl (SyscallDesc *desc, int num, Process *p, ThreadContext *tc, bool pseudoPipe)
 Internal pipe() handler. More...
 
SyscallReturn getpidFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target getpid() handler. More...
 
SyscallReturn getuidFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target getuid() handler. More...
 
SyscallReturn getgidFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target getgid() handler. More...
 
SyscallReturn getppidFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target getppid() handler. More...
 
SyscallReturn geteuidFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target geteuid() handler. More...
 
SyscallReturn getegidFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target getegid() handler. More...
 
SyscallReturn accessFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target access() handler. More...
 
SyscallReturn accessFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc, int index)
 
template<class OS >
SyscallReturn futexFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Futex system call Implemented by Daniel Sanchez Used by printf's in multi-threaded apps. More...
 
SyscallReturn pipePseudoFunc (SyscallDesc *desc, int num, 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 getpidPseudoFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target getpidPseudo() handler. More...
 
SyscallReturn getuidPseudoFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target getuidPseudo() handler. More...
 
SyscallReturn getgidPseudoFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target getgidPseudo() handler. More...
 
template<class T1 , class T2 >
void getElapsedTimeMicro (T1 &sec, T2 &usec)
 Helper function to convert current elapsed time to seconds and microseconds. More...
 
template<class T1 , class T2 >
void getElapsedTimeNano (T1 &sec, T2 &nsec)
 Helper function to convert current elapsed time to seconds and nanoseconds. More...
 
template<typename target_stat , typename host_stat >
void convertStatBuf (target_stat &tgt, host_stat *host, bool fakeTTY=false)
 
template<typename target_stat , typename host_stat64 >
void convertStat64Buf (target_stat &tgt, host_stat64 *host, bool fakeTTY=false)
 
template<class OS >
void copyOutStatBuf (SETranslatingPortProxy &mem, Addr addr, hst_stat *host, bool fakeTTY=false)
 
template<class OS >
void copyOutStat64Buf (SETranslatingPortProxy &mem, Addr addr, hst_stat64 *host, bool fakeTTY=false)
 
template<class OS >
void copyOutStatfsBuf (SETranslatingPortProxy &mem, Addr addr, hst_statfs *host)
 
template<class OS >
SyscallReturn ioctlFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 Target ioctl() handler. More...
 
template<class OS >
SyscallReturn openImpl (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, bool isopenat)
 
template<class OS >
SyscallReturn openFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target open() handler. More...
 
template<class OS >
SyscallReturn openatFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target openat() handler. More...
 
template<class OS >
SyscallReturn unlinkatFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target unlinkat() handler. More...
 
template<class OS >
SyscallReturn faccessatFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target facessat() handler. More...
 
template<class OS >
SyscallReturn readlinkatFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target readlinkat() handler. More...
 
template<class OS >
SyscallReturn renameatFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target renameat() handler. More...
 
template<class OS >
SyscallReturn sysinfoFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target sysinfo() handler. More...
 
template<class OS >
SyscallReturn chmodFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target chmod() handler. More...
 
template<class OS >
SyscallReturn fchmodFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 Target fchmod() handler. More...
 
template<class OS >
SyscallReturn mremapFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target mremap() handler. More...
 
template<class OS >
SyscallReturn statFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target stat() handler. More...
 
template<class OS >
SyscallReturn stat64Func (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target stat64() handler. More...
 
template<class OS >
SyscallReturn fstatat64Func (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target fstatat64() handler. More...
 
template<class OS >
SyscallReturn fstat64Func (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 Target fstat64() handler. More...
 
template<class OS >
SyscallReturn lstatFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target lstat() handler. More...
 
template<class OS >
SyscallReturn lstat64Func (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target lstat64() handler. More...
 
template<class OS >
SyscallReturn fstatFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 Target fstat() handler. More...
 
template<class OS >
SyscallReturn statfsFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target statfs() handler. More...
 
template<class OS >
SyscallReturn cloneFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 
template<class OS >
SyscallReturn fstatfsFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 Target fstatfs() handler. More...
 
template<class OS >
SyscallReturn writevFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 Target writev() handler. More...
 
template<class OS >
SyscallReturn mmapImpl (SyscallDesc *desc, int num, Process *p, ThreadContext *tc, bool is_mmap2)
 Real mmap handler. More...
 
template<class OS >
SyscallReturn pwrite64Func (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 
template<class OS >
SyscallReturn mmapFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target mmap() handler. More...
 
template<class OS >
SyscallReturn mmap2Func (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target mmap2() handler. More...
 
template<class OS >
SyscallReturn getrlimitFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target getrlimit() handler. More...
 
template<class OS >
SyscallReturn clock_gettimeFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target clock_gettime() function. More...
 
template<class OS >
SyscallReturn clock_getresFunc (SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
 Target clock_getres() function. More...
 
template<class OS >
SyscallReturn gettimeofdayFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target gettimeofday() handler. More...
 
template<class OS >
SyscallReturn utimesFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target utimes() handler. More...
 
template<class OS >
SyscallReturn execveFunc (SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
 
template<class OS >
SyscallReturn getrusageFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target getrusage() function. More...
 
template<class OS >
SyscallReturn timesFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target times() function. More...
 
template<class OS >
SyscallReturn timeFunc (SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
 Target time() function. More...
 
template<class OS >
SyscallReturn tgkillFunc (SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
 

Variables

const int one_million = 1000000
 A readable name for 1,000,000, for converting microseconds to seconds. More...
 
const int one_billion = 1000000000
 A readable name for 1,000,000,000, for converting nanoseconds to seconds. More...
 
const unsigned seconds_since_epoch = 1000000000
 Approximate seconds since the epoch (1/1/1970). More...
 

Detailed Description

This file defines objects used to emulate syscalls from the target application on the host machine.

Definition in file syscall_emul.hh.

Macro Definition Documentation

#define NO_FALLOCATE   0

Definition at line 67 of file syscall_emul.hh.

#define NO_STAT64   0

Definition at line 53 of file syscall_emul.hh.

#define NO_STATFS   0

Definition at line 60 of file syscall_emul.hh.

Typedef Documentation

typedef struct stat hst_stat

Definition at line 423 of file syscall_emul.hh.

typedef struct stat64 hst_stat64

Definition at line 424 of file syscall_emul.hh.

typedef struct statfs hst_statfs

Definition at line 418 of file syscall_emul.hh.

Function Documentation

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

Target access() handler.

Definition at line 1049 of file syscall_emul.cc.

References accessFunc().

Referenced by faccessatFunc().

SyscallReturn accessFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc,
int  index 
)
SyscallReturn brkFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
template<class OS >
SyscallReturn chmodFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
SyscallReturn chownFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
template<class OS >
SyscallReturn clock_getresFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target clock_getres() function.

Definition at line 1702 of file syscall_emul.hh.

References BaseBufferArg::copyOut(), ThreadContext::getMemProxy(), Process::getSyscallArg(), and MipsISA::index.

template<class OS >
SyscallReturn clock_gettimeFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
template<class OS >
SyscallReturn cloneFunc ( SyscallDesc desc,
int  callnum,
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.

template<typename target_stat , typename host_stat64 >
void convertStat64Buf ( target_stat &  tgt,
host_stat64 *  host,
bool  fakeTTY = false 
)

Definition at line 482 of file syscall_emul.hh.

References BigEndianGuest::htog().

template<typename target_stat , typename host_stat >
void convertStatBuf ( target_stat &  tgt,
host_stat *  host,
bool  fakeTTY = false 
)

Definition at line 433 of file syscall_emul.hh.

References BigEndianGuest::htog().

template<class OS >
void copyOutStat64Buf ( SETranslatingPortProxy mem,
Addr  addr,
hst_stat64 host,
bool  fakeTTY = false 
)

Definition at line 515 of file syscall_emul.hh.

template<class OS >
void copyOutStatBuf ( SETranslatingPortProxy mem,
Addr  addr,
hst_stat host,
bool  fakeTTY = false 
)

Definition at line 504 of file syscall_emul.hh.

template<class OS >
void copyOutStatfsBuf ( SETranslatingPortProxy mem,
Addr  addr,
hst_statfs host 
)

Definition at line 526 of file syscall_emul.hh.

References BaseBufferArg::copyOut(), and BigEndianGuest::htog().

SyscallReturn dup2Func ( SyscallDesc desc,
int  num,
Process process,
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 
)

Target dup() handler.

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.

template<class OS >
SyscallReturn execveFunc ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc 
)

Note that ProcessParams is generated by swig and there are no other examples of how to create anything but this default constructor. The fields are manually initialized instead of passing parameters to the constructor.

Prevent process object creation with identical PIDs (which will trip a fatal check in Process constructor). The execve call is supposed to take over the currently executing process' identity but replace whatever it is doing with a new process image. Instead of hijacking the process object in the simulator, we create a new process object and bind to the previous process' thread below (hijacking the thread).

Work through the file descriptor array and close any files marked close-on-exec.

Definition at line 1773 of file syscall_emul.hh.

References ThreadContext::activate(), Process::assignThreadContext(), ArmISA::b, BufferArg::bufferPtr(), ThreadContext::clearArchRegs(), ThreadContext::contextId(), BaseBufferArg::copyIn(), Process::egid(), Process::euid(), Process::fds, Process::getcwd(), ThreadContext::getMemProxy(), Process::getSyscallArg(), Process::gid(), ArmISA::i, MipsISA::index, Process::initState(), MipsISA::p, ThreadContext::pcState(), Process::pid(), System::PIDs, Process::ppid(), SyscallDesc::setFlags(), ThreadContext::setNPC(), ThreadContext::setProcessPtr(), Process::sigchld, SyscallDesc::SuppressReturnValue, Process::system, SETranslatingPortProxy::tryReadString(), and Process::uid().

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

Target exit() handler: terminate current context.

Definition at line 178 of file syscall_emul.cc.

References exitImpl().

SyscallReturn exitGroupFunc ( SyscallDesc desc,
int  num,
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().

template<class OS >
SyscallReturn faccessatFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target facessat() handler.

Definition at line 773 of file syscall_emul.hh.

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

SyscallReturn fallocateFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
template<class OS >
SyscallReturn fchmodFunc ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc 
)

Target fchmod() handler.

Definition at line 887 of file syscall_emul.hh.

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

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 process,
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 process,
ThreadContext tc 
)

Target fcntl() handler.

Definition at line 738 of file syscall_emul.cc.

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

template<class OS >
SyscallReturn fstat64Func ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc 
)

Target fstat64() handler.

Definition at line 1078 of file syscall_emul.hh.

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

template<class OS >
SyscallReturn fstatat64Func ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
template<class OS >
SyscallReturn fstatfsFunc ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc 
)

Target fstatfs() handler.

Definition at line 1365 of file syscall_emul.hh.

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

template<class OS >
SyscallReturn fstatFunc ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc 
)

Target fstat() handler.

Definition at line 1172 of file syscall_emul.hh.

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

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.

template<class OS >
SyscallReturn futexFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Futex system call Implemented by Daniel Sanchez Used by printf's in multi-threaded apps.

Definition at line 317 of file syscall_emul.hh.

References BufferArg::bufferPtr(), BaseBufferArg::copyIn(), System::futexMap, ThreadContext::getMemProxy(), Process::getSyscallArg(), ThreadContext::getSystemPtr(), MipsISA::index, X86ISA::op, Process::tgid(), X86ISA::val, and warn.

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

Target getegid() handler.

Definition at line 1001 of file syscall_emul.cc.

References Process::egid().

template<class T1 , class T2 >
void getElapsedTimeMicro ( T1 &  sec,
T2 &  usec 
)

Helper function to convert current elapsed time to seconds and microseconds.

Definition at line 393 of file syscall_emul.hh.

References curTick(), one_million, and SimClock::Int::us.

Referenced by getrusageFunc(), gettimeofdayFunc(), and timeFunc().

template<class T1 , class T2 >
void getElapsedTimeNano ( T1 &  sec,
T2 &  nsec 
)

Helper function to convert current elapsed time to seconds and nanoseconds.

Definition at line 404 of file syscall_emul.hh.

References curTick(), SimClock::Int::ns, and one_billion.

Referenced by clock_gettimeFunc().

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

Target geteuid() handler.

Definition at line 987 of file syscall_emul.cc.

References Process::euid().

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

Target getgid() handler.

Definition at line 994 of file syscall_emul.cc.

References Process::gid().

SyscallReturn getgidPseudoFunc ( SyscallDesc desc,
int  num,
Process p,
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  num,
Process p,
ThreadContext tc 
)

Target getpid() handler.

Definition at line 959 of file syscall_emul.cc.

References Process::tgid().

SyscallReturn getpidPseudoFunc ( SyscallDesc desc,
int  num,
Process p,
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  num,
Process p,
ThreadContext tc 
)

Target getppid() handler.

Definition at line 973 of file syscall_emul.cc.

References Process::ppid().

template<class OS >
SyscallReturn getrlimitFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target getrlimit() handler.

Definition at line 1648 of file syscall_emul.hh.

References ThreadContext::getMemProxy(), Process::getSyscallArg(), BigEndianGuest::htog(), MipsISA::index, and warn.

template<class OS >
SyscallReturn getrusageFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
SyscallReturn gettidFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target gettid() handler.

Definition at line 966 of file syscall_emul.cc.

References Process::pid().

template<class OS >
SyscallReturn gettimeofdayFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
SyscallReturn getuidFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target getuid() handler.

Definition at line 980 of file syscall_emul.cc.

References Process::uid().

SyscallReturn getuidPseudoFunc ( SyscallDesc desc,
int  num,
Process p,
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().

template<class OS >
SyscallReturn ioctlFunc ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc 
)

Target ioctl() handler.

For the most part, programs call ioctl() only to find out if their stdout is a tty, to determine whether to do line or block buffering. We always claim that output fds are not TTYs to provide repeatable results.

If the driver is valid, issue the ioctl through it. Otherwise, there's an implicit assumption that the device is a TTY type and we return that we do not have a valid TTY.

For lack of a better return code, return ENOTTY. Ideally, we should return something better here, but at least we issue the warning.

Definition at line 572 of file syscall_emul.hh.

References DPRINTF, Process::fds, Process::getSyscallArg(), MipsISA::index, EmulatedDriver::ioctl(), ThreadContext::pcState(), and warn.

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.

template<class OS >
SyscallReturn lstat64Func ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
template<class OS >
SyscallReturn lstatFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
SyscallReturn mkdirFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
template<class OS >
SyscallReturn mmap2Func ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target mmap2() handler.

Definition at line 1640 of file syscall_emul.hh.

References MipsISA::p.

template<class OS >
SyscallReturn mmapFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target mmap() handler.

Definition at line 1632 of file syscall_emul.hh.

References MipsISA::p.

template<class OS >
SyscallReturn mmapImpl ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc,
bool  is_mmap2 
)
template<class OS >
SyscallReturn mremapFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
SyscallReturn munmapFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target munmap() handler.

Definition at line 361 of file syscall_emul.cc.

template<class OS >
SyscallReturn openatFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target openat() handler.

Definition at line 750 of file syscall_emul.hh.

template<class OS >
SyscallReturn openFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target open() handler.

Definition at line 741 of file syscall_emul.hh.

template<class OS >
SyscallReturn openImpl ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc,
bool  isopenat 
)

If using the openat variant, read in the target directory file descriptor from the simulated process.

Retrieve the simulated process' memory proxy and then read in the path string from that memory space into the host's working memory space.

Translate target flags into host flags. Flags exist which are not ported between architectures which can cause check failures.

If the simulated process called open or openat with AT_FDCWD specified, take the current working directory value which was passed into the process class as a Python parameter and append the current path to create a full path. Otherwise, openat with a valid target directory file descriptor has been called. If the path option, which was passed in as a parameter, is not absolute, retrieve the directory file descriptor's path and prepend it to the path passed in as a parameter. In every case, we should have a full path (which is relevant to the host) to work with after this block has been passed.

Since this is an emulated environment, we create pseudo file descriptors for device requests that have been registered with the process class through Python; this allows us to create a file descriptor for subsequent ioctl or mmap calls.

Fall through here for pass through to host devices, such as /dev/zero

Some special paths and files cannot be called on the host and need to be handled as special cases inside the simulator. If the full path that was created above does not match any of the special cases, pass it through to the open call on the host to let the host open the file on our behalf. If the host cannot open the file, return the host's error code back through the system call to the simulated process.

The file was opened successfully and needs to be recorded in the process' file descriptor array so that it can be retrieved later. The target file descriptor that is chosen will be the lowest unused file descriptor. Return the indirect target file descriptor back to the simulated process to act as a handle for the opened file.

Definition at line 607 of file syscall_emul.hh.

References DPRINTF_SYSCALL, Process::fds, Process::findDriver(), Process::fullPath(), ThreadContext::getMemProxy(), Process::getSyscallArg(), ArmISA::i, MipsISA::index, ArmISA::mode, EmulatedDriver::open(), startswith(), SETranslatingPortProxy::tryReadString(), and warn.

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

Target pipe() handler.

Definition at line 871 of file syscall_emul.cc.

References pipeImpl().

SyscallReturn pipeImpl ( SyscallDesc desc,
int  num,
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  num,
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().

template<class OS >
SyscallReturn pwrite64Func ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn readFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
template<class OS >
SyscallReturn readlinkatFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target readlinkat() handler.

Definition at line 786 of file syscall_emul.hh.

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

SyscallReturn readlinkFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc,
int  index = 0 
)
SyscallReturn readlinkFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Definition at line 419 of file syscall_emul.cc.

References readlinkFunc().

Referenced by readlinkFunc().

template<class OS >
SyscallReturn renameatFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
SyscallReturn renameFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn setpgidFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn setTidAddressFunc ( SyscallDesc desc,
int  num,
Process p,
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  num,
Process p,
ThreadContext tc 
)

Target setuid() handler.

Definition at line 949 of file syscall_emul.cc.

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

template<class OS >
SyscallReturn stat64Func ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
template<class OS >
SyscallReturn statfsFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
template<class OS >
SyscallReturn statFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
template<class OS >
SyscallReturn sysinfoFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
template<class OS >
SyscallReturn tgkillFunc ( SyscallDesc desc,
int  num,
Process process,
ThreadContext tc 
)

This system call is intended to allow killing a specific thread within an arbitrary thread group if sanctioned with permission checks. It's usually true that threads share the termination signal as pointed out by the pthread_kill man page and this seems to be the intended usage. Due to this being an emulated environment, assume the following: Threads are allowed to call tgkill because the EUID for all threads should be the same. There is no signal handling mechanism for kernel registration of signal handlers since signals are poorly supported in emulation mode. Since signal handlers cannot be registered, all threads within in a thread group must share the termination signal. We never exhaust PIDs so there's no chance of finding the wrong one due to PID rollover.

Definition at line 1963 of file syscall_emul.hh.

References exitGroupFunc(), Process::getSyscallArg(), ThreadContext::getSystemPtr(), ArmISA::i, MipsISA::index, System::numContexts(), Process::pid(), Process::tgid(), and System::threadContexts.

template<class OS >
SyscallReturn timeFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
template<class OS >
SyscallReturn timesFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
SyscallReturn truncate64Func ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn truncateFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
SyscallReturn umaskFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)

Target umask() handler.

Definition at line 626 of file syscall_emul.cc.

SyscallReturn unimplementedFunc ( SyscallDesc desc,
int  num,
Process p,
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().

template<class OS >
SyscallReturn unlinkatFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)

Target unlinkat() handler.

Definition at line 759 of file syscall_emul.hh.

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

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 
)
template<class OS >
SyscallReturn utimesFunc ( SyscallDesc desc,
int  callnum,
Process process,
ThreadContext tc 
)
SyscallReturn writeFunc ( SyscallDesc desc,
int  num,
Process p,
ThreadContext tc 
)
template<class OS >
SyscallReturn writevFunc ( SyscallDesc desc,
int  callnum,
Process p,
ThreadContext tc 
)

Variable Documentation

const int one_billion = 1000000000

A readable name for 1,000,000,000, for converting nanoseconds to seconds.

Definition at line 382 of file syscall_emul.hh.

Referenced by getElapsedTimeNano().

const int one_million = 1000000

A readable name for 1,000,000, for converting microseconds to seconds.

Definition at line 380 of file syscall_emul.hh.

Referenced by getElapsedTimeMicro().

const unsigned seconds_since_epoch = 1000000000

Approximate seconds since the epoch (1/1/1970).

About a billion, by my reckoning. We want to keep this a constant (not use the real-world time) to keep simulations repeatable.

Definition at line 387 of file syscall_emul.hh.

Referenced by clock_gettimeFunc(), gettimeofdayFunc(), sysinfoFunc(), and timeFunc().


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