Syscalls: Make system calls access arguments like a stack, not an array.

When accessing arguments for a syscall, the position of an argument depends on
the policies of the ISA, how much space preceding arguments took up, and the
"alignment" of the index for this particular argument into the number of
possible storate locations. This change adjusts getSyscallArg to take its
index parameter by reference instead of value and to adjust it to point to the
possible location of the next argument on the stack, basically just after the
current one. This way, the rules for the new argument can be applied locally
without knowing about other arguments since those have already been taken into
account implicitly.

All system calls have also been changed to reflect the new interface. In a
number of cases this made the implementation clearer since it encourages
arguments to be collected in one place in order and then used as necessary
later, as opposed to scattering them throughout the function or using them in
place in long expressions. It also discourages using getSyscallArg over and
over to retrieve the same value when a temporary would do the job.
This commit is contained in:
Gabe Black 2009-10-30 00:44:55 -07:00
parent 25d9328689
commit 3f722b991f
27 changed files with 361 additions and 229 deletions

View file

@ -48,7 +48,8 @@ static SyscallReturn
unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index));
strcpy(name->sysname, "Linux");
strcpy(name->nodename, "m5.eecs.umich.edu");
@ -67,13 +68,15 @@ static SyscallReturn
osf_getsysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
unsigned op = process->getSyscallArg(tc, 0);
int index = 0;
unsigned op = process->getSyscallArg(tc, index);
Addr bufPtr = process->getSyscallArg(tc, index);
// unsigned nbytes = process->getSyscallArg(tc, 2);
switch (op) {
case 45: { // GSI_IEEE_FP_CONTROL
TypedBufferArg<uint64_t> fpcr(process->getSyscallArg(tc, 1));
TypedBufferArg<uint64_t> fpcr(bufPtr);
// I don't think this exactly matches the HW FPCR
*fpcr = 0;
fpcr.copyOut(tc->getMemPort());
@ -94,13 +97,15 @@ static SyscallReturn
osf_setsysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
unsigned op = process->getSyscallArg(tc, 0);
int index = 0;
unsigned op = process->getSyscallArg(tc, index);
Addr bufPtr = process->getSyscallArg(tc, index);
// unsigned nbytes = process->getSyscallArg(tc, 2);
switch (op) {
case 14: { // SSI_IEEE_FP_CONTROL
TypedBufferArg<uint64_t> fpcr(process->getSyscallArg(tc, 1));
TypedBufferArg<uint64_t> fpcr(bufPtr);
// I don't think this exactly matches the HW FPCR
fpcr.copyIn(tc->getMemPort());
DPRINTFR(SyscallVerbose, "osf_setsysinfo(SSI_IEEE_FP_CONTROL): "

View file

@ -193,10 +193,10 @@ AlphaLiveProcess::startup()
}
AlphaISA::IntReg
AlphaLiveProcess::getSyscallArg(ThreadContext *tc, int i)
AlphaLiveProcess::getSyscallArg(ThreadContext *tc, int &i)
{
assert(i < 6);
return tc->readIntReg(FirstArgumentReg + i);
return tc->readIntReg(FirstArgumentReg + i++);
}
void

View file

@ -44,7 +44,7 @@ class AlphaLiveProcess : public LiveProcess
void argsInit(int intSize, int pageSize);
public:
AlphaISA::IntReg getSyscallArg(ThreadContext *tc, int i);
AlphaISA::IntReg getSyscallArg(ThreadContext *tc, int &i);
void setSyscallArg(ThreadContext *tc, int i, AlphaISA::IntReg val);
void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value);
};

View file

@ -45,7 +45,8 @@ static SyscallReturn
unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
TypedBufferArg<AlphaTru64::utsname> name(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<AlphaTru64::utsname> name(process->getSyscallArg(tc, index));
strcpy(name->sysname, "OSF1");
strcpy(name->nodename, "m5.eecs.umich.edu");
@ -62,35 +63,36 @@ static SyscallReturn
getsysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
unsigned op = process->getSyscallArg(tc, 0);
unsigned nbytes = process->getSyscallArg(tc, 2);
int index = 0;
unsigned op = process->getSyscallArg(tc, index);
Addr bufPtr = process->getSyscallArg(tc, index);
unsigned nbytes = process->getSyscallArg(tc, index);
switch (op) {
case AlphaTru64::GSI_MAX_CPU: {
TypedBufferArg<uint32_t> max_cpu(process->getSyscallArg(tc, 1));
TypedBufferArg<uint32_t> max_cpu(bufPtr);
*max_cpu = htog((uint32_t)process->numCpus());
max_cpu.copyOut(tc->getMemPort());
return 1;
}
case AlphaTru64::GSI_CPUS_IN_BOX: {
TypedBufferArg<uint32_t> cpus_in_box(process->getSyscallArg(tc, 1));
TypedBufferArg<uint32_t> cpus_in_box(bufPtr);
*cpus_in_box = htog((uint32_t)process->numCpus());
cpus_in_box.copyOut(tc->getMemPort());
return 1;
}
case AlphaTru64::GSI_PHYSMEM: {
TypedBufferArg<uint64_t> physmem(process->getSyscallArg(tc, 1));
TypedBufferArg<uint64_t> physmem(bufPtr);
*physmem = htog((uint64_t)1024 * 1024); // physical memory in KB
physmem.copyOut(tc->getMemPort());
return 1;
}
case AlphaTru64::GSI_CPU_INFO: {
TypedBufferArg<AlphaTru64::cpu_info>
infop(process->getSyscallArg(tc, 1));
TypedBufferArg<AlphaTru64::cpu_info> infop(bufPtr);
infop->current_cpu = htog(0);
infop->cpus_in_box = htog(process->numCpus());
@ -107,14 +109,14 @@ getsysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
}
case AlphaTru64::GSI_PROC_TYPE: {
TypedBufferArg<uint64_t> proc_type(process->getSyscallArg(tc, 1));
TypedBufferArg<uint64_t> proc_type(bufPtr);
*proc_type = htog((uint64_t)11);
proc_type.copyOut(tc->getMemPort());
return 1;
}
case AlphaTru64::GSI_PLATFORM_NAME: {
BufferArg bufArg(process->getSyscallArg(tc, 1), nbytes);
BufferArg bufArg(bufPtr, nbytes);
strncpy((char *)bufArg.bufferPtr(),
"COMPAQ Professional Workstation XP1000",
nbytes);
@ -123,7 +125,7 @@ getsysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
}
case AlphaTru64::GSI_CLK_TCK: {
TypedBufferArg<uint64_t> clk_hz(process->getSyscallArg(tc, 1));
TypedBufferArg<uint64_t> clk_hz(bufPtr);
*clk_hz = htog((uint64_t)1024);
clk_hz.copyOut(tc->getMemPort());
return 1;
@ -142,12 +144,13 @@ static SyscallReturn
setsysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
unsigned op = process->getSyscallArg(tc, 0);
int index = 0;
unsigned op = process->getSyscallArg(tc, index);
switch (op) {
case AlphaTru64::SSI_IEEE_FP_CONTROL:
warn("setsysinfo: ignoring ieee_set_fp_control() arg 0x%x\n",
process->getSyscallArg(tc, 1));
process->getSyscallArg(tc, index));
break;
default:
@ -165,17 +168,19 @@ tableFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
{
using namespace std;
int id = process->getSyscallArg(tc, 0); // table ID
int index = process->getSyscallArg(tc, 1); // index into table
int argIndex = 0;
int id = process->getSyscallArg(tc, argIndex); // table ID
int index = process->getSyscallArg(tc, argIndex); // index into table
Addr bufPtr = process->getSyscallArg(tc, argIndex);
// arg 2 is buffer pointer; type depends on table ID
int nel = process->getSyscallArg(tc, 3); // number of elements
int lel = process->getSyscallArg(tc, 4); // expected element size
int nel = process->getSyscallArg(tc, argIndex); // number of elements
int lel = process->getSyscallArg(tc, argIndex); // expected element size
switch (id) {
case AlphaTru64::TBL_SYSINFO: {
if (index != 0 || nel != 1 || lel != sizeof(Tru64::tbl_sysinfo))
return -EINVAL;
TypedBufferArg<Tru64::tbl_sysinfo> elp(process->getSyscallArg(tc, 2));
TypedBufferArg<Tru64::tbl_sysinfo> elp(bufPtr);
const int clk_hz = one_million;
elp->si_user = htog(curTick / (Clock::Frequency / clk_hz));

View file

@ -50,7 +50,8 @@ static SyscallReturn
unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index));
strcpy(name->sysname, "Linux");
strcpy(name->nodename, "m5.eecs.umich.edu");
@ -417,7 +418,8 @@ static SyscallReturn
setTLSFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
uint32_t tlsPtr = process->getSyscallArg(tc, 0);
int index = 0;
uint32_t tlsPtr = process->getSyscallArg(tc, index);
tc->getMemPort()->writeBlob(ArmLinuxProcess::commPage + 0x0ff0,
(uint8_t *)&tlsPtr, sizeof(tlsPtr));
@ -511,12 +513,12 @@ ArmLinuxProcess::startup()
}
ArmISA::IntReg
ArmLinuxProcess::getSyscallArg(ThreadContext *tc, int i)
ArmLinuxProcess::getSyscallArg(ThreadContext *tc, int &i)
{
// Linux apparently allows more parameter than the ABI says it should.
// This limit may need to be increased even further.
assert(i < 6);
return tc->readIntReg(ArgumentReg0 + i);
return tc->readIntReg(ArgumentReg0 + i++);
}
void

View file

@ -44,7 +44,7 @@ class ArmLinuxProcess : public ArmLiveProcess
void startup();
ArmISA::IntReg getSyscallArg(ThreadContext *tc, int i);
ArmISA::IntReg getSyscallArg(ThreadContext *tc, int &i);
void setSyscallArg(ThreadContext *tc, int i, ArmISA::IntReg val);
/// The target system's hostname.

View file

@ -324,10 +324,10 @@ ArmLiveProcess::argsInit(int intSize, int pageSize)
}
ArmISA::IntReg
ArmLiveProcess::getSyscallArg(ThreadContext *tc, int i)
ArmLiveProcess::getSyscallArg(ThreadContext *tc, int &i)
{
assert(i < 4);
return tc->readIntReg(ArgumentReg0 + i);
return tc->readIntReg(ArgumentReg0 + i++);
}
void

View file

@ -53,7 +53,7 @@ class ArmLiveProcess : public LiveProcess
public:
void argsInit(int intSize, int pageSize);
ArmISA::IntReg getSyscallArg(ThreadContext *tc, int i);
ArmISA::IntReg getSyscallArg(ThreadContext *tc, int &i);
void setSyscallArg(ThreadContext *tc, int i, ArmISA::IntReg val);
void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value);
};

View file

@ -51,7 +51,8 @@ static SyscallReturn
unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index));
strcpy(name->sysname, "Linux");
strcpy(name->nodename,"m5.eecs.umich.edu");
@ -70,14 +71,16 @@ static SyscallReturn
sys_getsysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
unsigned op = process->getSyscallArg(tc, 0);
// unsigned nbytes = process->getSyscallArg(tc, 2);
int index = 0;
unsigned op = process->getSyscallArg(tc, index);
unsigned bufPtr = process->getSyscallArg(tc, index);
// unsigned nbytes = process->getSyscallArg(tc, index);
switch (op) {
case 45:
{
// GSI_IEEE_FP_CONTROL
TypedBufferArg<uint64_t> fpcr(process->getSyscallArg(tc, 1));
TypedBufferArg<uint64_t> fpcr(bufPtr);
// I don't think this exactly matches the HW FPCR
*fpcr = 0;
fpcr.copyOut(tc->getMemPort());
@ -97,15 +100,17 @@ static SyscallReturn
sys_setsysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
unsigned op = process->getSyscallArg(tc, 0);
// unsigned nbytes = process->getSyscallArg(tc, 2);
int index = 0;
unsigned op = process->getSyscallArg(tc, index);
Addr bufPtr = process->getSyscallArg(tc, index);
// unsigned nbytes = process->getSyscallArg(tc, index);
switch (op) {
case 14:
{
// SSI_IEEE_FP_CONTROL
TypedBufferArg<uint64_t> fpcr(process->getSyscallArg(tc, 1));
TypedBufferArg<uint64_t> fpcr(bufPtr);
// I don't think this exactly matches the HW FPCR
fpcr.copyIn(tc->getMemPort());
DPRINTFR(SyscallVerbose, "sys_setsysinfo(SSI_IEEE_FP_CONTROL): "

View file

@ -147,10 +147,10 @@ MipsLiveProcess::argsInit(int intSize, int pageSize)
MipsISA::IntReg
MipsLiveProcess::getSyscallArg(ThreadContext *tc, int i)
MipsLiveProcess::getSyscallArg(ThreadContext *tc, int &i)
{
assert(i < 6);
return tc->readIntReg(FirstArgumentReg + i);
return tc->readIntReg(FirstArgumentReg + i++);
}
void

View file

@ -50,7 +50,7 @@ class MipsLiveProcess : public LiveProcess
void argsInit(int intSize, int pageSize);
public:
MipsISA::IntReg getSyscallArg(ThreadContext *tc, int i);
MipsISA::IntReg getSyscallArg(ThreadContext *tc, int &i);
void setSyscallArg(ThreadContext *tc, int i, MipsISA::IntReg val);
void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value);
};

View file

@ -52,7 +52,8 @@ static SyscallReturn
unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index));
strcpy(name->sysname, "Linux");
strcpy(name->nodename, "m5.eecs.umich.edu");
@ -437,12 +438,12 @@ PowerLinuxProcess::startup()
}
PowerISA::IntReg
PowerLinuxProcess::getSyscallArg(ThreadContext *tc, int i)
PowerLinuxProcess::getSyscallArg(ThreadContext *tc, int &i)
{
// Linux apparently allows more parameter than the ABI says it should.
// This limit may need to be increased even further.
assert(i < 6);
return tc->readIntReg(ArgumentReg0 + i);
return tc->readIntReg(ArgumentReg0 + i++);
}
void

