gem5  v20.1.0.0
Macros | Typedefs | Functions | Variables
syscall_emul.hh File Reference
#include <sys/mount.h>
#include <fcntl.h>
#include <net/if.h>
#include <poll.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <cerrno>
#include <memory>
#include <string>
#include "arch/generic/tlb.hh"
#include "arch/utility.hh"
#include "base/intmath.hh"
#include "base/loader/object_file.hh"
#include "base/logging.hh"
#include "base/trace.hh"
#include "base/types.hh"
#include "config/the_isa.hh"
#include "cpu/base.hh"
#include "cpu/thread_context.hh"
#include "kern/linux/linux.hh"
#include "mem/page_table.hh"
#include "params/Process.hh"
#include "sim/emul_driver.hh"
#include "sim/futex_map.hh"
#include "sim/guest_abi.hh"
#include "sim/process.hh"
#include "sim/proxy_ptr.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
 

Typedefs

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

Functions

void warnUnsupportedOS (std::string syscall_name)
 
SyscallReturn unimplementedFunc (SyscallDesc *desc, ThreadContext *tc)
 Handler for unimplemented syscalls that we haven't thought about. More...
 
SyscallReturn ignoreFunc (SyscallDesc *desc, 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 ignoreWarnOnceFunc (SyscallDesc *desc, ThreadContext *tc)
 Like above, but only prints a warning once per syscall desc it's used with. More...
 
SyscallReturn fallocateFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int mode, off_t offset, off_t len)
 
SyscallReturn exitFunc (SyscallDesc *desc, ThreadContext *tc, int status)
 Target exit() handler: terminate current context. More...
 
SyscallReturn exitGroupFunc (SyscallDesc *desc, ThreadContext *tc, int status)
 Target exit_group() handler: terminate simulation. (exit all threads) More...
 
SyscallReturn setTidAddressFunc (SyscallDesc *desc, ThreadContext *tc, uint64_t tidPtr)
 Target set_tid_address() handler. More...
 
SyscallReturn getpagesizeFunc (SyscallDesc *desc, ThreadContext *tc)
 Target getpagesize() handler. More...
 
SyscallReturn brkFunc (SyscallDesc *desc, ThreadContext *tc, Addr new_brk)
 Target brk() handler: set brk address. More...
 
SyscallReturn closeFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd)
 Target close() handler. More...
 
SyscallReturn lseekFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint64_t offs, int whence)
 Target lseek() handler. More...
 
SyscallReturn _llseekFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint64_t offset_high, uint32_t offset_low, Addr result_ptr, int whence)
 Target _llseek() handler. More...
 
SyscallReturn munmapFunc (SyscallDesc *desc, ThreadContext *tc, Addr start, size_t length)
 Target munmap() handler. More...
 
SyscallReturn shutdownFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int how)
 Target shutdown() handler. More...
 
SyscallReturn gethostnameFunc (SyscallDesc *desc, ThreadContext *tc, Addr buf_ptr, int name_len)
 Target gethostname() handler. More...
 
SyscallReturn getcwdFunc (SyscallDesc *desc, ThreadContext *tc, Addr buf_ptr, unsigned long size)
 Target getcwd() handler. More...
 
SyscallReturn readlinkFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr buf, size_t bufsiz)
 Target readlink() handler. More...
 
SyscallReturn unlinkFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname)
 Target unlink() handler. More...
 
SyscallReturn linkFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr new_pathname)
 Target link() handler. More...
 
SyscallReturn symlinkFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr new_pathname)
 Target symlink() handler. More...
 
SyscallReturn mkdirFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode)
 Target mkdir() handler. More...
 
SyscallReturn mknodFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode, dev_t dev)
 Target mknod() handler. More...
 
SyscallReturn chdirFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname)
 Target chdir() handler. More...
 
SyscallReturn rmdirFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname)
 
SyscallReturn renameFunc (SyscallDesc *desc, ThreadContext *tc, Addr oldpath, Addr newpath)
 Target rename() handler. More...
 
SyscallReturn truncateFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, off_t length)
 Target truncate() handler. More...
 
SyscallReturn ftruncateFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, off_t length)
 Target ftruncate() handler. More...
 
SyscallReturn truncate64Func (SyscallDesc *desc, ThreadContext *tc, Addr pathname, int64_t length)
 Target truncate64() handler. More...
 
SyscallReturn ftruncate64Func (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int64_t length)
 Target ftruncate64() handler. More...
 
SyscallReturn umaskFunc (SyscallDesc *desc, ThreadContext *tc)
 Target umask() handler. More...
 
SyscallReturn gettidFunc (SyscallDesc *desc, ThreadContext *tc)
 Target gettid() handler. More...
 
SyscallReturn chownFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, uint32_t owner, uint32_t group)
 Target chown() handler. More...
 
SyscallReturn getpgrpFunc (SyscallDesc *desc, ThreadContext *tc)
 Target getpgrpFunc() handler. More...
 
SyscallReturn setpgidFunc (SyscallDesc *desc, ThreadContext *tc, int pid, int pgid)
 Target setpgid() handler. More...
 
SyscallReturn fchownFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint32_t owner, uint32_t group)
 Target fchown() handler. More...
 
SyscallReturn dupFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd)
 Target dup() handler. More...
 
SyscallReturn dup2Func (SyscallDesc *desc, ThreadContext *tc, int old_tgt_fd, int new_tgt_fd)
 Target dup2() handler. More...
 
SyscallReturn fcntlFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int cmd, GuestABI::VarArgs< int > varargs)
 Target fcntl() handler. More...
 
SyscallReturn fcntl64Func (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int cmd)
 Target fcntl64() handler. More...
 
SyscallReturn pipeFunc (SyscallDesc *desc, ThreadContext *tc, Addr tgt_addr)
 Target pipe() handler. More...
 
SyscallReturn pipe2Func (SyscallDesc *desc, ThreadContext *tc, Addr tgt_addr, int flags)
 Target pipe() handler. More...
 
SyscallReturn getpidFunc (SyscallDesc *desc, ThreadContext *tc)
 Target getpid() handler. More...
 
SyscallReturn getpeernameFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr sockAddrPtr, Addr addrlenPtr)
 
SyscallReturn bindFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int addrlen)
 
SyscallReturn listenFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int backlog)
 
SyscallReturn connectFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int addrlen)
 
SyscallReturn sendtoFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufrPtr, size_t bufrLen, int flags, Addr addrPtr, socklen_t addrLen)
 
