# Node ID b1f5e8d56292a3cca2912fb593a4db6219eff803 # Parent 69069d4df5430eaa921cee75341f87d801768236 diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc --- a/src/arch/x86/linux/process.cc +++ b/src/arch/x86/linux/process.cc @@ -455,7 +455,7 @@ /* 234 */ SyscallDesc("tgkill", tgkillFunc), /* 235 */ SyscallDesc("utimes", unimplementedFunc), /* 236 */ SyscallDesc("vserver", unimplementedFunc), - /* 237 */ SyscallDesc("mbind", unimplementedFunc), + /* 237 */ SyscallDesc("mbind", mbindFunc), /* 238 */ SyscallDesc("set_mempolicy", unimplementedFunc), /* 239 */ SyscallDesc("get_mempolicy", ignoreFunc), /* 240 */ SyscallDesc("mq_open", unimplementedFunc), @@ -480,14 +480,14 @@ /* 259 */ SyscallDesc("mknodat", unimplementedFunc), /* 260 */ SyscallDesc("fchownat", unimplementedFunc), /* 261 */ SyscallDesc("futimesat", unimplementedFunc), - /* 262 */ SyscallDesc("newfstatat", unimplementedFunc), + /* 262 */ SyscallDesc("newfstatat", newfstatatFunc), /* 263 */ SyscallDesc("unlinkat", unimplementedFunc), /* 264 */ SyscallDesc("renameat", unimplementedFunc), /* 265 */ SyscallDesc("linkat", unimplementedFunc), /* 266 */ SyscallDesc("symlinkat", unimplementedFunc), /* 267 */ SyscallDesc("readlinkat", readlinkFunc), /* 268 */ SyscallDesc("fchmodat", unimplementedFunc), - /* 269 */ SyscallDesc("faccessat", unimplementedFunc), + /* 269 */ SyscallDesc("faccessat", faccessatFunc), /* 270 */ SyscallDesc("pselect6", unimplementedFunc), /* 271 */ SyscallDesc("ppoll", unimplementedFunc), /* 272 */ SyscallDesc("unshare", unimplementedFunc), diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -407,6 +407,15 @@ SyscallReturn accessFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc, int index); +/// Target mbind() handler +template +SyscallReturn mbindFunc(SyscallDesc *desc, int num, + LiveProcess *p, ThreadContext *tc) +{ + warn("Ignoring mbind call\n"); + return 0; +} + /// Futex system call /// Implemented by Daniel Sanchez /// Used by printf's in multi-threaded apps @@ -1150,6 +1159,53 @@ return 0; } +template +SyscallReturn +fstatatImpl(SyscallDesc *desc, int callnum, LiveProcess *process, + ThreadContext *tc, bool want64) +{ + int index = 0; + + int dir_fd = process->getSyscallArg(tc, index); + Addr path_address = process->getSyscallArg(tc, index); + Addr buf_ptr = process->getSyscallArg(tc, index); + + std::string path; + if (!tc->getMemProxy().tryReadString(path, path_address)) + return -EFAULT; + + if (dir_fd != OS::TGT_AT_FDCWD) { + FDEntry *fde = process->getFDEntry(dir_fd); + path = fde->filename + path; + } + + // Adjust path for current working directory + path = process->checkPathRedirect(path); + DPRINTF_SYSCALL(Verbose, "fstatatImpl: using path: %s\n", path); + + if (want64) { +#if NO_STAT64 + fatal("fstatatImpl: unable to invoke stat64 on the host"); +#else + struct stat64 host_buf; + int result = stat64(path.c_str(), &host_buf); + if (result < 0) + return -errno; + + copyOutStat64Buf(tc->getMemProxy(), buf_ptr, &host_buf); +#endif + } else { + struct stat host_buf; + int result = stat(path.c_str(), &host_buf); + + if (result < 0) + return -errno; + + copyOutStatBuf(tc->getMemProxy(), buf_ptr, &host_buf); + } + + return 0; +} /// Target fstatat64() handler. template @@ -1157,36 +1213,17 @@ fstatat64Func(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *tc) { - int index = 0; - int dirfd = process->getSyscallArg(tc, index); - if (dirfd != OS::TGT_AT_FDCWD) - warn("fstatat64: first argument not AT_FDCWD; unlikely to work"); - - std::string path; - if (!tc->getMemProxy().tryReadString(path, - process->getSyscallArg(tc, index))) - return -EFAULT; - Addr bufPtr = process->getSyscallArg(tc, index); - - // Adjust path for cwd and redirection - path = process->checkPathRedirect(path); - -#if NO_STAT64 - struct stat hostBuf; - int result = stat(path.c_str(), &hostBuf); -#else - struct stat64 hostBuf; - int result = stat64(path.c_str(), &hostBuf); -#endif - - if (result < 0) - return -errno; - - copyOutStat64Buf(tc->getMemProxy(), bufPtr, &hostBuf); - - return 0; + return fstatatImpl(desc, callnum, process, tc, true); } +/// Target newfstatat() handler. +template +SyscallReturn +newfstatatFunc(SyscallDesc *desc, int callnum, LiveProcess *process, + ThreadContext *tc) +{ + return fstatatImpl(desc, callnum, process, tc, false); +} /// Target fstat64() handler. template