View file

@ -46,7 +46,7 @@ class PowerLinuxProcess : public PowerLiveProcess
void startup();
PowerISA::IntReg getSyscallArg(ThreadContext *tc, int i);
PowerISA::IntReg getSyscallArg(ThreadContext *tc, int &i);
void setSyscallArg(ThreadContext *tc, int i, PowerISA::IntReg val);
/// Array of syscall descriptors, indexed by call number.

View file

@ -266,10 +266,10 @@ PowerLiveProcess::argsInit(int intSize, int pageSize)
}
PowerISA::IntReg
PowerLiveProcess::getSyscallArg(ThreadContext *tc, int i)
PowerLiveProcess::getSyscallArg(ThreadContext *tc, int &i)
{
assert(i < 5);
return tc->readIntReg(ArgumentReg0 + i);
return tc->readIntReg(ArgumentReg0 + i++);
}
void

View file

@ -50,7 +50,7 @@ class PowerLiveProcess : public LiveProcess
public:
void argsInit(int intSize, int pageSize);
PowerISA::IntReg getSyscallArg(ThreadContext *tc, int i);
PowerISA::IntReg getSyscallArg(ThreadContext *tc, int &i);
void setSyscallArg(ThreadContext *tc, int i, PowerISA::IntReg val);
void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value);
};

View file

@ -41,7 +41,8 @@ static SyscallReturn
unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index));
strcpy(name->sysname, "Linux");
strcpy(name->nodename, "m5.eecs.umich.edu");
@ -59,9 +60,10 @@ SyscallReturn getresuidFunc(SyscallDesc *desc, int num,
LiveProcess *p, ThreadContext *tc)
{
const IntReg id = htog(100);
Addr ruid = p->getSyscallArg(tc, 0);
Addr euid = p->getSyscallArg(tc, 1);
Addr suid = p->getSyscallArg(tc, 2);
int index = 0;
Addr ruid = p->getSyscallArg(tc, index);
Addr euid = p->getSyscallArg(tc, index);
Addr suid = p->getSyscallArg(tc, index);
//Handle the EFAULT case
//Set the ruid
if(ruid)

View file

@ -514,10 +514,10 @@ void Sparc64LiveProcess::flushWindows(ThreadContext *tc)
}
IntReg
Sparc32LiveProcess::getSyscallArg(ThreadContext *tc, int i)
Sparc32LiveProcess::getSyscallArg(ThreadContext *tc, int &i)
{
assert(i < 6);
return bits(tc->readIntReg(FirstArgumentReg + i), 31, 0);
return bits(tc->readIntReg(FirstArgumentReg + i++), 31, 0);
}
void
@ -528,10 +528,10 @@ Sparc32LiveProcess::setSyscallArg(ThreadContext *tc, int i, IntReg val)
}
IntReg
Sparc64LiveProcess::getSyscallArg(ThreadContext *tc, int i)
Sparc64LiveProcess::getSyscallArg(ThreadContext *tc, int &i)
{
assert(i < 6);
return tc->readIntReg(FirstArgumentReg + i);
return tc->readIntReg(FirstArgumentReg + i++);
}
void

View file

@ -95,7 +95,7 @@ class Sparc32LiveProcess : public SparcLiveProcess
void flushWindows(ThreadContext *tc);
SparcISA::IntReg getSyscallArg(ThreadContext *tc, int i);
SparcISA::IntReg getSyscallArg(ThreadContext *tc, int &i);
void setSyscallArg(ThreadContext *tc, int i, SparcISA::IntReg val);
};
@ -123,7 +123,7 @@ class Sparc64LiveProcess : public SparcLiveProcess
void flushWindows(ThreadContext *tc);
SparcISA::IntReg getSyscallArg(ThreadContext *tc, int i);
SparcISA::IntReg getSyscallArg(ThreadContext *tc, int &i);
void setSyscallArg(ThreadContext *tc, int i, SparcISA::IntReg val);
};

View file

@ -48,7 +48,8 @@ static SyscallReturn
unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
TypedBufferArg<Solaris::utsname> name(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<Solaris::utsname> name(process->getSyscallArg(tc, index));
strcpy(name->sysname, "SunOS");
strcpy(name->nodename, "m5.eecs.umich.edu");

View file

@ -68,7 +68,8 @@ static SyscallReturn
unameFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<Linux::utsname> name(process->getSyscallArg(tc, index));
strcpy(name->sysname, "Linux");
strcpy(name->nodename, "m5.eecs.umich.edu");
@ -94,8 +95,9 @@ archPrctlFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
};
//First argument is the code, second is the address
int code = process->getSyscallArg(tc, 0);
uint64_t addr = process->getSyscallArg(tc, 1);
int index = 0;
int code = process->getSyscallArg(tc, index);
uint64_t addr = process->getSyscallArg(tc, index);
uint64_t fsBase, gsBase;
TranslatingPort *p = tc->getMemPort();
switch(code)
@ -159,7 +161,8 @@ setThreadArea32Func(SyscallDesc *desc, int callnum,
assert((maxTLSEntry + 1) * sizeof(uint64_t) <= x86lp->gdtSize());
TypedBufferArg<UserDesc32> userDesc(process->getSyscallArg(tc, 0));
int argIndex = 0;
TypedBufferArg<UserDesc32> userDesc(process->getSyscallArg(tc, argIndex));
TypedBufferArg<uint64_t>
gdt(x86lp->gdtStart() + minTLSEntry * sizeof(uint64_t),
numTLSEntries * sizeof(uint64_t));

View file

@ -698,10 +698,10 @@ X86LiveProcess::setSyscallReturn(ThreadContext *tc, SyscallReturn return_value)
}
X86ISA::IntReg
X86_64LiveProcess::getSyscallArg(ThreadContext *tc, int i)
X86_64LiveProcess::getSyscallArg(ThreadContext *tc, int &i)
{
assert(i < NumArgumentRegs);
return tc->readIntReg(ArgumentReg[i]);
return tc->readIntReg(ArgumentReg[i++]);
}
void
@ -712,10 +712,21 @@ X86_64LiveProcess::setSyscallArg(ThreadContext *tc, int i, X86ISA::IntReg val)
}
X86ISA::IntReg
I386LiveProcess::getSyscallArg(ThreadContext *tc, int i)
I386LiveProcess::getSyscallArg(ThreadContext *tc, int &i)
{
assert(i < NumArgumentRegs32);
return tc->readIntReg(ArgumentReg32[i]);
return tc->readIntReg(ArgumentReg32[i++]);
}
X86ISA::IntReg
I386LiveProcess::getSyscallArg(ThreadContext *tc, int &i, int width)
{
assert(width == 32 || width == 64);
assert(i < NumArgumentRegs);
uint64_t retVal = tc->readIntReg(ArgumentReg32[i++]) & mask(32);
if (width == 64)
retVal |= ((uint64_t)tc->readIntReg(ArgumentReg[i++]) << 32);
return retVal;
}
void

