summaryrefslogtreecommitdiff
path: root/src/sim/syscall_emul.hh
diff options
context:
space:
mode:
authorBrandon Potter <brandon.potter@amd.com>2015-07-24 12:25:23 -0700
committerBrandon Potter <brandon.potter@amd.com>2015-07-24 12:25:23 -0700
commitd5a7f09eb15bec3ecf2318418589d223beab02f4 (patch)
tree1580297c124158a4436e911367f32e09aa3ed1d7 /src/sim/syscall_emul.hh
parentb90711ea53f51d85890dd6e1bed0ca852adb8074 (diff)
downloadgem5-d5a7f09eb15bec3ecf2318418589d223beab02f4.tar.xz
syscall_emul: standardized file descriptor name and add return checks.
The patch clarifies whether file descriptors are host file descriptors or target file descriptors in the system call code. (Host file descriptors are file descriptors which have been allocated through real system calls where target file descriptors are allocated from an array in the Process class.)
Diffstat (limited to 'src/sim/syscall_emul.hh')
-rw-r--r--src/sim/syscall_emul.hh54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index b942cb601..5ed697314 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -809,20 +809,20 @@ fchmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
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;
@@ -1003,25 +1003,25 @@ fstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
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;
}
@@ -1097,21 +1097,22 @@ fstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
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;
}
@@ -1154,14 +1155,15 @@ fstatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
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;
@@ -1179,11 +1181,11 @@ writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
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);
@@ -1200,7 +1202,7 @@ writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
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;