From: Michael Müller michael@fds-team.de
Remove extra ifdefs
From: Michael Müller michael@fds-team.de Signed-off-by: Vijay Kiran Kamuju infyquest@gmail.com --- dlls/ntdll/nt.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c index f429349698..687f31bd4f 100644 --- a/dlls/ntdll/nt.c +++ b/dlls/ntdll/nt.c @@ -30,6 +30,9 @@ #ifdef HAVE_SYS_SYSCTL_H # include <sys/sysctl.h> #endif +#ifdef HAVE_SYS_SYSINFO_H +# include <sys/sysinfo.h> +#endif #ifdef HAVE_MACHINE_CPU_H # include <machine/cpu.h> #endif @@ -2319,6 +2322,37 @@ NTSTATUS WINAPI NtQuerySystemInformation( spi.IdleTime.QuadPart = ++idle; }
+#ifdef HAVE_SYSINFO + struct sysinfo sinfo; + + if (!sysinfo(&sinfo)) + { + ULONG64 freeram = (ULONG64)sinfo.freeram * sinfo.mem_unit; + ULONG64 totalram = (ULONG64)sinfo.totalram * sinfo.mem_unit; + ULONG64 totalswap = (ULONG64)sinfo.totalswap * sinfo.mem_unit; + ULONG64 freeswap = (ULONG64)sinfo.freeswap * sinfo.mem_unit; + + if ((fp = fopen("/proc/meminfo", "r"))) + { + unsigned long long available; + char line[64]; + while (fgets(line, sizeof(line), fp)) + { + if (sscanf(line, "MemAvailable: %llu kB", &available) == 1) + { + freeram = min(available * 1024, totalram); + break; + } + } + fclose(fp); + } + + spi.AvailablePages = freeram / page_size; + spi.TotalCommittedPages = (totalram + totalswap - freeram - freeswap) / page_size; + spi.TotalCommitLimit = (totalram + totalswap) / page_size; + } +#endif + if (Length >= len) { if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
Vijay Kiran Kamuju infyquest@gmail.com writes:
+#ifdef HAVE_SYSINFO
struct sysinfo sinfo;
if (!sysinfo(&sinfo))
{
ULONG64 freeram = (ULONG64)sinfo.freeram * sinfo.mem_unit;
ULONG64 totalram = (ULONG64)sinfo.totalram * sinfo.mem_unit;
ULONG64 totalswap = (ULONG64)sinfo.totalswap * sinfo.mem_unit;
ULONG64 freeswap = (ULONG64)sinfo.freeswap * sinfo.mem_unit;
if ((fp = fopen("/proc/meminfo", "r")))
{
unsigned long long available;
char line[64];
while (fgets(line, sizeof(line), fp))
{
if (sscanf(line, "MemAvailable: %llu kB", &available) == 1)
{
freeram = min(available * 1024, totalram);
break;
}
}
fclose(fp);
}
It seems to me that as long as we are parsing /proc/meminfo, we could get everything from there, instead of mixing it up with sysinfo().
On Mon, Apr 15, 2019 at 9:24 PM Alexandre Julliard julliard@winehq.org wrote:
Vijay Kiran Kamuju infyquest@gmail.com writes:
+#ifdef HAVE_SYSINFO
struct sysinfo sinfo;
if (!sysinfo(&sinfo))
{
ULONG64 freeram = (ULONG64)sinfo.freeram * sinfo.mem_unit;
ULONG64 totalram = (ULONG64)sinfo.totalram * sinfo.mem_unit;
ULONG64 totalswap = (ULONG64)sinfo.totalswap * sinfo.mem_unit;
ULONG64 freeswap = (ULONG64)sinfo.freeswap * sinfo.mem_unit;
if ((fp = fopen("/proc/meminfo", "r")))
{
unsigned long long available;
char line[64];
while (fgets(line, sizeof(line), fp))
{
if (sscanf(line, "MemAvailable: %llu kB", &available) == 1)
{
freeram = min(available * 1024, totalram);
break;
}
}
fclose(fp);
}
It seems to me that as long as we are parsing /proc/meminfo, we could get everything from there, instead of mixing it up with sysinfo().
-- Alexandre Julliard julliard@winehq.org
I believe the original author's intent was to make it work also in the *bsd systems where '/proc/meminfo' is not available and sysinfo syscall is available. I can rewrite this patch by parsing the /proc/meminfo, that might make this smaller and not dependent on sysinfo but working only in linux.
--- Vijay