merge from gcc
This commit is contained in:
parent
ad18820186
commit
ef8038066b
|
@ -1,3 +1,8 @@
|
||||||
|
2003-02-24 Danny Smith <dannysmith@users.source.forge.net>
|
||||||
|
|
||||||
|
* physmem.c (physmem_total): Add _WIN32 support.
|
||||||
|
(physmem_available): Likewise.
|
||||||
|
|
||||||
2003-02-24 Rainer Orth <ro@TechFak.Uni-Bielefeld.DE>
|
2003-02-24 Rainer Orth <ro@TechFak.Uni-Bielefeld.DE>
|
||||||
|
|
||||||
* physmem.c (physmem_total) [HAVE_GETSYSINFO]: Test for
|
* physmem.c (physmem_total) [HAVE_GETSYSINFO]: Test for
|
||||||
|
|
|
@ -56,6 +56,25 @@
|
||||||
# include <sys/systemcfg.h>
|
# include <sys/systemcfg.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
/* MEMORYSTATUSEX is missing from older windows headers, so define
|
||||||
|
a local replacement. */
|
||||||
|
typedef struct {
|
||||||
|
DWORD dwLength;
|
||||||
|
DWORD dwMemoryLoad;
|
||||||
|
DWORDLONG ullTotalPhys;
|
||||||
|
DWORDLONG ullAvailPhys;
|
||||||
|
DWORDLONG ullTotalPageFile;
|
||||||
|
DWORDLONG ullAvailPageFile;
|
||||||
|
DWORDLONG ullTotalVirtual;
|
||||||
|
DWORDLONG ullAvailVirtual;
|
||||||
|
DWORDLONG ullAvailExtendedVirtual;
|
||||||
|
} lMEMORYSTATUSEX;
|
||||||
|
typedef WINBOOL (WINAPI *PFN_MS_EX) (lMEMORYSTATUSEX*);
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "libiberty.h"
|
#include "libiberty.h"
|
||||||
|
|
||||||
/* Return the total amount of physical memory. */
|
/* Return the total amount of physical memory. */
|
||||||
|
@ -129,6 +148,35 @@ physmem_total ()
|
||||||
return _system_configuration.physmem;
|
return _system_configuration.physmem;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined _WIN32
|
||||||
|
{ /* this works on windows */
|
||||||
|
PFN_MS_EX pfnex;
|
||||||
|
HMODULE h = GetModuleHandle("kernel32.dll");
|
||||||
|
|
||||||
|
if (!h)
|
||||||
|
return 0.0;
|
||||||
|
|
||||||
|
/* Use GlobalMemoryStatusEx if available. */
|
||||||
|
if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx")))
|
||||||
|
{
|
||||||
|
lMEMORYSTATUSEX lms_ex;
|
||||||
|
lms_ex.dwLength = sizeof lms_ex;
|
||||||
|
if (!pfnex (&lms_ex))
|
||||||
|
return 0.0;
|
||||||
|
return (double)lms_ex.ullTotalPhys;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fall back to GlobalMemoryStatus which is always available.
|
||||||
|
but returns wrong results for physical memory > 4GB. */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MEMORYSTATUS ms;
|
||||||
|
GlobalMemoryStatus (&ms);
|
||||||
|
return (double)ms.dwTotalPhys;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Return 0 if we can't determine the value. */
|
/* Return 0 if we can't determine the value. */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -201,6 +249,35 @@ physmem_available ()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined _WIN32
|
||||||
|
{ /* this works on windows */
|
||||||
|
PFN_MS_EX pfnex;
|
||||||
|
HMODULE h = GetModuleHandle ("kernel32.dll");
|
||||||
|
|
||||||
|
if (!h)
|
||||||
|
return 0.0;
|
||||||
|
|
||||||
|
/* Use GlobalMemoryStatusEx if available. */
|
||||||
|
if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx")))
|
||||||
|
{
|
||||||
|
lMEMORYSTATUSEX lms_ex;
|
||||||
|
lms_ex.dwLength = sizeof lms_ex;
|
||||||
|
if (!pfnex (&lms_ex))
|
||||||
|
return 0.0;
|
||||||
|
return (double) lms_ex.ullAvailPhys;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fall back to GlobalMemoryStatus which is always available.
|
||||||
|
but returns wrong results for physical memory > 4GB */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MEMORYSTATUS ms;
|
||||||
|
GlobalMemoryStatus (&ms);
|
||||||
|
return (double)ms.dwAvailPhys;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Guess 25% of physical memory. */
|
/* Guess 25% of physical memory. */
|
||||||
return physmem_total () / 4;
|
return physmem_total () / 4;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue