45 #ifndef __SIM_SYSCALL_EMUL_HH__
46 #define __SIM_SYSCALL_EMUL_HH__
48 #if (defined(__APPLE__) || defined(__OpenBSD__) || \
49 defined(__FreeBSD__) || defined(__CYGWIN__) || \
56 #if (defined(__APPLE__) || defined(__OpenBSD__) || \
57 defined(__FreeBSD__) || defined(__NetBSD__))
63 #if (defined(__APPLE__) || defined(__OpenBSD__) || \
64 defined(__FreeBSD__) || defined(__NetBSD__))
65 #define NO_FALLOCATE 1
67 #define NO_FALLOCATE 0
77 #include <sys/fcntl.h>
84 #include <sys/statfs.h>
86 #include <sys/mount.h>
96 #include "arch/utility.hh"
102 #include "config/the_isa.hh"
106 #include "params/Process.hh"
331 op &= ~OS::TGT_FUTEX_PRIVATE_FLAG;
335 if (OS::TGT_FUTEX_WAIT ==
op) {
347 return -OS::TGT_EWOULDBLOCK;
349 futex_map.suspend(uaddr, process->
tgid(), tc);
352 }
else if (OS::TGT_FUTEX_WAKE ==
op) {
353 return futex_map.wakeup(uaddr, process->
tgid(),
val);
356 warn(
"futex: op %d not implemented; ignoring.",
op);
391 template <
class T1,
class T2>
402 template <
class T1,
class T2>
431 template <
typename target_stat,
typename host_stat>
435 using namespace TheISA;
440 tgt->st_dev = host->st_dev;
442 tgt->st_ino = host->st_ino;
444 tgt->st_mode = host->st_mode;
447 tgt->st_mode &= ~S_IFMT;
448 tgt->st_mode |= S_IFCHR;
451 tgt->st_nlink = host->st_nlink;
453 tgt->st_uid = host->st_uid;
455 tgt->st_gid = host->st_gid;
458 tgt->st_rdev = 0x880d;
460 tgt->st_rdev = host->st_rdev;
462 tgt->st_size = host->st_size;
464 tgt->st_atimeX = host->st_atime;
466 tgt->st_mtimeX = host->st_mtime;
468 tgt->st_ctimeX = host->st_ctime;
472 tgt->st_blksize = 0x2000;
474 tgt->st_blocks = host->st_blocks;
480 template <
typename target_stat,
typename host_stat64>
484 using namespace TheISA;
486 convertStatBuf<target_stat, host_stat64>(tgt, host, fakeTTY);
487 #if defined(STAT_HAVE_NSEC)
488 tgt->st_atime_nsec = host->st_atime_nsec;
490 tgt->st_mtime_nsec = host->st_mtime_nsec;
492 tgt->st_ctime_nsec = host->st_ctime_nsec;
495 tgt->st_atime_nsec = 0;
496 tgt->st_mtime_nsec = 0;
497 tgt->st_ctime_nsec = 0;
505 hst_stat *host,
bool fakeTTY =
false)
508 tgt_stat_buf tgt(addr);
509 convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host, fakeTTY);
519 tgt_stat_buf tgt(addr);
520 convertStat64Buf<tgt_stat_buf, hst_stat64>(tgt, host, fakeTTY);
532 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
542 memcpy(&tgt->f_fsid, &host->f_fsid,
sizeof(host->f_fsid));
543 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
546 #elif defined(__APPLE__)
553 #if defined(__linux__)
554 memcpy(&tgt->f_spare, &host->f_spare,
sizeof(host->f_spare));
560 memset(&tgt->f_spare, 0,
sizeof(tgt->f_spare));
578 DPRINTF(SyscallVerbose,
"ioctl(%d, 0x%x, ...)\n", tgt_fd, req);
580 if (OS::isTtyReq(req))
594 return emul_driver->
ioctl(p, tc, req);
600 warn(
"Unsupported ioctl call (return ENOTTY): ioctl(%d, 0x%x, ...) @ \n",
629 int host_flags = O_BINARY;
638 for (
int i = 0;
i < OS::NUM_OPEN_FLAGS;
i++) {
639 if (tgt_flags & OS::openFlagTable[
i].tgtFlag) {
640 tgt_flags &= ~OS::openFlagTable[
i].tgtFlag;
641 host_flags |= OS::openFlagTable[
i].hostFlag;
645 warn(
"open%s: cannot decode flags 0x%x",
646 isopenat ?
"at" :
"", tgt_flags);
649 host_flags |= O_BINARY;
666 if (!isopenat || (isopenat && tgt_dirfd == OS::TGT_AT_FDCWD)) {
669 std::shared_ptr<FDEntry> fdep = ((*p->
fds)[tgt_dirfd]);
670 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>(fdep);
673 path.insert(0, ffdp->getFileName());
683 std::string filename = path.substr(strlen(
"/dev/"));
687 "driver open with path[%s]\n",
688 isopenat ?
"at" :
"", path.c_str());
689 return drv->
open(p, tc, mode, host_flags);
708 {
"/proc/",
"/system/",
"/sys/",
"/platform/",
"/etc/passwd" };
709 for (
auto entry : special_paths) {
711 sim_fd = OS::openSpecialFile(path, p, tc);
714 sim_fd = open(path.c_str(), host_flags,
mode);
719 isopenat ?
"at" :
"", path.c_str());
731 auto ffdp = std::make_shared<FileFDEntry>(sim_fd, host_flags, path, 0);
732 int tgt_fd = p->
fds->allocFD(ffdp);
733 DPRINTF_SYSCALL(Verbose,
"open%s: sim_fd[%d], target_fd[%d] -> path:%s\n",
734 isopenat ?
"at" :
"", sim_fd, tgt_fd, path.c_str());
744 return openImpl<OS>(desc, callnum, process, tc,
false);
753 return openImpl<OS>(desc, callnum, process, tc,
true);
764 if (dirfd != OS::TGT_AT_FDCWD)
765 warn(
"unlinkat: first argument not AT_FDCWD; unlikely to work");
778 if (dirfd != OS::TGT_AT_FDCWD)
779 warn(
"faccessat: first argument not AT_FDCWD; unlikely to work");
780 return accessFunc(desc, callnum, process, tc, 1);
791 if (dirfd != OS::TGT_AT_FDCWD)
792 warn(
"openat: first argument not AT_FDCWD; unlikely to work");
805 if (olddirfd != OS::TGT_AT_FDCWD)
806 warn(
"renameat: first argument not AT_FDCWD; unlikely to work");
808 std::string old_name;
815 if (newdirfd != OS::TGT_AT_FDCWD)
816 warn(
"renameat: third argument not AT_FDCWD; unlikely to work");
818 std::string new_name;
825 old_name = process->
fullPath(old_name);
826 new_name = process->
fullPath(new_name);
828 int result = rename(old_name.c_str(), new_name.c_str());
829 return (result == -1) ? -errno : result;
845 sysinfo->mem_unit = 1;
876 int result = chmod(path.c_str(), hostMode);
893 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>((*p->
fds)[tgt_fd]);
896 int sim_fd = ffdp->getSimFD();
898 mode_t hostMode =
mode;
900 int result = fchmod(sim_fd, hostMode);
902 return (result < 0) ? -errno : 0;
915 uint64_t provided_address = 0;
916 bool use_provided_address = flags & OS::TGT_MREMAP_FIXED;
918 if (use_provided_address)
923 warn(
"mremap failing: arguments not page aligned");
929 if (new_length > old_length) {
930 std::shared_ptr<MemState> mem_state = process->
memState;
931 Addr mmap_end = mem_state->getMmapEnd();
933 if ((start + old_length) == mmap_end &&
934 (!use_provided_address || provided_address == start)) {
935 uint64_t diff = new_length - old_length;
937 mem_state->setMmapEnd(mmap_end + diff);
940 if (!use_provided_address && !(flags & OS::TGT_MREMAP_MAYMOVE)) {
941 warn(
"can't remap here and MREMAP_MAYMOVE flag not set\n");
944 uint64_t new_start = use_provided_address ?
945 provided_address : mmap_end;
946 process->
pTable->
remap(start, old_length, new_start);
947 warn(
"mremapping to new vaddr %08p-%08p, adding %d\n",
948 new_start, new_start + new_length,
949 new_length - old_length);
952 new_length - old_length,
953 use_provided_address );
954 if (!use_provided_address)
955 mem_state->setMmapEnd(mmap_end + new_length);
956 if (use_provided_address &&
957 new_start + new_length > mem_state->getMmapEnd()) {
960 warn(
"mmap region limit exceeded with MREMAP_FIXED\n");
962 warn(
"returning %08p as start\n", new_start);
967 if (use_provided_address && provided_address != start)
968 process->
pTable->
remap(start, new_length, provided_address);
969 process->
pTable->
unmap(start + new_length, old_length - new_length);
970 return use_provided_address ? provided_address : start;
993 int result = stat(path.c_str(), &hostBuf);
998 copyOutStatBuf<OS>(tc->
getMemProxy(), bufPtr, &hostBuf);
1022 struct stat hostBuf;
1023 int result = stat(path.c_str(), &hostBuf);
1025 struct stat64 hostBuf;
1026 int result = stat64(path.c_str(), &hostBuf);
1032 copyOutStat64Buf<OS>(tc->
getMemProxy(), bufPtr, &hostBuf);
1046 if (dirfd != OS::TGT_AT_FDCWD)
1047 warn(
"fstatat64: first argument not AT_FDCWD; unlikely to work");
1059 struct stat hostBuf;
1060 int result = stat(path.c_str(), &hostBuf);
1062 struct stat64 hostBuf;
1063 int result = stat64(path.c_str(), &hostBuf);
1069 copyOutStat64Buf<OS>(tc->
getMemProxy(), bufPtr, &hostBuf);
1084 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>((*p->
fds)[tgt_fd]);
1087 int sim_fd = ffdp->getSimFD();
1090 struct stat hostBuf;
1091 int result = fstat(sim_fd, &hostBuf);
1093 struct stat64 hostBuf;
1094 int result = fstat64(sim_fd, &hostBuf);
1100 copyOutStat64Buf<OS>(tc->
getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1124 struct stat hostBuf;
1125 int result = lstat(path.c_str(), &hostBuf);
1130 copyOutStatBuf<OS>(tc->
getMemProxy(), bufPtr, &hostBuf);
1154 struct stat hostBuf;
1155 int result = lstat(path.c_str(), &hostBuf);
1157 struct stat64 hostBuf;
1158 int result = lstat64(path.c_str(), &hostBuf);
1164 copyOutStat64Buf<OS>(tc->
getMemProxy(), bufPtr, &hostBuf);
1180 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>((*p->
fds)[tgt_fd]);
1183 int sim_fd = ffdp->getSimFD();
1185 struct stat hostBuf;
1186 int result = fstat(sim_fd, &hostBuf);
1191 copyOutStatBuf<OS>(tc->
getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1204 warn(
"Host OS cannot support calls to statfs. Ignoring syscall");
1218 struct statfs hostBuf;
1219 int result = statfs(path.c_str(), &hostBuf);
1224 copyOutStatfsBuf<OS>(tc->
getMemProxy(), bufPtr, &hostBuf);
1240 if (((flags & OS::TGT_CLONE_SIGHAND)&& !(flags & OS::TGT_CLONE_VM)) ||
1241 ((flags & OS::TGT_CLONE_THREAD) && !(flags & OS::TGT_CLONE_SIGHAND)) ||
1242 ((flags & OS::TGT_CLONE_FS) && (flags & OS::TGT_CLONE_NEWNS)) ||
1243 ((flags & OS::TGT_CLONE_NEWIPC) && (flags & OS::TGT_CLONE_SYSVSEM)) ||
1244 ((flags & OS::TGT_CLONE_NEWPID) && (flags & OS::TGT_CLONE_THREAD)) ||
1245 ((flags & OS::TGT_CLONE_VM) && !(newStack)))
1250 fatal(
"clone: no spare thread context in system");
1258 ProcessParams *pp =
new ProcessParams();
1259 pp->executable.assign(*(
new std::string(p->
progName())));
1260 pp->cmd.push_back(*(
new std::string(p->
progName())));
1262 pp->cwd.assign(p->
getcwd());
1263 pp->input.assign(
"stdin");
1264 pp->output.assign(
"stdout");
1265 pp->errout.assign(
"stderr");
1267 pp->euid = p->
euid();
1269 pp->egid = p->
egid();
1273 int temp_pid = *pids.begin();
1276 }
while (pids.find(temp_pid) != pids.end());
1278 fatal(
"temp_pid is too large: %d", temp_pid);
1281 pp->ppid = (flags & OS::TGT_CLONE_THREAD) ? p->
ppid() : p->
pid();
1290 if (flags & OS::TGT_CLONE_PARENT_SETTID) {
1291 BufferArg ptidBuf(ptidPtr,
sizeof(
long));
1292 long *ptid = (
long *)ptidBuf.
bufferPtr();
1298 p->
clone(tc, ctc, cp, flags);
1300 if (flags & OS::TGT_CLONE_THREAD) {
1303 }
else if (flags & OS::TGT_SIGCHLD) {
1307 if (flags & OS::TGT_CLONE_CHILD_SETTID) {
1308 BufferArg ctidBuf(ctidPtr,
sizeof(
long));
1309 long *ctid = (
long *)ctidBuf.
bufferPtr();
1314 if (flags & OS::TGT_CLONE_CHILD_CLEARTID)
1319 #if THE_ISA == ALPHA_ISA
1321 #elif THE_ISA == SPARC_ISA
1331 for (
int y = 8; y < 32; y++)
1333 #elif THE_ISA == ARM_ISA or THE_ISA == X86_ISA
1337 #if THE_ISA == X86_ISA
1338 if (flags & OS::TGT_CLONE_SETTLS) {
1349 #if THE_ISA == ALPHA_ISA
1351 #elif THE_ISA == SPARC_ISA
1371 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>((*p->
fds)[tgt_fd]);
1374 int sim_fd = ffdp->getSimFD();
1376 struct statfs hostBuf;
1377 int result = fstatfs(sim_fd, &hostBuf);
1382 copyOutStatfsBuf<OS>(tc->
getMemProxy(), bufPtr, &hostBuf);
1396 auto hbfdp = std::dynamic_pointer_cast<
HBFDEntry>((*p->
fds)[tgt_fd]);
1399 int sim_fd = hbfdp->getSimFD();
1404 struct iovec hiov[count];
1405 for (
size_t i = 0;
i <
count; ++
i) {
1406 typename OS::tgt_iovec tiov;
1408 prox.
readBlob(tiov_base +
i*
sizeof(
typename OS::tgt_iovec),
1409 (uint8_t*)&tiov,
sizeof(
typename OS::tgt_iovec));
1411 hiov[
i].iov_base =
new char [hiov[
i].iov_len];
1416 int result = writev(sim_fd, hiov, count);
1419 delete [] (
char *)hiov[
i].iov_base;
1446 (tgt_flags & OS::TGT_MAP_PRIVATE &&
1447 tgt_flags & OS::TGT_MAP_SHARED) ||
1448 (!(tgt_flags & OS::TGT_MAP_PRIVATE) &&
1449 !(tgt_flags & OS::TGT_MAP_SHARED)) ||
1454 if ((prot & PROT_WRITE) && (tgt_flags & OS::TGT_MAP_SHARED)) {
1475 warn(
"mmap: writing to shared mmap region is currently "
1476 "unsupported. The write succeeds on the target, but it "
1477 "will not be propagated to the host or shared mappings");
1483 uint8_t *pmap =
nullptr;
1484 if (!(tgt_flags & OS::TGT_MAP_ANONYMOUS)) {
1485 std::shared_ptr<FDEntry> fdep = (*p->
fds)[tgt_fd];
1490 return emul_driver->
mmap(p, tc, start, length, prot,
1491 tgt_flags, tgt_fd, offset);
1494 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>(fdep);
1499 pmap = (decltype(pmap))mmap(
nullptr, length, PROT_READ, MAP_PRIVATE,
1502 if (pmap == (decltype(pmap))-1) {
1503 warn(
"mmap: failed to map file into host address space");
1510 if (!(tgt_flags & OS::TGT_MAP_FIXED)) {
1511 std::shared_ptr<MemState> mem_state = p->
memState;
1512 Addr mmap_end = mem_state->getMmapEnd();
1517 mem_state->setMmapEnd(mmap_end);
1521 start, start + length - 1);
1526 int clobber = tgt_flags & OS::TGT_MAP_FIXED;
1543 if (tgt_flags & OS::TGT_MAP_ANONYMOUS) {
1558 struct stat file_stat;
1559 if (fstat(sim_fd, &file_stat) > 0)
1560 fatal(
"mmap: cannot stat file");
1566 uint64_t
size = std::min((uint64_t)file_stat.st_size - offset,
1571 munmap(pmap, length);
1586 if (pc >= text_start && pc < text_end) {
1587 std::shared_ptr<FDEntry> fdep = (*p->
fds)[tgt_fd];
1588 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>(fdep);
1593 lib->textBase(), start);
1616 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>((*p->
fds)[tgt_fd]);
1619 int sim_fd = ffdp->getSimFD();
1624 int bytes_written = pwrite(sim_fd, bufArg.
bufferPtr(), nbytes,
offset);
1626 return (bytes_written == -1) ? -errno : bytes_written;
1634 return mmapImpl<OS>(desc, num,
p, tc,
false);
1642 return mmapImpl<OS>(desc, num,
p, tc,
true);
1656 case OS::TGT_RLIMIT_STACK:
1658 rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
1663 case OS::TGT_RLIMIT_DATA:
1665 rlp->rlim_cur = rlp->rlim_max = 256 * 1024 * 1024;
1671 warn(
"getrlimit: unimplemented resource %d", resource);
1754 struct timeval hostTimeval[2];
1755 for (
int i = 0;
i < 2; ++
i) {
1763 int result = utimes(path.c_str(), hostTimeval);
1783 if (access(path.c_str(), F_OK) == -1)
1790 for (
int inc = 0; ; inc++) {
1797 vect.push_back(std::string());
1808 ProcessParams *pp =
new ProcessParams();
1809 pp->executable = path;
1811 read_in(pp->cmd, mem_proxy, argv_mem_loc);
1813 read_in(pp->env, mem_proxy, envp_mem_loc);
1815 pp->egid = p->
egid();
1816 pp->euid = p->
euid();
1818 pp->ppid = p->
ppid();
1820 pp->input.assign(
"cin");
1821 pp->output.assign(
"cout");
1822 pp->errout.assign(
"cerr");
1823 pp->cwd.assign(p->
getcwd());
1834 Process *new_p = pp->create();
1842 for (
int i = 0;
i < new_p->
fds->getSize();
i++) {
1843 std::shared_ptr<FDEntry> fdep = (*new_p->
fds)[
i];
1844 if (fdep && fdep->getCOE())
1845 new_p->
fds->closeFDEntry(
i);
1857 tc->
setNPC(pcState.instAddr());
1873 rup->ru_utime.tv_sec = 0;
1874 rup->ru_utime.tv_usec = 0;
1875 rup->ru_stime.tv_sec = 0;
1876 rup->ru_stime.tv_usec = 0;
1884 rup->ru_inblock = 0;
1885 rup->ru_oublock = 0;
1888 rup->ru_nsignals = 0;
1893 case OS::TGT_RUSAGE_SELF:
1895 rup->ru_utime.tv_sec =
TheISA::htog(rup->ru_utime.tv_sec);
1896 rup->ru_utime.tv_usec =
TheISA::htog(rup->ru_utime.tv_usec);
1899 case OS::TGT_RUSAGE_CHILDREN:
1906 warn(
"getrusage() only supports RUSAGE_SELF. Parameter %d ignored.",
1926 bufp->tms_utime = clocks;
1927 bufp->tms_stime = 0;
1928 bufp->tms_cutime = 0;
1929 bufp->tms_cstime = 0;
1946 typename OS::time_t sec, usec;
1953 typename OS::time_t
t = sec;
1956 p.
writeBlob(taddr, (uint8_t*)&t, (
int)
sizeof(
typename OS::time_t));
1989 if (temp->
pid() == tid) {
1995 if (sig != 0 || sig != OS::TGT_SIGABRT)
1998 if (tgt_proc ==
nullptr)
2001 if (tgid != -1 && tgt_proc->
tgid() != tgid)
2004 if (sig == OS::TGT_SIGABRT)
2011 #endif // __SIM_SYSCALL_EMUL_HH__
SyscallReturn closeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target close() handler.
SyscallReturn setpgidFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target setpgid() handler.
SyscallReturn accessFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target access() handler.
This file defines buffer classes used to handle pointer arguments in emulated syscalls.
SyscallReturn _llseekFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target _llseek() handler.
SyscallReturn writevFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
Target writev() handler.
SyscallReturn mmapFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target mmap() handler.
SyscallReturn clock_getresFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target clock_getres() function.
virtual System * getSystemPtr()=0
SyscallReturn gettidFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target gettid() handler.
SyscallReturn getgidPseudoFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target getgidPseudo() handler.
SyscallReturn getuidFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target getuid() handler.
void revokeThreadContext(int context_id)
After delegating a thread context to a child process no longer should relate to the ThreadContext...
virtual void unmap(Addr vaddr, int64_t size)=0
uint64_t childClearTID
Calls a futex wakeup at the address specified by this pointer when this process exits.
SyscallReturn openImpl(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc, bool isopenat)
const int one_million
A readable name for 1,000,000, for converting microseconds to seconds.
SyscallReturn renameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target rename() handler.
SyscallReturn getrlimitFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target getrlimit() handler.
SyscallReturn gettimeofdayFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target gettimeofday() handler.
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
virtual bool mmapGrowsDown() const
Does mmap region grow upward or downward from mmapEnd? Most platforms grow downward, but a few (such as Alpha) grow upward instead, so they can override this method to return false.
SyscallReturn truncateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target truncate() handler.
bool copyIn(SETranslatingPortProxy &memproxy)
copy data into simulator space (read from target memory)
SyscallReturn sysinfoFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target sysinfo() handler.
const int one_billion
A readable name for 1,000,000,000, for converting nanoseconds to seconds.
virtual void setMiscReg(int misc_reg, const MiscReg &val)=0
virtual Process * getProcessPtr()=0
virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i)=0
Holds file descriptors for host-backed files; host-backed files are files which were opened on the ph...
virtual void readBlob(Addr addr, uint8_t *p, int size) const
Read size bytes memory at address and store in p.
SymbolTable * debugSymbolTable
Global unified debugging symbol table (for target).
virtual void setIntReg(int reg_idx, uint64_t val)=0
ObjectFile * getInterpreter()
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
SyscallReturn unlinkatFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target unlinkat() handler.
virtual TheISA::PCState pcState()=0
void getElapsedTimeMicro(T1 &sec, T2 &usec)
Helper function to convert current elapsed time to seconds and microseconds.
T roundUp(const T &val, const U &align)
SyscallReturn pwrite64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
std::shared_ptr< MemState > memState
TypedBufferArg is a class template; instances of this template represent typed buffers in target user...
SyscallReturn mmapImpl(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, bool is_mmap2)
Real mmap handler.
SyscallReturn fstatFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
Target fstat() handler.
ThreadContext is the external interface to all thread state for anything outside of the CPU...
SyscallReturn cloneFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
#define DPRINTF_SYSCALL(FLAGEXT, FMT,...)
This macro is intended to help with readability.
SyscallReturn lstat64Func(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target lstat64() handler.
SyscallReturn timeFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target time() function.
virtual int ioctl(Process *p, ThreadContext *tc, unsigned req)=0
Abstract method, invoked when the user program calls ioctl() on the file descriptor returned by a pre...
SyscallReturn exitFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target exit() handler: terminate current context.
SyscallReturn getpidFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target getpid() handler.
SyscallReturn timesFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target times() function.
SyscallReturn execveFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
void copyOutStatfsBuf(SETranslatingPortProxy &mem, Addr addr, hst_statfs *host)
SyscallReturn ftruncate64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target ftruncate64() handler.
SyscallReturn ioctlFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
Target ioctl() handler.
bool copyOut(SETranslatingPortProxy &memproxy)
copy data out of simulator space (write to target memory)
SyscallReturn gethostnameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target gethostname() handler.
Tick curTick()
The current simulated tick.
virtual uint64_t readIntReg(int reg_idx)=0
SyscallReturn ftruncateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target ftruncate() handler.
SyscallReturn utimesFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target utimes() handler.
void assignThreadContext(ContextID context_id)
SyscallReturn faccessatFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target facessat() handler.
virtual void remap(Addr vaddr, int64_t size, Addr new_vaddr)=0
SyscallReturn chmodFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target chmod() handler.
bool tryReadString(std::string &str, Addr addr) const
SyscallReturn writeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target write() handler.
SyscallReturn clock_gettimeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target clock_gettime() function.
void copyOutStat64Buf(SETranslatingPortProxy &mem, Addr addr, hst_stat64 *host, bool fakeTTY=false)
virtual void setProcessPtr(Process *p)=0
SyscallReturn chownFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target chown() handler.
virtual int open(Process *p, ThreadContext *tc, int mode, int flags)=0
Abstract method, invoked when the user program calls open() on the device driver. ...
virtual TheISA::TLB * getDTBPtr()=0
std::set< int > PIDs
Process set to track which PIDs have already been allocated.
SyscallReturn mmap2Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target mmap2() handler.
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.
SyscallReturn mkdirFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target mkdir() handler.
const char * progName() const
SyscallReturn fcntl64Func(SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
Target fcntl64() handler.
virtual Addr nextInstAddr()=0
std::vector< ThreadContext * > threadContexts
ThreadContext * findFreeContext()
void copyMiscRegs(ThreadContext *src, ThreadContext *dest)
SyscallReturn getpagesizeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target getpagesize() handler.
Extends the base class to include a host-backed file descriptor field that records the integer used t...
SyscallReturn setuidFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target setuid() handler.
SyscallReturn readlinkatFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target readlinkat() handler.
SyscallReturn unlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
void * bufferPtr()
Return a pointer to the internal simulator-space buffer.
SyscallReturn umaskFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target umask() handler.
SyscallReturn getegidFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target getegid() handler.
const RegIndex StackPointerReg
const RegIndex SyscallPseudoReturnReg
SyscallReturn renameatFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target renameat() handler.
virtual SETranslatingPortProxy & getMemProxy()=0
SyscallReturn lseekFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target lseek() handler.
SyscallReturn fstatfsFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
Target fstatfs() handler.
virtual void activate()=0
Set the status to Active.
void getElapsedTimeNano(T1 &sec, T2 &nsec)
Helper function to convert current elapsed time to seconds and nanoseconds.
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
std::string getcwd() const
EmulatedDriver * findDriver(std::string filename)
Find an emulated device driver.
SyscallReturn dupFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
Target dup() handler.
SyscallReturn readFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
SyscallReturn getpidPseudoFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target getpidPseudo() handler.
SyscallReturn mremapFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target mremap() handler.
SyscallReturn tgkillFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
bool startswith(const char *s, const char *prefix)
Return true if 's' starts with the prefix string 'prefix'.
Ancillary State Registers.
SyscallReturn fstatat64Func(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target fstatat64() handler.
std::string fullPath(const std::string &filename)
SyscallReturn unlinkHelper(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, int index)
Target unlink() handler.
void convertStatBuf(target_stat &tgt, host_stat *host, bool fakeTTY=false)
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...
SyscallReturn unimplementedFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Handler for unimplemented syscalls that we haven't thought about.
This class provides the wrapper interface for the system call implementations which are defined in th...
static const int NumArgumentRegs M5_VAR_USED
Addr memSize() const
Amount of physical memory that exists.
SyscallReturn fchownFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target fchown() handler.
SyscallReturn statFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target stat() handler.
SyscallReturn fchmodFunc(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
Target fchmod() handler.
SyscallReturn getcwdFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target getcwd() handler.
Declarations of a non-full system Page Table.
SyscallReturn truncate64Func(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target truncate64() handler.
SyscallReturn openatFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target openat() handler.
SyscallReturn geteuidFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target geteuid() handler.
SyscallReturn pipeImpl(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, bool pseudoPipe)
Internal pipe() handler.
SyscallReturn stat64Func(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target stat64() handler.
SyscallReturn brkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target brk() handler: set brk address.
virtual bool loadAllSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=maxAddr)=0
ObjectFile * createObjectFile(const string &fname, bool raw)
SyscallReturn exitGroupFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target exit_group() handler: terminate simulation. (exit all threads)
GenericISA::SimplePCState< MachInst > PCState
SyscallReturn fcntlFunc(SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
Target fcntl() handler.
virtual int contextId() const =0
SyscallReturn pipeFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target pipe() handler.
SyscallReturn readlinkFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc, int index=0)
Target readlink() handler.
FutexMap class holds a map of all futexes used in the system.
SyscallReturn openFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target open() handler.
SyscallReturn getrusageFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target getrusage() function.
SyscallReturn munmapFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target munmap() handler.
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 regis...
void copyRegs(ThreadContext *src, ThreadContext *dest)
BufferArg represents an untyped buffer in target user space that is passed by reference to an (emulat...
virtual void clearArchRegs()=0
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
Do not set return registers according to executor return value.
SyscallReturn lstatFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target lstat() handler.
SyscallReturn dup2Func(SyscallDesc *desc, int num, Process *process, ThreadContext *tc)
Target dup2() handler.
void copyOutStatBuf(SETranslatingPortProxy &mem, Addr addr, hst_stat *host, bool fakeTTY=false)
Holds file descriptors needed to simulate devices opened with pseudo files (commonly with calls to io...
virtual void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value)=0
SyscallReturn getgidFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target getgid() handler.
SyscallReturn statfsFunc(SyscallDesc *desc, int callnum, Process *process, ThreadContext *tc)
Target statfs() handler.
SyscallReturn getuidPseudoFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target getuidPseudo() handler.
This class represents the return value from an emulated system call, including any errno setting...
void convertStat64Buf(target_stat &tgt, host_stat64 *host, bool fakeTTY=false)
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p, TheISA::IntReg flags)
virtual void setMiscRegNoEffect(int misc_reg, const MiscReg &val)=0
SyscallReturn getppidFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target getppid() handler.
const RegIndex SyscallSuccessReg
SyscallReturn fallocateFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
const unsigned seconds_since_epoch
Approximate seconds since the epoch (1/1/1970).
virtual Addr mmap(Process *p, ThreadContext *tc, Addr start, uint64_t length, int prot, int tgtFlags, int tgtFd, int offset)
Virtual method, invoked when the user program calls mmap() on the file descriptor returned by a previ...
virtual TheISA::TLB * getITBPtr()=0
SyscallReturn setTidAddressFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
Target set_tid_address() handler.
SyscallReturn fstat64Func(SyscallDesc *desc, int callnum, Process *p, ThreadContext *tc)
Target fstat64() handler.
virtual void writeBlob(Addr addr, const uint8_t *p, int size) const
Write size bytes from p to address.
std::shared_ptr< FDArray > fds