You should set all the fields in the structure explicitly. As a matter of fact, it would be even better to memset the whole thing to zero to get the padding too. Even if these values aren't used at all in the code that calls this syscall, they can bounce around on memory that used to be the stack, etc., and introduce non-determinism into a simulation. Other than that, if it works, it looks ok to me.
Gabe Vince Weaver wrote: > Hello > > the patch below implements the linux sysinfo() syscall on the SE targets. > Currently it only really implements the memory size parameter. > > This allows a set of qemu regression tests I have run to completion > ( http://deater.net/weave/vmwprod/asm/ll/qemu_tests.html ) > > The patch has been tested with all architectures, although SPARC and X86 > have unrelated issues keeping the tests from completing. > > Vince > > diff -r 3b2d7fdff6b1 src/arch/alpha/linux/linux.hh > --- a/src/arch/alpha/linux/linux.hh Fri Sep 11 16:19:31 2009 -0500 > +++ b/src/arch/alpha/linux/linux.hh Mon Sep 14 17:43:08 2009 -0400 > @@ -125,6 +125,21 @@ > TGT_RLIMIT_MEMLOCK = 9, > TGT_RLIMIT_LOCKS = 10 > }; > + > + typedef struct { > + int64_t uptime; /* Seconds since boot */ > + uint64_t loads[3]; /* 1, 5, and 15 minute load averages */ > + uint64_t totalram; /* Total usable main memory size */ > + uint64_t freeram; /* Available memory size */ > + uint64_t sharedram; /* Amount of shared memory */ > + uint64_t bufferram; /* Memory used by buffers */ > + uint64_t totalswap; /* Total swap space size */ > + uint64_t freeswap; /* swap space still available */ > + uint16_t procs; /* Number of current processes */ > + uint64_t totalhigh; /* Total high memory size */ > + uint64_t freehigh; /* Available high memory size */ > + uint64_t mem_unit; /* Memory unit size in bytes */ > + } tgt_sysinfo; > }; > > #endif // __ALPHA_ALPHA_LINUX_LINUX_HH__ > diff -r 3b2d7fdff6b1 src/arch/alpha/linux/process.cc > --- a/src/arch/alpha/linux/process.cc Fri Sep 11 16:19:31 2009 -0500 > +++ b/src/arch/alpha/linux/process.cc Mon Sep 14 17:43:08 2009 -0400 > @@ -440,7 +440,7 @@ > /* 315 */ SyscallDesc("munlock", unimplementedFunc), > /* 316 */ SyscallDesc("mlockall", unimplementedFunc), > /* 317 */ SyscallDesc("munlockall", unimplementedFunc), > - /* 318 */ SyscallDesc("sysinfo", unimplementedFunc), > + /* 318 */ SyscallDesc("sysinfo", sysinfoFunc<AlphaLinux>), > /* 319 */ SyscallDesc("_sysctl", unimplementedFunc), > /* 320 */ SyscallDesc("was sys_idle", unimplementedFunc), > /* 321 */ SyscallDesc("oldumount", unimplementedFunc), > diff -r 3b2d7fdff6b1 src/arch/arm/linux/linux.hh > --- a/src/arch/arm/linux/linux.hh Fri Sep 11 16:19:31 2009 -0500 > +++ b/src/arch/arm/linux/linux.hh Mon Sep 14 17:43:08 2009 -0400 > @@ -147,6 +147,21 @@ > uint64_t st_ino; > } tgt_stat64; > > + typedef struct { > + int32_t uptime; /* Seconds since boot */ > + uint32_t loads[3]; /* 1, 5, and 15 minute load averages */ > + uint32_t totalram; /* Total usable main memory size */ > + uint32_t freeram; /* Available memory size */ > + uint32_t sharedram; /* Amount of shared memory */ > + uint32_t bufferram; /* Memory used by buffers */ > + uint32_t totalswap; /* Total swap space size */ > + uint32_t freeswap; /* swap space still available */ > + uint16_t procs; /* Number of current processes */ > + uint32_t totalhigh; /* Total high memory size */ > + uint32_t freehigh; /* Available high memory size */ > + uint32_t mem_unit; /* Memory unit size in bytes */ > + } tgt_sysinfo; > + > > }; > > diff -r 3b2d7fdff6b1 src/arch/arm/linux/process.cc > --- a/src/arch/arm/linux/process.cc Fri Sep 11 16:19:31 2009 -0500 > +++ b/src/arch/arm/linux/process.cc Mon Sep 14 17:43:08 2009 -0400 > @@ -179,7 +179,7 @@ > /* 113 */ SyscallDesc("vm86", unimplementedFunc), > /* 114 */ SyscallDesc("wait4", unimplementedFunc), > /* 115 */ SyscallDesc("swapoff", unimplementedFunc), > - /* 116 */ SyscallDesc("sysinfo", unimplementedFunc), > + /* 116 */ SyscallDesc("sysinfo", sysinfoFunc<ArmLinux>), > /* 117 */ SyscallDesc("ipc", unimplementedFunc), > /* 118 */ SyscallDesc("fsync", unimplementedFunc), > /* 119 */ SyscallDesc("sigreturn", unimplementedFunc), > diff -r 3b2d7fdff6b1 src/arch/mips/linux/linux.hh > --- a/src/arch/mips/linux/linux.hh Fri Sep 11 16:19:31 2009 -0500 > +++ b/src/arch/mips/linux/linux.hh Mon Sep 14 17:43:08 2009 -0400 > @@ -126,6 +126,22 @@ > /// assign themselves to process IDs reserved for > /// the root users. > static const int NUM_ROOT_PROCS = 2; > + > + typedef struct { > + int32_t uptime; /* Seconds since boot */ > + uint32_t loads[3]; /* 1, 5, and 15 minute load averages */ > + uint32_t totalram; /* Total usable main memory size */ > + uint32_t freeram; /* Available memory size */ > + uint32_t sharedram; /* Amount of shared memory */ > + uint32_t bufferram; /* Memory used by buffers */ > + uint32_t totalswap; /* Total swap space size */ > + uint32_t freeswap; /* swap space still available */ > + uint16_t procs; /* Number of current processes */ > + uint32_t totalhigh; /* Total high memory size */ > + uint32_t freehigh; /* Available high memory size */ > + uint32_t mem_unit; /* Memory unit size in bytes */ > + } tgt_sysinfo; > + > }; > > #endif > diff -r 3b2d7fdff6b1 src/arch/mips/linux/process.cc > --- a/src/arch/mips/linux/process.cc Fri Sep 11 16:19:31 2009 -0500 > +++ b/src/arch/mips/linux/process.cc Mon Sep 14 17:43:08 2009 -0400 > @@ -238,7 +238,7 @@ > /* 113 */ SyscallDesc("vm86", unimplementedFunc), > /* 114 */ SyscallDesc("wait4", unimplementedFunc), > /* 115 */ SyscallDesc("swapoff", unimplementedFunc), > - /* 116 */ SyscallDesc("sysinfo", unimplementedFunc), > + /* 116 */ SyscallDesc("sysinfo", sysinfoFunc<MipsLinux>), > /* 117 */ SyscallDesc("ipc", unimplementedFunc), > /* 118 */ SyscallDesc("fsync", unimplementedFunc), > /* 119 */ SyscallDesc("sigreturn", unimplementedFunc), > diff -r 3b2d7fdff6b1 src/arch/sparc/linux/linux.hh > --- a/src/arch/sparc/linux/linux.hh Fri Sep 11 16:19:31 2009 -0500 > +++ b/src/arch/sparc/linux/linux.hh Mon Sep 14 17:43:08 2009 -0400 > @@ -77,6 +77,22 @@ > static const int NUM_OPEN_FLAGS; > > static const unsigned TGT_MAP_ANONYMOUS = 0x20; > + > + typedef struct { > + int64_t uptime; /* Seconds since boot */ > + uint64_t loads[3]; /* 1, 5, and 15 minute load averages */ > + uint64_t totalram; /* Total usable main memory size */ > + uint64_t freeram; /* Available memory size */ > + uint64_t sharedram; /* Amount of shared memory */ > + uint64_t bufferram; /* Memory used by buffers */ > + uint64_t totalswap; /* Total swap space size */ > + uint64_t freeswap; /* swap space still available */ > + uint16_t procs; /* Number of current processes */ > + uint64_t totalhigh; /* Total high memory size */ > + uint64_t freehigh; /* Available high memory size */ > + uint64_t mem_unit; /* Memory unit size in bytes */ > + } tgt_sysinfo; > + > }; > > class Sparc32Linux : public SparcLinux > @@ -105,6 +121,22 @@ > uint32_t __unused4; > uint32_t __unused5; > } tgt_stat64; > + > + typedef struct { > + int32_t uptime; /* Seconds since boot */ > + uint32_t loads[3]; /* 1, 5, and 15 minute load averages */ > + uint32_t totalram; /* Total usable main memory size */ > + uint32_t freeram; /* Available memory size */ > + uint32_t sharedram; /* Amount of shared memory */ > + uint32_t bufferram; /* Memory used by buffers */ > + uint32_t totalswap; /* Total swap space size */ > + uint32_t freeswap; /* swap space still available */ > + uint16_t procs; /* Number of current processes */ > + uint32_t totalhigh; /* Total high memory size */ > + uint32_t freehigh; /* Available high memory size */ > + uint32_t mem_unit; /* Memory unit size in bytes */ > + } tgt_sysinfo; > + > }; > > #endif > diff -r 3b2d7fdff6b1 src/arch/sparc/linux/syscalls.cc > --- a/src/arch/sparc/linux/syscalls.cc Fri Sep 11 16:19:31 2009 -0500 > +++ b/src/arch/sparc/linux/syscalls.cc Mon Sep 14 17:43:08 2009 -0400 > @@ -302,7 +302,7 @@ > /* 211 */ SyscallDesc("tgkill", unimplementedFunc), //32 bit > /* 212 */ SyscallDesc("waitpid", unimplementedFunc), //32 bit > /* 213 */ SyscallDesc("swapoff", unimplementedFunc), > - /* 214 */ SyscallDesc("sysinfo", unimplementedFunc), //32 bit > + /* 214 */ SyscallDesc("sysinfo", sysinfoFunc<Sparc32Linux>), //32 bit > /* 215 */ SyscallDesc("ipc", unimplementedFunc), //32 bit > /* 216 */ SyscallDesc("sigreturn", unimplementedFunc), //32 bit > /* 217 */ SyscallDesc("clone", cloneFunc), > @@ -608,7 +608,7 @@ > /* 211 */ SyscallDesc("tgkill", unimplementedFunc), > /* 212 */ SyscallDesc("waitpid", unimplementedFunc), > /* 213 */ SyscallDesc("swapoff", unimplementedFunc), > - /* 214 */ SyscallDesc("sysinfo", unimplementedFunc), > + /* 214 */ SyscallDesc("sysinfo", sysinfoFunc<SparcLinux>), > /* 215 */ SyscallDesc("ipc", unimplementedFunc), > /* 216 */ SyscallDesc("sigreturn", unimplementedFunc), > /* 217 */ SyscallDesc("clone", cloneFunc), > diff -r 3b2d7fdff6b1 src/arch/x86/linux/linux.hh > --- a/src/arch/x86/linux/linux.hh Fri Sep 11 16:19:31 2009 -0500 > +++ b/src/arch/x86/linux/linux.hh Mon Sep 14 17:43:08 2009 -0400 > @@ -111,6 +111,22 @@ > uint64_t iov_base; // void * > uint64_t iov_len; // size_t > } tgt_iovec; > + > + typedef struct { > + int64_t uptime; /* Seconds since boot */ > + uint64_t loads[3]; /* 1, 5, and 15 minute load averages */ > + uint64_t totalram; /* Total usable main memory size */ > + uint64_t freeram; /* Available memory size */ > + uint64_t sharedram; /* Amount of shared memory */ > + uint64_t bufferram; /* Memory used by buffers */ > + uint64_t totalswap; /* Total swap space size */ > + uint64_t freeswap; /* swap space still available */ > + uint16_t procs; /* Number of current processes */ > + uint64_t totalhigh; /* Total high memory size */ > + uint64_t freehigh; /* Available high memory size */ > + uint64_t mem_unit; /* Memory unit size in bytes */ > + } tgt_sysinfo; > + > }; > > class X86Linux32 : public Linux > @@ -160,6 +176,21 @@ > static const int NUM_OPEN_FLAGS; > > static const unsigned TGT_MAP_ANONYMOUS = 0x20; > + > + typedef struct { > + int32_t uptime; /* Seconds since boot */ > + uint32_t loads[3]; /* 1, 5, and 15 minute load averages */ > + uint32_t totalram; /* Total usable main memory size */ > + uint32_t freeram; /* Available memory size */ > + uint32_t sharedram; /* Amount of shared memory */ > + uint32_t bufferram; /* Memory used by buffers */ > + uint32_t totalswap; /* Total swap space size */ > + uint32_t freeswap; /* swap space still available */ > + uint16_t procs; /* Number of current processes */ > + uint32_t totalhigh; /* Total high memory size */ > + uint32_t freehigh; /* Available high memory size */ > + uint32_t mem_unit; /* Memory unit size in bytes */ > + } tgt_sysinfo; > }; > > #endif > diff -r 3b2d7fdff6b1 src/arch/x86/linux/syscalls.cc > --- a/src/arch/x86/linux/syscalls.cc Fri Sep 11 16:19:31 2009 -0500 > +++ b/src/arch/x86/linux/syscalls.cc Mon Sep 14 17:43:08 2009 -0400 > @@ -327,7 +327,7 @@ > /* 96 */ SyscallDesc("gettimeofday", unimplementedFunc), > /* 97 */ SyscallDesc("getrlimit", unimplementedFunc), > /* 98 */ SyscallDesc("getrusage", unimplementedFunc), > - /* 99 */ SyscallDesc("sysinfo", unimplementedFunc), > + /* 99 */ SyscallDesc("sysinfo", sysinfoFunc<X86Linux64>), > /* 100 */ SyscallDesc("times", unimplementedFunc), > /* 101 */ SyscallDesc("ptrace", unimplementedFunc), > /* 102 */ SyscallDesc("getuid", getuidFunc), > @@ -623,7 +623,7 @@ > /* 113 */ SyscallDesc("vm86old", unimplementedFunc), > /* 114 */ SyscallDesc("wait4", unimplementedFunc), > /* 115 */ SyscallDesc("swapoff", unimplementedFunc), > - /* 116 */ SyscallDesc("sysinfo", unimplementedFunc), > + /* 116 */ SyscallDesc("sysinfo", sysinfoFunc<X86Linux32>), > /* 117 */ SyscallDesc("ipc", unimplementedFunc), > /* 118 */ SyscallDesc("fsync", unimplementedFunc), > /* 119 */ SyscallDesc("sigreturn", unimplementedFunc), > diff -r 3b2d7fdff6b1 src/sim/syscall_emul.hh > --- a/src/sim/syscall_emul.hh Fri Sep 11 16:19:31 2009 -0500 > +++ b/src/sim/syscall_emul.hh Mon Sep 14 17:43:08 2009 -0400 > @@ -59,6 +59,7 @@ > #include "cpu/thread_context.hh" > #include "mem/translating_port.hh" > #include "mem/page_table.hh" > +#include "sim/system.hh" > #include "sim/process.hh" > > /// > @@ -558,6 +559,22 @@ > > } > > +/// Target sysinfo() handler. > +template <class OS> > +SyscallReturn > +sysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process, > + ThreadContext *tc) > +{ > + > + TypedBufferArg<typename OS::tgt_sysinfo> > sysinfo(process->getSyscallArg(tc, 0)); > + > + sysinfo->uptime=seconds_since_epoch; > + sysinfo->totalram=process->system->memSize(); > + > + sysinfo.copyOut(tc->getMemPort()); > + > + return 0; > +} > > /// Target chmod() handler. > template <class OS> > _______________________________________________ > m5-dev mailing list > [email protected] > http://m5sim.org/mailman/listinfo/m5-dev > _______________________________________________ m5-dev mailing list [email protected] http://m5sim.org/mailman/listinfo/m5-dev
