Syscalls: Implement sysinfo() syscall.
authorVince Weaver <vince@csl.cornell.edu>
Wed, 16 Sep 2009 05:36:47 +0000 (22:36 -0700)
committerVince Weaver <vince@csl.cornell.edu>
Wed, 16 Sep 2009 05:36:47 +0000 (22:36 -0700)
src/arch/alpha/linux/linux.hh
src/arch/alpha/linux/process.cc
src/arch/arm/linux/linux.hh
src/arch/arm/linux/process.cc
src/arch/mips/linux/linux.hh
src/arch/mips/linux/process.cc
src/arch/sparc/linux/linux.hh
src/arch/sparc/linux/syscalls.cc
src/arch/x86/linux/linux.hh
src/arch/x86/linux/syscalls.cc
src/sim/syscall_emul.hh

index c622c5ef1e383ede0a68b0a07bec81e424e59b8f..e9947644cb56c738f287d7e97b72d141eaa02c5b 100644 (file)
@@ -125,6 +125,21 @@ class AlphaLinux : public Linux
         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__
index 9886c7ea7e88ba3bb4f83d7fb6e7a34b195375fc..0f09e472b707f48858cc33209a65ae075a2859c5 100644 (file)
@@ -440,7 +440,7 @@ SyscallDesc AlphaLinuxProcess::syscallDescs[] = {
     /* 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),
index d99fa8e49789758f9f15811e6e75eae6e9b074cf..b9b10a59369df12d31194b585dc66df317b8577d 100644 (file)
@@ -147,6 +147,21 @@ class ArmLinux : public Linux
         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;
+   
 
 };
 
index 56e3588a769add4e14e157ebe48c4f845ad6920c..a7f36e18d45c5dc432b59871b00c5660b8951428 100644 (file)
@@ -179,7 +179,7 @@ SyscallDesc ArmLinuxProcess::syscallDescs[] = {
     /* 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),
index ee81fa18f85dfbc9e63c9f130eccd324a16006b5..b30cca2fbcb48e46a72b5c4de4f017d865527da8 100644 (file)
@@ -126,6 +126,22 @@ class MipsLinux : public Linux
     /// 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
index 53a24487fbee70ef1cd94695608c4df303a1179e..0fa3c382ac70b97f1164271aaf94c196bbb1cf7a 100644 (file)
@@ -238,7 +238,7 @@ SyscallDesc MipsLinuxProcess::syscallDescs[] = {
     /* 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),
index b1dc691ce3a1beee343e79f1da309b0bec5d8a5c..1f7567d43da334d941bc75aebfe65e7c973b1d3f 100644 (file)
@@ -77,6 +77,22 @@ class SparcLinux : public Linux
     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 @@ class Sparc32Linux : public SparcLinux
         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
index f4781d886d746b65efd2fdfb228f1138f1b2f8e1..c508039762685da08c7a0e2a4e8b8f2430d49cee 100644 (file)
@@ -302,7 +302,7 @@ SyscallDesc SparcLinuxProcess::syscall32Descs[] = {
     /* 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 @@ SyscallDesc SparcLinuxProcess::syscallDescs[] = {
     /* 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),
index c2941c7692a1cf03cf6c6b4749eda2c06036260c..d5bead8f3dca29ceda6ea0d1b6ef0cc64370084a 100644 (file)
@@ -111,6 +111,22 @@ class X86Linux64 : public Linux
         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 @@ class X86Linux32 : public Linux
     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
index 5a425ed9a22fc08e37fc26175e02848554699548..52352ee807a541613e6f4572c852ee3453b0e7c3 100644 (file)
@@ -327,7 +327,7 @@ SyscallDesc X86_64LinuxProcess::syscallDescs[] = {
     /*  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 @@ SyscallDesc I386LinuxProcess::syscallDescs[] = {
     /* 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),
index 5f2ebd428df8c3bddc01f1f82c0673d9f3ee6936..c00edfdc618b48bea8f7a9d58aae1f1224bf244b 100644 (file)
@@ -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 @@ openFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
 
 }
 
+/// 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>