SyscallReturn recvfromFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufrPtr, size_t bufrLen, int flags, Addr addrPtr, Addr addrlenPtr)
 
SyscallReturn recvmsgFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr msgPtr, int flags)
 
SyscallReturn sendmsgFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr msgPtr, int flags)
 
SyscallReturn getuidFunc (SyscallDesc *desc, ThreadContext *tc)
 
SyscallReturn getgidFunc (SyscallDesc *desc, ThreadContext *tc)
 Target getgid() handler. More...
 
SyscallReturn getppidFunc (SyscallDesc *desc, ThreadContext *tc)
 Target getppid() handler. More...
 
SyscallReturn geteuidFunc (SyscallDesc *desc, ThreadContext *tc)
 Target geteuid() handler. More...
 
SyscallReturn getegidFunc (SyscallDesc *desc, ThreadContext *tc)
 Target getegid() handler. More...
 
SyscallReturn accessFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode)
 Target access() handler. More...
 
SyscallReturn getsockoptFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int level, int optname, Addr valPtr, Addr lenPtr)
 
SyscallReturn setsockoptFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int level, int optname, Addr valPtr, socklen_t len)
 
SyscallReturn getcpuFunc (SyscallDesc *desc, ThreadContext *tc, VPtr< uint32_t > cpu, VPtr< uint32_t > node, VPtr< uint32_t > tcache)
 
SyscallReturn getsocknameFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr addrPtr, Addr lenPtr)
 
template<class OS >
SyscallReturn futexFunc (SyscallDesc *desc, ThreadContext *tc, Addr uaddr, int op, int val, int timeout, Addr uaddr2, int val3)
 Futex system call Implemented by Daniel Sanchez Used by printf's in multi-threaded apps. More...
 
SyscallReturn pipePseudoFunc (SyscallDesc *desc, 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...
 
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 OS , typename TgtStatPtr , typename HostStatPtr >
void copyOutStatBuf (TgtStatPtr tgt, HostStatPtr host, bool fakeTTY=false)
 
template<typename OS , typename TgtStatPtr , typename HostStatPtr >
void copyOutStat64Buf (TgtStatPtr tgt, HostStatPtr host, bool fakeTTY=false)
 
template<class OS , typename TgtStatPtr , typename HostStatPtr >
void copyOutStatfsBuf (TgtStatPtr tgt, HostStatPtr host)
 
template<class OS >
SyscallReturn ioctlFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, unsigned req, Addr addr)
 Target ioctl() handler. More...
 
template<class OS >
SyscallReturn openatFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_dirfd, Addr pathname, int tgt_flags, int mode)
 Target open() handler. More...
 
template<class OS >
SyscallReturn openFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, int tgt_flags, int mode)
 Target open() handler. More...
 
template<class OS >
SyscallReturn unlinkatFunc (SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname)
 Target unlinkat() handler. More...
 
template<class OS >
SyscallReturn faccessatFunc (SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname, int mode)
 Target facessat() handler. More...
 
template<class OS >
SyscallReturn readlinkatFunc (SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname, Addr buf, size_t bufsiz)
 Target readlinkat() handler. More...
 
template<class OS >
SyscallReturn renameatFunc (SyscallDesc *desc, ThreadContext *tc, int olddirfd, Addr oldpath, int newdirfd, Addr newpath)
 Target renameat() handler. More...
 
template<class OS >
SyscallReturn sysinfoFunc (SyscallDesc *desc, ThreadContext *tc, VPtr< typename OS::tgt_sysinfo > sysinfo)
 Target sysinfo() handler. More...
 
template<class OS >
SyscallReturn chmodFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode)
 Target chmod() handler. More...
 
template<class OS >
SyscallReturn pollFunc (SyscallDesc *desc, ThreadContext *tc, Addr fdsPtr, int nfds, int tmout)
 
template<class OS >
SyscallReturn fchmodFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint32_t mode)
 Target fchmod() handler. More...
 
template<class OS >
SyscallReturn mremapFunc (SyscallDesc *desc, ThreadContext *tc, Addr start, uint64_t old_length, uint64_t new_length, uint64_t flags, GuestABI::VarArgs< uint64_t > varargs)
 Target mremap() handler. More...
 
template<class OS >
SyscallReturn statFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::tgt_stat > tgt_stat)
 Target stat() handler. More...
 
template<class OS >
SyscallReturn stat64Func (SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::tgt_stat64 > tgt_stat)
 Target stat64() handler. More...
 
template<class OS >
SyscallReturn fstatat64Func (SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname, VPtr< typename OS::tgt_stat64 > tgt_stat)
 Target fstatat64() handler. More...
 
template<class OS >
SyscallReturn fstat64Func (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, VPtr< typename OS::tgt_stat64 > tgt_stat)
 Target fstat64() handler. More...
 
template<class OS >
SyscallReturn lstatFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::tgt_stat > tgt_stat)
 Target lstat() handler. More...
 
template<class OS >
SyscallReturn lstat64Func (SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::tgt_stat64 > tgt_stat)
 Target lstat64() handler. More...
 
template<class OS >
SyscallReturn fstatFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, VPtr< typename OS::tgt_stat > tgt_stat)
 Target fstat() handler. More...
 
template<class OS >
SyscallReturn statfsFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::tgt_statfs > tgt_stat)
 Target statfs() handler. More...
 
template<class OS >
SyscallReturn cloneFunc (SyscallDesc *desc, ThreadContext *tc, RegVal flags, RegVal newStack, Addr ptidPtr, Addr ctidPtr, Addr tlsPtr)
 
template<class OS >
SyscallReturn cloneBackwardsFunc (SyscallDesc *desc, ThreadContext *tc, RegVal flags, RegVal newStack, Addr ptidPtr, Addr tlsPtr, Addr ctidPtr)
 
template<class OS >
SyscallReturn fstatfsFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, VPtr< typename OS::tgt_statfs > tgt_stat)
 Target fstatfs() handler. More...
 
template<class OS >
SyscallReturn readvFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint64_t tiov_base, size_t count)
 Target readv() handler. More...
 
template<class OS >
SyscallReturn writevFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint64_t tiov_base, size_t count)
 Target writev() handler. More...
 
template<class OS >
SyscallReturn mmapFunc (SyscallDesc *desc, ThreadContext *tc, Addr start, typename OS::size_t length, int prot, int tgt_flags, int tgt_fd, typename OS::off_t offset)
 Target mmap() handler. More...
 
template<class OS >
SyscallReturn pread64Func (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufPtr, int nbytes, int offset)
 
