Skip to content
Snippets Groups Projects
Commit 8292b6c1 authored by Fred Wright's avatar Fred Wright Committed by Christopher Nielsen
Browse files

sysconf: Speed up _SC_PHYS_PAGES.

It's a silly waste of time to use the string-lookup version of
sysconf() rather than using the numeric version, even though that's
what Apple's code does.

Also adds comment explaining 32-bit issues.

Also, since the "i386" bug in Apple's code is really a 32-bit bug, the
feature-flag condition is adjusted to be more honest.  This has no
actual effect, since i386 is the only supported 32-bit processor in
the relevant OS versions.  This removes the only reference to
__MPLS_APPLE_I386__, but the definition is retained in case it's
useful in the future.

TESTED:
Passes tests on all platforms.
parent 616bb9fc
Branches
No related tags found
No related merge requests found
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
#define __MPLS_SDK_SUPPORT_SYSCONF_PHYS_PAGES__ (__MPLS_SDK_MAJOR < 101100) #define __MPLS_SDK_SUPPORT_SYSCONF_PHYS_PAGES__ (__MPLS_SDK_MAJOR < 101100)
#define __MPLS_LIB_SUPPORT_SYSCONF_PHYS_PAGES__ (__MPLS_TARGET_OSVER < 101100 \ #define __MPLS_LIB_SUPPORT_SYSCONF_PHYS_PAGES__ (__MPLS_TARGET_OSVER < 101100 \
|| __MPLS_APPLE_I386__) || !__MPLS_64BIT)
#define __MPLS_LIB_SUPPORT_SYSCONF_WRAP__ (__MPLS_LIB_SUPPORT_SYSCONF_NPROCESSORS__ \ #define __MPLS_LIB_SUPPORT_SYSCONF_WRAP__ (__MPLS_LIB_SUPPORT_SYSCONF_NPROCESSORS__ \
|| __MPLS_LIB_SUPPORT_SYSCONF_PHYS_PAGES__) || __MPLS_LIB_SUPPORT_SYSCONF_PHYS_PAGES__)
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <unistd.h> #include <unistd.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h>
/* /*
* Emulate several commonly used but missing (or broken) selectors from * Emulate several commonly used but missing (or broken) selectors from
...@@ -75,10 +76,21 @@ long sysconf(int name) { ...@@ -75,10 +76,21 @@ long sysconf(int name) {
/* the number of pages is the total memory / pagesize */ /* the number of pages is the total memory / pagesize */
uint64_t mem_size; uint64_t mem_size;
size_t len = sizeof(mem_size); size_t len = sizeof(mem_size);
int ms_mib[] = {CTL_HW, HW_MEMSIZE};
size_t ms_miblen = sizeof(ms_mib) / sizeof(ms_mib[0]);
int pagesize = getpagesize(); int pagesize = getpagesize();
sysctlbyname("hw.memsize", &mem_size, &len, NULL, 0); if (sysctl(ms_mib, ms_miblen, &mem_size, &len, NULL, 0)) {
return -1;
}
/*
* Note that the 32-bit version of this function is inherently
* invalid in any system with >=1TB of RAM.
* Apple's 32-bit implementation is invalid in any system with
* >=2GB of RAM, which is why we override any existing Apple
* implementation in all 32-bit builds.
*/
return (long)(mem_size/pagesize); return (long)(mem_size/pagesize);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment