diff options
author | kib <kib@FreeBSD.org> | 2010-08-17 09:13:26 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2010-08-17 09:13:26 +0000 |
commit | 5a79777b4407edd39781e06216e4dc6ca68bb6a7 (patch) | |
tree | 2f639ad563c61b228d123038b15beca40d36a4ba /lib/libc/gen/getpagesize.c | |
parent | 680fe863d9e18febb130562fe69135f824b59b45 (diff) | |
download | FreeBSD-src-5a79777b4407edd39781e06216e4dc6ca68bb6a7.zip FreeBSD-src-5a79777b4407edd39781e06216e4dc6ca68bb6a7.tar.gz |
Use aux vector to get values for SSP canary, pagesize, pagesizes array,
number of host CPUs and osreldate.
This eliminates the last sysctl(2) calls from the dynamically linked image
startup.
No objections from: kan
Tested by: marius (sparc64)
MFC after: 1 month
Diffstat (limited to 'lib/libc/gen/getpagesize.c')
-rw-r--r-- | lib/libc/gen/getpagesize.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/libc/gen/getpagesize.c b/lib/libc/gen/getpagesize.c index d796b9d..f4b8128 100644 --- a/lib/libc/gen/getpagesize.c +++ b/lib/libc/gen/getpagesize.c @@ -36,8 +36,12 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/sysctl.h> +#include <errno.h> +#include <link.h> #include <unistd.h> +#include "libc_private.h" + /* * This is unlikely to change over the running time of any * program, so we cache the result to save some syscalls. @@ -52,13 +56,20 @@ getpagesize() int mib[2]; static int value; size_t size; + int error; + + if (value != 0) + return (value); + + error = _elf_aux_info(AT_PAGESZ, &value, sizeof(value)); + if (error == 0 && value != 0) + return (value); + + mib[0] = CTL_HW; + mib[1] = HW_PAGESIZE; + size = sizeof value; + if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) + return (-1); - if (!value) { - mib[0] = CTL_HW; - mib[1] = HW_PAGESIZE; - size = sizeof value; - if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) - return (-1); - } return (value); } |