template<class OS >
SyscallReturn pwrite64Func (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufPtr, int nbytes, int offset)
 
template<class OS >
SyscallReturn mmap2Func (SyscallDesc *desc, ThreadContext *tc, Addr start, typename OS::size_t length, int prot, int tgt_flags, int tgt_fd, typename OS::off_t offset)
 Target mmap2() handler. More...
 
template<class OS >
SyscallReturn getrlimitFunc (SyscallDesc *desc, ThreadContext *tc, unsigned resource, VPtr< typename OS::rlimit > rlp)
 Target getrlimit() handler. More...
 
template<class OS >
SyscallReturn prlimitFunc (SyscallDesc *desc, ThreadContext *tc, int pid, int resource, Addr n, VPtr< typename OS::rlimit > rlp)
 
template<class OS >
SyscallReturn clock_gettimeFunc (SyscallDesc *desc, ThreadContext *tc, int clk_id, VPtr< typename OS::timespec > tp)
 Target clock_gettime() function. More...
 
template<class OS >
SyscallReturn clock_getresFunc (SyscallDesc *desc, ThreadContext *tc, int clk_id, VPtr< typename OS::timespec > tp)
 Target clock_getres() function. More...
 
template<class OS >
SyscallReturn gettimeofdayFunc (SyscallDesc *desc, ThreadContext *tc, VPtr< typename OS::timeval > tp, Addr tz_ptr)
 Target gettimeofday() handler. More...
 
template<class OS >
SyscallReturn utimesFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::timeval[2]> tp)
 Target utimes() handler. More...
 
template<class OS >
SyscallReturn execveFunc (SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr argv_mem_loc, Addr envp_mem_loc)
 
template<class OS >
SyscallReturn getrusageFunc (SyscallDesc *desc, ThreadContext *tc, int who, VPtr< typename OS::rusage > rup)
 Target getrusage() function. More...
 
template<class OS >
SyscallReturn timesFunc (SyscallDesc *desc, ThreadContext *tc, VPtr< typename OS::tms > bufp)
 Target times() function. More...
 
template<class OS >
SyscallReturn timeFunc (SyscallDesc *desc, ThreadContext *tc, Addr taddr)
 Target time() function. More...
 
template<class OS >
SyscallReturn tgkillFunc (SyscallDesc *desc, ThreadContext *tc, int tgid, int tid, int sig)
 
template<class OS >
SyscallReturn socketFunc (SyscallDesc *desc, ThreadContext *tc, int domain, int type, int prot)
 
template<class OS >
SyscallReturn socketpairFunc (SyscallDesc *desc, ThreadContext *tc, int domain, int type, int prot, Addr svPtr)
 
template<class OS >
SyscallReturn selectFunc (SyscallDesc *desc, ThreadContext *tc, int nfds, VPtr< typename OS::fd_set > readfds, VPtr< typename OS::fd_set > writefds, VPtr< typename OS::fd_set > errorfds, VPtr< typename OS::timeval > timeout)
 
template<class OS >
SyscallReturn readFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int nbytes)
 
template<class OS >
SyscallReturn writeFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int nbytes)
 
template<class OS >
SyscallReturn wait4Func (SyscallDesc *desc, ThreadContext *tc, pid_t pid, Addr statPtr, int options, Addr rusagePtr)
 
template<class OS >
SyscallReturn acceptFunc (SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr addrPtr, Addr lenPtr)
 
template<class OS >
SyscallReturn eventfdFunc (SyscallDesc *desc, ThreadContext *tc, unsigned initval, int in_flags)
 Target eventfd() function. More...
 

Variables

const unsigned seconds_since_epoch = 1000 * 1000 * 1000
 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

◆ NO_STAT64

#define NO_STAT64   0

Definition at line 50 of file syscall_emul.hh.

Typedef Documentation

◆ hst_stat

typedef struct stat hst_stat

Definition at line 551 of file syscall_emul.hh.

◆ hst_stat64

typedef struct stat64 hst_stat64

Definition at line 552 of file syscall_emul.hh.

◆ hst_statfs

typedef struct statfs hst_statfs

Definition at line 546 of file syscall_emul.hh.

Function Documentation

◆ _llseekFunc()

SyscallReturn _llseekFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
uint64_t  offset_high,
uint32_t  offset_low,
Addr  result_ptr,
int  whence 
)

◆ acceptFunc()

template<class OS >
SyscallReturn acceptFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  addrPtr,
Addr  lenPtr 
)

We poll the socket file descriptor first to guarantee that we do not block on our accept call. The socket can be opened without the non-blocking flag (it blocks). This will cause deadlocks between communicating processes.

Definition at line 2514 of file syscall_emul.hh.

References BufferArg::bufferPtr(), BaseBufferArg::copyIn(), BaseBufferArg::copyOut(), ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), MipsISA::p, SyscallReturn::retry(), and ArmISA::sa.

◆ accessFunc()

SyscallReturn accessFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
mode_t  mode 
)

◆ bindFunc()

SyscallReturn bindFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  buf_ptr,
int  addrlen 
)

◆ brkFunc()

SyscallReturn brkFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  new_brk 
)

Target brk() handler: set brk address.

Definition at line 249 of file syscall_emul.cc.

References DPRINTF_SYSCALL, ThreadContext::getProcessPtr(), and MipsISA::p.

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ chdirFunc()

SyscallReturn chdirFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname 
)

◆ chmodFunc()

template<class OS >
SyscallReturn chmodFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
mode_t  mode 
)

Target chmod() handler.

Definition at line 973 of file syscall_emul.hh.

References ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), ArmISA::mode, and PortProxy::tryReadString().

◆ chownFunc()

SyscallReturn chownFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
uint32_t  owner,
uint32_t  group 
)

◆ clock_getresFunc()

template<class OS >
SyscallReturn clock_getresFunc ( SyscallDesc desc,
ThreadContext tc,
int  clk_id,
VPtr< typename OS::timespec >  tp 
)

Target clock_getres() function.

Definition at line 1910 of file syscall_emul.hh.

◆ clock_gettimeFunc()

template<class OS >
SyscallReturn clock_gettimeFunc ( SyscallDesc desc,
ThreadContext tc,
int  clk_id,
VPtr< typename OS::timespec >  tp 
)

Target clock_gettime() function.

Definition at line 1896 of file syscall_emul.hh.

References ArmISA::byteOrder(), getElapsedTimeNano(), htog(), and seconds_since_epoch.

◆ cloneBackwardsFunc()

template<class OS >
SyscallReturn cloneBackwardsFunc ( SyscallDesc desc,
ThreadContext tc,
RegVal  flags,
RegVal  newStack,
Addr  ptidPtr,
Addr  tlsPtr,
Addr  ctidPtr 
)

Definition at line 1525 of file syscall_emul.hh.

◆ cloneFunc()

template<class OS >
SyscallReturn cloneFunc ( SyscallDesc desc,
ThreadContext tc,
RegVal  flags,
RegVal  newStack,
Addr  ptidPtr,
Addr  ctidPtr,
Addr  tlsPtr 
)

◆ closeFunc()

SyscallReturn closeFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd 
)

Target close() handler.

Definition at line 280 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), and MipsISA::p.

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ connectFunc()

SyscallReturn connectFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  buf_ptr,
int  addrlen 
)

◆ copyOutStat64Buf()

template<typename OS , typename TgtStatPtr , typename HostStatPtr >
void copyOutStat64Buf ( TgtStatPtr  tgt,
HostStatPtr  host,
bool  fakeTTY = false 
)

Definition at line 610 of file syscall_emul.hh.

References PowerISA::bo, ArmISA::byteOrder(), and htog().

◆ copyOutStatBuf()

template<typename OS , typename TgtStatPtr , typename HostStatPtr >
void copyOutStatBuf ( TgtStatPtr  tgt,
HostStatPtr  host,
bool  fakeTTY = false 
)

Definition at line 561 of file syscall_emul.hh.

References PowerISA::bo, ArmISA::byteOrder(), and htog().

◆ copyOutStatfsBuf()

template<class OS , typename TgtStatPtr , typename HostStatPtr >
void copyOutStatfsBuf ( TgtStatPtr  tgt,
HostStatPtr  host 
)

Definition at line 632 of file syscall_emul.hh.

References PowerISA::bo, ArmISA::byteOrder(), and htog().

◆ dup2Func()

SyscallReturn dup2Func ( SyscallDesc desc,
ThreadContext tc,
int  old_tgt_fd,
int  new_tgt_fd 
)

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 691 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), and MipsISA::p.

◆ dupFunc()

SyscallReturn dupFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd 
)

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 671 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), and MipsISA::p.

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ eventfdFunc()

template<class OS >
SyscallReturn eventfdFunc ( SyscallDesc desc,
ThreadContext tc,
unsigned  initval,
int  in_flags 
)

Target eventfd() function.

Definition at line 2581 of file syscall_emul.hh.

References ThreadContext::getProcessPtr(), MipsISA::p, and warnUnsupportedOS().

◆ execveFunc()

template<class OS >
SyscallReturn execveFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
Addr  argv_mem_loc,
Addr  envp_mem_loc 
)

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 1966 of file syscall_emul.hh.

References ThreadContext::activate(), Process::assignThreadContext(), ArmISA::b, ThreadContext::clearArchRegs(), ThreadContext::contextId(), Process::fds, ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), ArmISA::i, sc_dt::inc(), Process::initState(), MipsISA::p, ThreadContext::pcState(), ThreadContext::setNPC(), ThreadContext::setProcessPtr(), Process::sigchld, and PortProxy::tryReadString().

◆ exitFunc()

SyscallReturn exitFunc ( SyscallDesc desc,
ThreadContext tc,
int  status 
)

Target exit() handler: terminate current context.

Definition at line 230 of file syscall_emul.cc.

References exitImpl(), and ArmISA::status.

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ exitGroupFunc()

SyscallReturn exitGroupFunc ( SyscallDesc desc,
ThreadContext tc,
int  status 
)

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

Definition at line 236 of file syscall_emul.cc.

References exitImpl(), and ArmISA::status.

Referenced by SyscallTable32::SyscallTable32(), SyscallTable64::SyscallTable64(), and tgkillFunc().

◆ faccessatFunc()

template<class OS >
SyscallReturn faccessatFunc ( SyscallDesc desc,
ThreadContext tc,
int  dirfd,
Addr  pathname,
int  mode 
)

Target facessat() handler.

Definition at line 921 of file syscall_emul.hh.

References accessFunc(), ArmISA::mode, and warn.

◆ fallocateFunc()

SyscallReturn fallocateFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
int  mode,
off_t  offset,
off_t  len 
)

◆ fchmodFunc()

template<class OS >
SyscallReturn fchmodFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
uint32_t  mode 
)

Target fchmod() handler.

Definition at line 1073 of file syscall_emul.hh.

References ThreadContext::getProcessPtr(), ArmISA::mode, and MipsISA::p.

◆ fchownFunc()

SyscallReturn fchownFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
uint32_t  owner,
uint32_t  group 
)

Target fchown() handler.

Definition at line 646 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), and MipsISA::p.

◆ fcntl64Func()

SyscallReturn fcntl64Func ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
int  cmd 
)

Target fcntl64() handler.

Definition at line 761 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), MipsISA::p, and warn.

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ fcntlFunc()

SyscallReturn fcntlFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
int  cmd,
GuestABI::VarArgs< int >  varargs 
)

◆ fstat64Func()

template<class OS >
SyscallReturn fstat64Func ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
VPtr< typename OS::tgt_stat64 >  tgt_stat 
)

Target fstat64() handler.

Definition at line 1268 of file syscall_emul.hh.

References ThreadContext::getProcessPtr(), and MipsISA::p.

◆ fstatat64Func()

template<class OS >
SyscallReturn fstatat64Func ( SyscallDesc desc,
ThreadContext tc,
int  dirfd,
Addr  pathname,
VPtr< typename OS::tgt_stat64 >  tgt_stat 
)

Target fstatat64() handler.

Definition at line 1234 of file syscall_emul.hh.

References ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), PortProxy::tryReadString(), and warn.

◆ fstatfsFunc()

template<class OS >
SyscallReturn fstatfsFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
VPtr< typename OS::tgt_statfs >  tgt_stat 
)

Target fstatfs() handler.

Definition at line 1534 of file syscall_emul.hh.

References ThreadContext::getProcessPtr(), and MipsISA::p.

◆ fstatFunc()

template<class OS >
SyscallReturn fstatFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
VPtr< typename OS::tgt_stat >  tgt_stat 
)

Target fstat() handler.

Definition at line 1355 of file syscall_emul.hh.

References DPRINTF_SYSCALL, ThreadContext::getProcessPtr(), and MipsISA::p.

◆ ftruncate64Func()

SyscallReturn ftruncate64Func ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
int64_t  length 
)

