closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int index = 0;
- int target_fd = p->getSyscallArg(tc, index);
- int sim_fd = p->sim_fd(target_fd);
+ int tgt_fd = p->getSyscallArg(tc, index);
+
+ int sim_fd = p->sim_fd(tgt_fd);
+ if (sim_fd < 0)
+ return -EBADF;
+
int status = 0;
if (sim_fd > 2)
status = close(sim_fd);
if (status >= 0)
- p->reset_fd_entry(target_fd);
+ p->reset_fd_entry(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));
- assert(fd >= 0);
+ 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->sim_fd(tgt_fd);
+ if (sim_fd < 0)
+ return -EBADF;
+
+ int bytes_read = read(sim_fd, bufArg.bufferPtr(), nbytes);
if (bytes_read != -1)
bufArg.copyOut(tc->getMemProxy());
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);
+ int sim_fd = p->sim_fd(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));
- assert(fd >= 0);
+ 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->sim_fd(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));
- assert(fd >= 0);
+ 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->sim_fd(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) {
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->sim_fd(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;
}
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->sim_fd(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
- int64_t length = process->getSyscallArg(tc, index, 64);
-
#if NO_STAT64
- int result = ftruncate(fd, length);
+ int result = ftruncate(sim_fd, length);
#else
- int result = ftruncate64(fd, length);
+ int result = ftruncate64(sim_fd, length);
#endif
return (result == -1) ? -errno : result;
}
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->sim_fd(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;
}
{
int index = 0;
int tgt_fd = process->getSyscallArg(tc, index);
+
int sim_fd = process->sim_fd(tgt_fd);
if (sim_fd < 0)
return -EBADF;
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->sim_fd(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->sim_fd(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;
}
}
ThreadContext *tc)
{
int index = 0;
- int fd = process->getSyscallArg(tc, index);
- if (fd < 0 || process->sim_fd(fd) < 0) {
- // doesn't map to any simulator fd: not a valid target fd
+ int tgt_fd = process->getSyscallArg(tc, index);
+ uint32_t mode = process->getSyscallArg(tc, index);
+
+ int sim_fd = process->sim_fd(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
- }
- uint32_t mode = process->getSyscallArg(tc, index);
mode_t hostMode = 0;
// XXX translate mode flags via OS::someting???
hostMode = mode;
// do the fchmod
- int result = fchmod(process->sim_fd(fd), hostMode);
+ int result = fchmod(sim_fd, hostMode);
if (result < 0)
return -errno;
ThreadContext *tc)
{
int index = 0;
- int fd = process->getSyscallArg(tc, index);
+ int tgt_fd = process->getSyscallArg(tc, index);
Addr bufPtr = process->getSyscallArg(tc, index);
- if (fd < 0 || process->sim_fd(fd) < 0) {
- // doesn't map to any simulator fd: not a valid target fd
+
+ int sim_fd = process->sim_fd(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
- }
#if NO_STAT64
struct stat hostBuf;
- int result = fstat(process->sim_fd(fd), &hostBuf);
+ int result = fstat(sim_fd, &hostBuf);
#else
struct stat64 hostBuf;
- int result = fstat64(process->sim_fd(fd), &hostBuf);
+ int result = fstat64(sim_fd, &hostBuf);
#endif
if (result < 0)
return -errno;
- copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (fd == 1));
+ copyOutStat64Buf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
return 0;
}
ThreadContext *tc)
{
int index = 0;
- int fd = process->sim_fd(process->getSyscallArg(tc, index));
+ int tgt_fd = process->getSyscallArg(tc, index);
Addr bufPtr = process->getSyscallArg(tc, index);
- DPRINTF(SyscallVerbose, "fstat(%d, ...)\n", fd);
+ DPRINTF(SyscallVerbose, "fstat(%d, ...)\n", tgt_fd);
- if (fd < 0)
+ int sim_fd = process->sim_fd(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
struct stat hostBuf;
- int result = fstat(fd, &hostBuf);
+ int result = fstat(sim_fd, &hostBuf);
if (result < 0)
return -errno;
- copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (fd == 1));
+ copyOutStatBuf<OS>(tc->getMemProxy(), bufPtr, &hostBuf, (sim_fd == 1));
return 0;
}
ThreadContext *tc)
{
int index = 0;
- int fd = process->sim_fd(process->getSyscallArg(tc, index));
+ int tgt_fd = process->getSyscallArg(tc, index);
Addr bufPtr = process->getSyscallArg(tc, index);
- if (fd < 0)
+ int sim_fd = process->sim_fd(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
struct statfs hostBuf;
- int result = fstatfs(fd, &hostBuf);
+ int result = fstatfs(sim_fd, &hostBuf);
if (result < 0)
return -errno;
ThreadContext *tc)
{
int index = 0;
- int fd = process->getSyscallArg(tc, index);
- if (fd < 0 || process->sim_fd(fd) < 0) {
- // doesn't map to any simulator fd: not a valid target fd
+ int tgt_fd = process->getSyscallArg(tc, index);
+
+ int sim_fd = process->sim_fd(tgt_fd);
+ if (sim_fd < 0)
return -EBADF;
- }
SETranslatingPortProxy &p = tc->getMemProxy();
uint64_t tiov_base = process->getSyscallArg(tc, index);
hiov[i].iov_len);
}
- int result = writev(process->sim_fd(fd), hiov, count);
+ int result = writev(sim_fd, hiov, count);
for (size_t i = 0; i < count; ++i)
delete [] (char *)hiov[i].iov_base;