#include <iostream>
#include <string>
-#include "sim/syscall_emul.hh"
+#include "arch/utility.hh"
#include "base/chunk_generator.hh"
#include "base/trace.hh"
#include "config/the_isa.hh"
-#include "cpu/thread_context.hh"
#include "cpu/base.hh"
+#include "cpu/thread_context.hh"
+#include "debug/SyscallVerbose.hh"
#include "mem/page_table.hh"
#include "sim/process.hh"
-#include "sim/system.hh"
#include "sim/sim_exit.hh"
+#include "sim/syscall_emul.hh"
+#include "sim/system.hh"
using namespace std;
using namespace TheISA;
void
SyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc)
{
-#if TRACING_ON
- int index = 0;
-#endif
- DPRINTFR(SyscallVerbose,
- "%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n",
- curTick, tc->getCpuPtr()->name(), name,
- process->getSyscallArg(tc, index),
- process->getSyscallArg(tc, index),
- process->getSyscallArg(tc, index),
- process->getSyscallArg(tc, index));
+ if (DTRACE(SyscallVerbose)) {
+ int index = 0;
+ IntReg arg[4] M5_VAR_USED;
+
+ // we can't just put the calls to getSyscallArg() in the
+ // DPRINTF arg list, because C++ doesn't guarantee their order
+ for (int i = 0; i < 4; ++i)
+ arg[i] = process->getSyscallArg(tc, index);
+
+ DPRINTFNR("%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n",
+ curTick(), tc->getCpuPtr()->name(), name,
+ arg[0], arg[1], arg[2], arg[3]);
+ }
SyscallReturn retval = (*funcPtr)(this, callnum, process, tc);
- DPRINTFR(SyscallVerbose, "%d: %s: syscall %s returns %d\n",
- curTick,tc->getCpuPtr()->name(), name, retval.value());
+ if (retval.needsRetry()) {
+ DPRINTFS(SyscallVerbose, tc->getCpuPtr(), "syscall %s needs retry\n",
+ name);
+ } else {
+ DPRINTFS(SyscallVerbose, tc->getCpuPtr(), "syscall %s returns %d\n",
+ name, retval.encodedValue());
+ }
- if (!(flags & SyscallDesc::SuppressReturnValue))
+ if (!(flags & SyscallDesc::SuppressReturnValue) && !retval.needsRetry())
process->setSyscallReturn(tc, retval);
}
ThreadContext *tc)
{
int index = 0;
- warn("ignoring syscall %s(%d, %d, ...)", desc->name,
- process->getSyscallArg(tc, index), process->getSyscallArg(tc, index));
+ const char *extra_text = "";
+
+ if (desc->warnOnce()) {
+ if (desc->warned)
+ return 0;
+
+ desc->warned = true;
+ extra_text = "\n (further warnings will be suppressed)";
+ }
+
+ warn("ignoring syscall %s(%d, ...)%s", desc->name,
+ process->getSyscallArg(tc, index), extra_text);
return 0;
}
exitGroupFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
- // really should just halt all thread contexts belonging to this
- // process in case there's another process running...
- int index = 0;
- exitSimLoop("target called exit()",
- process->getSyscallArg(tc, index) & 0xff);
+ // halt all threads belonging to this process
+ for (auto i: process->contextIds) {
+ process->system->getThreadContext(i)->halt();
+ }
+
+ if (!process->system->numRunningContexts()) {
+ // all threads belonged to this process... exit simulator
+ int index = 0;
+ exitSimLoop("target called exit()",
+ process->getSyscallArg(tc, index) & 0xff);
+ }
return 1;
}
SyscallReturn
getpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
- return (int)VMPageSize;
+ return (int)PageBytes;
}
if (new_brk > p->brk_point) {
// might need to allocate some new pages
for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point,
- VMPageSize); !gen.done(); gen.next()) {
+ PageBytes); !gen.done(); gen.next()) {
if (!p->pTable->translate(gen.addr()))
- p->pTable->allocate(roundDown(gen.addr(), VMPageSize),
- VMPageSize);
+ p->allocateMem(roundDown(gen.addr(), PageBytes), PageBytes);
// if the address is already there, zero it out
else {
uint8_t zero = 0;
- TranslatingPort *tp = tc->getMemPort();
+ SETranslatingPortProxy &tp = tc->getMemProxy();
// split non-page aligned accesses
- Addr next_page = roundUp(gen.addr(), VMPageSize);
+ Addr next_page = roundUp(gen.addr(), PageBytes);
uint32_t size_needed = next_page - gen.addr();
- tp->memsetBlob(gen.addr(), zero, size_needed);
- if (gen.addr() + VMPageSize > next_page &&
+ tp.memsetBlob(gen.addr(), zero, size_needed);
+ if (gen.addr() + PageBytes > next_page &&
next_page < new_brk &&
p->pTable->translate(next_page))
{
- size_needed = VMPageSize - size_needed;
- tp->memsetBlob(next_page, zero, size_needed);
+ size_needed = PageBytes - size_needed;
+ tp.memsetBlob(next_page, zero, size_needed);
}
}
}
closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int index = 0;
- int target_fd = p->getSyscallArg(tc, index);
- int status = close(p->sim_fd(target_fd));
+ int tgt_fd = p->getSyscallArg(tc, index);
+
+ int sim_fd = p->getSimFD(tgt_fd);
+ if (sim_fd < 0)
+ return -EBADF;
+
+ int status = 0;
+ if (sim_fd > 2)
+ status = close(sim_fd);
if (status >= 0)
- p->free_fd(target_fd);
+ p->resetFDEntry(tgt_fd);
return status;
}
readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int index = 0;
- int fd = p->sim_fd(p->getSyscallArg(tc, index));
+ int tgt_fd = p->getSyscallArg(tc, index);
Addr bufPtr = p->getSyscallArg(tc, index);
int nbytes = p->getSyscallArg(tc, index);
BufferArg bufArg(bufPtr, nbytes);
- int bytes_read = read(fd, bufArg.bufferPtr(), nbytes);
+ int sim_fd = p->getSimFD(tgt_fd);
+ if (sim_fd < 0)
+ return -EBADF;
+
+ int bytes_read = read(sim_fd, bufArg.bufferPtr(), nbytes);
if (bytes_read != -1)
- bufArg.copyOut(tc->getMemPort());
+ bufArg.copyOut(tc->getMemProxy());
return bytes_read;
}
writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int index = 0;
- int fd = p->sim_fd(p->getSyscallArg(tc, index));
+ int tgt_fd = p->getSyscallArg(tc, index);
Addr bufPtr = p->getSyscallArg(tc, index);
int nbytes = p->getSyscallArg(tc, index);
BufferArg bufArg(bufPtr, nbytes);
- bufArg.copyIn(tc->getMemPort());
+ int sim_fd = p->getSimFD(tgt_fd);
+ if (sim_fd < 0)
+ return -EBADF;
+
+ bufArg.copyIn(tc->getMemProxy());
- int bytes_written = write(fd, bufArg.bufferPtr(), nbytes);
+ int bytes_written = write(sim_fd, bufArg.bufferPtr(), nbytes);
- fsync(fd);
+ fsync(sim_fd);
return bytes_written;
}
lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int index = 0;
- int fd = p->sim_fd(p->getSyscallArg(tc, index));
+ int tgt_fd = p->getSyscallArg(tc, index);
uint64_t offs = p->getSyscallArg(tc, index);
int whence = p->getSyscallArg(tc, index);
- off_t result = lseek(fd, offs, whence);
+ int sim_fd = p->getSimFD(tgt_fd);
+ if (sim_fd < 0)
+ return -EBADF;
+
+ off_t result = lseek(sim_fd, offs, whence);
return (result == (off_t)-1) ? -errno : result;
}
_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int index = 0;
- int fd = p->sim_fd(p->getSyscallArg(tc, index));
+ int tgt_fd = p->getSyscallArg(tc, index);
uint64_t offset_high = p->getSyscallArg(tc, index);
uint32_t offset_low = p->getSyscallArg(tc, index);
Addr result_ptr = p->getSyscallArg(tc, index);
int whence = p->getSyscallArg(tc, index);
+ int sim_fd = p->getSimFD(tgt_fd);
+ if (sim_fd < 0)
+ return -EBADF;
+
uint64_t offset = (offset_high << 32) | offset_low;
- uint64_t result = lseek(fd, offset, whence);
+ uint64_t result = lseek(sim_fd, offset, whence);
result = TheISA::htog(result);
if (result == (off_t)-1) {
// target platform
BufferArg result_buf(result_ptr, sizeof(result));
memcpy(result_buf.bufferPtr(), &result, sizeof(result));
- result_buf.copyOut(tc->getMemPort());
+ result_buf.copyOut(tc->getMemProxy());
return 0;
}
-
-
- return (result == (off_t)-1) ? -errno : result;
}
strncpy((char *)name.bufferPtr(), hostname, name_len);
- name.copyOut(tc->getMemPort());
+ name.copyOut(tc->getMemProxy());
return 0;
}
}
}
- buf.copyOut(tc->getMemPort());
+ buf.copyOut(tc->getMemProxy());
return (result == -1) ? -errno : result;
}
+/// Target open() handler.
+SyscallReturn
+readlinkFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
+ ThreadContext *tc)
+{
+ return readlinkFunc(desc, callnum, process, tc, 0);
+}
SyscallReturn
-readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
+readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc,
+ int index)
{
string path;
- int index = 0;
- if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
- return (TheISA::IntReg)-EFAULT;
+ if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
+ return -EFAULT;
// Adjust path for current working directory
path = p->fullPath(path);
int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz);
- buf.copyOut(tc->getMemPort());
+ buf.copyOut(tc->getMemProxy());
return (result == -1) ? -errno : result;
}
SyscallReturn
unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
+{
+ return unlinkHelper(desc, num, p, tc, 0);
+}
+
+SyscallReturn
+unlinkHelper(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc,
+ int index)
{
string path;
- int index = 0;
- if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
- return (TheISA::IntReg)-EFAULT;
+ if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
+ return -EFAULT;
// Adjust path for current working directory
path = p->fullPath(path);
string path;
int index = 0;
- if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
- return (TheISA::IntReg)-EFAULT;
+ if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
+ return -EFAULT;
// Adjust path for current working directory
path = p->fullPath(path);
string old_name;
int index = 0;
- if (!tc->getMemPort()->tryReadString(old_name, p->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(old_name, p->getSyscallArg(tc, index)))
return -EFAULT;
string new_name;
- if (!tc->getMemPort()->tryReadString(new_name, p->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(new_name, p->getSyscallArg(tc, index)))
return -EFAULT;
// Adjust path for current working directory
string path;
int index = 0;
- if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
return -EFAULT;
off_t length = p->getSyscallArg(tc, index);
LiveProcess *process, ThreadContext *tc)
{
int index = 0;
- int fd = process->sim_fd(process->getSyscallArg(tc, index));
+ int tgt_fd = process->getSyscallArg(tc, index);
+ off_t length = process->getSyscallArg(tc, index);
- if (fd < 0)
+ int sim_fd = process->getSimFD(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
- off_t length = process->getSyscallArg(tc, index);
-
- int result = ftruncate(fd, length);
+ int result = ftruncate(sim_fd, length);
return (result == -1) ? -errno : result;
}
int index = 0;
string path;
- if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(path, process->getSyscallArg(tc, index)))
return -EFAULT;
- loff_t length = process->getSyscallArg(tc, index, 64);
+ int64_t length = process->getSyscallArg(tc, index, 64);
// Adjust path for current working directory
path = process->fullPath(path);
+#if NO_STAT64
+ int result = truncate(path.c_str(), length);
+#else
int result = truncate64(path.c_str(), length);
+#endif
return (result == -1) ? -errno : result;
}
LiveProcess *process, ThreadContext *tc)
{
int index = 0;
- int fd = process->sim_fd(process->getSyscallArg(tc, index));
+ int tgt_fd = process->getSyscallArg(tc, index);
+ int64_t length = process->getSyscallArg(tc, index, 64);
- if (fd < 0)
+ int sim_fd = process->getSimFD(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
- loff_t length = process->getSyscallArg(tc, index, 64);
-
- int result = ftruncate64(fd, length);
+#if NO_STAT64
+ int result = ftruncate(sim_fd, length);
+#else
+ int result = ftruncate64(sim_fd, length);
+#endif
return (result == -1) ? -errno : result;
}
string path;
int index = 0;
- if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
+ if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
return -EFAULT;
/* XXX endianess */
fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
{
int index = 0;
- int fd = process->sim_fd(process->getSyscallArg(tc, index));
+ int tgt_fd = process->getSyscallArg(tc, index);
- if (fd < 0)
+ int sim_fd = process->getSimFD(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
/* XXX endianess */
uint32_t group = process->getSyscallArg(tc, index);
gid_t hostGroup = group;
- int result = fchown(fd, hostOwner, hostGroup);
+ int result = fchown(sim_fd, hostOwner, hostGroup);
return (result == -1) ? -errno : result;
}
dupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
{
int index = 0;
- int fd = process->sim_fd(process->getSyscallArg(tc, index));
- if (fd < 0)
+ int tgt_fd = process->getSyscallArg(tc, index);
+
+ int sim_fd = process->getSimFD(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
- Process::FdMap *fdo = process->sim_fd_obj(fd);
+ FDEntry *fde = process->getFDEntry(tgt_fd);
- int result = dup(fd);
+ int result = dup(sim_fd);
return (result == -1) ? -errno :
- process->alloc_fd(result, fdo->filename, fdo->flags, fdo->mode, false);
+ process->allocFD(result, fde->filename, fde->flags, fde->mode, false);
}
ThreadContext *tc)
{
int index = 0;
- int fd = process->getSyscallArg(tc, index);
+ int tgt_fd = process->getSyscallArg(tc, index);
- if (fd < 0 || process->sim_fd(fd) < 0)
+ int sim_fd = process->getSimFD(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
int cmd = process->getSyscallArg(tc, index);
case 0: // F_DUPFD
// if we really wanted to support this, we'd need to do it
// in the target fd space.
- warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd);
+ warn("fcntl(%d, F_DUPFD) not supported, error returned\n", tgt_fd);
return -EMFILE;
case 1: // F_GETFD (get close-on-exec flag)
case 4: // F_SETFL (set file flags)
// not sure if this is totally valid, but we'll pass it through
// to the underlying OS
- warn("fcntl(%d, %d) passed through to host\n", fd, cmd);
- return fcntl(process->sim_fd(fd), cmd);
+ warn("fcntl(%d, %d) passed through to host\n", tgt_fd, cmd);
+ return fcntl(sim_fd, cmd);
// return 0;
case 7: // F_GETLK (get lock)
case 8: // F_SETLK (set lock)
case 9: // F_SETLKW (set lock and wait)
// don't mess with file locking... just act like it's OK
- warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd);
+ warn("File lock call (fcntl(%d, %d)) ignored.\n", tgt_fd, cmd);
return 0;
default:
ThreadContext *tc)
{
int index = 0;
- int fd = process->getSyscallArg(tc, index);
+ int tgt_fd = process->getSyscallArg(tc, index);
- if (fd < 0 || process->sim_fd(fd) < 0)
+ int sim_fd = process->getSimFD(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
int cmd = process->getSyscallArg(tc, index);
switch (cmd) {
case 33: //F_GETLK64
- warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd);
+ warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", tgt_fd);
return -EMFILE;
case 34: // F_SETLK64
case 35: // F_SETLKW64
- warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd);
+ warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n",
+ tgt_fd);
return -EMFILE;
default:
// not sure if this is totally valid, but we'll pass it through
// to the underlying OS
- warn("fcntl64(%d, %d) passed through to host\n", fd, cmd);
- return fcntl(process->sim_fd(fd), cmd);
+ warn("fcntl64(%d, %d) passed through to host\n", tgt_fd, cmd);
+ return fcntl(sim_fd, cmd);
// return 0;
}
}
return pipe_retval;
}
- sim_fds[0] = process->alloc_fd(fds[0], "PIPE-READ", O_WRONLY, -1, true);
- sim_fds[1] = process->alloc_fd(fds[1], "PIPE-WRITE", O_RDONLY, -1, true);
+ sim_fds[0] = process->allocFD(fds[0], "PIPE-READ", O_WRONLY, -1, true);
+ sim_fds[1] = process->allocFD(fds[1], "PIPE-WRITE", O_RDONLY, -1, true);
process->setReadPipeSource(sim_fds[0], sim_fds[1]);
// Alpha Linux convention for pipe() is that fd[0] is returned as
ctc->setMiscReg(MISCREG_CWP, 0);
ctc->setIntReg(NumIntArchRegs + 7, 0);
ctc->setMiscRegNoEffect(MISCREG_TL, 0);
- ctc->setMiscRegNoEffect(MISCREG_ASI, ASI_PRIMARY);
+ ctc->setMiscReg(MISCREG_ASI, ASI_PRIMARY);
for (int y = 8; y < 32; y++)
ctc->setIntReg(y, tc->readIntReg(y));
+ #elif THE_ISA == ARM_ISA
+ TheISA::copyRegs(tc, ctc);
#else
fatal("sys_clone is not implemented for this ISA\n");
#endif
ctc->setIntReg(TheISA::SyscallPseudoReturnReg, 1);
#endif
- ctc->setPC(tc->readNextPC());
- ctc->setNextPC(tc->readNextPC() + sizeof(TheISA::MachInst));
- ctc->setNextNPC(tc->readNextNPC() + sizeof(TheISA::MachInst));
+ ctc->pcState(tc->nextInstAddr());
ctc->activate();
}
}
+SyscallReturn
+accessFunc(SyscallDesc *desc, int callnum, LiveProcess *p, ThreadContext *tc,
+ int index)
+{
+ string path;
+ if (!tc->getMemProxy().tryReadString(path, p->getSyscallArg(tc, index)))
+ return -EFAULT;
+
+ // Adjust path for current working directory
+ path = p->fullPath(path);
+
+ mode_t mode = p->getSyscallArg(tc, index);
+
+ int result = access(path.c_str(), mode);
+ return (result == -1) ? -errno : result;
+}
+
+SyscallReturn
+accessFunc(SyscallDesc *desc, int callnum, LiveProcess *p, ThreadContext *tc)
+{
+ return accessFunc(desc, callnum, p, tc, 0);
+}
+