Target ftruncate64() handler.

Definition at line 595 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), length, and MipsISA::p.

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ ftruncateFunc()

SyscallReturn ftruncateFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
off_t  length 
)

Target ftruncate() handler.

Definition at line 560 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), length, and MipsISA::p.

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ futexFunc()

template<class OS >
SyscallReturn futexFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  uaddr,
int  op,
int  val,
int  timeout,
Addr  uaddr2,
int  val3 
)

◆ getcpuFunc()

SyscallReturn getcpuFunc ( SyscallDesc desc,
ThreadContext tc,
VPtr< uint32_t >  cpu,
VPtr< uint32_t >  node,
VPtr< uint32_t >  tcache 
)

◆ getcwdFunc()

SyscallReturn getcwdFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  buf_ptr,
unsigned long  size 
)

◆ getegidFunc()

SyscallReturn getegidFunc ( SyscallDesc desc,
ThreadContext tc 
)

Target getegid() handler.

Definition at line 970 of file syscall_emul.cc.

References Process::egid(), and ThreadContext::getProcessPtr().

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ getElapsedTimeMicro()

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 517 of file syscall_emul.hh.

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

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

◆ getElapsedTimeNano()

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 530 of file syscall_emul.hh.

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

Referenced by clock_gettimeFunc().

◆ geteuidFunc()

SyscallReturn geteuidFunc ( SyscallDesc desc,
ThreadContext tc 
)

Target geteuid() handler.

Definition at line 956 of file syscall_emul.cc.

References Process::euid(), and ThreadContext::getProcessPtr().

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ getgidFunc()

SyscallReturn getgidFunc ( SyscallDesc desc,
ThreadContext tc 
)

Target getgid() handler.

Definition at line 963 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), and Process::gid().

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ gethostnameFunc()

SyscallReturn gethostnameFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  buf_ptr,
int  name_len 
)

Target gethostname() handler.

Definition at line 354 of file syscall_emul.cc.

References ThreadContext::getVirtProxy(), hostname, and name().

◆ getpagesizeFunc()

SyscallReturn getpagesizeFunc ( SyscallDesc desc,
ThreadContext tc 
)

Target getpagesize() handler.

Definition at line 242 of file syscall_emul.cc.

References System::getPageBytes(), and ThreadContext::getSystemPtr().

◆ getpeernameFunc()

SyscallReturn getpeernameFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  sockAddrPtr,
Addr  addrlenPtr 
)

◆ getpgrpFunc()

SyscallReturn getpgrpFunc ( SyscallDesc desc,
ThreadContext tc 
)

Target getpgrpFunc() handler.

Definition at line 887 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), and Process::pgid().

◆ getpidFunc()

SyscallReturn getpidFunc ( SyscallDesc desc,
ThreadContext tc 
)

Target getpid() handler.

Definition at line 928 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), and Process::tgid().

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ getppidFunc()

SyscallReturn getppidFunc ( SyscallDesc desc,
ThreadContext tc 
)

Target getppid() handler.

Definition at line 942 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), and Process::ppid().

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ getrlimitFunc()

template<class OS >
SyscallReturn getrlimitFunc ( SyscallDesc desc,
ThreadContext tc,
unsigned  resource,
VPtr< typename OS::rlimit >  rlp 
)

Target getrlimit() handler.

Definition at line 1824 of file syscall_emul.hh.

References PowerISA::bo, ArmISA::byteOrder(), ThreadContext::getSystemPtr(), htog(), System::Threads::size(), System::threads, and warn.

◆ getrusageFunc()

template<class OS >
SyscallReturn getrusageFunc ( SyscallDesc desc,
ThreadContext tc,
int  who,
VPtr< typename OS::rusage >  rup 
)

Target getrusage() function.

Definition at line 2055 of file syscall_emul.hh.

References ArmISA::byteOrder(), getElapsedTimeMicro(), htog(), and warn.

◆ getsocknameFunc()

SyscallReturn getsocknameFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  addrPtr,
Addr  lenPtr 
)

◆ getsockoptFunc()

SyscallReturn getsockoptFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
int  level,
int  optname,
Addr  valPtr,
Addr  lenPtr 
)

◆ gettidFunc()

SyscallReturn gettidFunc ( SyscallDesc desc,
ThreadContext tc 
)

Target gettid() handler.

Definition at line 935 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), and Process::pid().

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ gettimeofdayFunc()

template<class OS >
SyscallReturn gettimeofdayFunc ( SyscallDesc desc,
ThreadContext tc,
VPtr< typename OS::timeval >  tp,
Addr  tz_ptr 
)

Target gettimeofday() handler.

Definition at line 1923 of file syscall_emul.hh.

References ArmISA::byteOrder(), getElapsedTimeMicro(), htog(), and seconds_since_epoch.

◆ getuidFunc()

SyscallReturn getuidFunc ( SyscallDesc desc,
ThreadContext tc 
)

◆ ignoreFunc()

SyscallReturn ignoreFunc ( SyscallDesc desc,
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.

Prints a warning. Return success to the target program.

Definition at line 73 of file syscall_emul.cc.

References SyscallDesc::name(), and warn.

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ ignoreWarnOnceFunc()

SyscallReturn ignoreWarnOnceFunc ( SyscallDesc desc,
ThreadContext tc 
)

Like above, but only prints a warning once per syscall desc it's used with.

Definition at line 80 of file syscall_emul.cc.

References SyscallDesc::name(), and warn.

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ ioctlFunc()

template<class OS >
SyscallReturn ioctlFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
unsigned  req,
Addr  addr 
)

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.

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 676 of file syscall_emul.hh.

References addr, BufferArg::bufferPtr(), BaseBufferArg::copyIn(), BaseBufferArg::copyOut(), DPRINTF_SYSCALL, ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), EmulatedDriver::ioctl(), MipsISA::p, ThreadContext::pcState(), ArmISA::status, and warn.

◆ linkFunc()

SyscallReturn linkFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
Addr  new_pathname 
)

Target link() handler.

Definition at line 467 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), and MipsISA::p.

◆ listenFunc()

SyscallReturn listenFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
int  backlog 
)

Definition at line 1184 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), MipsISA::p, and ArmISA::status.

◆ lseekFunc()

SyscallReturn lseekFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
uint64_t  offs,
int  whence 
)

Target lseek() handler.

Definition at line 287 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), and MipsISA::p.

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ lstat64Func()

template<class OS >
SyscallReturn lstat64Func ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
VPtr< typename OS::tgt_stat64 >  tgt_stat 
)

