Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYaakov Selkowitz <yselkowi@redhat.com>2011-05-06 22:53:21 +0400
committerYaakov Selkowitz <yselkowi@redhat.com>2011-05-06 22:53:21 +0400
commit2f52cad971308db5625059e07547f1a1159fa520 (patch)
treea8231f945a81fa5b79807397e2ee70a10c5ef11e /winsup/cygwin/sysconf.cc
parentcc718e26c6549a55a892cebe1d29fd59f4b08651 (diff)
* 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.
Diffstat (limited to 'winsup/cygwin/sysconf.cc')
-rw-r--r--winsup/cygwin/sysconf.cc99
1 files changed, 98 insertions, 1 deletions
diff --git a/winsup/cygwin/sysconf.cc b/winsup/cygwin/sysconf.cc
index 8d4febaa3..de84dbc3e 100644
--- a/winsup/cygwin/sysconf.cc
+++ b/winsup/cygwin/sysconf.cc
@@ -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;
+}