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" 99 #include "params/Process.hh" 109 #if defined(__APPLE__) && defined(__MACH__) && !defined(CMSG_ALIGN) 110 #define CMSG_ALIGN(len) (((len) + sizeof(size_t) - 1) & ~(sizeof(size_t) - 1)) 160 int tgt_fd, uint64_t offs,
int whence);
164 int tgt_fd, uint64_t offset_high,
165 uint32_t offset_low,
Addr result_ptr,
int whence);
173 int tgt_fd,
int how);
177 Addr buf_ptr,
int name_len);
181 Addr buf_ptr,
unsigned long size);
185 Addr pathname,
Addr buf,
size_t bufsiz);
204 Addr pathname, mode_t
mode, dev_t dev);
224 int tgt_fd, off_t
length);
233 int tgt_fd, int64_t
length);
243 Addr pathname, uint32_t owner, uint32_t group);
254 int tgt_fd, uint32_t owner, uint32_t group);
262 int old_tgt_fd,
int new_tgt_fd);
270 int tgt_fd,
int cmd);
277 Addr tgt_addr,
int flags);
284 int tgt_fd,
Addr sockAddrPtr,
Addr addrlenPtr);
288 int tgt_fd,
Addr buf_ptr,
int addrlen);
292 int tgt_fd,
int backlog);
296 int tgt_fd,
Addr buf_ptr,
int addrlen);
298 #if defined(SYS_getdents) 301 int tgt_fd,
Addr buf_ptr,
unsigned count);
304 #if defined(SYS_getdents64) 307 int tgt_fd,
Addr buf_ptr,
unsigned count);
312 int tgt_fd,
Addr bufrPtr,
size_t bufrLen,
int flags,
313 Addr addrPtr, socklen_t addrLen);
317 int tgt_fd,
Addr bufrPtr,
size_t bufrLen,
318 int flags,
Addr addrPtr,
Addr addrlenPtr);
322 int tgt_fd,
Addr msgPtr,
int flags);
326 int tgt_fd,
Addr msgPtr,
int flags);
349 int tgt_fd,
int level,
int optname,
354 int tgt_fd,
int level,
int optname,
359 int tgt_fd,
Addr addrPtr,
Addr lenPtr);
367 Addr uaddr,
int op,
int val,
int timeout,
Addr uaddr2,
int val3)
377 op &= ~OS::TGT_FUTEX_PRIVATE_FLAG;
378 op &= ~OS::TGT_FUTEX_CLOCK_REALTIME_FLAG;
382 if (OS::TGT_FUTEX_WAIT == op || OS::TGT_FUTEX_WAIT_BITSET == op) {
394 return -OS::TGT_EWOULDBLOCK;
396 if (OS::TGT_FUTEX_WAIT == op) {
397 futex_map.
suspend(uaddr, process->tgid(), tc);
403 }
else if (OS::TGT_FUTEX_WAKE == op) {
404 return futex_map.
wakeup(uaddr, process->tgid(),
val);
405 }
else if (OS::TGT_FUTEX_WAKE_BITSET == op) {
406 return futex_map.
wakeup_bitset(uaddr, process->tgid(), val3);
407 }
else if (OS::TGT_FUTEX_REQUEUE == op ||
408 OS::TGT_FUTEX_CMP_REQUEUE == op) {
418 if (OS::TGT_FUTEX_CMP_REQUEUE && val3 != mem_val)
419 return -OS::TGT_EWOULDBLOCK;
420 return futex_map.
requeue(uaddr, process->tgid(),
val, timeout, uaddr2);
421 }
else if (OS::TGT_FUTEX_WAKE_OP == op) {
449 int wake_cmparg = val3 & 0xfff;
450 int wake_oparg = (val3 & 0xfff000) >> 12;
451 int wake_cmp = (val3 & 0xf000000) >> 24;
452 int wake_op = (val3 & 0xf0000000) >> 28;
453 if ((wake_op & OS::TGT_FUTEX_OP_ARG_SHIFT) >> 3 == 1)
454 wake_oparg = (1 << wake_oparg);
455 wake_op &= ~OS::TGT_FUTEX_OP_ARG_SHIFT;
457 if (wake_op == OS::TGT_FUTEX_OP_SET)
459 else if (wake_op == OS::TGT_FUTEX_OP_ADD)
460 newval += wake_oparg;
461 else if (wake_op == OS::TGT_FUTEX_OP_OR)
462 newval |= wake_oparg;
463 else if (wake_op == OS::TGT_FUTEX_OP_ANDN)
464 newval &= ~wake_oparg;
465 else if (wake_op == OS::TGT_FUTEX_OP_XOR)
466 newval ^= wake_oparg;
471 int woken1 = futex_map.
wakeup(uaddr, process->tgid(),
val);
474 bool is_wake2 =
false;
475 if (wake_cmp == OS::TGT_FUTEX_OP_CMP_EQ)
476 is_wake2 = oldval == wake_cmparg;
477 else if (wake_cmp == OS::TGT_FUTEX_OP_CMP_NE)
478 is_wake2 = oldval != wake_cmparg;
479 else if (wake_cmp == OS::TGT_FUTEX_OP_CMP_LT)
480 is_wake2 = oldval < wake_cmparg;
481 else if (wake_cmp == OS::TGT_FUTEX_OP_CMP_LE)
482 is_wake2 = oldval <= wake_cmparg;
483 else if (wake_cmp == OS::TGT_FUTEX_OP_CMP_GT)
484 is_wake2 = oldval > wake_cmparg;
485 else if (wake_cmp == OS::TGT_FUTEX_OP_CMP_GE)
486 is_wake2 = oldval >= wake_cmparg;
489 woken2 = futex_map.
wakeup(uaddr2, process->tgid(), timeout);
491 return woken1 + woken2;
493 warn(
"futex: op %d not implemented; ignoring.", op);
509 template <
class T1,
class T2>
513 static const int OneMillion = 1000 * 1000;
516 sec = elapsed_usecs / OneMillion;
517 usec = elapsed_usecs % OneMillion;
522 template <
class T1,
class T2>
526 static const int OneBillion = 1000 * 1000 * 1000;
529 sec = elapsed_nsecs / OneBillion;
530 nsec = elapsed_nsecs % OneBillion;
553 template <
typename target_stat,
typename host_stat>
561 tgt->st_dev = host->st_dev;
562 tgt->st_dev =
htog(tgt->st_dev, bo);
563 tgt->st_ino = host->st_ino;
564 tgt->st_ino =
htog(tgt->st_ino, bo);
565 tgt->st_mode = host->st_mode;
568 tgt->st_mode &= ~S_IFMT;
569 tgt->st_mode |= S_IFCHR;
571 tgt->st_mode =
htog(tgt->st_mode, bo);
572 tgt->st_nlink = host->st_nlink;
573 tgt->st_nlink =
htog(tgt->st_nlink, bo);
574 tgt->st_uid = host->st_uid;
575 tgt->st_uid =
htog(tgt->st_uid, bo);
576 tgt->st_gid = host->st_gid;
577 tgt->st_gid =
htog(tgt->st_gid, bo);
579 tgt->st_rdev = 0x880d;
581 tgt->st_rdev = host->st_rdev;
582 tgt->st_rdev =
htog(tgt->st_rdev, bo);
583 tgt->st_size = host->st_size;
584 tgt->st_size =
htog(tgt->st_size, bo);
585 tgt->st_atimeX = host->st_atime;
586 tgt->st_atimeX =
htog(tgt->st_atimeX, bo);
587 tgt->st_mtimeX = host->st_mtime;
588 tgt->st_mtimeX =
htog(tgt->st_mtimeX, bo);
589 tgt->st_ctimeX = host->st_ctime;
590 tgt->st_ctimeX =
htog(tgt->st_ctimeX, bo);
593 tgt->st_blksize = 0x2000;
594 tgt->st_blksize =
htog(tgt->st_blksize, bo);
595 tgt->st_blocks = host->st_blocks;
596 tgt->st_blocks =
htog(tgt->st_blocks, bo);
601 template <
typename target_stat,
typename host_stat64>
606 convertStatBuf<target_stat, host_stat64>(tgt, host,
bo, fakeTTY);
607 #if defined(STAT_HAVE_NSEC) 608 tgt->st_atime_nsec = host->st_atime_nsec;
609 tgt->st_atime_nsec =
htog(tgt->st_atime_nsec, bo);
610 tgt->st_mtime_nsec = host->st_mtime_nsec;
611 tgt->st_mtime_nsec =
htog(tgt->st_mtime_nsec, bo);
612 tgt->st_ctime_nsec = host->st_ctime_nsec;
613 tgt->st_ctime_nsec =
htog(tgt->st_ctime_nsec, bo);
615 tgt->st_atime_nsec = 0;
616 tgt->st_mtime_nsec = 0;
617 tgt->st_ctime_nsec = 0;
625 hst_stat *host,
bool fakeTTY =
false)
628 tgt_stat_buf tgt(addr);
629 convertStatBuf<tgt_stat_buf, hst_stat>(tgt, host,
OS::byteOrder, fakeTTY);
639 tgt_stat_buf tgt(addr);
640 convertStat64Buf<tgt_stat_buf, hst_stat64>(
654 tgt->f_type =
htog(host->f_type, bo);
655 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) 656 tgt->f_bsize =
htog(host->f_iosize, bo);
658 tgt->f_bsize =
htog(host->f_bsize, bo);
660 tgt->f_blocks =
htog(host->f_blocks, bo);
661 tgt->f_bfree =
htog(host->f_bfree, bo);
662 tgt->f_bavail =
htog(host->f_bavail, bo);
663 tgt->f_files =
htog(host->f_files, bo);
664 tgt->f_ffree =
htog(host->f_ffree, bo);
665 memcpy(&tgt->f_fsid, &host->f_fsid,
sizeof(host->f_fsid));
666 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) 667 tgt->f_namelen =
htog(host->f_namemax, bo);
668 tgt->f_frsize =
htog(host->f_bsize, bo);
669 #elif defined(__APPLE__) 673 tgt->f_namelen =
htog(host->f_namelen, bo);
674 tgt->f_frsize =
htog(host->f_frsize, bo);
676 #if defined(__linux__) 677 memcpy(&tgt->f_spare, &host->f_spare,
sizeof(host->f_spare));
683 memset(&tgt->f_spare, 0,
sizeof(tgt->f_spare));
696 int tgt_fd,
unsigned req,
Addr addr)
702 if (OS::isTtyReq(req))
705 auto dfdp = std::dynamic_pointer_cast<
DeviceFDEntry>((*
p->fds)[tgt_fd]);
709 return emul_driver->
ioctl(tc, req, addr);
712 auto sfdp = std::dynamic_pointer_cast<
SocketFDEntry>((*
p->fds)[tgt_fd]);
718 BufferArg conf_arg(addr,
sizeof(ifconf));
721 ifconf *conf = (ifconf*)conf_arg.
bufferPtr();
722 Addr ifc_buf_addr = (
Addr)conf->ifc_buf;
723 BufferArg ifc_buf_arg(ifc_buf_addr, conf->ifc_len);
726 conf->ifc_buf = (
char*)ifc_buf_arg.bufferPtr();
728 status = ioctl(sfdp->getSimFD(), req, conf_arg.
bufferPtr());
730 conf->ifc_buf = (
char*)ifc_buf_addr;
738 #if defined(__linux__) 743 #if defined(__linux__) 750 status = ioctl(sfdp->getSimFD(), req, req_arg.
bufferPtr());
762 warn(
"Unsupported ioctl call (return ENOTTY): ioctl(%d, 0x%x, ...) @ \n",
771 int tgt_dirfd,
Addr pathname,
int tgt_flags,
int mode)
784 int host_flags = O_BINARY;
792 for (
int i = 0;
i < OS::NUM_OPEN_FLAGS;
i++) {
793 if (tgt_flags & OS::openFlagTable[
i].tgtFlag) {
794 tgt_flags &= ~OS::openFlagTable[
i].tgtFlag;
795 host_flags |= OS::openFlagTable[
i].hostFlag;
799 warn(
"%s: cannot decode flags %#x", desc->
name(), tgt_flags);
802 host_flags |= O_BINARY;
817 std::string redir_path = path;
818 std::string abs_path = path;
819 if (tgt_dirfd == OS::TGT_AT_FDCWD) {
820 abs_path =
p->absolutePath(path,
true);
821 redir_path =
p->checkPathRedirect(path);
823 std::shared_ptr<FDEntry> fdep = ((*
p->fds)[tgt_dirfd]);
824 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>(fdep);
828 redir_path =
p->checkPathRedirect(abs_path);
838 std::string filename = abs_path.substr(strlen(
"/dev/"));
842 "driver open with path[%s]\n",
843 desc->
name(), abs_path.c_str());
844 return drv->
open(tc, mode, host_flags);
877 std::string used_path;
879 {
"/proc/meminfo/",
"/system/",
"/platform/",
"/etc/passwd",
880 "/proc/self/maps",
"/dev/urandom",
881 "/sys/devices/system/cpu/online" };
882 for (
auto entry : special_paths) {
884 sim_fd = OS::openSpecialFile(abs_path,
p, tc);
885 used_path = abs_path;
889 sim_fd = open(redir_path.c_str(), host_flags,
mode);
890 used_path = redir_path;
895 "(inferred from:%s)\n", desc->
name(),
896 used_path.c_str(), path.c_str());
908 auto ffdp = std::make_shared<FileFDEntry>(sim_fd, host_flags, path, 0);
909 int tgt_fd =
p->fds->allocFD(ffdp);
911 "(inferred from:%s)\n", desc->
name(),
912 sim_fd, tgt_fd, used_path.c_str(), path.c_str());
920 Addr pathname,
int tgt_flags,
int mode)
922 return openatFunc<OS>(
923 desc, tc, OS::TGT_AT_FDCWD, pathname, tgt_flags,
mode);
931 if (dirfd != OS::TGT_AT_FDCWD)
932 warn(
"unlinkat: first argument not AT_FDCWD; unlikely to work");
943 if (dirfd != OS::TGT_AT_FDCWD)
944 warn(
"faccessat: first argument not AT_FDCWD; unlikely to work");
952 int dirfd,
Addr pathname,
Addr buf,
size_t bufsiz)
954 if (dirfd != OS::TGT_AT_FDCWD)
955 warn(
"openat: first argument not AT_FDCWD; unlikely to work");
963 int olddirfd,
Addr oldpath,
int newdirfd,
Addr newpath)
965 if (olddirfd != OS::TGT_AT_FDCWD)
966 warn(
"renameat: first argument not AT_FDCWD; unlikely to work");
968 if (newdirfd != OS::TGT_AT_FDCWD)
969 warn(
"renameat: third argument not AT_FDCWD; unlikely to work");
971 return renameFunc(desc, tc, oldpath, newpath);
984 sysinfo->totalram = process->system->memSize();
985 sysinfo->mem_unit = 1;
1003 mode_t hostMode = 0;
1009 path = process->checkPathRedirect(path);
1012 int result = chmod(path.c_str(), hostMode);
1022 Addr fdsPtr,
int nfds,
int tmout)
1026 BufferArg fdsBuf(fdsPtr,
sizeof(
struct pollfd) * nfds);
1035 int temp_tgt_fds[nfds];
1038 auto tgt_fd = temp_tgt_fds[
index];
1039 auto hbfdp = std::dynamic_pointer_cast<
HBFDEntry>((*
p->fds)[tgt_fd]);
1042 auto host_fd = hbfdp->getSimFD();
1054 status = poll((
struct pollfd *)fdsBuf.
bufferPtr(), nfds, 0);
1064 if (it->receiver ==
p)
1069 status = poll((
struct pollfd *)fdsBuf.
bufferPtr(), nfds, 0);
1079 auto tgt_fd = temp_tgt_fds[
index];
1099 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>((*
p->fds)[tgt_fd]);
1102 int sim_fd = ffdp->getSimFD();
1104 mode_t hostMode =
mode;
1106 int result = fchmod(sim_fd, hostMode);
1108 return (result < 0) ? -errno : 0;
1115 Addr start, uint64_t old_length, uint64_t new_length, uint64_t flags,
1120 uint64_t provided_address = 0;
1121 bool use_provided_address = flags & OS::TGT_MREMAP_FIXED;
1123 if (use_provided_address)
1124 provided_address = varargs.
get<uint64_t>();
1126 if ((start % page_bytes != 0) ||
1127 (provided_address % page_bytes != 0)) {
1128 warn(
"mremap failing: arguments not page aligned");
1132 new_length =
roundUp(new_length, page_bytes);
1134 if (new_length > old_length) {
1135 Addr mmap_end =
p->memState->getMmapEnd();
1137 if ((start + old_length) == mmap_end &&
1138 (!use_provided_address || provided_address == start)) {
1141 uint64_t diff = new_length - old_length;
1142 p->memState->mapRegion(mmap_end, diff,
"remapped");
1143 p->memState->setMmapEnd(mmap_end + diff);
1146 if (!use_provided_address && !(flags & OS::TGT_MREMAP_MAYMOVE)) {
1147 warn(
"can't remap here and MREMAP_MAYMOVE flag not set\n");
1150 uint64_t new_start = provided_address;
1151 if (!use_provided_address) {
1152 new_start =
p->mmapGrowsDown() ?
1153 mmap_end - new_length : mmap_end;
1154 mmap_end =
p->mmapGrowsDown() ?
1155 new_start : mmap_end + new_length;
1156 p->memState->setMmapEnd(mmap_end);
1159 warn(
"mremapping to new vaddr %08p-%08p, adding %d\n",
1160 new_start, new_start + new_length,
1161 new_length - old_length);
1164 p->allocateMem(new_start + old_length,
1165 new_length - old_length,
1166 use_provided_address );
1168 if (use_provided_address &&
1169 ((new_start + new_length >
p->memState->getMmapEnd() &&
1170 !
p->mmapGrowsDown()) ||
1171 (new_start < p->memState->getMmapEnd() &&
1172 p->mmapGrowsDown()))) {
1175 warn(
"mmap region limit exceeded with MREMAP_FIXED\n");
1178 warn(
"returning %08p as start\n", new_start);
1179 p->memState->remapRegion(start, new_start, old_length);
1185 if (use_provided_address && provided_address != start)
1186 p->memState->remapRegion(start, provided_address, new_length);
1187 if (new_length != old_length)
1188 p->memState->unmapRegion(start + new_length,
1189 old_length - new_length);
1190 return use_provided_address ? provided_address : start;
1208 struct stat hostBuf;
1209 int result = stat(path.c_str(), &hostBuf);
1214 copyOutStatBuf<OS>(tc->
getVirtProxy(), bufPtr, &hostBuf);
1235 struct stat hostBuf;
1236 int result = stat(path.c_str(), &hostBuf);
1238 struct stat64 hostBuf;
1239 int result = stat64(path.c_str(), &hostBuf);
1245 copyOutStat64Buf<OS>(tc->
getVirtProxy(), bufPtr, &hostBuf);
1255 int dirfd,
Addr pathname,
Addr bufPtr)
1258 if (dirfd != OS::TGT_AT_FDCWD)
1259 warn(
"fstatat64: first argument not AT_FDCWD; unlikely to work");
1266 path = process->checkPathRedirect(path);
1269 struct stat hostBuf;
1270 int result = stat(path.c_str(), &hostBuf);
1272 struct stat64 hostBuf;
1273 int result = stat64(path.c_str(), &hostBuf);
1279 copyOutStat64Buf<OS>(tc->
getVirtProxy(), bufPtr, &hostBuf);
1292 auto ffdp = std::dynamic_pointer_cast<
HBFDEntry>((*
p->fds)[tgt_fd]);
1295 int sim_fd = ffdp->getSimFD();
1298 struct stat hostBuf;
1299 int result = fstat(sim_fd, &hostBuf);
1301 struct stat64 hostBuf;
1302 int result = fstat64(sim_fd, &hostBuf);
1308 copyOutStat64Buf<OS>(tc->
getVirtProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1328 struct stat hostBuf;
1329 int result = lstat(path.c_str(), &hostBuf);
1334 copyOutStatBuf<OS>(tc->
getVirtProxy(), bufPtr, &hostBuf);
1354 struct stat hostBuf;
1355 int result = lstat(path.c_str(), &hostBuf);
1357 struct stat64 hostBuf;
1358 int result = lstat64(path.c_str(), &hostBuf);
1364 copyOutStat64Buf<OS>(tc->
getVirtProxy(), bufPtr, &hostBuf);
1378 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>((*
p->fds)[tgt_fd]);
1381 int sim_fd = ffdp->getSimFD();
1383 struct stat hostBuf;
1384 int result = fstat(sim_fd, &hostBuf);
1389 copyOutStatBuf<OS>(tc->
getVirtProxy(), bufPtr, &hostBuf, (sim_fd == 1));
1399 #if defined(__linux__) 1409 struct statfs hostBuf;
1410 int result = statfs(path.c_str(), &hostBuf);
1415 copyOutStatfsBuf<OS>(tc->
getVirtProxy(), bufPtr, &hostBuf);
1430 if (((flags & OS::TGT_CLONE_SIGHAND)&& !(flags & OS::TGT_CLONE_VM)) ||
1431 ((flags & OS::TGT_CLONE_THREAD) && !(flags & OS::TGT_CLONE_SIGHAND)) ||
1432 ((flags & OS::TGT_CLONE_FS) && (flags & OS::TGT_CLONE_NEWNS)) ||
1433 ((flags & OS::TGT_CLONE_NEWIPC) && (flags & OS::TGT_CLONE_SYSVSEM)) ||
1434 ((flags & OS::TGT_CLONE_NEWPID) && (flags & OS::TGT_CLONE_THREAD)) ||
1435 ((flags & OS::TGT_CLONE_VM) && !(newStack)))
1451 ProcessParams *pp =
new ProcessParams();
1452 pp->executable.assign(*(
new std::string(
p->progName())));
1453 pp->cmd.push_back(*(
new std::string(
p->progName())));
1454 pp->system =
p->system;
1455 pp->cwd.assign(
p->tgtCwd);
1456 pp->input.assign(
"stdin");
1457 pp->output.assign(
"stdout");
1458 pp->errout.assign(
"stderr");
1460 pp->euid =
p->euid();
1462 pp->egid =
p->egid();
1465 std::set<int>
const& pids =
p->system->PIDs;
1466 int temp_pid = *pids.begin();
1469 }
while (pids.find(temp_pid) != pids.end());
1471 fatal(
"temp_pid is too large: %d", temp_pid);
1474 pp->ppid = (flags & OS::TGT_CLONE_THREAD) ?
p->ppid() :
p->pid();
1475 pp->useArchPT =
p->useArchPT;
1476 pp->kvmInSE =
p->kvmInSE;
1487 if (flags & OS::TGT_CLONE_PARENT_SETTID) {
1488 BufferArg ptidBuf(ptidPtr,
sizeof(
long));
1489 long *ptid = (
long *)ptidBuf.
bufferPtr();
1494 if (flags & OS::TGT_CLONE_THREAD) {
1499 p->clone(tc, ctc, cp, flags);
1501 if (flags & OS::TGT_CLONE_THREAD) {
1504 }
else if (flags & OS::TGT_SIGCHLD) {
1508 if (flags & OS::TGT_CLONE_CHILD_SETTID) {
1509 BufferArg ctidBuf(ctidPtr,
sizeof(
long));
1510 long *ctid = (
long *)ctidBuf.
bufferPtr();
1515 if (flags & OS::TGT_CLONE_CHILD_CLEARTID)
1520 OS::archClone(flags,
p, cp, tc, ctc, newStack, tlsPtr);
1524 #if THE_ISA == SPARC_ISA 1543 return cloneFunc<OS>(desc, tc, flags, newStack, ptidPtr, ctidPtr, tlsPtr);
1553 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>((*
p->fds)[tgt_fd]);
1556 int sim_fd = ffdp->getSimFD();
1558 struct statfs hostBuf;
1559 int result = fstatfs(sim_fd, &hostBuf);
1564 copyOutStatfsBuf<OS>(tc->
getVirtProxy(), bufPtr, &hostBuf);
1573 int tgt_fd, uint64_t tiov_base,
size_t count)
1577 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>((*
p->fds)[tgt_fd]);
1580 int sim_fd = ffdp->getSimFD();
1583 typename OS::tgt_iovec tiov[
count];
1584 struct iovec hiov[count];
1585 for (
size_t i = 0;
i <
count; ++
i) {
1586 prox.
readBlob(tiov_base + (
i *
sizeof(
typename OS::tgt_iovec)),
1587 &tiov[
i],
sizeof(
typename OS::tgt_iovec));
1589 hiov[
i].iov_base =
new char [hiov[
i].iov_len];
1592 int result = readv(sim_fd, hiov, count);
1593 int local_errno = errno;
1595 for (
size_t i = 0;
i <
count; ++
i) {
1598 hiov[
i].iov_base, hiov[
i].iov_len);
1600 delete [] (
char *)hiov[
i].iov_base;
1603 return (result == -1) ? -local_errno : result;
1610 int tgt_fd, uint64_t tiov_base,
size_t count)
1614 auto hbfdp = std::dynamic_pointer_cast<
HBFDEntry>((*
p->fds)[tgt_fd]);
1617 int sim_fd = hbfdp->getSimFD();
1620 struct iovec hiov[count];
1621 for (
size_t i = 0;
i <
count; ++
i) {
1622 typename OS::tgt_iovec tiov;
1624 prox.
readBlob(tiov_base +
i*
sizeof(
typename OS::tgt_iovec),
1625 &tiov,
sizeof(
typename OS::tgt_iovec));
1627 hiov[
i].iov_base =
new char [hiov[
i].iov_len];
1632 int result = writev(sim_fd, hiov, count);
1635 delete [] (
char *)hiov[
i].iov_base;
1637 return (result == -1) ? -errno : result;
1645 int tgt_flags,
int tgt_fd,
typename OS::off_t
offset)
1650 if (start & (page_bytes - 1) ||
1651 offset & (page_bytes - 1) ||
1652 (tgt_flags & OS::TGT_MAP_PRIVATE &&
1653 tgt_flags & OS::TGT_MAP_SHARED) ||
1654 (!(tgt_flags & OS::TGT_MAP_PRIVATE) &&
1655 !(tgt_flags & OS::TGT_MAP_SHARED)) ||
1660 if ((prot & PROT_WRITE) && (tgt_flags & OS::TGT_MAP_SHARED)) {
1681 warn_once(
"mmap: writing to shared mmap region is currently " 1682 "unsupported. The write succeeds on the target, but it " 1683 "will not be propagated to the host or shared mappings");
1686 length =
roundUp(length, page_bytes);
1689 if (!(tgt_flags & OS::TGT_MAP_ANONYMOUS)) {
1690 std::shared_ptr<FDEntry> fdep = (*
p->fds)[tgt_fd];
1695 return emul_driver->
mmap(tc, start, length, prot, tgt_flags,
1699 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>(fdep);
1712 if (
p->interpImage.contains(tc->
pcState().instAddr())) {
1713 std::shared_ptr<FDEntry> fdep = (*
p->fds)[tgt_fd];
1714 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>(fdep);
1716 ffdp->getFileName()));
1718 ffdp->getFileName());
1722 lib->buildImage().minAddr(), start);
1730 if (!(tgt_flags & OS::TGT_MAP_FIXED)) {
1738 if (!(start &&
p->memState->isUnmapped(start, length))) {
1742 start =
p->memState->extendMmap(length);
1747 start, start + length - 1);
1754 if (tgt_flags & OS::TGT_MAP_FIXED) {
1759 p->memState->unmapRegion(start, length);
1765 std::string region_name;
1766 if (tgt_flags & OS::TGT_MAP_ANONYMOUS) {
1767 region_name =
"anon";
1769 std::shared_ptr<FDEntry> fdep = (*
p->fds)[tgt_fd];
1770 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>(fdep);
1778 p->memState->mapRegion(start, length, region_name, sim_fd, offset);
1786 int tgt_fd,
Addr bufPtr,
int nbytes,
int offset)
1790 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>((*
p->fds)[tgt_fd]);
1793 int sim_fd = ffdp->getSimFD();
1801 return (bytes_read == -1) ? -errno : bytes_read;
1807 int tgt_fd,
Addr bufPtr,
int nbytes,
int offset)
1811 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>((*
p->fds)[tgt_fd]);
1814 int sim_fd = ffdp->getSimFD();
1819 int bytes_written = pwrite(sim_fd, bufArg.
bufferPtr(), nbytes,
offset);
1821 return (bytes_written == -1) ? -errno : bytes_written;
1829 int tgt_flags,
int tgt_fd,
typename OS::off_t
offset)
1831 return mmapFunc<OS>(desc, tc, start,
length,
prot, tgt_flags,
1832 tgt_fd, offset * tc->getSystemPtr()->getPageBytes());
1839 unsigned resource,
Addr rlim)
1845 case OS::TGT_RLIMIT_STACK:
1847 rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
1848 rlp->rlim_cur =
htog(rlp->rlim_cur, bo);
1849 rlp->rlim_max =
htog(rlp->rlim_max, bo);
1852 case OS::TGT_RLIMIT_DATA:
1854 rlp->rlim_cur = rlp->rlim_max = 256 * 1024 * 1024;
1855 rlp->rlim_cur =
htog(rlp->rlim_cur, bo);
1856 rlp->rlim_max =
htog(rlp->rlim_max, bo);
1859 case OS::TGT_RLIMIT_NPROC:
1861 rlp->rlim_cur =
htog(rlp->rlim_cur, bo);
1862 rlp->rlim_max =
htog(rlp->rlim_max, bo);
1866 warn(
"getrlimit: unimplemented resource %d", resource);
1881 warn(
"prlimit: ignoring rlimits for nonzero pid");
1885 warn(
"prlimit: ignoring new rlimit");
1890 case OS::TGT_RLIMIT_STACK:
1892 rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
1893 rlp->rlim_cur =
htog(rlp->rlim_cur, bo);
1894 rlp->rlim_max =
htog(rlp->rlim_max, bo);
1896 case OS::TGT_RLIMIT_DATA:
1898 rlp->rlim_cur = rlp->rlim_max = 256*1024*1024;
1899 rlp->rlim_cur =
htog(rlp->rlim_cur, bo);
1900 rlp->rlim_max =
htog(rlp->rlim_max, bo);
1903 warn(
"prlimit: unimplemented resource %d", resource);
1916 int clk_id,
Addr tp_ptr)
1979 struct timeval hostTimeval[2];
1980 for (
int i = 0;
i < 2; ++
i) {
1986 path = process->checkPathRedirect(path);
1988 int result = utimes(path.c_str(), hostTimeval);
2008 if (access(path.c_str(), F_OK) == -1)
2014 for (
int inc = 0; ;
inc++) {
2021 vect.push_back(std::string());
2032 ProcessParams *pp =
new ProcessParams();
2033 pp->executable = path;
2034 read_in(pp->cmd, mem_proxy, argv_mem_loc);
2035 read_in(pp->env, mem_proxy, envp_mem_loc);
2037 pp->egid =
p->egid();
2038 pp->euid =
p->euid();
2040 pp->ppid =
p->ppid();
2042 pp->input.assign(
"cin");
2043 pp->output.assign(
"cout");
2044 pp->errout.assign(
"cerr");
2045 pp->cwd.assign(
p->tgtCwd);
2046 pp->system =
p->system;
2055 p->system->PIDs.erase(
p->pid());
2056 Process *new_p = pp->create();
2063 new_p->
fds =
p->fds;
2064 for (
int i = 0;
i < new_p->
fds->getSize();
i++) {
2065 std::shared_ptr<FDEntry> fdep = (*new_p->
fds)[
i];
2066 if (fdep && fdep->getCOE())
2067 new_p->
fds->closeFDEntry(
i);
2079 tc->
setNPC(pcState.instAddr());
2092 rup->ru_utime.tv_sec = 0;
2093 rup->ru_utime.tv_usec = 0;
2094 rup->ru_stime.tv_sec = 0;
2095 rup->ru_stime.tv_usec = 0;
2103 rup->ru_inblock = 0;
2104 rup->ru_oublock = 0;
2107 rup->ru_nsignals = 0;
2112 case OS::TGT_RUSAGE_SELF:
2118 case OS::TGT_RUSAGE_CHILDREN:
2125 warn(
"getrusage() only supports RUSAGE_SELF. Parameter %d ignored.",
2143 bufp->tms_utime = clocks;
2144 bufp->tms_stime = 0;
2145 bufp->tms_cutime = 0;
2146 bufp->tms_cstime = 0;
2163 typename OS::time_t sec, usec;
2168 typename OS::time_t
t = sec;
2171 p.
writeBlob(taddr, &t, (
int)
sizeof(
typename OS::time_t));
2199 if (temp->
pid() == tid) {
2205 if (sig != 0 || sig != OS::TGT_SIGABRT)
2208 if (tgt_proc ==
nullptr)
2211 if (tgid != -1 && tgt_proc->
tgid() != tgid)
2214 if (sig == OS::TGT_SIGABRT)
2227 int sim_fd = socket(domain, type, prot);
2231 auto sfdp = std::make_shared<SocketFDEntry>(sim_fd,
domain,
type,
prot);
2232 int tgt_fd =
p->fds->allocFD(sfdp);
2245 int status = socketpair(domain, type, prot, (
int *)svBuf.
bufferPtr());
2251 auto sfdp1 = std::make_shared<SocketFDEntry>(fds[0],
domain,
type,
prot);
2252 fds[0] =
p->fds->allocFD(sfdp1);
2253 auto sfdp2 = std::make_shared<SocketFDEntry>(fds[1],
domain,
type,
prot);
2254 fds[1] =
p->fds->allocFD(sfdp2);
2263 int nfds_t,
Addr fds_read_ptr,
Addr fds_writ_ptr,
2264 Addr fds_excp_ptr,
Addr time_val_ptr)
2307 std::map<int, int> trans_map;
2308 auto try_add_host_set = [&](fd_set *tgt_set_entry,
2309 fd_set *hst_set_entry,
2317 if (FD_ISSET(iter, tgt_set_entry)) {
2323 auto hbfdp = std::dynamic_pointer_cast<
HBFDEntry>((*
p->fds)[iter]);
2326 auto sim_fd = hbfdp->getSimFD();
2333 trans_map[sim_fd] = iter;
2340 nfds_h = std::max(nfds_h - 1, sim_fd + 1);
2346 FD_SET(sim_fd, hst_set_entry);
2351 for (
int i = 0;
i < nfds_t;
i++) {
2353 bool ebadf = try_add_host_set((fd_set*)&*rd_t, &rd_h,
i);
2354 if (ebadf)
return -EBADF;
2357 bool ebadf = try_add_host_set((fd_set*)&*wr_t, &wr_h,
i);
2358 if (ebadf)
return -EBADF;
2361 bool ebadf = try_add_host_set((fd_set*)&*ex_t, &ex_h,
i);
2362 if (ebadf)
return -EBADF;
2377 retval = select(nfds_h,
2378 fds_read_ptr ? &rd_h :
nullptr,
2379 fds_writ_ptr ? &wr_h :
nullptr,
2380 fds_excp_ptr ? &ex_h :
nullptr,
2390 struct timeval tv = { 0, 0 };
2392 retval = select(nfds_h,
2393 fds_read_ptr ? &rd_h :
nullptr,
2394 fds_writ_ptr ? &wr_h :
nullptr,
2395 fds_excp_ptr ? &ex_h :
nullptr,
2405 if (sig.receiver ==
p)
2414 FD_ZERO((fd_set*)&*rd_t);
2415 FD_ZERO((fd_set*)&*wr_t);
2416 FD_ZERO((fd_set*)&*ex_t);
2423 for (
int i = 0;
i < nfds_h;
i++) {
2425 if (FD_ISSET(
i, &rd_h))
2426 FD_SET(trans_map[
i], (fd_set*)&*rd_t);
2430 if (FD_ISSET(
i, &wr_h))
2431 FD_SET(trans_map[
i], (fd_set*)&*wr_t);
2435 if (FD_ISSET(
i, &ex_h))
2436 FD_SET(trans_map[
i], (fd_set*)&*ex_t);
2455 int tgt_fd,
Addr buf_ptr,
int nbytes)
2459 auto hbfdp = std::dynamic_pointer_cast<
HBFDEntry>((*
p->fds)[tgt_fd]);
2462 int sim_fd = hbfdp->getSimFD();
2466 pfd.events = POLLIN | POLLPRI;
2467 if ((poll(&pfd, 1, 0) == 0)
2468 && !(hbfdp->getFlags() & OS::TGT_O_NONBLOCK))
2472 int bytes_read = read(sim_fd, buf_arg.
bufferPtr(), nbytes);
2477 return (bytes_read == -1) ? -errno : bytes_read;
2483 int tgt_fd,
Addr buf_ptr,
int nbytes)
2487 auto hbfdp = std::dynamic_pointer_cast<
HBFDEntry>((*
p->fds)[tgt_fd]);
2490 int sim_fd = hbfdp->getSimFD();
2497 pfd.events = POLLOUT;
2505 auto ffdp = std::dynamic_pointer_cast<
FileFDEntry>(hbfdp);
2506 if (ffdp && (ffdp->getFileName() !=
"/dev/random")) {
2507 if (!poll(&pfd, 1, 0) && !(ffdp->getFlags() & OS::TGT_O_NONBLOCK))
2511 int bytes_written = write(sim_fd, buf_arg.
bufferPtr(), nbytes);
2513 if (bytes_written != -1)
2516 return (bytes_written == -1) ? -errno : bytes_written;
2522 pid_t pid,
Addr statPtr,
int options,
Addr rusagePtr)
2527 DPRINTF_SYSCALL(Verbose,
"wait4: rusage pointer provided %lx, however " 2528 "functionality not supported. Ignoring rusage pointer.\n",
2542 if (iter->receiver ==
p) {
2544 if ((iter->sender->pgid() == -pid)
2545 && (iter->signalValue == OS::TGT_SIGCHLD))
2547 }
else if (pid == -1) {
2548 if (iter->signalValue == OS::TGT_SIGCHLD)
2550 }
else if (pid == 0) {
2551 if ((iter->sender->pgid() ==
p->pgid())
2552 && (iter->signalValue == OS::TGT_SIGCHLD))
2555 if ((iter->sender->pid() == pid)
2556 && (iter->signalValue == OS::TGT_SIGCHLD))
2566 const int EXITED = 0;
2567 BufferArg statusBuf(statPtr,
sizeof(
int));
2572 pid_t retval = iter->sender->pid();
2580 int tgt_fd,
Addr addrPtr,
Addr lenPtr)
2590 auto sfdp = std::dynamic_pointer_cast<
SocketFDEntry>((*
p->fds)[tgt_fd]);
2593 int sim_fd = sfdp->getSimFD();
2603 pfd.events = POLLIN | POLLPRI;
2604 if ((poll(&pfd, 1, 0) == 0) && !(sfdp->getFlags() & OS::TGT_O_NONBLOCK))
2608 lenBufPtr =
new BufferArg(lenPtr,
sizeof(socklen_t));
2610 memcpy(&addrLen, (socklen_t *)lenBufPtr->
bufferPtr(),
2615 addrBufPtr =
new BufferArg(addrPtr,
sizeof(
struct sockaddr));
2617 memcpy(&sa, (
struct sockaddr *)addrBufPtr->
bufferPtr(),
2618 sizeof(
struct sockaddr));
2621 host_fd = accept(sim_fd, &sa, &addrLen);
2633 *(socklen_t *)lenBufPtr->
bufferPtr() = addrLen;
2638 auto afdp = std::make_shared<SocketFDEntry>(host_fd, sfdp->_domain,
2639 sfdp->_type, sfdp->_protocol);
2640 return p->fds->allocFD(afdp);
2647 unsigned initval,
int in_flags)
2649 #if defined(__linux__) 2652 int sim_fd = eventfd(initval, in_flags);
2656 bool cloexec = in_flags & OS::TGT_O_CLOEXEC;
2658 int flags = cloexec ? OS::TGT_O_CLOEXEC : 0;
2659 flags |= (in_flags & OS::TGT_O_NONBLOCK) ? OS::TGT_O_NONBLOCK : 0;
2661 auto hbfdp = std::make_shared<HBFDEntry>(flags, sim_fd, cloexec);
2662 int tgt_fd =
p->fds->allocFD(hbfdp);
2670 #endif // __SIM_SYSCALL_EMUL_HH__
SyscallReturn gethostnameFunc(SyscallDesc *desc, ThreadContext *tc, Addr buf_ptr, int name_len)
Target gethostname() handler.
This file defines buffer classes used to handle pointer arguments in emulated syscalls.
SyscallReturn writevFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint64_t tiov_base, size_t count)
Target writev() 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 fstatFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufPtr)
Target fstat() 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 listenFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int backlog)
virtual System * getSystemPtr()=0
SyscallReturn cloneFunc(SyscallDesc *desc, ThreadContext *tc, RegVal flags, RegVal newStack, Addr ptidPtr, Addr ctidPtr, Addr tlsPtr)
ObjectFile * createObjectFile(const std::string &fname, bool raw)
SyscallReturn getgidFunc(SyscallDesc *desc, ThreadContext *tc)
Target getgid() handler.
SyscallReturn symlinkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr new_pathname)
Target symlink() handler.
SyscallReturn getpeernameFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr sockAddrPtr, Addr addrlenPtr)
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 revokeThreadContext(int context_id)
After delegating a thread context to a child process no longer should relate to the ThreadContext...
#define fatal(...)
This implements a cprintf based fatal() function.
SyscallReturn connectFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int addrlen)
SyscallReturn lstatFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr bufPtr)
Target lstat() handler.
uint64_t childClearTID
Calls a futex wakeup at the address specified by this pointer when this process exits.
T gtoh(T value, ByteOrder guest_byte_order)
SyscallReturn unlinkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname)
Target unlink() handler.
SyscallReturn getegidFunc(SyscallDesc *desc, ThreadContext *tc)
Target getegid() handler.
void copyOutStatfsBuf(PortProxy &mem, Addr addr, hst_statfs *host)
SyscallReturn bindFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int addrlen)
SyscallReturn sysinfoFunc(SyscallDesc *desc, ThreadContext *tc, Addr info)
Target sysinfo() handler.
virtual TheISA::PCState pcState() const =0
SyscallReturn truncateFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, off_t length)
Target truncate() handler.
SyscallReturn getpidFunc(SyscallDesc *desc, ThreadContext *tc)
Target getpid() handler.
SyscallReturn rmdirFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname)
bool copyIn(PortProxy &memproxy)
copy data into simulator space (read from target memory)
SyscallReturn socketpairFunc(SyscallDesc *desc, ThreadContext *tc, int domain, int type, int prot, Addr svPtr)
SyscallReturn cloneBackwardsFunc(SyscallDesc *desc, ThreadContext *tc, RegVal flags, RegVal newStack, Addr ptidPtr, Addr tlsPtr, Addr ctidPtr)
SyscallReturn getrlimitFunc(SyscallDesc *desc, ThreadContext *tc, unsigned resource, Addr rlim)
Target getrlimit() handler.
SyscallReturn sendtoFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufrPtr, size_t bufrLen, int flags, Addr addrPtr, socklen_t addrLen)
SyscallReturn fallocateFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int mode, off_t offset, off_t len)
SyscallReturn chmodFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode)
Target chmod() handler.
SyscallReturn umaskFunc(SyscallDesc *desc, ThreadContext *tc)
Target umask() handler.
SyscallReturn getpagesizeFunc(SyscallDesc *desc, ThreadContext *tc)
Target getpagesize() handler.
SyscallReturn getppidFunc(SyscallDesc *desc, ThreadContext *tc)
Target getppid() handler.
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.
virtual PortProxy & getVirtProxy()=0
SyscallReturn pollFunc(SyscallDesc *desc, ThreadContext *tc, Addr fdsPtr, int nfds, int tmout)
virtual Process * getProcessPtr()=0
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.
Holds file descriptors for host-backed files; host-backed files are files which were opened on the ph...
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.
SyscallReturn eventfdFunc(SyscallDesc *desc, ThreadContext *tc, unsigned initval, int in_flags)
Target eventfd() function.
Overload hash function for BasicBlockRange type.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
SyscallReturn readlinkatFunc(SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname, Addr buf, size_t bufsiz)
Target readlinkat() handler.
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)
This function is used to align addresses in memory.
SyscallReturn writeFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int nbytes)
SyscallReturn openatFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_dirfd, Addr pathname, int tgt_flags, int mode)
Target open() handler.
TypedBufferArg is a class template; instances of this template represent typed buffers in target user...
SyscallReturn readFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr buf_ptr, int nbytes)
ThreadContext is the external interface to all thread state for anything outside of the CPU...
int requeue(Addr addr1, uint64_t tgid, int count, int count2, Addr addr2)
This operation wakes a given number (val) of waiters.
SyscallReturn chownFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, uint32_t owner, uint32_t group)
Target chown() handler.
void usage(const char *progname)
SyscallReturn shutdownFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int how)
Target shutdown() handler.
SyscallReturn getsockoptFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int level, int optname, Addr valPtr, Addr lenPtr)
#define DPRINTF_SYSCALL(FLAGEXT, FMT,...)
This macro is intended to help with readability.
SyscallReturn fcntlFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int cmd, GuestABI::VarArgs< int > varargs)
Target fcntl() handler.
SyscallReturn lstat64Func(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr bufPtr)
Target lstat64() handler.
SyscallReturn getpgrpFunc(SyscallDesc *desc, ThreadContext *tc)
Target getpgrpFunc() handler.
SyscallReturn pipePseudoFunc(SyscallDesc *desc, ThreadContext *tc)
Pseudo Funcs - These functions use a different return convension, returning a second value in a regis...
SyscallReturn linkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr new_pathname)
Target link() handler.
SyscallReturn recvmsgFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr msgPtr, int flags)
SyscallReturn brkFunc(SyscallDesc *desc, ThreadContext *tc, Addr new_brk)
Target brk() handler: set brk address.
SyscallReturn exitFunc(SyscallDesc *desc, ThreadContext *tc, int status)
Target exit() handler: terminate current context.
SyscallReturn exitGroupFunc(SyscallDesc *desc, ThreadContext *tc, int status)
Target exit_group() handler: terminate simulation. (exit all threads)
void copyOutStat64Buf(PortProxy &mem, Addr addr, hst_stat64 *host, bool fakeTTY=false)
SyscallReturn gettidFunc(SyscallDesc *desc, ThreadContext *tc)
Target gettid() handler.
Tick curTick()
The current simulated tick.
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.
void assignThreadContext(ContextID context_id)
SyscallReturn fcntl64Func(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int cmd)
Target fcntl64() handler.
void inc(scfx_mant &mant)
T htog(T value, ByteOrder guest_byte_order)
SyscallReturn ftruncateFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, off_t length)
Target ftruncate() handler.
virtual int cpuId() const =0
SyscallReturn socketFunc(SyscallDesc *desc, ThreadContext *tc, int domain, int type, int prot)
SyscallReturn mkdirFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode)
Target mkdir() handler.
virtual void setProcessPtr(Process *p)=0
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
int wakeup(Addr addr, uint64_t tgid, int count)
Wakes up at most count waiting threads on a futex.
SyscallReturn getrusageFunc(SyscallDesc *desc, ThreadContext *tc, int who, Addr usage)
Target getrusage() function.
SyscallReturn timeFunc(SyscallDesc *desc, ThreadContext *tc, Addr taddr)
Target time() function.
SyscallReturn execveFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr argv_mem_loc, Addr envp_mem_loc)
SyscallReturn setpgidFunc(SyscallDesc *desc, ThreadContext *tc, int pid, int pgid)
Target setpgid() handler.
SyscallReturn closeFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd)
Target close() handler.
SyscallReturn wait4Func(SyscallDesc *desc, ThreadContext *tc, pid_t pid, Addr statPtr, int options, Addr rusagePtr)
static SyscallReturn retry()
Pseudo-constructor to create an instance with the retry flag set.
std::vector< ThreadContext * > threadContexts
Extends the base class to include a host-backed file descriptor field that records the integer used t...
unsigned numContexts() const
SyscallReturn sendmsgFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr msgPtr, int flags)
void * bufferPtr()
Return a pointer to the internal simulator-space buffer.
SyscallReturn renameFunc(SyscallDesc *desc, ThreadContext *tc, Addr oldpath, Addr newpath)
Target rename() handler.
SyscallReturn getuidFunc(SyscallDesc *desc, ThreadContext *tc)
SyscallReturn timesFunc(SyscallDesc *desc, ThreadContext *tc, Addr bufPtr)
Target times() function.
std::string const & getFileName() const
SyscallReturn tgkillFunc(SyscallDesc *desc, ThreadContext *tc, int tgid, int tid, int sig)
ThreadContext * findFreeContext()
void warnUnsupportedOS(std::string syscall_name)
SyscallReturn truncate64Func(SyscallDesc *desc, ThreadContext *tc, Addr pathname, int64_t length)
Target truncate64() handler.
SyscallReturn selectFunc(SyscallDesc *desc, ThreadContext *tc, int nfds_t, Addr fds_read_ptr, Addr fds_writ_ptr, Addr fds_excp_ptr, Addr time_val_ptr)
SyscallReturn clock_getresFunc(SyscallDesc *desc, ThreadContext *tc, int clk_id, Addr tp_ptr)
Target clock_getres() function.
virtual void activate()=0
Set the status to Active.
virtual int open(ThreadContext *tc, int mode, int flags)=0
Abstract method, invoked when the user program calls open() on the device driver. ...
void getElapsedTimeNano(T1 &sec, T2 &nsec)
Helper function to convert current elapsed time to seconds and nanoseconds.
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
SyscallReturn ioctlFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, unsigned req, Addr addr)
Target ioctl() handler.
SyscallReturn fchmodFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint32_t mode)
Target fchmod() handler.
SyscallReturn fstatfsFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufPtr)
Target fstatfs() handler.
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
SyscallReturn dupFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd)
Target dup() handler.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
SyscallReturn fstat64Func(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufPtr)
Target fstat64() handler.
SyscallReturn geteuidFunc(SyscallDesc *desc, ThreadContext *tc)
Target geteuid() handler.
SyscallReturn readvFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint64_t tiov_base, size_t count)
Target readv() handler.
SyscallReturn unimplementedFunc(SyscallDesc *desc, ThreadContext *tc)
Handler for unimplemented syscalls that we haven't thought about.
std::list< BasicSignal > signalList
bool startswith(const char *s, const char *prefix)
Return true if 's' starts with the prefix string 'prefix'.
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
SyscallReturn statfsFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr bufPtr)
Target statfs() handler.
void copyOutStatBuf(PortProxy &mem, Addr addr, hst_stat *host, bool fakeTTY=false)
This class provides the wrapper interface for the system call implementations which are defined in th...
This object is a proxy for a port or other object which implements the functional response protocol...
EmulationPageTable * pTable
SyscallReturn setTidAddressFunc(SyscallDesc *desc, ThreadContext *tc, uint64_t tidPtr)
Target set_tid_address() handler.
Declarations of a non-full system Page Table.
const int SyscallPseudoReturnReg
void suspend_bitset(Addr addr, uint64_t tgid, ThreadContext *tc, int bitmask)
inserts a futex into the map with one waiting TC associates the waiter with a given bitmask ...
int wakeup_bitset(Addr addr, uint64_t tgid, int bitmask)
Wakes up all waiters waiting on the addr and associated with the given bitset.
SyscallReturn pipe2Func(SyscallDesc *desc, ThreadContext *tc, Addr tgt_addr, int flags)
Target pipe() handler.
SyscallReturn prlimitFunc(SyscallDesc *desc, ThreadContext *tc, int pid, int resource, Addr n, Addr o)
SyscallReturn readlinkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr buf, size_t bufsiz)
Target readlink() handler.
void suspend(Addr addr, uint64_t tgid, ThreadContext *tc)
Inserts a futex into the map with one waiting TC.
virtual int threadId() const =0
std::string checkPathRedirect(const std::string &filename)
Redirect file path if it matches any keys initialized by system object.
bool copyOut(PortProxy &memproxy)
copy data out of simulator space (write to target memory)
SyscallReturn chdirFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname)
Target chdir() handler.
SyscallReturn pread64Func(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufPtr, int nbytes, int offset)
SyscallReturn accessFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode)
Target access() handler.
FutexMap class holds a map of all futexes used in the system.
virtual ContextID contextId() const =0
SyscallReturn setsockoptFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int level, int optname, Addr valPtr, socklen_t len)
void convertStat64Buf(target_stat &tgt, host_stat64 *host, ByteOrder bo, bool fakeTTY=false)
SyscallReturn utimesFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr times)
Target utimes() handler.
SyscallReturn statFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr bufPtr)
Target stat() handler.
SyscallReturn getsocknameFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr addrPtr, Addr lenPtr)
BufferArg represents an untyped buffer in target user space that is passed by reference to an (emulat...
SymbolTable * debugSymbolTable
Global unified debugging symbol table (for target).
virtual void clearArchRegs()=0
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
SyscallReturn clock_gettimeFunc(SyscallDesc *desc, ThreadContext *tc, int clk_id, Addr tp_ptr)
Target clock_gettime() function.
SyscallReturn lseekFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint64_t offs, int whence)
Target lseek() handler.
Holds file descriptors needed to simulate devices opened with pseudo files (commonly with calls to io...
SyscallReturn pwrite64Func(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufPtr, int nbytes, int offset)
SyscallReturn pipeFunc(SyscallDesc *desc, ThreadContext *tc, Addr tgt_addr)
Target pipe() 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 ignoreWarnOnceFunc(SyscallDesc *desc, ThreadContext *tc)
Like above, but only prints a warning once per syscall desc it's used with.
SyscallReturn openFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, int tgt_flags, int mode)
Target open() handler.
This class represents the return value from an emulated system call, including any errno setting...
SyscallReturn fstatat64Func(SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname, Addr bufPtr)
Target fstatat64() handler.
SyscallReturn recvfromFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr bufrPtr, size_t bufrLen, int flags, Addr addrPtr, Addr addrlenPtr)
SyscallReturn stat64Func(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr bufPtr)
Target stat64() handler.
void convertStatBuf(target_stat &tgt, host_stat *host, ByteOrder bo, bool fakeTTY=false)
SyscallReturn munmapFunc(SyscallDesc *desc, ThreadContext *tc, Addr start, size_t length)
Target munmap() handler.
bool tryReadString(std::string &str, Addr addr) const
Reads the string at guest address addr into the std::string str.
GenericISA::DelaySlotPCState< MachInst > PCState
SyscallReturn renameatFunc(SyscallDesc *desc, ThreadContext *tc, int olddirfd, Addr oldpath, int newdirfd, Addr newpath)
Target renameat() 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...
const unsigned seconds_since_epoch
Approximate seconds since the epoch (1/1/1970).
SyscallReturn unlinkatFunc(SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname)
Target unlinkat() handler.
SyscallReturn faccessatFunc(SyscallDesc *desc, ThreadContext *tc, int dirfd, Addr pathname, int mode)
Target facessat() handler.
SyscallReturn acceptFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, Addr addrPtr, Addr lenPtr)
SyscallReturn gettimeofdayFunc(SyscallDesc *desc, ThreadContext *tc, Addr tv_ptr, Addr tz_ptr)
Target gettimeofday() handler.
SyscallReturn dup2Func(SyscallDesc *desc, ThreadContext *tc, int old_tgt_fd, int new_tgt_fd)
Target dup2() handler.
Addr getPageBytes() const
Get the page bytes for the ISA.
SyscallReturn fchownFunc(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, uint32_t owner, uint32_t group)
Target fchown() handler.
SyscallReturn mknodFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode, dev_t dev)
Target mknod() handler.
ByteOrder byteOrder(const ThreadContext *tc)
std::shared_ptr< FDArray > fds
SyscallReturn ftruncate64Func(SyscallDesc *desc, ThreadContext *tc, int tgt_fd, int64_t length)
Target ftruncate64() handler.