◆ lstatFunc()

template<class OS >
SyscallReturn lstatFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
VPtr< typename OS::tgt_stat >  tgt_stat 
)

◆ mkdirFunc()

SyscallReturn mkdirFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
mode_t  mode 
)

◆ mknodFunc()

SyscallReturn mknodFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
mode_t  mode,
dev_t  dev 
)

◆ mmap2Func()

template<class OS >
SyscallReturn mmap2Func ( SyscallDesc desc,
ThreadContext tc,
Addr  start,
typename OS::size_t  length,
int  prot,
int  tgt_flags,
int  tgt_fd,
typename OS::off_t  offset 
)

Target mmap2() handler.

Definition at line 1813 of file syscall_emul.hh.

References System::getPageBytes(), ThreadContext::getSystemPtr(), length, ArmISA::offset, and X86ISA::prot.

◆ mmapFunc()

template<class OS >
SyscallReturn mmapFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  start,
typename OS::size_t  length,
int  prot,
int  tgt_flags,
int  tgt_fd,
typename OS::off_t  offset 
)

Target mmap() handler.

Maintain the symbol table for dynamic executables. The loader will call mmap to map the images into its address space and we intercept that here. We can verify that we are executing inside the loader by checking the program counter value. XXX: with multiprogrammed workloads or multi-node configurations, this will not work since there is a single global symbol table.

Not TGT_MAP_FIXED means we can start wherever we want.

If the application provides us with a hint, we should make some small amount of effort to accomodate it. Basically, we check if every single VA within the requested range is unused. If it is, we give the application the range. If not, we fall back to extending the global mmap region.

Extend global mmap region to give us some room for the app.

We only allow mappings to overwrite existing mappings if TGT_MAP_FIXED is set. Otherwise it shouldn't be a problem because we ignore the start hint if TGT_MAP_FIXED is not set.

We might already have some old VMAs mapped to this region, so make sure to clear em out!

Figure out a human-readable name for the mapping.

Setup the correct VMA for this region. The physical pages will be mapped lazily.

Definition at line 1629 of file syscall_emul.hh.

References Loader::createObjectFile(), Loader::debugSymbolTable, DPRINTF_SYSCALL, System::getPageBytes(), ThreadContext::getProcessPtr(), ThreadContext::getSystemPtr(), Loader::SymbolTable::insert(), length, EmulatedDriver::mmap(), ArmISA::offset, MipsISA::p, ThreadContext::pcState(), X86ISA::prot, roundUp(), and warn_once.

◆ mremapFunc()

template<class OS >
SyscallReturn mremapFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  start,
uint64_t  old_length,
uint64_t  new_length,
uint64_t  flags,
GuestABI::VarArgs< uint64_t >  varargs 
)

◆ munmapFunc()

SyscallReturn munmapFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  start,
size_t  length 
)

◆ openatFunc()

template<class OS >
SyscallReturn openatFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_dirfd,
Addr  pathname,
int  tgt_flags,
int  mode 
)

Target open() handler.

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

We make several attempts resolve a call to open.

1) Resolve any path redirection before hand. This will set the path up with variable 'redir_path' which may contain a modified path or the original path value. This should already be done in prior code. 2) Try to handle the access using 'special_paths'. Some special_paths and files cannot be called on the host and need to be handled as special cases inside the simulator. These special_paths are handled by C++ routines to provide output back to userspace. 3) 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. Again, the openImpl tries to USE_THE_HOST_FILESYSTEM_OPEN (with a possible redirection to the faux-filesystem files). The faux-filesystem is dynamically created during simulator configuration using Python functions. 4) If the host cannot open the file, the open attempt failed in "3)". Return the host's error code back through the system call to the simulated process. If running a debug trace, also notify the user that the open call failed.

Any success will set sim_fd to something other than -1 and skip the next conditions effectively bypassing them.

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 751 of file syscall_emul.hh.

References DPRINTF_SYSCALL, ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), ArmISA::i, ArmISA::mode, SyscallDesc::name(), EmulatedDriver::open(), MipsISA::p, startswith(), PortProxy::tryReadString(), and warn.

◆ openFunc()

template<class OS >
SyscallReturn openFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
int  tgt_flags,
int  mode 
)

Target open() handler.

Definition at line 900 of file syscall_emul.hh.

References ArmISA::mode.

◆ pipe2Func()

SyscallReturn pipe2Func ( SyscallDesc desc,
ThreadContext tc,
Addr  tgt_addr,
int  flags 
)

Target pipe() handler.

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

On some architectures, it's possible to use more than one register for a return value. In those cases, pipe returns its values rather than write them into a buffer.

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

Definition at line 802 of file syscall_emul.cc.

References BufferArg::bufferPtr(), BaseBufferArg::copyOut(), ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), and MipsISA::p.

Referenced by pipeFunc(), and pipePseudoFunc().

◆ pipeFunc()

SyscallReturn pipeFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  tgt_addr 
)

Target pipe() handler.

Definition at line 796 of file syscall_emul.cc.

References pipe2Func().

◆ pipePseudoFunc()

SyscallReturn pipePseudoFunc ( SyscallDesc desc,
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 790 of file syscall_emul.cc.

References pipe2Func().

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ pollFunc()

template<class OS >
SyscallReturn pollFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  fdsPtr,
int  nfds,
int  tmout 
)

Record the target file descriptors in a local variable. We need to replace them with host file descriptors but we need a temporary copy for later. Afterwards, replace each target file descriptor in the poll_fd array with its host_fd.

We cannot allow an infinite poll to occur or it will inevitably cause a deadlock in the gem5 simulator with clone. We must pass in tmout with a non-negative value, however it also makes no sense to poll on the underlying host for any other time than tmout a zero timeout.

If blocking indefinitely, check the signal list to see if a signal would break the poll out of the retry cycle and try to return the signal interrupt instead.

Replace each host_fd in the returned poll_fd array with its original target file descriptor.

Copy out the pollfd struct because the host may have updated fields in the structure.

Definition at line 999 of file syscall_emul.hh.

References BufferArg::bufferPtr(), BaseBufferArg::copyIn(), BaseBufferArg::copyOut(), ArmISA::fd, ThreadContext::getProcessPtr(), ThreadContext::getSystemPtr(), ThreadContext::getVirtProxy(), MipsISA::index, MipsISA::p, SyscallReturn::retry(), System::signalList, and ArmISA::status.

◆ pread64Func()

