]> sourceware.org Git - newlib-cygwin.git/commitdiff
* sysconf.cc (sysinfo): New function.
authorYaakov Selkowitz <yselkowi@redhat.com>
Fri, 6 May 2011 18:53:21 +0000 (18:53 +0000)
committerYaakov Selkowitz <yselkowi@redhat.com>
Fri, 6 May 2011 18:53:21 +0000 (18:53 +0000)
* cygwin.din (sysinfo): Export.
* posix.sgml (std-gnu): Add sysinfo.
* include/sys/sysinfo.h (struct sysinfo): Define.
(sysinfo): Declare.
* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.

winsup/cygwin/ChangeLog
winsup/cygwin/cygwin.din
winsup/cygwin/include/cygwin/version.h
winsup/cygwin/include/sys/sysinfo.h
winsup/cygwin/posix.sgml
winsup/cygwin/sysconf.cc

index 827083a33046a33521ef208bffafd5cd849908c7..7a974169078b6a140f26ca51502a93fac0d7f116 100644 (file)
@@ -1,3 +1,12 @@
+2011-05-06  Yaakov Selkowitz  <yselkowitz@users.sourceforge.net>
+
+       * sysconf.cc (sysinfo): New function.
+       * cygwin.din (sysinfo): Export.
+       * posix.sgml (std-gnu): Add sysinfo.
+       * include/sys/sysinfo.h (struct sysinfo): Define.
+       (sysinfo): Declare.
+       * include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
+
 2011-05-06  Corinna Vinschen  <corinna@vinschen.de>
 
        * libc/minires-os-if.c (get_dns_info): Drop printing uninitialized
index 36a1fadadb6d9ed5789b5e5e6065b4c519f45272..e918b08add2c3b16301dab33004b3f7f49f81914 100644 (file)
@@ -1682,6 +1682,7 @@ symlinkat SIGFE
 sync SIGFE
 sysconf SIGFE
 _sysconf = sysconf SIGFE
+sysinfo SIGFE
 syslog SIGFE
 _syslog = syslog SIGFE
 system SIGFE
index 7a29749457861757436da8d013a8669951f7ea17..ef92244adee6a836fb6caf3fe749f18136e3d3ea 100644 (file)
@@ -408,12 +408,13 @@ details. */
       241: Export pthread_attr_getstack, pthread_attr_getstackaddr,
           pthread_getattr_np.
       242: Export psiginfo, psignal, sys_siglist.
+      243: Export sysinfo.
      */
 
      /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
 
 #define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 242
+#define CYGWIN_VERSION_API_MINOR 243
 
      /* There is also a compatibity version number associated with the
        shared memory regions.  It is incremented when incompatible
index 1e24c860a597e39337e14894051584842d193e3c..693e7b5930f751b22ac6283dbff2893d5e397921 100644 (file)
@@ -1,6 +1,6 @@
 /* sys/sysinfo.h
 
-   Copyright 2009 Red Hat, Inc.
+   Copyright 2009, 2011 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -17,6 +17,23 @@ details. */
 
 __BEGIN_DECLS
 
+struct sysinfo {
+  long uptime;                /* Seconds since boot */
+  unsigned long loads[3];     /* 1, 5, and 15 minute load averages */
+  unsigned long totalram;     /* Total usable main memory size */
+  unsigned long freeram;      /* Available memory size */
+  unsigned long sharedram;    /* Amount of shared memory */
+  unsigned long bufferram;    /* Memory used by buffers */
+  unsigned long totalswap;    /* Total swap space size */
+  unsigned long freeswap;     /* swap space still available */
+  unsigned short procs;       /* Number of current processes */
+  unsigned long totalhigh;    /* Total high memory size */
+  unsigned long freehigh;     /* Available high memory size */
+  unsigned int mem_unit;      /* Memory unit size in bytes */
+  char __unused[10];          /* Pads structure to 64 bytes */
+};
+
+extern int sysinfo (struct sysinfo *);
 extern int get_nprocs_conf (void);
 extern int get_nprocs (void);
 extern long get_phys_pages (void);
index 640cd63c6990f3a2d84b08457c545d2e19a21363..cdc6a9382544340df3244e6cafaf14bed02a31d9 100644 (file)
@@ -1124,6 +1124,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008).</para>
     removexattr
     setxattr
     strchrnul
+    sysinfo
     tdestroy
     timegm
     timelocal
