Go to the documentation of this file.
42 #ifndef __SIM_SYSCALL_EMUL_HH__
43 #define __SIM_SYSCALL_EMUL_HH__
45 #if (defined(__APPLE__) || defined(__OpenBSD__) || \
46 defined(__FreeBSD__) || defined(__CYGWIN__) || \
59 #if defined(__linux__)
60 #include <sys/eventfd.h>
61 #include <sys/statfs.h>
64 #include <sys/mount.h>
69 #include <sys/fcntl.h>
75 #include <sys/ioctl.h>
77 #include <sys/socket.h>
80 #include <sys/types.h>
89 #include "arch/utility.hh"
95 #include "config/the_isa.hh"
100 #include "params/Process.hh"
111 #if defined(__APPLE__) && defined(__MACH__) && !defined(CMSG_ALIGN)
112 #define CMSG_ALIGN(len) (((len) + sizeof(size_t) - 1) & ~(sizeof(size_t) - 1))
162 int tgt_fd, uint64_t offs,
int whence);
166 int tgt_fd, uint64_t offset_high,
167 uint32_t offset_low,
Addr result_ptr,
int whence);
175 int tgt_fd,
int how);
179 Addr buf_ptr,
int name_len);
183 Addr buf_ptr,
unsigned long size);
187 Addr pathname,
Addr buf,
size_t bufsiz);
206 Addr pathname, mode_t
mode, dev_t dev);
226 int tgt_fd, off_t
length);
235 int tgt_fd, int64_t
length);
245 Addr pathname, uint32_t owner, uint32_t group);
256 int tgt_fd, uint32_t owner, uint32_t group);
264 int old_tgt_fd,
int new_tgt_fd);
272 int tgt_fd,
int cmd);
279 Addr tgt_addr,
int flags);
286 int tgt_fd,
Addr sockAddrPtr,
Addr addrlenPtr);
290 int tgt_fd,
Addr buf_ptr,
int addrlen);
294 int tgt_fd,
int backlog);
298 int tgt_fd,
Addr buf_ptr,
int addrlen);
300 #if defined(SYS_getdents)
303 int tgt_fd,
Addr buf_ptr,
unsigned count);
306 #if defined(SYS_getdents64)
309 int tgt_fd,
Addr buf_ptr,
unsigned count);
314 int tgt_fd,
Addr bufrPtr,
size_t bufrLen,
int flags,
315 Addr addrPtr, socklen_t addrLen);
319 int tgt_fd,
Addr bufrPtr,
size_t bufrLen,
320 int flags,
Addr addrPtr,
Addr addrlenPtr);
324 int tgt_fd,
Addr msgPtr,
int flags);
328 int tgt_fd,
Addr msgPtr,
int flags);
351 int tgt_fd,
int level,
int optname,
356 int tgt_fd,
int level,
int optname,
365 int tgt_fd,
Addr addrPtr,
Addr lenPtr);
373 Addr uaddr,
int op,
int val,
int timeout,
Addr uaddr2,
int val3)
383 op &= ~OS::TGT_FUTEX_PRIVATE_FLAG;
384 op &= ~OS::TGT_FUTEX_CLOCK_REALTIME_FLAG;
388 if (OS::TGT_FUTEX_WAIT ==
op || OS::TGT_FUTEX_WAIT_BITSET ==
op) {
400 return -OS::TGT_EWOULDBLOCK;
402 if (OS::TGT_FUTEX_WAIT ==
op) {
403 futex_map.
suspend(uaddr, process->tgid(), tc);
409 }
else if (OS::TGT_FUTEX_WAKE ==
op) {
410 return futex_map.
wakeup(uaddr, process->tgid(),
val);
411 }
else if (OS::TGT_FUTEX_WAKE_BITSET ==
op) {
412 return futex_map.
wakeup_bitset(uaddr, process->tgid(), val3);
413 }
else if (OS::TGT_FUTEX_REQUEUE ==
op ||
414 OS::TGT_FUTEX_CMP_REQUEUE ==
op) {
424 if (OS::TGT_FUTEX_CMP_REQUEUE && val3 != mem_val)
425 return -OS::TGT_EWOULDBLOCK;
426 return futex_map.
requeue(uaddr, process->tgid(),
val, timeout, uaddr2);
427 }
else if (OS::TGT_FUTEX_WAKE_OP ==
op) {
455 int wake_cmparg = val3 & 0xfff;
456 int wake_oparg = (val3 & 0xfff000) >> 12;
457 int wake_cmp = (val3 & 0xf000000) >> 24;
458 int wake_op = (val3 & 0xf0000000) >> 28;
459 if ((wake_op & OS::TGT_FUTEX_OP_ARG_SHIFT) >> 3 == 1)
460 wake_oparg = (1 << wake_oparg);
461 wake_op &= ~OS::TGT_FUTEX_OP_ARG_SHIFT;
463 if (wake_op == OS::TGT_FUTEX_OP_SET)
465 else if (wake_op == OS::TGT_FUTEX_OP_ADD)
466 newval += wake_oparg;
467 else if (wake_op == OS::TGT_FUTEX_OP_OR)
468 newval |= wake_oparg;
469 else if (wake_op == OS::TGT_FUTEX_OP_ANDN)
470 newval &= ~wake_oparg;
471 else if (wake_op == OS::TGT_FUTEX_OP_XOR)
472 newval ^= wake_oparg;
477 int woken1 = futex_map.
wakeup(uaddr, process->tgid(),
val);
480 bool is_wake2 =
false;
481 if (wake_cmp == OS::TGT_FUTEX_OP_CMP_EQ)
482 is_wake2 = oldval == wake_cmparg;
483 else if (wake_cmp == OS::TGT_FUTEX_OP_CMP_NE)
484 is_wake2 = oldval != wake_cmparg;
485 else if (wake_cmp == OS::TGT_FUTEX_OP_CMP_LT)
486 is_wake2 = oldval < wake_cmparg;
487 else if (wake_cmp == OS::TGT_FUTEX_OP_CMP_LE)
488 is_wake2 = oldval <= wake_cmparg;
489 else if (wake_cmp == OS::TGT_FUTEX_OP_CMP_GT)
490 is_wake2 = oldval > wake_cmparg;
491 else if (wake_cmp == OS::TGT_FUTEX_OP_CMP_GE)
492 is_wake2 = oldval >= wake_cmparg;
495 woken2 = futex_map.
wakeup(uaddr2, process->tgid(), timeout);
497 return woken1 + woken2;
499 warn(
"futex: op %d not implemented; ignoring.",
op);
515 template <
class T1,
class T2>
519 static const int OneMillion = 1000 * 1000;
522 sec = elapsed_usecs / OneMillion;
523 usec = elapsed_usecs % OneMillion;
528 template <
class T1,
class T2>
532 static const int OneBillion = 1000 * 1000 * 1000;
535 sec = elapsed_nsecs / OneBillion;
536 nsec = elapsed_nsecs % OneBillion;
559 template <
typename OS,
typename TgtStatPtr,
typename HostStatPtr>
568 tgt->st_dev = host->st_dev;
569 tgt->st_dev =
htog(tgt->st_dev,
bo);
570 tgt->st_ino = host->st_ino;
571 tgt->st_ino =
htog(tgt->st_ino,
bo);
572 tgt->st_mode = host->st_mode;
575 tgt->st_mode &= ~S_IFMT;
576 tgt->st_mode |= S_IFCHR;
578 tgt->st_mode =
htog(tgt->st_mode,
bo);
579 tgt->st_nlink = host->st_nlink;
580 tgt->st_nlink =
htog(tgt->st_nlink,
bo);
581 tgt->st_uid = host->st_uid;
582 tgt->st_uid =
htog(tgt->st_uid,
bo);
583 tgt->st_gid = host->st_gid;
584 tgt->st_gid =
htog(tgt->st_gid,
bo);
586 tgt->st_rdev = 0x880d;
588 tgt->st_rdev = host->st_rdev;
589 tgt->st_rdev =
htog(tgt->st_rdev,
bo);
590 tgt->st_size = host->st_size;
591 tgt->st_size =
htog(tgt->st_size,
bo);
592 tgt->st_atimeX = host->st_atime;
593 tgt->st_atimeX =
htog(tgt->st_atimeX,
bo);
594 tgt->st_mtimeX = host->st_mtime;
595 tgt->st_mtimeX =
htog(tgt->st_mtimeX,
bo);
596 tgt->st_ctimeX = host->st_ctime;
597 tgt->st_ctimeX =
htog(tgt->st_ctimeX,
bo);
600 tgt->st_blksize = 0x2000;
601 tgt->st_blksize =
htog(tgt->st_blksize,
bo);
602 tgt->st_blocks = host->st_blocks;
603 tgt->st_blocks =
htog(tgt->st_blocks,
bo);
608 template <
typename OS,
typename TgtStatPtr,
typename HostStatPtr>
613 copyOutStatBuf<OS>(tgt, host, fakeTTY);
614 #if defined(STAT_HAVE_NSEC)
617 tgt->st_atime_nsec = host->st_atime_nsec;
618 tgt->st_atime_nsec =
htog(tgt->st_atime_nsec,
bo);
619 tgt->st_mtime_nsec = host->st_mtime_nsec;
620 tgt->st_mtime_nsec =
htog(tgt->st_mtime_nsec,
bo);
621 tgt->st_ctime_nsec = host->st_ctime_nsec;
622 tgt->st_ctime_nsec =
htog(tgt->st_ctime_nsec,
bo);
624 tgt->st_atime_nsec = 0;
625 tgt->st_mtime_nsec = 0;
626 tgt->st_ctime_nsec = 0;
630 template <
class OS,
typename TgtStatPtr,
typename HostStatPtr>
636 tgt->f_type =
htog(host->f_type,
bo);
637 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
638 tgt->f_bsize =
htog(host->f_iosize,
bo);
640 tgt->f_bsize =
htog(host->f_bsize,
bo);
642 tgt->f_blocks =
htog(host->f_blocks,
bo);
643 tgt->f_bfree =
htog(host->f_bfree,
bo);
644 tgt->f_bavail =
htog(host->f_bavail,
bo);
645 tgt->f_files =
htog(host->f_files,
bo);
646 tgt->f_ffree =
htog(host->f_ffree,
bo);
647 memcpy(&tgt->f_fsid, &host->f_fsid,
sizeof(host->f_fsid));
648 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
649 tgt->f_namelen =
htog(host->f_namemax,
bo);
650 tgt->f_frsize =
htog(host->f_bsize,
bo);
651 #elif defined(__APPLE__)
655 tgt->f_namelen =
htog(host->f_namelen,
bo);
656 tgt->f_frsize =
htog(host->f_frsize,
bo);
658 #if defined(__linux__)
659 memcpy(&tgt->f_spare, &host->f_spare,
660 std::min(
sizeof(host->f_spare),
sizeof(tgt->f_spare)));
666 memset(&tgt->f_spare, 0,
sizeof(tgt->f_spare));
677 int tgt_fd,
unsigned req,
Addr addr)
683 if (OS::isTtyReq(req))
686 auto dfdp = std::dynamic_pointer_cast<DeviceFDEntry>((*
p->fds)[tgt_fd]);
690 return emul_driver->
ioctl(tc, req,
addr);
693 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*
p->fds)[tgt_fd]);
702 ifconf *conf = (ifconf*)conf_arg.
bufferPtr();
703 Addr ifc_buf_addr = (
Addr)conf->ifc_buf;
704 BufferArg ifc_buf_arg(ifc_buf_addr, conf->ifc_len);
707 conf->ifc_buf = (
char*)ifc_buf_arg.bufferPtr();
711 conf->ifc_buf = (
char*)ifc_buf_addr;
719 #if defined(__linux__)
724 #if defined(__linux__)
743 warn(
"Unsupported ioctl call (return ENOTTY): ioctl(%d, 0x%x, ...) @ \n",
752 int tgt_dirfd,
Addr pathname,
int tgt_flags,
int mode)
765 int host_flags = O_BINARY;
773 for (
int i = 0;
i < OS::NUM_OPEN_FLAGS;
i++) {
774 if (tgt_flags & OS::openFlagTable[
i].tgtFlag) {
775 tgt_flags &= ~OS::openFlagTable[
i].tgtFlag;
776 host_flags |= OS::openFlagTable[
i].hostFlag;
780 warn(
"%s: cannot decode flags %#x", desc->
name(), tgt_flags);
783 host_flags |= O_BINARY;
798 std::string redir_path = path;
799 std::string abs_path = path;
800 if (tgt_dirfd == OS::TGT_AT_FDCWD) {
801 abs_path =
p->absolutePath(path,
true);
802 redir_path =
p->checkPathRedirect(path);
804 std::shared_ptr<FDEntry> fdep = ((*
p->fds)[tgt_dirfd]);
805 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>(fdep);
808 abs_path = ffdp->getFileName() + path;
809 redir_path =
p->checkPathRedirect(abs_path);
819 std::string filename = abs_path.substr(strlen(
"/dev/"));
823 "driver open with path[%s]\n",
824 desc->
name(), abs_path.c_str());
825 return drv->
open(tc,
mode, host_flags);
858 std::string used_path;
860 {
"/proc/meminfo/",
"/system/",
"/platform/",
"/etc/passwd",
861 "/proc/self/maps",
"/dev/urandom",
862 "/sys/devices/system/cpu/online" };
863 for (
auto entry : special_paths) {
865 sim_fd = OS::openSpecialFile(abs_path,
p, tc);
866 used_path = abs_path;
870 sim_fd = open(redir_path.c_str(), host_flags,
mode);
871 used_path = redir_path;
876 "(inferred from:%s)\n", desc->
name(),
877 used_path.c_str(), path.c_str());
889 auto ffdp = std::make_shared<FileFDEntry>(sim_fd, host_flags, path, 0);
890 int tgt_fd =
p->fds->allocFD(ffdp);
892 "(inferred from:%s)\n", desc->
name(),
893 sim_fd, tgt_fd, used_path.c_str(), path.c_str());
901 Addr pathname,
int tgt_flags,
int mode)
903 return openatFunc<OS>(
904 desc, tc, OS::TGT_AT_FDCWD, pathname, tgt_flags,
mode);
912 if (dirfd != OS::TGT_AT_FDCWD)
913 warn(
"unlinkat: first argument not AT_FDCWD; unlikely to work");
924 if (dirfd != OS::TGT_AT_FDCWD)
925 warn(
"faccessat: first argument not AT_FDCWD; unlikely to work");
933 int dirfd,
Addr pathname,
Addr buf,
size_t bufsiz)
935 if (dirfd != OS::TGT_AT_FDCWD)
936 warn(
"openat: first argument not AT_FDCWD; unlikely to work");
944 int olddirfd,
Addr oldpath,
int newdirfd,
Addr newpath)
946 if (olddirfd != OS::TGT_AT_FDCWD)
947 warn(
"renameat: first argument not AT_FDCWD; unlikely to work");
949 if (newdirfd != OS::TGT_AT_FDCWD)
950 warn(
"renameat: third argument not AT_FDCWD; unlikely to work");
952 return renameFunc(desc, tc, oldpath, newpath);
964 sysinfo->totalram = process->system->memSize();
965 sysinfo->mem_unit = 1;
987 path = process->checkPathRedirect(path);
990 int result = chmod(path.c_str(), hostMode);
1000 Addr fdsPtr,
int nfds,
int tmout)
1004 BufferArg fdsBuf(fdsPtr,
sizeof(
struct pollfd) * nfds);
1013 int temp_tgt_fds[nfds];
1016 auto tgt_fd = temp_tgt_fds[
index];
1017 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*
p->fds)[tgt_fd]);
1020 auto host_fd = hbfdp->getSimFD();
1042 if (it->receiver ==
p)
1057 auto tgt_fd = temp_tgt_fds[
index];
1077 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*
p->fds)[tgt_fd]);
1080 int sim_fd = ffdp->getSimFD();
1082 mode_t hostMode =
mode;
1084 int result = fchmod(sim_fd, hostMode);
1086 return (result < 0) ? -errno : 0;
1093 Addr start, uint64_t old_length, uint64_t new_length, uint64_t flags,
1098 uint64_t provided_address = 0;
1099 bool use_provided_address = flags & OS::TGT_MREMAP_FIXED;
1101 if (use_provided_address)
1102 provided_address = varargs.
get<uint64_t>();
1104 if ((start % page_bytes != 0) ||
1105 (provided_address % page_bytes != 0)) {
1106 warn(
"mremap failing: arguments not page aligned");
1110 new_length =
roundUp(new_length, page_bytes);
1112 if (new_length > old_length) {
1113 Addr mmap_end =
p->memState->getMmapEnd();
1115 if ((start + old_length) == mmap_end &&
1116 (!use_provided_address || provided_address == start)) {
1119 uint64_t diff = new_length - old_length;
1120 p->memState->mapRegion(mmap_end, diff,
"remapped");
1121 p->memState->setMmapEnd(mmap_end + diff);
1124 if (!use_provided_address && !(flags & OS::TGT_MREMAP_MAYMOVE)) {
1125 warn(
"can't remap here and MREMAP_MAYMOVE flag not set\n");
1128 uint64_t new_start = provided_address;
1129 if (!use_provided_address) {
1130 new_start =
p->mmapGrowsDown() ?
1131 mmap_end - new_length : mmap_end;
1132 mmap_end =
p->mmapGrowsDown() ?
1133 new_start : mmap_end + new_length;
1134 p->memState->setMmapEnd(mmap_end);
1137 warn(
"mremapping to new vaddr %08p-%08p, adding %d\n",
1138 new_start, new_start + new_length,
1139 new_length - old_length);
1142 p->allocateMem(new_start + old_length,
1143 new_length - old_length,
1144 use_provided_address );
1146 if (use_provided_address &&
1147 ((new_start + new_length >
p->memState->getMmapEnd() &&
1148 !
p->mmapGrowsDown()) ||
1149 (new_start < p->memState->getMmapEnd() &&
1150 p->mmapGrowsDown()))) {
1153 warn(
"mmap region limit exceeded with MREMAP_FIXED\n");
1156 warn(
"returning %08p as start\n", new_start);
1157 p->memState->remapRegion(start, new_start, old_length);
1163 if (use_provided_address && provided_address != start)
1164 p->memState->remapRegion(start, provided_address, new_length);
1165 if (new_length != old_length)
1166 p->memState->unmapRegion(start + new_length,
1167 old_length - new_length);
1168 return use_provided_address ? provided_address : start;
1187 struct stat hostBuf;
1188 int result = stat(path.c_str(), &hostBuf);
1193 copyOutStatBuf<OS>(tgt_stat, &hostBuf);
1215 struct stat hostBuf;
1216 int result = stat(path.c_str(), &hostBuf);
1218 struct stat64 hostBuf;
1219 int result = stat64(path.c_str(), &hostBuf);
1225 copyOutStat64Buf<OS>(tgt_stat, &hostBuf);
1238 if (dirfd != OS::TGT_AT_FDCWD)
1239 warn(
"fstatat64: first argument not AT_FDCWD; unlikely to work");
1246 path = process->checkPathRedirect(path);
1249 struct stat hostBuf;
1250 int result = stat(path.c_str(), &hostBuf);
1252 struct stat64 hostBuf;
1253 int result = stat64(path.c_str(), &hostBuf);
1259 copyOutStat64Buf<OS>(tgt_stat, &hostBuf);
1273 auto ffdp = std::dynamic_pointer_cast<HBFDEntry>((*
p->fds)[tgt_fd]);
1276 int sim_fd = ffdp->getSimFD();
1279 struct stat hostBuf;
1280 int result = fstat(sim_fd, &hostBuf);
1282 struct stat64 hostBuf;
1283 int result = fstat64(sim_fd, &hostBuf);
1289 copyOutStat64Buf<OS>(tgt_stat, &hostBuf, (sim_fd == 1));
1310 struct stat hostBuf;
1311 int result = lstat(path.c_str(), &hostBuf);
1316 copyOutStatBuf<OS>(tgt_stat, &hostBuf);
1337 struct stat hostBuf;
1338 int result = lstat(path.c_str(), &hostBuf);
1340 struct stat64 hostBuf;
1341 int result = lstat64(path.c_str(), &hostBuf);
1347 copyOutStat64Buf<OS>(tgt_stat, &hostBuf);
1362 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*
p->fds)[tgt_fd]);
1365 int sim_fd = ffdp->getSimFD();
1367 struct stat hostBuf;
1368 int result = fstat(sim_fd, &hostBuf);
1373 copyOutStatBuf<OS>(tgt_stat, &hostBuf, (sim_fd == 1));
1384 #if defined(__linux__)
1394 struct statfs hostBuf;
1395 int result = statfs(path.c_str(), &hostBuf);
1400 copyOutStatfsBuf<OS>(tgt_stat, &hostBuf);
1415 if (((flags & OS::TGT_CLONE_SIGHAND)&& !(flags & OS::TGT_CLONE_VM)) ||
1416 ((flags & OS::TGT_CLONE_THREAD) && !(flags & OS::TGT_CLONE_SIGHAND)) ||
1417 ((flags & OS::TGT_CLONE_FS) && (flags & OS::TGT_CLONE_NEWNS)) ||
1418 ((flags & OS::TGT_CLONE_NEWIPC) && (flags & OS::TGT_CLONE_SYSVSEM)) ||
1419 ((flags & OS::TGT_CLONE_NEWPID) && (flags & OS::TGT_CLONE_THREAD)) ||
1420 ((flags & OS::TGT_CLONE_VM) && !(newStack)))
1436 ProcessParams *pp =
new ProcessParams();
1437 pp->executable.assign(*(
new std::string(
p->progName())));
1438 pp->cmd.push_back(*(
new std::string(
p->progName())));
1439 pp->system =
p->system;
1440 pp->cwd.assign(
p->tgtCwd);
1441 pp->input.assign(
"stdin");
1442 pp->output.assign(
"stdout");
1443 pp->errout.assign(
"stderr");
1445 pp->euid =
p->euid();
1447 pp->egid =
p->egid();
1450 std::set<int>
const& pids =
p->system->PIDs;
1451 int temp_pid = *pids.begin();
1454 }
while (pids.find(temp_pid) != pids.end());
1456 fatal(
"temp_pid is too large: %d", temp_pid);
1459 pp->ppid = (flags & OS::TGT_CLONE_THREAD) ?
p->ppid() :
p->pid();
1460 pp->useArchPT =
p->useArchPT;
1461 pp->kvmInSE =
p->kvmInSE;
1472 if (flags & OS::TGT_CLONE_PARENT_SETTID) {
1473 BufferArg ptidBuf(ptidPtr,
sizeof(
long));
1474 long *ptid = (
long *)ptidBuf.
bufferPtr();
1479 if (flags & OS::TGT_CLONE_THREAD) {
1480 cp->pTable->shared =
true;
1481 cp->useForClone =
true;
1484 p->clone(tc, ctc,
cp, flags);
1486 if (flags & OS::TGT_CLONE_THREAD) {
1488 cp->sigchld =
p->sigchld;
1489 }
else if (flags & OS::TGT_SIGCHLD) {
1490 *
cp->sigchld =
true;
1493 if (flags & OS::TGT_CLONE_CHILD_SETTID) {
1494 BufferArg ctidBuf(ctidPtr,
sizeof(
long));
1495 long *ctid = (
long *)ctidBuf.
bufferPtr();
1500 if (flags & OS::TGT_CLONE_CHILD_CLEARTID)
1501 cp->childClearTID = (uint64_t)ctidPtr;
1505 OS::archClone(flags,
p,
cp, tc, ctc, newStack, tlsPtr);
1509 #if THE_ISA == SPARC_ISA
1528 return cloneFunc<OS>(desc, tc, flags, newStack, ptidPtr, ctidPtr, tlsPtr);
1539 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*
p->fds)[tgt_fd]);
1542 int sim_fd = ffdp->getSimFD();
1544 struct statfs hostBuf;
1545 int result = fstatfs(sim_fd, &hostBuf);
1550 copyOutStatfsBuf<OS>(tgt_stat, &hostBuf);
1559 int tgt_fd, uint64_t tiov_base,
size_t count)
1563 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*
p->fds)[tgt_fd]);
1566 int sim_fd = ffdp->getSimFD();
1569 typename OS::tgt_iovec tiov[
count];
1570 struct iovec hiov[
count];
1571 for (
size_t i = 0;
i <
count; ++
i) {
1572 prox.
readBlob(tiov_base + (
i *
sizeof(
typename OS::tgt_iovec)),
1573 &tiov[
i],
sizeof(
typename OS::tgt_iovec));
1575 hiov[
i].iov_base =
new char [hiov[
i].iov_len];
1578 int result = readv(sim_fd, hiov,
count);
1579 int local_errno = errno;
1581 for (
size_t i = 0;
i <
count; ++
i) {
1584 hiov[
i].iov_base, hiov[
i].iov_len);
1586 delete [] (
char *)hiov[
i].iov_base;
1589 return (result == -1) ? -local_errno : result;
1596 int tgt_fd, uint64_t tiov_base,
size_t count)
1600 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*
p->fds)[tgt_fd]);
1603 int sim_fd = hbfdp->getSimFD();
1606 struct iovec hiov[
count];
1607 for (
size_t i = 0;
i <
count; ++
i) {
1608 typename OS::tgt_iovec tiov;
1610 prox.
readBlob(tiov_base +
i*
sizeof(
typename OS::tgt_iovec),
1611 &tiov,
sizeof(
typename OS::tgt_iovec));
1613 hiov[
i].iov_base =
new char [hiov[
i].iov_len];
1618 int result = writev(sim_fd, hiov,
count);
1621 delete [] (
char *)hiov[
i].iov_base;
1623 return (result == -1) ? -errno : result;
1631 int tgt_flags,
int tgt_fd,
typename OS::off_t
offset)
1636 if (start & (page_bytes - 1) ||
1637 offset & (page_bytes - 1) ||
1638 (tgt_flags & OS::TGT_MAP_PRIVATE &&
1639 tgt_flags & OS::TGT_MAP_SHARED) ||
1640 (!(tgt_flags & OS::TGT_MAP_PRIVATE) &&
1641 !(tgt_flags & OS::TGT_MAP_SHARED)) ||
1646 if ((
prot & PROT_WRITE) && (tgt_flags & OS::TGT_MAP_SHARED)) {
1667 warn_once(
"mmap: writing to shared mmap region is currently "
1668 "unsupported. The write succeeds on the target, but it "
1669 "will not be propagated to the host or shared mappings");
1675 if (!(tgt_flags & OS::TGT_MAP_ANONYMOUS)) {
1676 std::shared_ptr<FDEntry> fdep = (*
p->fds)[tgt_fd];
1678 auto dfdp = std::dynamic_pointer_cast<DeviceFDEntry>(fdep);
1685 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>(fdep);
1688 sim_fd = ffdp->getSimFD();
1698 if (
p->interpImage.contains(tc->
pcState().instAddr())) {
1699 std::shared_ptr<FDEntry> fdep = (*
p->fds)[tgt_fd];
1700 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>(fdep);
1702 ffdp->getFileName()));
1704 ffdp->getFileName());
1707 Addr offset = lib->buildImage().minAddr() + start;
1716 if (!(tgt_flags & OS::TGT_MAP_FIXED)) {
1724 if (!(start &&
p->memState->isUnmapped(start,
length))) {
1728 start =
p->memState->extendMmap(
length);
1733 start, start +
length - 1);
1740 if (tgt_flags & OS::TGT_MAP_FIXED) {
1745 p->memState->unmapRegion(start,
length);
1751 std::string region_name;
1752 if (tgt_flags & OS::TGT_MAP_ANONYMOUS) {
1753 region_name =
"anon";
1755 std::shared_ptr<FDEntry> fdep = (*
p->fds)[tgt_fd];
1756 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>(fdep);
1757 region_name = ffdp->getFileName();
1764 p->memState->mapRegion(start,
length, region_name, sim_fd,
offset);
1772 int tgt_fd,
Addr bufPtr,
int nbytes,
int offset)
1776 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*
p->fds)[tgt_fd]);
1779 int sim_fd = ffdp->getSimFD();
1787 return (bytes_read == -1) ? -errno : bytes_read;
1793 int tgt_fd,
Addr bufPtr,
int nbytes,
int offset)
1797 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>((*
p->fds)[tgt_fd]);
1800 int sim_fd = ffdp->getSimFD();
1805 int bytes_written = pwrite(sim_fd, bufArg.
bufferPtr(), nbytes,
offset);
1807 return (bytes_written == -1) ? -errno : bytes_written;
1815 int tgt_flags,
int tgt_fd,
typename OS::off_t
offset)
1817 return mmapFunc<OS>(desc, tc, start,
length,
prot, tgt_flags,
1829 case OS::TGT_RLIMIT_STACK:
1831 rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
1832 rlp->rlim_cur =
htog(rlp->rlim_cur,
bo);
1833 rlp->rlim_max =
htog(rlp->rlim_max,
bo);
1836 case OS::TGT_RLIMIT_DATA:
1838 rlp->rlim_cur = rlp->rlim_max = 256 * 1024 * 1024;
1839 rlp->rlim_cur =
htog(rlp->rlim_cur,
bo);
1840 rlp->rlim_max =
htog(rlp->rlim_max,
bo);
1843 case OS::TGT_RLIMIT_NPROC:
1845 rlp->rlim_cur =
htog(rlp->rlim_cur,
bo);
1846 rlp->rlim_max =
htog(rlp->rlim_max,
bo);
1850 warn(
"getrlimit: unimplemented resource %d", resource);
1864 warn(
"prlimit: ignoring rlimits for nonzero pid");
1868 warn(
"prlimit: ignoring new rlimit");
1872 case OS::TGT_RLIMIT_STACK:
1874 rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
1875 rlp->rlim_cur =
htog(rlp->rlim_cur,
bo);
1876 rlp->rlim_max =
htog(rlp->rlim_max,
bo);
1878 case OS::TGT_RLIMIT_DATA:
1880 rlp->rlim_cur = rlp->rlim_max = 256*1024*1024;
1881 rlp->rlim_cur =
htog(rlp->rlim_cur,
bo);
1882 rlp->rlim_max =
htog(rlp->rlim_max,
bo);
1885 warn(
"prlimit: unimplemented resource %d", resource);
1939 VPtr<
typename OS::timeval [2]> tp)
1947 struct timeval hostTimeval[2];
1948 for (
int i = 0;
i < 2; ++
i) {
1954 path = process->checkPathRedirect(path);
1956 int result = utimes(path.c_str(), hostTimeval);
1976 if (access(path.c_str(), F_OK) == -1)
1982 for (
int inc = 0; ;
inc++) {
1984 b.copyIn(mem_proxy);
1986 if (!*(
Addr*)
b.bufferPtr())
1989 vect.push_back(std::string());
1990 mem_proxy.tryReadString(vect[
inc], *(
Addr*)
b.bufferPtr());
2000 ProcessParams *pp =
new ProcessParams();
2001 pp->executable = path;
2002 read_in(pp->cmd, mem_proxy, argv_mem_loc);
2003 read_in(pp->env, mem_proxy, envp_mem_loc);
2005 pp->egid =
p->egid();
2006 pp->euid =
p->euid();
2008 pp->ppid =
p->ppid();
2010 pp->input.assign(
"cin");
2011 pp->output.assign(
"cout");
2012 pp->errout.assign(
"cerr");
2013 pp->cwd.assign(
p->tgtCwd);
2014 pp->system =
p->system;
2023 p->system->PIDs.erase(
p->pid());
2024 Process *new_p = pp->create();
2031 new_p->
fds =
p->fds;
2032 for (
int i = 0;
i < new_p->
fds->getSize();
i++) {
2033 std::shared_ptr<FDEntry> fdep = (*new_p->
fds)[
i];
2034 if (fdep && fdep->getCOE())
2035 new_p->
fds->closeFDEntry(
i);
2047 tc->
setNPC(pcState.instAddr());
2059 rup->ru_utime.tv_sec = 0;
2060 rup->ru_utime.tv_usec = 0;
2061 rup->ru_stime.tv_sec = 0;
2062 rup->ru_stime.tv_usec = 0;
2070 rup->ru_inblock = 0;
2071 rup->ru_oublock = 0;
2074 rup->ru_nsignals = 0;
2079 case OS::TGT_RUSAGE_SELF:
2085 case OS::TGT_RUSAGE_CHILDREN:
2092 warn(
"getrusage() only supports RUSAGE_SELF. Parameter %d ignored.",
2106 bufp->tms_utime = clocks;
2107 bufp->tms_stime = 0;
2108 bufp->tms_cutime = 0;
2109 bufp->tms_cstime = 0;
2123 typename OS::time_t sec, usec;
2128 typename OS::time_t
t = sec;
2131 p.writeBlob(taddr, &
t, (
int)
sizeof(
typename OS::time_t));
2157 for (
auto *tc: sys->
threads) {
2159 if (temp->
pid() == tid) {
2165 if (sig != 0 || sig != OS::TGT_SIGABRT)
2168 if (tgt_proc ==
nullptr)
2171 if (tgid != -1 && tgt_proc->
tgid() != tgid)
2174 if (sig == OS::TGT_SIGABRT)
2191 auto sfdp = std::make_shared<SocketFDEntry>(sim_fd,
domain,
type,
prot);
2192 int tgt_fd =
p->fds->allocFD(sfdp);
2211 auto sfdp1 = std::make_shared<SocketFDEntry>(fds[0],
domain,
type,
prot);
2212 fds[0] =
p->fds->allocFD(sfdp1);
2213 auto sfdp2 = std::make_shared<SocketFDEntry>(fds[1],
domain,
type,
prot);
2214 fds[1] =
p->fds->allocFD(sfdp2);
2238 FD_ZERO(&readfds_h);
2240 FD_ZERO(&writefds_h);
2242 FD_ZERO(&errorfds_h);
2254 std::map<int, int> trans_map;
2255 auto try_add_host_set = [&](
typename OS::fd_set *tgt_set_entry,
2256 fd_set *hst_set_entry,
2264 if (FD_ISSET(iter, (fd_set *)tgt_set_entry)) {
2270 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*
p->fds)[iter]);
2273 auto sim_fd = hbfdp->getSimFD();
2280 trans_map[sim_fd] = iter;
2287 nfds_h = std::max(nfds_h - 1, sim_fd + 1);
2293 FD_SET(sim_fd, hst_set_entry);
2298 for (
int i = 0;
i < nfds;
i++) {
2300 bool ebadf = try_add_host_set(readfds, &readfds_h,
i);
2305 bool ebadf = try_add_host_set(writefds, &writefds_h,
i);
2310 bool ebadf = try_add_host_set(errorfds, &errorfds_h,
i);
2324 timeout->tv_sec = 0;
2325 timeout->tv_usec = 0;
2327 retval = select(nfds_h,
2328 readfds ? &readfds_h :
nullptr,
2329 writefds ? &writefds_h :
nullptr,
2330 errorfds ? &errorfds_h :
nullptr,
2331 (timeval *)(
typename OS::timeval *)timeout);
2340 struct timeval tv = { 0, 0 };
2342 retval = select(nfds_h,
2343 readfds ? &readfds_h :
nullptr,
2344 readfds ? &writefds_h :
nullptr,
2345 readfds ? &errorfds_h :
nullptr,
2355 if (sig.receiver ==
p)
2364 FD_ZERO(
reinterpret_cast<fd_set *
>((
typename OS::fd_set *)readfds));
2365 FD_ZERO(
reinterpret_cast<fd_set *
>((
typename OS::fd_set *)writefds));
2366 FD_ZERO(
reinterpret_cast<fd_set *
>((
typename OS::fd_set *)errorfds));
2373 for (
int i = 0;
i < nfds_h;
i++) {
2374 if (readfds && FD_ISSET(
i, &readfds_h))
2375 FD_SET(trans_map[
i], readfds);
2377 if (writefds && FD_ISSET(
i, &writefds_h))
2378 FD_SET(trans_map[
i], writefds);
2380 if (errorfds && FD_ISSET(
i, &errorfds_h))
2381 FD_SET(trans_map[
i], errorfds);
2390 int tgt_fd,
Addr buf_ptr,
int nbytes)
2394 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*
p->fds)[tgt_fd]);
2397 int sim_fd = hbfdp->getSimFD();
2401 pfd.events = POLLIN | POLLPRI;
2402 if ((poll(&pfd, 1, 0) == 0)
2403 && !(hbfdp->getFlags() & OS::TGT_O_NONBLOCK))
2407 int bytes_read = read(sim_fd, buf_arg.
bufferPtr(), nbytes);
2412 return (bytes_read == -1) ? -errno : bytes_read;
2418 int tgt_fd,
Addr buf_ptr,
int nbytes)
2422 auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*
p->fds)[tgt_fd]);
2425 int sim_fd = hbfdp->getSimFD();
2432 pfd.events = POLLOUT;
2440 auto ffdp = std::dynamic_pointer_cast<FileFDEntry>(hbfdp);
2441 if (ffdp && (ffdp->getFileName() !=
"/dev/random")) {
2442 if (!poll(&pfd, 1, 0) && !(ffdp->getFlags() & OS::TGT_O_NONBLOCK))
2446 int bytes_written = write(sim_fd, buf_arg.
bufferPtr(), nbytes);
2448 if (bytes_written != -1)
2451 return (bytes_written == -1) ? -errno : bytes_written;
2457 pid_t pid,
Addr statPtr,
int options,
Addr rusagePtr)
2462 DPRINTF_SYSCALL(Verbose,
"wait4: rusage pointer provided %lx, however "
2463 "functionality not supported. Ignoring rusage pointer.\n",
2477 if (iter->receiver ==
p) {
2479 if ((iter->sender->pgid() == -pid)
2480 && (iter->signalValue == OS::TGT_SIGCHLD))
2482 }
else if (pid == -1) {
2483 if (iter->signalValue == OS::TGT_SIGCHLD)
2485 }
else if (pid == 0) {
2486 if ((iter->sender->pgid() ==
p->pgid())
2487 && (iter->signalValue == OS::TGT_SIGCHLD))
2490 if ((iter->sender->pid() == pid)
2491 && (iter->signalValue == OS::TGT_SIGCHLD))
2501 const int EXITED = 0;
2502 BufferArg statusBuf(statPtr,
sizeof(
int));
2507 pid_t retval = iter->sender->pid();
2515 int tgt_fd,
Addr addrPtr,
Addr lenPtr)
2525 auto sfdp = std::dynamic_pointer_cast<SocketFDEntry>((*
p->fds)[tgt_fd]);
2528 int sim_fd = sfdp->getSimFD();
2538 pfd.events = POLLIN | POLLPRI;
2539 if ((poll(&pfd, 1, 0) == 0) && !(sfdp->getFlags() & OS::TGT_O_NONBLOCK))
2543 lenBufPtr =
new BufferArg(lenPtr,
sizeof(socklen_t));
2545 memcpy(&addrLen, (socklen_t *)lenBufPtr->
bufferPtr(),
2550 addrBufPtr =
new BufferArg(addrPtr,
sizeof(
struct sockaddr));
2552 memcpy(&
sa, (
struct sockaddr *)addrBufPtr->
bufferPtr(),
2553 sizeof(
struct sockaddr));
2556 host_fd = accept(sim_fd, &
sa, &addrLen);
2568 *(socklen_t *)lenBufPtr->
bufferPtr() = addrLen;
2573 auto afdp = std::make_shared<SocketFDEntry>(host_fd, sfdp->_domain,
2574 sfdp->_type, sfdp->_protocol);
2575 return p->fds->allocFD(afdp);
2582 unsigned initval,
int in_flags)
2584 #if defined(__linux__)
2587 int sim_fd = eventfd(initval, in_flags);
2591 bool cloexec = in_flags & OS::TGT_O_CLOEXEC;
2593 int flags = cloexec ? OS::TGT_O_CLOEXEC : 0;
2594 flags |= (in_flags & OS::TGT_O_NONBLOCK) ? OS::TGT_O_NONBLOCK : 0;
2596 auto hbfdp = std::make_shared<HBFDEntry>(flags, sim_fd, cloexec);
2597 int tgt_fd =
p->fds->allocFD(hbfdp);
2605 #endif // __SIM_SYSCALL_EMUL_HH__
std::list< BasicSignal > signalList
#define fatal(...)
This implements a cprintf based fatal() function.
void suspend(Addr addr, uint64_t tgid, ThreadContext *tc)
Inserts a futex into the map with one waiting TC.
SyscallReturn dup2Func(SyscallDesc *desc, ThreadContext *tc, int old_tgt_fd, int new_tgt_fd)
Target dup2() handler.
virtual int open(ThreadContext *tc, int mode, int flags)=0
Abstract method, invoked when the user program calls open() on the device driver.
SyscallReturn getrusageFunc(SyscallDesc *desc, ThreadContext *tc, int who, VPtr< typename OS::rusage > rup)
Target getrusage() function.
SyscallReturn fstatat64Func(SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname, VPtr< typename OS::tgt_stat64 > tgt_stat)
Target fstatat64() handler.
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.
SyscallReturn renameFunc(SyscallDesc *desc, ThreadContext *tc, Addr oldpath, Addr newpath)
Target rename() handler.
SyscallReturn ioctlFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, unsigned req, Addr addr)
Target ioctl() handler.
SyscallReturn tgkillFunc(SyscallDesc *desc, ThreadContext *tc, int tgid, int tid, int sig)
int wakeup(Addr addr, uint64_t tgid, int count)
Wakes up at most count waiting threads on a futex.
SyscallReturn gethostnameFunc(SyscallDesc *desc, ThreadContext *tc, Addr buf_ptr, int name_len)
Target gethostname() handler.
SyscallReturn readvFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint64_t tiov_base, size_t count)
Target readv() handler.
virtual void activate()=0
Set the status to Active.
SyscallReturn fstatfsFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, VPtr< typename OS::tgt_statfs > tgt_stat)
Target fstatfs() handler.
void warnUnsupportedOS(std::string syscall_name)
SyscallReturn lstat64Func(SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::tgt_stat64 > tgt_stat)
Target lstat64() handler.
ByteOrder byteOrder(const ThreadContext *tc)
std::shared_ptr< FDArray > fds
void assignThreadContext(ContextID context_id)
Addr getPageBytes() const
Get the page bytes for the ISA.
SyscallReturn pipe2Func(SyscallDesc *desc, ThreadContext *tc, Addr tgt_addr, int flags)
Target pipe() handler.
SyscallReturn cloneFunc(SyscallDesc *desc, ThreadContext *tc, RegVal flags, RegVal newStack, Addr ptidPtr, Addr ctidPtr, Addr tlsPtr)
SyscallReturn symlinkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr new_pathname)
Target symlink() handler.
void suspend_bitset(Addr addr, uint64_t tgid, ThreadContext *tc, int bitmask)
SyscallReturn truncateFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, off_t length)
Target truncate() handler.
SyscallReturn getpgrpFunc(SyscallDesc *desc, ThreadContext *tc)
Target getpgrpFunc() handler.
SyscallReturn ignoreFunc(SyscallDesc *desc, ThreadContext *tc)
Handler for unimplemented syscalls that we never intend to implement (signal handling,...
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
SyscallReturn chownFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, uint32_t owner, uint32_t group)
Target chown() handler.
SyscallReturn statfsFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::tgt_statfs > tgt_stat)
Target statfs() handler.
ObjectFile * createObjectFile(const std::string &fname, bool raw)
SyscallReturn recvfromFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufrPtr, size_t bufrLen, int flags, Addr addrPtr, Addr addrlenPtr)
SyscallReturn prlimitFunc(SyscallDesc *desc, ThreadContext *tc, int pid, int resource, Addr n, VPtr< typename OS::rlimit > rlp)
FutexMap class holds a map of all futexes used in the system.
SyscallReturn utimesFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::timeval[2]> tp)
Target utimes() handler.
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.
SyscallReturn munmapFunc(SyscallDesc *desc, ThreadContext *tc, Addr start, size_t length)
Target munmap() handler.
SyscallReturn brkFunc(SyscallDesc *desc, ThreadContext *tc, Addr new_brk)
Target brk() handler: set brk address.
virtual Process * getProcessPtr()=0
void copyOutStatBuf(TgtStatPtr tgt, HostStatPtr host, bool fakeTTY=false)
SyscallReturn gettimeofdayFunc(SyscallDesc *desc, ThreadContext *tc, VPtr< typename OS::timeval > tp, Addr tz_ptr)
Target gettimeofday() handler.
SyscallReturn setpgidFunc(SyscallDesc *desc, ThreadContext *tc, int pid, int pgid)
Target setpgid() handler.
SyscallReturn getsockoptFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int level, int optname, Addr valPtr, Addr lenPtr)
void copyOutStatfsBuf(TgtStatPtr tgt, HostStatPtr host)
SyscallReturn writeFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int nbytes)
SyscallReturn getppidFunc(SyscallDesc *desc, ThreadContext *tc)
Target getppid() handler.
SyscallReturn getsocknameFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr addrPtr, Addr lenPtr)
virtual int threadId() const =0
ThreadContext * findFree()
void inc(scfx_mant &mant)
SyscallReturn connectFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int addrlen)
SyscallReturn acceptFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr addrPtr, Addr lenPtr)
SyscallReturn fallocateFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int mode, off_t offset, off_t len)
SyscallReturn socketFunc(SyscallDesc *desc, ThreadContext *tc, int domain, int type, int prot)
SyscallReturn timesFunc(SyscallDesc *desc, ThreadContext *tc, VPtr< typename OS::tms > bufp)
Target times() function.
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
SyscallReturn execveFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr argv_mem_loc, Addr envp_mem_loc)
SyscallReturn openatFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_dirfd, Addr pathname, int tgt_flags, int mode)
Target open() handler.
const int SyscallPseudoReturnReg
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.
void revokeThreadContext(int context_id)
After delegating a thread context to a child process no longer should relate to the ThreadContext.
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
virtual void clearArchRegs()=0
void getElapsedTimeNano(T1 &sec, T2 &nsec)
Helper function to convert current elapsed time to seconds and nanoseconds.
SyscallReturn pollFunc(SyscallDesc *desc, ThreadContext *tc, Addr fdsPtr, int nfds, int tmout)
SyscallReturn ftruncateFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, off_t length)
Target ftruncate() handler.
SyscallReturn socketpairFunc(SyscallDesc *desc, ThreadContext *tc, int domain, int type, int prot, Addr svPtr)
ThreadContext is the external interface to all thread state for anything outside of the CPU.
SyscallReturn lstatFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::tgt_stat > tgt_stat)
Target lstat() handler.
SyscallReturn exitGroupFunc(SyscallDesc *desc, ThreadContext *tc, int status)
Target exit_group() handler: terminate simulation. (exit all threads)
std::string checkPathRedirect(const std::string &filename)
Redirect file path if it matches any keys initialized by system object.
SyscallReturn lseekFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint64_t offs, int whence)
Target lseek() handler.
SyscallReturn getegidFunc(SyscallDesc *desc, ThreadContext *tc)
Target getegid() handler.
#define DPRINTF_SYSCALL(FLAGEXT, FMT,...)
This macro is intended to help with readability.
SyscallReturn exitFunc(SyscallDesc *desc, ThreadContext *tc, int status)
Target exit() handler: terminate current context.
T htog(T value, ByteOrder guest_byte_order)
SyscallReturn listenFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int backlog)
SyscallReturn setTidAddressFunc(SyscallDesc *desc, ThreadContext *tc, uint64_t tidPtr)
Target set_tid_address() handler.
SyscallReturn setsockoptFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int level, int optname, Addr valPtr, socklen_t len)
SyscallReturn unlinkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname)
Target unlink() handler.
SyscallReturn unlinkatFunc(SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname)
Target unlinkat() handler.
SyscallReturn getpidFunc(SyscallDesc *desc, ThreadContext *tc)
Target getpid() handler.
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)
virtual int cpuId() const =0
SyscallReturn sysinfoFunc(SyscallDesc *desc, ThreadContext *tc, VPtr< typename OS::tgt_sysinfo > sysinfo)
Target sysinfo() handler.
SyscallReturn openFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, int tgt_flags, int mode)
Target open() handler.
virtual ContextID contextId() const =0
SyscallReturn clock_gettimeFunc(SyscallDesc *desc, ThreadContext *tc, int clk_id, VPtr< typename OS::timespec > tp)
Target clock_gettime() function.
SyscallReturn fchownFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint32_t owner, uint32_t group)
Target fchown() handler.
SyscallReturn bindFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int addrlen)
SyscallReturn getgidFunc(SyscallDesc *desc, ThreadContext *tc)
Target getgid() handler.
virtual Addr mmap(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...
SyscallReturn umaskFunc(SyscallDesc *desc, ThreadContext *tc)
Target umask() handler.
SyscallReturn rmdirFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname)
SyscallReturn ftruncate64Func(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int64_t length)
Target ftruncate64() handler.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
SyscallReturn statFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::tgt_stat > tgt_stat)
Target stat() handler.
This class represents the return value from an emulated system call, including any errno setting.
SyscallReturn eventfdFunc(SyscallDesc *desc, ThreadContext *tc, unsigned initval, int in_flags)
Target eventfd() function.
SyscallReturn clock_getresFunc(SyscallDesc *desc, ThreadContext *tc, int clk_id, VPtr< typename OS::timespec > tp)
Target clock_getres() function.
bool copyIn(PortProxy &memproxy)
copy data into simulator space (read from target memory)
SyscallReturn readlinkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr buf, size_t bufsiz)
Target readlink() handler.
void * bufferPtr()
Return a pointer to the internal simulator-space buffer.
SyscallReturn getrlimitFunc(SyscallDesc *desc, ThreadContext *tc, unsigned resource, VPtr< typename OS::rlimit > rlp)
Target getrlimit() handler.
virtual TheISA::PCState pcState() const =0
SyscallReturn pipePseudoFunc(SyscallDesc *desc, ThreadContext *tc)
Pseudo Funcs - These functions use a different return convension, returning a second value in a regis...
SyscallReturn mknodFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode, dev_t dev)
Target mknod() handler.
virtual PortProxy & getVirtProxy()=0
int requeue(Addr addr1, uint64_t tgid, int count, int count2, Addr addr2)
This operation wakes a given number (val) of waiters.
SyscallReturn readFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int nbytes)
void copyOutStat64Buf(TgtStatPtr tgt, HostStatPtr host, bool fakeTTY=false)
SyscallReturn pread64Func(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufPtr, int nbytes, int offset)
SyscallReturn chdirFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname)
Target chdir() handler.
SyscallReturn faccessatFunc(SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname, int mode)
Target facessat() handler.
SyscallReturn recvmsgFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr msgPtr, int flags)
This object is a proxy for a port or other object which implements the functional response protocol,...
SyscallReturn fcntlFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int cmd, GuestABI::VarArgs< int > varargs)
Target fcntl() handler.
virtual int ioctl(ThreadContext *tc, unsigned req, Addr buf)=0
Abstract method, invoked when the user program calls ioctl() on the file descriptor returned by a pre...
SyscallReturn getcwdFunc(SyscallDesc *desc, ThreadContext *tc, Addr buf_ptr, unsigned long size)
Target getcwd() handler.
SyscallReturn fstatFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, VPtr< typename OS::tgt_stat > tgt_stat)
Target fstat() handler.
Overload hash function for BasicBlockRange type.
SyscallReturn getcpuFunc(SyscallDesc *desc, ThreadContext *tc, VPtr< uint32_t > cpu, VPtr< uint32_t > node, VPtr< uint32_t > tcache)
GenericISA::DelaySlotPCState< MachInst > PCState
bool startswith(const char *s, const char *prefix)
Return true if 's' starts with the prefix string 'prefix'.
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.
SyscallReturn sendtoFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufrPtr, size_t bufrLen, int flags, Addr addrPtr, socklen_t addrLen)
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.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
SyscallReturn ignoreWarnOnceFunc(SyscallDesc *desc, ThreadContext *tc)
Like above, but only prints a warning once per syscall desc it's used with.
SyscallReturn truncate64Func(SyscallDesc *desc, ThreadContext *tc, Addr pathname, int64_t length)
Target truncate64() handler.
int wakeup_bitset(Addr addr, uint64_t tgid, int bitmask)
SyscallReturn pipeFunc(SyscallDesc *desc, ThreadContext *tc, Addr tgt_addr)
Target pipe() handler.
SyscallReturn getpagesizeFunc(SyscallDesc *desc, ThreadContext *tc)
Target getpagesize() handler.
virtual void returnInto(ThreadContext *tc, const SyscallReturn &ret)=0
For use within the system call executor if new threads are created and need something returned into t...
SyscallReturn readlinkatFunc(SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname, Addr buf, size_t bufsiz)
Target readlinkat() handler.
SyscallReturn geteuidFunc(SyscallDesc *desc, ThreadContext *tc)
Target geteuid() handler.
void getElapsedTimeMicro(T1 &sec, T2 &usec)
Helper function to convert current elapsed time to seconds and microseconds.
SyscallReturn writevFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint64_t tiov_base, size_t count)
Target writev() handler.
SyscallReturn chmodFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode)
Target chmod() handler.
SyscallReturn renameatFunc(SyscallDesc *desc, ThreadContext *tc, int olddirfd, Addr oldpath, int newdirfd, Addr newpath)
Target renameat() handler.
SyscallReturn getpeernameFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr sockAddrPtr, Addr addrlenPtr)
SyscallReturn gettidFunc(SyscallDesc *desc, ThreadContext *tc)
Target gettid() handler.
T gtoh(T value, ByteOrder guest_byte_order)
bool insert(const Symbol &symbol)
SyscallReturn getuidFunc(SyscallDesc *desc, ThreadContext *tc)
SyscallReturn fcntl64Func(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int cmd)
Target fcntl64() handler.
SyscallReturn fchmodFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint32_t mode)
Target fchmod() handler.
static SyscallReturn retry()
Pseudo-constructor to create an instance with the retry flag set.
SyscallReturn shutdownFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int how)
Target shutdown() handler.
BufferArg represents an untyped buffer in target user space that is passed by reference to an (emulat...
SyscallReturn closeFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd)
Target close() handler.
SyscallReturn fstat64Func(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, VPtr< typename OS::tgt_stat64 > tgt_stat)
Target fstat64() handler.
const unsigned seconds_since_epoch
Approximate seconds since the epoch (1/1/1970).
SyscallReturn cloneBackwardsFunc(SyscallDesc *desc, ThreadContext *tc, RegVal flags, RegVal newStack, Addr ptidPtr, Addr tlsPtr, Addr ctidPtr)
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
bool tryReadString(std::string &str, Addr addr) const
Reads the string at guest address addr into the std::string str.
SyscallReturn stat64Func(SyscallDesc *desc, ThreadContext *tc, Addr pathname, VPtr< typename OS::tgt_stat64 > tgt_stat)
Target stat64() handler.
SyscallReturn linkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr new_pathname)
Target link() handler.
SyscallReturn pwrite64Func(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufPtr, int nbytes, int offset)
SyscallReturn unimplementedFunc(SyscallDesc *desc, ThreadContext *tc)
Handler for unimplemented syscalls that we haven't thought about.
SyscallReturn sendmsgFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr msgPtr, int flags)
This class provides the wrapper interface for the system call implementations which are defined in th...
virtual void setProcessPtr(Process *p)=0
virtual System * getSystemPtr()=0
SyscallReturn mkdirFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode)
Target mkdir() handler.
bool copyOut(PortProxy &memproxy)
copy data out of simulator space (write to target memory)
SyscallReturn accessFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode)
Target access() handler.
SyscallReturn timeFunc(SyscallDesc *desc, ThreadContext *tc, Addr taddr)
Target time() function.
Tick curTick()
The current simulated tick.
SyscallReturn wait4Func(SyscallDesc *desc, ThreadContext *tc, pid_t pid, Addr statPtr, int options, Addr rusagePtr)
SyscallReturn dupFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd)
Target dup() handler.
Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17