template<class OS >
SyscallReturn pread64Func ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  bufPtr,
int  nbytes,
int  offset 
)

◆ prlimitFunc()

template<class OS >
SyscallReturn prlimitFunc ( SyscallDesc desc,
ThreadContext tc,
int  pid,
int  resource,
Addr  n,
VPtr< typename OS::rlimit >  rlp 
)

Definition at line 1860 of file syscall_emul.hh.

References PowerISA::bo, ArmISA::byteOrder(), htog(), ArmISA::n, and warn.

◆ pwrite64Func()

template<class OS >
SyscallReturn pwrite64Func ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  bufPtr,
int  nbytes,
int  offset 
)

◆ readFunc()

template<class OS >
SyscallReturn readFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  buf_ptr,
int  nbytes 
)

◆ readlinkatFunc()

template<class OS >
SyscallReturn readlinkatFunc ( SyscallDesc desc,
ThreadContext tc,
int  dirfd,
Addr  pathname,
Addr  buf,
size_t  bufsiz 
)

Target readlinkat() handler.

Definition at line 932 of file syscall_emul.hh.

References readlinkFunc(), and warn.

◆ readlinkFunc()

SyscallReturn readlinkFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
Addr  buf,
size_t  bufsiz 
)

◆ readvFunc()

template<class OS >
SyscallReturn readvFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
uint64_t  tiov_base,
size_t  count 
)

◆ recvfromFunc()

SyscallReturn recvfromFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  bufrPtr,
size_t  bufrLen,
int  flags,
Addr  addrPtr,
Addr  addrlenPtr 
)

◆ recvmsgFunc()

SyscallReturn recvmsgFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  msgPtr,
int  flags 
)

struct msghdr { void *msg_name; // optional address socklen_t msg_namelen; // size of address struct iovec *msg_iov; // iovec array size_t msg_iovlen; // number entries in msg_iov i // entries correspond to buffer void *msg_control; // ancillary data size_t msg_controllen; // ancillary data buffer len int msg_flags; // flags on received message };

struct iovec { void *iov_base; // starting address size_t iov_len; // number of bytes to transfer };

The plan with this system call is to replace all of the pointers in the structure and the substructure with BufferArg class pointers. We will copy every field from the structures into our BufferArg classes.

We will use these address place holders to retain the pointers which we are going to replace with our own buffers in our simulator address space.

Record msg_name pointer then replace with buffer pointer.

Record msg_iov pointer then replace with buffer pointer. Also, setup an array of buffer pointers for the iovec structs record and replace their pointers with buffer pointers.

Record msg_control pointer then replace with buffer pointer.

Definition at line 1312 of file syscall_emul.cc.

References BufferArg::bufferPtr(), BaseBufferArg::copyIn(), BaseBufferArg::copyOut(), ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), ArmISA::i, and MipsISA::p.

◆ renameatFunc()

template<class OS >
SyscallReturn renameatFunc ( SyscallDesc desc,
ThreadContext tc,
int  olddirfd,
Addr  oldpath,
int  newdirfd,
Addr  newpath 
)

Target renameat() handler.

Definition at line 943 of file syscall_emul.hh.

References renameFunc(), and warn.

◆ renameFunc()

SyscallReturn renameFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  oldpath,
Addr  newpath 
)

◆ rmdirFunc()

SyscallReturn rmdirFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname 
)

◆ selectFunc()

template<class OS >
SyscallReturn selectFunc ( SyscallDesc desc,
ThreadContext tc,
int  nfds,
VPtr< typename OS::fd_set >  readfds,
VPtr< typename OS::fd_set >  writefds,
VPtr< typename OS::fd_set >  errorfds,
VPtr< typename OS::timeval >  timeout 
)

Host fields. Notice that these use the definitions from the system headers instead of the gem5 headers and libraries. If the host and target have different header file definitions, this will not work.

We need to translate the target file descriptor set into a host file descriptor set. This involves both our internal process fd array and the fd_set defined in Linux header files. The nfds field also needs to be updated as it will be only target specific after retrieving it from the target; the nfds value is expected to be the highest file descriptor that needs to be checked, so we need to extend it out for nfds_h when we do the update.

By this point, we know that we are looking at a valid file descriptor set on the target. We need to check if the target file descriptor value passed in as iter is part of the set.

We know that the target file descriptor belongs to the set, but we do not yet know if the file descriptor is valid or that we have a host mapping. Check that now.

Add the sim_fd to tgt_fd translation into trans_map for use later when we need to zero the target fd_set structures and then update them with hits returned from the host select call.

We know that the host file descriptor exists so now we check if we need to update the max count for nfds_h before passing the duplicated structure into the host.

Add the host file descriptor to the set that we are going to pass into the host.

It might be possible to decrement the timeval based on some derivation of wall clock determined from elapsed simulator ticks but that seems like overkill. Rather, we just set the timeval with zero timeout. (There is no reason to block during the simulation as it only decreases simulator performance.)

If the timeval pointer is null, setup a new timeval structure to pass into the host select call. Unfortunately, we will need to manually check the return value and throw a retry fault if the return value is zero. Allowing the system call to block will likely deadlock the event queue.

If blocking indefinitely, check the signal list to see if a signal would break the poll out of the retry cycle and try to return the signal interrupt instead.

We need to translate the host file descriptor set into a target file descriptor set. This involves both our internal process fd array and the fd_set defined in header files.

Definition at line 2222 of file syscall_emul.hh.

References ThreadContext::getProcessPtr(), ThreadContext::getSystemPtr(), ArmISA::i, MipsISA::p, SyscallReturn::retry(), and System::signalList.

◆ sendmsgFunc()

SyscallReturn sendmsgFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  msgPtr,
int  flags 
)

Reserve buffer space.

Assuming msgHdr.msg_iovlen >= 1, then there is no point calling recvmsg without a buffer.

Cannot instantiate buffers till inside the loop. Create array to hold buffer addresses, to be used during copyIn of send data.

Iterate through the iovec structures: Get the base buffer addreses, reserve iov_len amount of space for each. Put the buf address into the bufferArray for later retrieval.

Free dynamically allocated memory.

Malloced above.

Definition at line 1450 of file syscall_emul.cc.

References BufferArg::bufferPtr(), BaseBufferArg::copyIn(), ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), and MipsISA::p.

◆ sendtoFunc()

SyscallReturn sendtoFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  bufrPtr,
size_t  bufrLen,
int  flags,
Addr  addrPtr,
socklen_t  addrLen 
)

◆ setpgidFunc()