View file

@ -105,7 +105,7 @@ namespace X86ISA
void argsInit(int intSize, int pageSize);
void startup();
X86ISA::IntReg getSyscallArg(ThreadContext *tc, int i);
X86ISA::IntReg getSyscallArg(ThreadContext *tc, int &i);
void setSyscallArg(ThreadContext *tc, int i, X86ISA::IntReg val);
};
@ -130,7 +130,8 @@ namespace X86ISA
void startup();
void syscall(int64_t callnum, ThreadContext *tc);
X86ISA::IntReg getSyscallArg(ThreadContext *tc, int i);
X86ISA::IntReg getSyscallArg(ThreadContext *tc, int &i);
X86ISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width);
void setSyscallArg(ThreadContext *tc, int i, X86ISA::IntReg val);
};
}

View file

@ -440,10 +440,11 @@ class Tru64 : public OperatingSystem
#ifdef __CYGWIN__
panic("getdirent not implemented on cygwin!");
#else
int fd = process->sim_fd(process->getSyscallArg(tc, 0));
Addr tgt_buf = process->getSyscallArg(tc, 1);
int tgt_nbytes = process->getSyscallArg(tc, 2);
Addr tgt_basep = process->getSyscallArg(tc, 3);
int index = 0;
int fd = process->sim_fd(process->getSyscallArg(tc, index));
Addr tgt_buf = process->getSyscallArg(tc, index);
int tgt_nbytes = process->getSyscallArg(tc, index);
Addr tgt_basep = process->getSyscallArg(tc, index);
char * const host_buf = new char[tgt_nbytes];
@ -498,7 +499,8 @@ class Tru64 : public OperatingSystem
{
using namespace TheISA;
TypedBufferArg<Tru64::sigcontext> sc(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<Tru64::sigcontext> sc(process->getSyscallArg(tc, index));
sc.copyIn(tc->getMemPort());
@ -530,7 +532,8 @@ class Tru64 : public OperatingSystem
{
using namespace TheISA;
TypedBufferArg<Tru64::vm_stack> argp(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<Tru64::vm_stack> argp(process->getSyscallArg(tc, index));
argp.copyIn(tc->getMemPort());
@ -578,9 +581,10 @@ class Tru64 : public OperatingSystem
using namespace std;
using namespace TheISA;
int index = 0;
TypedBufferArg<Tru64::nxm_task_attr>
attrp(process->getSyscallArg(tc, 0));
TypedBufferArg<Addr> configptr_ptr(process->getSyscallArg(tc, 1));
attrp(process->getSyscallArg(tc, index));
TypedBufferArg<Addr> configptr_ptr(process->getSyscallArg(tc, index));
attrp.copyIn(tc->getMemPort());
@ -712,10 +716,11 @@ class Tru64 : public OperatingSystem
using namespace std;
using namespace TheISA;
int index = 0;
TypedBufferArg<Tru64::nxm_thread_attr>
attrp(process->getSyscallArg(tc, 0));
TypedBufferArg<uint64_t> kidp(process->getSyscallArg(tc, 1));
int thread_index = process->getSyscallArg(tc, 2);
attrp(process->getSyscallArg(tc, index));
TypedBufferArg<uint64_t> kidp(process->getSyscallArg(tc, index));
int thread_index = process->getSyscallArg(tc, index);
// get attribute args
attrp.copyIn(tc->getMemPort());
@ -834,11 +839,12 @@ class Tru64 : public OperatingSystem
{
using namespace std;
uint64_t tid = process->getSyscallArg(tc, 0);
uint64_t secs = process->getSyscallArg(tc, 1);
uint64_t flags = process->getSyscallArg(tc, 2);
uint64_t action = process->getSyscallArg(tc, 3);
uint64_t usecs = process->getSyscallArg(tc, 4);
int index = 0;
uint64_t tid = process->getSyscallArg(tc, index);
uint64_t secs = process->getSyscallArg(tc, index);
uint64_t flags = process->getSyscallArg(tc, index);
uint64_t action = process->getSyscallArg(tc, index);
uint64_t usecs = process->getSyscallArg(tc, index);
cout << tc->getCpuPtr()->name() << ": nxm_thread_block " << tid << " "
<< secs << " " << flags << " " << action << " " << usecs << endl;
@ -853,11 +859,12 @@ class Tru64 : public OperatingSystem
{
using namespace std;
Addr uaddr = process->getSyscallArg(tc, 0);
uint64_t val = process->getSyscallArg(tc, 1);
uint64_t secs = process->getSyscallArg(tc, 2);
uint64_t usecs = process->getSyscallArg(tc, 3);
uint64_t flags = process->getSyscallArg(tc, 4);
int index = 0;
Addr uaddr = process->getSyscallArg(tc, index);
uint64_t val = process->getSyscallArg(tc, index);
uint64_t secs = process->getSyscallArg(tc, index);
uint64_t usecs = process->getSyscallArg(tc, index);
uint64_t flags = process->getSyscallArg(tc, index);
BaseCPU *cpu = tc->getCpuPtr();
@ -876,7 +883,8 @@ class Tru64 : public OperatingSystem
{
using namespace std;
Addr uaddr = process->getSyscallArg(tc, 0);
int index = 0;
Addr uaddr = process->getSyscallArg(tc, index);
cout << tc->getCpuPtr()->name() << ": nxm_unblock "
<< hex << uaddr << dec << endl;
@ -977,7 +985,8 @@ class Tru64 : public OperatingSystem
m5_mutex_lockFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
Addr uaddr = process->getSyscallArg(tc, 0);
int index = 0;
Addr uaddr = process->getSyscallArg(tc, index);
m5_lock_mutex(uaddr, process, tc);
@ -994,7 +1003,8 @@ class Tru64 : public OperatingSystem
{
using namespace TheISA;
Addr uaddr = process->getSyscallArg(tc, 0);
int index = 0;
Addr uaddr = process->getSyscallArg(tc, index);
TypedBufferArg<uint64_t> lockp(uaddr);
lockp.copyIn(tc->getMemPort());
@ -1014,7 +1024,8 @@ class Tru64 : public OperatingSystem
m5_mutex_unlockFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
Addr uaddr = process->getSyscallArg(tc, 0);
int index = 0;
Addr uaddr = process->getSyscallArg(tc, index);
m5_unlock_mutex(uaddr, process, tc);
@ -1026,7 +1037,8 @@ class Tru64 : public OperatingSystem
m5_cond_signalFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
Addr cond_addr = process->getSyscallArg(tc, 0);
int index = 0;
Addr cond_addr = process->getSyscallArg(tc, index);
// Wake up one process waiting on the condition variable.
activate_waiting_context(cond_addr, process);
@ -1039,7 +1051,8 @@ class Tru64 : public OperatingSystem
m5_cond_broadcastFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
Addr cond_addr = process->getSyscallArg(tc, 0);
int index = 0;
Addr cond_addr = process->getSyscallArg(tc, index);
activate_waiting_context(cond_addr, process, true);
@ -1053,8 +1066,9 @@ class Tru64 : public OperatingSystem
{
using namespace TheISA;
Addr cond_addr = process->getSyscallArg(tc, 0);
Addr lock_addr = process->getSyscallArg(tc, 1);
int index = 0;
Addr cond_addr = process->getSyscallArg(tc, index);
Addr lock_addr = process->getSyscallArg(tc, index);
TypedBufferArg<uint64_t> condp(cond_addr);
TypedBufferArg<uint64_t> lockp(lock_addr);
@ -1086,10 +1100,11 @@ class Tru64 : public OperatingSystem
indirectSyscallFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
int new_callnum = process->getSyscallArg(tc, 0);
int index = 0;
int new_callnum = process->getSyscallArg(tc, index);
for (int i = 0; i < 5; ++i)
process->setSyscallArg(tc, i, process->getSyscallArg(tc, i+1));
process->setSyscallArg(tc, i, process->getSyscallArg(tc, index));
SyscallDesc *new_desc = process->getDesc(new_callnum);

View file

@ -647,6 +647,12 @@ LiveProcess::syscall(int64_t callnum, ThreadContext *tc)
desc->doSyscall(callnum, this, tc);
}
IntReg
LiveProcess::getSyscallArg(ThreadContext *tc, int &i, int width)
{
return getSyscallArg(tc, i);
}
LiveProcess *
LiveProcess::create(LiveProcessParams * params)
{

View file

@ -325,7 +325,9 @@ class LiveProcess : public Process
std::string getcwd() const { return cwd; }
virtual void syscall(int64_t callnum, ThreadContext *tc);
virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int i) = 0;
virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0;
virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width);
virtual void setSyscallArg(ThreadContext *tc,
int i, TheISA::IntReg val) = 0;
virtual void setSyscallReturn(ThreadContext *tc,

View file

@ -52,11 +52,14 @@ using namespace TheISA;
void
SyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc)
{
int index = 0;
DPRINTFR(SyscallVerbose,
"%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n",
curTick, tc->getCpuPtr()->name(), name,
process->getSyscallArg(tc, 0), process->getSyscallArg(tc, 1),
process->getSyscallArg(tc, 2), process->getSyscallArg(tc, 3));
process->getSyscallArg(tc, index),
process->getSyscallArg(tc, index),
process->getSyscallArg(tc, index),
process->getSyscallArg(tc, index));
SyscallReturn retval = (*funcPtr)(this, callnum, process, tc);
@ -82,8 +85,9 @@ SyscallReturn
ignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
int index = 0;
warn("ignoring syscall %s(%d, %d, ...)", desc->name,
process->getSyscallArg(tc, 0), process->getSyscallArg(tc, 1));
process->getSyscallArg(tc, index), process->getSyscallArg(tc, index));
return 0;
}
@ -95,8 +99,9 @@ exitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
{
if (process->system->numRunningContexts() == 1) {
// Last running context... exit simulator
int index = 0;
exitSimLoop("target called exit()",
process->getSyscallArg(tc, 0) & 0xff);
process->getSyscallArg(tc, index) & 0xff);
} else {
// other running threads... just halt this one
tc->halt();
@ -112,8 +117,9 @@ exitGroupFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
{
// 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, 0) & 0xff);
process->getSyscallArg(tc, index) & 0xff);
return 1;
}
@ -130,7 +136,8 @@ SyscallReturn
brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
// change brk addr to first arg
Addr new_brk = p->getSyscallArg(tc, 0);
int index = 0;
Addr new_brk = p->getSyscallArg(tc, index);
// in Linux at least, brk(0) returns the current break value
// (note that the syscall and the glibc function have different behavior)
@ -174,7 +181,8 @@ brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
SyscallReturn
closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int target_fd = p->getSyscallArg(tc, 0);
int index = 0;
int target_fd = p->getSyscallArg(tc, index);
int status = close(p->sim_fd(target_fd));
if (status >= 0)
p->free_fd(target_fd);
@ -185,9 +193,11 @@ closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
SyscallReturn
readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int fd = p->sim_fd(p->getSyscallArg(tc, 0));
int nbytes = p->getSyscallArg(tc, 2);
BufferArg bufArg(p->getSyscallArg(tc, 1), nbytes);
int index = 0;
int fd = p->sim_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);
@ -200,9 +210,11 @@ readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
SyscallReturn
writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int fd = p->sim_fd(p->getSyscallArg(tc, 0));
int nbytes = p->getSyscallArg(tc, 2);
BufferArg bufArg(p->getSyscallArg(tc, 1), nbytes);
int index = 0;
int fd = p->sim_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());
@ -217,9 +229,10 @@ writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
SyscallReturn
lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int fd = p->sim_fd(p->getSyscallArg(tc, 0));
uint64_t offs = p->getSyscallArg(tc, 1);
int whence = p->getSyscallArg(tc, 2);
int index = 0;
int fd = p->sim_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);
@ -230,11 +243,12 @@ lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
SyscallReturn
_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int fd = p->sim_fd(p->getSyscallArg(tc, 0));
uint64_t offset_high = p->getSyscallArg(tc, 1);
uint32_t offset_low = p->getSyscallArg(tc, 2);
Addr result_ptr = p->getSyscallArg(tc, 3);
int whence = p->getSyscallArg(tc, 4);
int index = 0;
int fd = p->sim_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);
uint64_t offset = (offset_high << 32) | offset_low;
@ -273,8 +287,10 @@ const char *hostname = "m5.eecs.umich.edu";
SyscallReturn
gethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int name_len = p->getSyscallArg(tc, 1);
BufferArg name(p->getSyscallArg(tc, 0), name_len);
int index = 0;
Addr bufPtr = p->getSyscallArg(tc, index);
int name_len = p->getSyscallArg(tc, index);
BufferArg name(bufPtr, name_len);
strncpy((char *)name.bufferPtr(), hostname, name_len);
@ -287,8 +303,10 @@ SyscallReturn
getcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
int result = 0;
unsigned long size = p->getSyscallArg(tc, 1);
BufferArg buf(p->getSyscallArg(tc, 0), size);
int index;
Addr bufPtr = p->getSyscallArg(tc, index);
unsigned long size = p->getSyscallArg(tc, index);
BufferArg buf(bufPtr, size);
// Is current working directory defined?
string cwd = p->getcwd();
@ -320,14 +338,17 @@ readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
string path;
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
return (TheISA::IntReg)-EFAULT;
// Adjust path for current working directory
path = p->fullPath(path);
size_t bufsiz = p->getSyscallArg(tc, 2);
BufferArg buf(p->getSyscallArg(tc, 1), bufsiz);
Addr bufPtr = p->getSyscallArg(tc, index);
size_t bufsiz = p->getSyscallArg(tc, index);
BufferArg buf(bufPtr, bufsiz);
int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz);
@ -341,7 +362,8 @@ unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
string path;
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
return (TheISA::IntReg)-EFAULT;
// Adjust path for current working directory
@ -357,13 +379,14 @@ mkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
string path;
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
return (TheISA::IntReg)-EFAULT;
// Adjust path for current working directory
path = p->fullPath(path);
mode_t mode = p->getSyscallArg(tc, 1);
mode_t mode = p->getSyscallArg(tc, index);
int result = mkdir(path.c_str(), mode);
return (result == -1) ? -errno : result;
@ -374,12 +397,13 @@ renameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
string old_name;
if (!tc->getMemPort()->tryReadString(old_name, p->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(old_name, p->getSyscallArg(tc, index)))
return -EFAULT;
string new_name;
if (!tc->getMemPort()->tryReadString(new_name, p->getSyscallArg(tc, 1)))
if (!tc->getMemPort()->tryReadString(new_name, p->getSyscallArg(tc, index)))
return -EFAULT;
// Adjust path for current working directory
@ -395,10 +419,11 @@ truncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
string path;
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
return -EFAULT;
off_t length = p->getSyscallArg(tc, 1);
off_t length = p->getSyscallArg(tc, index);
// Adjust path for current working directory
path = p->fullPath(path);
@ -411,12 +436,13 @@ SyscallReturn
ftruncateFunc(SyscallDesc *desc, int num,
LiveProcess *process, ThreadContext *tc)
{
int fd = process->sim_fd(process->getSyscallArg(tc, 0));
int index = 0;
int fd = process->sim_fd(process->getSyscallArg(tc, index));
if (fd < 0)
return -EBADF;
off_t length = process->getSyscallArg(tc, 1);
off_t length = process->getSyscallArg(tc, index);
int result = ftruncate(fd, length);
return (result == -1) ? -errno : result;
@ -426,13 +452,13 @@ SyscallReturn
ftruncate64Func(SyscallDesc *desc, int num,
LiveProcess *process, ThreadContext *tc)
{
int fd = process->sim_fd(process->getSyscallArg(tc, 0));
int index = 0;
int fd = process->sim_fd(process->getSyscallArg(tc, index));
if (fd < 0)
return -EBADF;
// I'm not sure why, but the length argument is in arg reg 3
loff_t length = process->getSyscallArg(tc, 3);
loff_t length = process->getSyscallArg(tc, index, 64);
int result = ftruncate64(fd, length);
return (result == -1) ? -errno : result;
@ -454,13 +480,14 @@ chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
string path;
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path, p->getSyscallArg(tc, index)))
return -EFAULT;
/* XXX endianess */
uint32_t owner = p->getSyscallArg(tc, 1);
uint32_t owner = p->getSyscallArg(tc, index);
uid_t hostOwner = owner;
uint32_t group = p->getSyscallArg(tc, 2);
uint32_t group = p->getSyscallArg(tc, index);
gid_t hostGroup = group;
// Adjust path for current working directory
@ -473,15 +500,16 @@ chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
SyscallReturn
fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
{
int fd = process->sim_fd(process->getSyscallArg(tc, 0));
int index = 0;
int fd = process->sim_fd(process->getSyscallArg(tc, index));
if (fd < 0)
return -EBADF;
/* XXX endianess */
uint32_t owner = process->getSyscallArg(tc, 1);
uint32_t owner = process->getSyscallArg(tc, index);
uid_t hostOwner = owner;
uint32_t group = process->getSyscallArg(tc, 2);
uint32_t group = process->getSyscallArg(tc, index);
gid_t hostGroup = group;
int result = fchown(fd, hostOwner, hostGroup);
@ -492,11 +520,12 @@ fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
SyscallReturn
dupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
{
int fd = process->sim_fd(process->getSyscallArg(tc, 0));
int index = 0;
int fd = process->sim_fd(process->getSyscallArg(tc, index));
if (fd < 0)
return -EBADF;
Process::FdMap *fdo = process->sim_fd_obj(process->getSyscallArg(tc, 0));
Process::FdMap *fdo = process->sim_fd_obj(fd);
int result = dup(fd);
return (result == -1) ? -errno :
@ -508,12 +537,13 @@ SyscallReturn
fcntlFunc(SyscallDesc *desc, int num, LiveProcess *process,
ThreadContext *tc)
{
int fd = process->getSyscallArg(tc, 0);
int index = 0;
int fd = process->getSyscallArg(tc, index);
if (fd < 0 || process->sim_fd(fd) < 0)
return -EBADF;
int cmd = process->getSyscallArg(tc, 1);
int cmd = process->getSyscallArg(tc, index);
switch (cmd) {
case 0: // F_DUPFD
// if we really wanted to support this, we'd need to do it
@ -550,12 +580,13 @@ SyscallReturn
fcntl64Func(SyscallDesc *desc, int num, LiveProcess *process,
ThreadContext *tc)
{
int fd = process->getSyscallArg(tc, 0);
int index = 0;
int fd = process->getSyscallArg(tc, index);
if (fd < 0 || process->sim_fd(fd) < 0)
return -EBADF;
int cmd = process->getSyscallArg(tc, 1);
int cmd = process->getSyscallArg(tc, index);
switch (cmd) {
case 33: //F_GETLK64
warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd);
@ -639,7 +670,8 @@ setuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
// can't fathom why a benchmark would call this.
warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, 0));
int index = 0;
warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, index));
return 0;
}
@ -695,17 +727,20 @@ SyscallReturn
cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
int index = 0;
IntReg flags = process->getSyscallArg(tc, index);
IntReg newStack = process->getSyscallArg(tc, index);
DPRINTF(SyscallVerbose, "In sys_clone:\n");
DPRINTF(SyscallVerbose, " Flags=%llx\n", process->getSyscallArg(tc, 0));
DPRINTF(SyscallVerbose, " Child stack=%llx\n",
process->getSyscallArg(tc, 1));
DPRINTF(SyscallVerbose, " Flags=%llx\n", flags);
DPRINTF(SyscallVerbose, " Child stack=%llx\n", newStack);
if (process->getSyscallArg(tc, 0) != 0x10f00) {
if (flags != 0x10f00) {
warn("This sys_clone implementation assumes flags "
"CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD "
"(0x10f00), and may not work correctly with given flags "
"0x%llx\n", process->getSyscallArg(tc, 0));
"0x%llx\n", flags);
}
ThreadContext* ctc; // child thread context
@ -738,7 +773,7 @@ cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
#endif
// Set up stack register
ctc->setIntReg(TheISA::StackPointerReg, process->getSyscallArg(tc, 1));
ctc->setIntReg(TheISA::StackPointerReg, newStack);
// Set up syscall return values in parent and child
ctc->setIntReg(ReturnValueReg, 0); // return value, child

View file

@ -481,8 +481,9 @@ SyscallReturn
ioctlFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
int fd = process->getSyscallArg(tc, 0);
unsigned req = process->getSyscallArg(tc, 1);
int index = 0;
int fd = process->getSyscallArg(tc, index);
unsigned req = process->getSyscallArg(tc, index);
DPRINTF(SyscallVerbose, "ioctl(%d, 0x%x, ...)\n", fd, req);
@ -517,7 +518,9 @@ openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
{
std::string path;
if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path,
process->getSyscallArg(tc, index)))
return -EFAULT;
if (path == "/dev/sysdev0") {
@ -527,8 +530,8 @@ openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
return -ENOENT;
}
int tgtFlags = process->getSyscallArg(tc, 1);
int mode = process->getSyscallArg(tc, 2);
int tgtFlags = process->getSyscallArg(tc, index);
int mode = process->getSyscallArg(tc, index);
int hostFlags = 0;
// translate open flags
@ -573,7 +576,9 @@ sysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
TypedBufferArg<typename OS::tgt_sysinfo> sysinfo(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<typename OS::tgt_sysinfo>
sysinfo(process->getSyscallArg(tc, index));
sysinfo->uptime=seconds_since_epoch;
sysinfo->totalram=process->system->memSize();
@ -591,10 +596,13 @@ chmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
{
std::string path;
if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
uint32_t mode = process->getSyscallArg(tc, 1);
uint32_t mode = process->getSyscallArg(tc, index);
mode_t hostMode = 0;
// XXX translate mode flags via OS::something???
@ -618,13 +626,14 @@ SyscallReturn
fchmodFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
int fd = process->getSyscallArg(tc, 0);
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
return -EBADF;
}
uint32_t mode = process->getSyscallArg(tc, 1);
uint32_t mode = process->getSyscallArg(tc, index);
mode_t hostMode = 0;
// XXX translate mode flags via OS::someting???
@ -643,10 +652,11 @@ template <class OS>
SyscallReturn
mremapFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *tc)
{
Addr start = process->getSyscallArg(tc, 0);
uint64_t old_length = process->getSyscallArg(tc, 1);
uint64_t new_length = process->getSyscallArg(tc, 2);
uint64_t flags = process->getSyscallArg(tc, 3);
int index = 0;
Addr start = process->getSyscallArg(tc, index);
uint64_t old_length = process->getSyscallArg(tc, index);
uint64_t new_length = process->getSyscallArg(tc, index);
uint64_t flags = process->getSyscallArg(tc, index);
if ((start % TheISA::VMPageSize != 0) ||
(new_length % TheISA::VMPageSize != 0)) {
@ -692,8 +702,12 @@ statFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
{
std::string path;
if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
Addr bufPtr = process->getSyscallArg(tc, index);
// Adjust path for current working directory
path = process->fullPath(path);
@ -704,8 +718,7 @@ statFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
if (result < 0)
return -errno;
copyOutStatBuf<OS>(tc->getMemPort(), process->getSyscallArg(tc, 1),
&hostBuf);
copyOutStatBuf<OS>(tc->getMemPort(), bufPtr, &hostBuf);
return 0;
}
@ -719,8 +732,11 @@ stat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
{
std::string path;
if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path,
process->getSyscallArg(tc, index)))
return -EFAULT;
Addr bufPtr = process->getSyscallArg(tc, index);
// Adjust path for current working directory
path = process->fullPath(path);
@ -736,8 +752,7 @@ stat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
if (result < 0)
return -errno;
copyOutStat64Buf<OS>(tc->getMemPort(), process->getSyscallArg(tc, 1),
&hostBuf);
copyOutStat64Buf<OS>(tc->getMemPort(), bufPtr, &hostBuf);
return 0;
}
@ -749,7 +764,9 @@ SyscallReturn
fstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
int fd = process->getSyscallArg(tc, 0);
int index = 0;
int 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
return -EBADF;
@ -766,8 +783,7 @@ fstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
if (result < 0)
return -errno;
copyOutStat64Buf<OS>(tc->getMemPort(), process->getSyscallArg(tc, 1),
&hostBuf, (fd == 1));
copyOutStat64Buf<OS>(tc->getMemPort(), bufPtr, &hostBuf, (fd == 1));
return 0;
}
@ -781,8 +797,12 @@ lstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
{
std::string path;
if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
Addr bufPtr = process->getSyscallArg(tc, index);
// Adjust path for current working directory
path = process->fullPath(path);
@ -793,8 +813,7 @@ lstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
if (result < 0)
return -errno;
copyOutStatBuf<OS>(tc->getMemPort(), process->getSyscallArg(tc, 1),
&hostBuf);
copyOutStatBuf<OS>(tc->getMemPort(), bufPtr, &hostBuf);
return 0;
}
@ -807,8 +826,12 @@ lstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
{
std::string path;
if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
Addr bufPtr = process->getSyscallArg(tc, index);
// Adjust path for current working directory
path = process->fullPath(path);
@ -824,8 +847,7 @@ lstat64Func(SyscallDesc *desc, int callnum, LiveProcess *process,
if (result < 0)
return -errno;
copyOutStat64Buf<OS>(tc->getMemPort(), process->getSyscallArg(tc, 1),
&hostBuf);
copyOutStat64Buf<OS>(tc->getMemPort(), bufPtr, &hostBuf);
return 0;
}
@ -836,7 +858,9 @@ SyscallReturn
fstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
int fd = process->sim_fd(process->getSyscallArg(tc, 0));
int index = 0;
int fd = process->sim_fd(process->getSyscallArg(tc, index));
Addr bufPtr = process->getSyscallArg(tc, index);
DPRINTF(SyscallVerbose, "fstat(%d, ...)\n", fd);
@ -849,8 +873,7 @@ fstatFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
if (result < 0)
return -errno;
copyOutStatBuf<OS>(tc->getMemPort(), process->getSyscallArg(tc, 1),
&hostBuf, (fd == 1));
copyOutStatBuf<OS>(tc->getMemPort(), bufPtr, &hostBuf, (fd == 1));
return 0;
}
@ -864,8 +887,12 @@ statfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
{
std::string path;
if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
Addr bufPtr = process->getSyscallArg(tc, index);
// Adjust path for current working directory
path = process->fullPath(path);
@ -876,8 +903,7 @@ statfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
if (result < 0)
return -errno;
OS::copyOutStatfsBuf(tc->getMemPort(),
(Addr)(process->getSyscallArg(tc, 1)), &hostBuf);
OS::copyOutStatfsBuf(tc->getMemPort(), bufPtr, &hostBuf);
return 0;
}
@ -889,7 +915,9 @@ SyscallReturn
fstatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
int fd = process->sim_fd(process->getSyscallArg(tc, 0));
int index = 0;
int fd = process->sim_fd(process->getSyscallArg(tc, index));
Addr bufPtr = process->getSyscallArg(tc, index);
if (fd < 0)
return -EBADF;
@ -900,8 +928,7 @@ fstatfsFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
if (result < 0)
return -errno;
OS::copyOutStatfsBuf(tc->getMemPort(), process->getSyscallArg(tc, 1),
&hostBuf);
OS::copyOutStatfsBuf(tc->getMemPort(), bufPtr, &hostBuf);
return 0;
}
@ -913,15 +940,16 @@ SyscallReturn
writevFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
int fd = process->getSyscallArg(tc, 0);
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
return -EBADF;
}
TranslatingPort *p = tc->getMemPort();
uint64_t tiov_base = process->getSyscallArg(tc, 1);
size_t count = process->getSyscallArg(tc, 2);
uint64_t tiov_base = process->getSyscallArg(tc, index);
size_t count = process->getSyscallArg(tc, index);
struct iovec hiov[count];
for (size_t i = 0; i < count; ++i) {
typename OS::tgt_iovec tiov;
@ -962,12 +990,13 @@ template <class OS>
SyscallReturn
mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
{
Addr start = p->getSyscallArg(tc, 0);
uint64_t length = p->getSyscallArg(tc, 1);
// int prot = p->getSyscallArg(tc, 2);
int flags = p->getSyscallArg(tc, 3);
// int fd = p->sim_fd(p->getSyscallArg(tc, 4));
// int offset = p->getSyscallArg(tc, 5);
int index = 0;
Addr start = p->getSyscallArg(tc, index);
uint64_t length = p->getSyscallArg(tc, index);
index++; // int prot = p->getSyscallArg(tc, index);
int flags = p->getSyscallArg(tc, index);
int fd = p->sim_fd(p->getSyscallArg(tc, index));
// int offset = p->getSyscallArg(tc, index);
if ((start % TheISA::VMPageSize) != 0 ||
@ -995,7 +1024,7 @@ mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
if (!(flags & OS::TGT_MAP_ANONYMOUS)) {
warn("allowing mmap of file @ fd %d. "
"This will break if not /dev/zero.", p->getSyscallArg(tc, 4));
"This will break if not /dev/zero.", fd);
}
return start;
@ -1007,8 +1036,9 @@ SyscallReturn
getrlimitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
unsigned resource = process->getSyscallArg(tc, 0);
TypedBufferArg<typename OS::rlimit> rlp(process->getSyscallArg(tc, 1));
int index = 0;
unsigned resource = process->getSyscallArg(tc, index);
TypedBufferArg<typename OS::rlimit> rlp(process->getSyscallArg(tc, index));
switch (resource) {
case OS::TGT_RLIMIT_STACK:
@ -1042,7 +1072,8 @@ SyscallReturn
gettimeofdayFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
TypedBufferArg<typename OS::timeval> tp(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<typename OS::timeval> tp(process->getSyscallArg(tc, index));
getElapsedTime(tp->tv_sec, tp->tv_usec);
tp->tv_sec += seconds_since_epoch;
@ -1063,10 +1094,14 @@ utimesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
{
std::string path;
if (!tc->getMemPort()->tryReadString(path, process->getSyscallArg(tc, 0)))
int index = 0;
if (!tc->getMemPort()->tryReadString(path,
process->getSyscallArg(tc, index))) {
return -EFAULT;
}
TypedBufferArg<typename OS::timeval [2]> tp(process->getSyscallArg(tc, 1));
TypedBufferArg<typename OS::timeval [2]>
tp(process->getSyscallArg(tc, index));
tp.copyIn(tc->getMemPort());
struct timeval hostTimeval[2];
@ -1092,8 +1127,9 @@ SyscallReturn
getrusageFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
int who = process->getSyscallArg(tc, 0); // THREAD, SELF, or CHILDREN
TypedBufferArg<typename OS::rusage> rup(process->getSyscallArg(tc, 1));
int index = 0;
int who = process->getSyscallArg(tc, index); // THREAD, SELF, or CHILDREN
TypedBufferArg<typename OS::rusage> rup(process->getSyscallArg(tc, index));
rup->ru_utime.tv_sec = 0;
rup->ru_utime.tv_usec = 0;
@ -1143,7 +1179,8 @@ SyscallReturn
timesFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
ThreadContext *tc)
{
TypedBufferArg<typename OS::tms> bufp(process->getSyscallArg(tc, 0));
int index = 0;
TypedBufferArg<typename OS::tms> bufp(process->getSyscallArg(tc, index));
// Fill in the time structure (in clocks)
int64_t clocks = curTick * OS::_SC_CLK_TCK / Clock::Int::s;
@ -1172,7 +1209,8 @@ timeFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
getElapsedTime(sec, usec);
sec += seconds_since_epoch;
Addr taddr = (Addr)process->getSyscallArg(tc, 0);
int index = 0;
Addr taddr = (Addr)process->getSyscallArg(tc, index);
if(taddr != 0) {
typename OS::time_t t = sec;
t = htog(t);