index 8d4febaa35f48a43c53dff0b0406db4e0f7d9335..de84dbc3ed699310776dc774bd766b2eefb40b53 100644 (file)
@@ -1,7 +1,7 @@
 /* sysconf.cc
 
    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-   2006, 2007, 2009 Red Hat, Inc.
+   2006, 2007, 2009, 2010, 2011 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -17,6 +17,7 @@ details. */
 #include "path.h"
 #include "fhandler.h"
 #include "dtable.h"
+#include "pinfo.h"
 #include "ntdll.h"
 
 static long
@@ -317,3 +318,99 @@ get_avphys_pages (void)
 {
   return get_avphys (_SC_AVPHYS_PAGES);
 }
+
+extern "C" int
+sysinfo (struct sysinfo *info)
+{
+  unsigned long long uptime = 0ULL, totalram = 0ULL, freeram = 0ULL,
+               totalswap = 0ULL, freeswap = 0ULL;
+  MEMORYSTATUSEX memory_status;
+  PSYSTEM_PAGEFILE_INFORMATION spi = NULL;
+  ULONG sizeof_spi = 512;
+  PSYSTEM_TIME_OF_DAY_INFORMATION stodi = NULL;
+  ULONG sizeof_stodi = sizeof (SYSTEM_TIME_OF_DAY_INFORMATION);
+  NTSTATUS ret = STATUS_SUCCESS;
+  winpids pids ((DWORD) 0);
+
+  if (!info)
+    {
+      set_errno (EFAULT);
+      return -1;
+    }
+
+  stodi = (PSYSTEM_TIME_OF_DAY_INFORMATION) malloc (sizeof_stodi);
+  ret = NtQuerySystemInformation (SystemTimeOfDayInformation, (PVOID) stodi,
+                                 sizeof_stodi, NULL);
+  if (NT_SUCCESS (ret))
+    uptime = (stodi->CurrentTime.QuadPart - stodi->BootTime.QuadPart) / 10000000ULL;
+  else
+    {
+      debug_printf ("NtQuerySystemInformation(SystemTimeOfDayInformation), "
+                 "status %p", ret);
+    }
+
+  if (stodi)
+    free (stodi);
+
+  memory_status.dwLength = sizeof (MEMORYSTATUSEX);
+  GlobalMemoryStatusEx (&memory_status);
+  totalram = memory_status.ullTotalPhys / getsystempagesize ();
+  freeram = memory_status.ullAvailPhys / getsystempagesize ();
+
+  spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (sizeof_spi);
+  if (spi)
+    {
+      ret = NtQuerySystemInformation (SystemPagefileInformation, (PVOID) spi,
+                                     sizeof_spi, &sizeof_spi);
+      if (ret == STATUS_INFO_LENGTH_MISMATCH)
+       {
+         free (spi);
+         spi = (PSYSTEM_PAGEFILE_INFORMATION) malloc (sizeof_spi);
+         if (spi)
+           ret = NtQuerySystemInformation (SystemPagefileInformation,
+                                           (PVOID) spi, sizeof_spi, &sizeof_spi);
+       }
+    }
+  if (!spi || ret || (!ret && GetLastError () == ERROR_PROC_NOT_FOUND))
+    {
+      debug_printf ("NtQuerySystemInformation(SystemPagefileInformation), "
+                 "status %p", ret);
+      totalswap = (memory_status.ullTotalPageFile - memory_status.ullTotalPhys)
+                        / getsystempagesize ();
+      freeswap = (memory_status.ullAvailPageFile - memory_status.ullTotalPhys)
+                        / getsystempagesize ();
+    }
+  else
+    {
+      PSYSTEM_PAGEFILE_INFORMATION spp = spi;
+      do
+       {
+         totalswap += spp->CurrentSize;
+         freeswap += spp->CurrentSize - spp->TotalUsed;
+       }
+      while (spp->NextEntryOffset
+            && (spp = (PSYSTEM_PAGEFILE_INFORMATION)
+                          ((char *) spp + spp->NextEntryOffset)));
+    }
+  if (spi)
+    free (spi);
+
+  info->uptime = (long) uptime;
+  info->totalram = (unsigned long) totalram;
+  info->freeram = (unsigned long) freeram;
+  info->totalswap = (unsigned long) totalswap;
+  info->freeswap = (unsigned long) freeswap;
+  info->procs = (unsigned short) pids.npids;
+  info->mem_unit = (unsigned int) getsystempagesize ();
+
+  /* FIXME: unsupported */
+  info->loads[0] = 0UL;
+  info->loads[1] = 0UL;
+  info->loads[2] = 0UL;
+  info->sharedram = 0UL;
+  info->bufferram = 0UL;
+  info->totalhigh = 0UL;
+  info->freehigh = 0UL;
+
+  return 0;
+}
This page took 0.045007 seconds and 5 git commands to generate.