SyscallReturn setpgidFunc ( SyscallDesc desc,
ThreadContext tc,
int  pid,
int  pgid 
)

◆ setsockoptFunc()

SyscallReturn setsockoptFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
int  level,
int  optname,
Addr  valPtr,
socklen_t  len 
)

◆ setTidAddressFunc()

SyscallReturn setTidAddressFunc ( SyscallDesc desc,
ThreadContext tc,
uint64_t  tidPtr 
)

Target set_tid_address() handler.

Definition at line 271 of file syscall_emul.cc.

References Process::childClearTID, and ThreadContext::getProcessPtr().

Referenced by SyscallTable32::SyscallTable32(), and SyscallTable64::SyscallTable64().

◆ shutdownFunc()

SyscallReturn shutdownFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
int  how 
)

Target shutdown() handler.

Definition at line 1148 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), and MipsISA::p.

◆ socketFunc()

template<class OS >
SyscallReturn socketFunc ( SyscallDesc desc,
ThreadContext tc,
int  domain,
int  type,
int  prot 
)

◆ socketpairFunc()

template<class OS >
SyscallReturn socketpairFunc ( SyscallDesc desc,
ThreadContext tc,
int  domain,
int  type,
int  prot,
Addr  svPtr 
)

◆ stat64Func()

template<class OS >
SyscallReturn stat64Func ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
VPtr< typename OS::tgt_stat64 >  tgt_stat 
)

◆ statfsFunc()

template<class OS >
SyscallReturn statfsFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
VPtr< typename OS::tgt_statfs >  tgt_stat 
)

◆ statFunc()

template<class OS >
SyscallReturn statFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
VPtr< typename OS::tgt_stat >  tgt_stat 
)

◆ symlinkFunc()

SyscallReturn symlinkFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
Addr  new_pathname 
)

Target symlink() handler.

Definition at line 488 of file syscall_emul.cc.

References ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), and MipsISA::p.

◆ sysinfoFunc()

template<class OS >
SyscallReturn sysinfoFunc ( SyscallDesc desc,
ThreadContext tc,
VPtr< typename OS::tgt_sysinfo >  sysinfo 
)

Target sysinfo() handler.

Definition at line 958 of file syscall_emul.hh.

References ThreadContext::getProcessPtr(), and seconds_since_epoch.

◆ tgkillFunc()

template<class OS >
SyscallReturn tgkillFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgid,
int  tid,
int  sig 
)

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 2138 of file syscall_emul.hh.

References exitGroupFunc(), ThreadContext::getProcessPtr(), ThreadContext::getSystemPtr(), Process::pid(), Process::tgid(), and System::threads.

◆ timeFunc()

template<class OS >
SyscallReturn timeFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  taddr 
)

◆ timesFunc()

template<class OS >
SyscallReturn timesFunc ( SyscallDesc desc,
ThreadContext tc,
VPtr< typename OS::tms >  bufp 
)

Target times() function.

Definition at line 2102 of file syscall_emul.hh.

References ArmISA::byteOrder(), curTick(), htog(), and SimClock::Int::s.

◆ truncate64Func()

SyscallReturn truncate64Func ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
int64_t  length 
)

◆ truncateFunc()

SyscallReturn truncateFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
off_t  length 
)

◆ umaskFunc()

SyscallReturn umaskFunc ( SyscallDesc desc,
ThreadContext tc 
)

Target umask() handler.

Definition at line 614 of file syscall_emul.cc.

Referenced by SyscallTable32::SyscallTable32().

◆ unimplementedFunc()

SyscallReturn unimplementedFunc ( SyscallDesc desc,
ThreadContext tc 
)

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

Definition at line 66 of file syscall_emul.cc.

References fatal, SyscallDesc::name(), and SyscallDesc::num().

◆ unlinkatFunc()

template<class OS >
SyscallReturn unlinkatFunc ( SyscallDesc desc,
ThreadContext tc,
int  dirfd,
Addr  pathname 
)

Target unlinkat() handler.

Definition at line 910 of file syscall_emul.hh.

References unlinkFunc(), and warn.

◆ unlinkFunc()

SyscallReturn unlinkFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname 
)

◆ utimesFunc()

template<class OS >
SyscallReturn utimesFunc ( SyscallDesc desc,
ThreadContext tc,
Addr  pathname,
VPtr< typename OS::timeval[2]>  tp 
)

◆ wait4Func()

template<class OS >
SyscallReturn wait4Func ( SyscallDesc desc,
ThreadContext tc,
pid_t  pid,
Addr  statPtr,
int  options,
Addr  rusagePtr 
)

Currently, wait4 is only implemented so that it will wait for children exit conditions which are denoted by a SIGCHLD signals posted into the system signal list. We return no additional information via any of the parameters supplied to wait4. If nothing is found in the system signal list, we will wait indefinitely for SIGCHLD to post by retrying the call.

Definition at line 2456 of file syscall_emul.hh.

References BufferArg::bufferPtr(), BaseBufferArg::copyOut(), DPRINTF_SYSCALL, ThreadContext::getProcessPtr(), ThreadContext::getSystemPtr(), ThreadContext::getVirtProxy(), MipsISA::p, SyscallReturn::retry(), and System::signalList.

◆ warnUnsupportedOS()

void warnUnsupportedOS ( std::string  syscall_name)

Definition at line 60 of file syscall_emul.cc.

References warn.

Referenced by eventfdFunc(), fallocateFunc(), and statfsFunc().

◆ writeFunc()

template<class OS >
SyscallReturn writeFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
Addr  buf_ptr,
int  nbytes 
)

We don't want to poll on /dev/random. The kernel will not enable the file descriptor for writing unless the entropy in the system falls below write_wakeup_threshold. This is not guaranteed to happen depending on host settings.

Definition at line 2417 of file syscall_emul.hh.

References BufferArg::bufferPtr(), BaseBufferArg::copyIn(), ThreadContext::getProcessPtr(), ThreadContext::getVirtProxy(), MipsISA::p, and SyscallReturn::retry().

◆ writevFunc()

template<class OS >
SyscallReturn writevFunc ( SyscallDesc desc,
ThreadContext tc,
int  tgt_fd,
uint64_t  tiov_base,
size_t  count 
)

Variable Documentation

◆ seconds_since_epoch

const unsigned seconds_since_epoch = 1000 * 1000 * 1000

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 511 of file syscall_emul.hh.

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


Generated on Wed Sep 30 2020 14:02:19 for gem5 by doxygen 1.8.17