diff options
author | kib <kib@FreeBSD.org> | 2010-08-17 09:05:39 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2010-08-17 09:05:39 +0000 |
commit | 3c2c3f33ee230b5a0169bd5dd2d57e42fdb22d05 (patch) | |
tree | 2a4b7d1ddfeee3c1c0711a89f2cac3b60b2c3d0f /libexec/rtld-elf/malloc.c | |
parent | d9f088a03e65b9a9a1109213406f79fc4a1b33ae (diff) | |
download | FreeBSD-src-3c2c3f33ee230b5a0169bd5dd2d57e42fdb22d05.zip FreeBSD-src-3c2c3f33ee230b5a0169bd5dd2d57e42fdb22d05.tar.gz |
Use the newly provided aux vectors to get pagesize and osreldate information.
Use local version of getpagesize(), rtld_getpagesize() in private allocator.
Override the __getosreldate() previously fetched from libc_pic.a with
local version that uses aux value if present. Note that __getosreldate()
is used by rtld indirectly, by mmap(2) libc wrapper.
To be able to utilize aux, split digest_dynamic() for use by init_rtld()
into two parts, where the first one does not call malloc(), and the
second part uses it. init_rtld() is able to initialize global variables
before digest_dynamic2() calls. In particular, pagesize and osreldate are
set up from the aux values.
Now, rtld avoids (two) sysctl calls in startup.
Tested by: marius (sparc64)
MFC after: 1 month
Diffstat (limited to 'libexec/rtld-elf/malloc.c')
-rw-r--r-- | libexec/rtld-elf/malloc.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/libexec/rtld-elf/malloc.c b/libexec/rtld-elf/malloc.c index 3da5bee..38ae89a 100644 --- a/libexec/rtld-elf/malloc.c +++ b/libexec/rtld-elf/malloc.c @@ -48,6 +48,7 @@ static char *rcsid = "$FreeBSD$"; */ #include <sys/types.h> +#include <sys/sysctl.h> #include <err.h> #include <paths.h> #include <stdarg.h> @@ -152,6 +153,26 @@ botch(s) static void xprintf(const char *, ...); #define TRACE() xprintf("TRACE %s:%d\n", __FILE__, __LINE__) +extern int pagesize; + +static int +rtld_getpagesize(void) +{ + int mib[2]; + size_t size; + + if (pagesize != 0) + return (pagesize); + + mib[0] = CTL_HW; + mib[1] = HW_PAGESIZE; + size = sizeof(pagesize); + if (sysctl(mib, 2, &pagesize, &size, NULL, 0) == -1) + return (-1); + return (pagesize); + +} + void * malloc(nbytes) size_t nbytes; @@ -166,7 +187,7 @@ malloc(nbytes) * align break pointer so all data will be page aligned. */ if (pagesz == 0) { - pagesz = n = getpagesize(); + pagesz = n = rtld_getpagesize(); if (morepages(NPOOLPAGES) == 0) return NULL; op = (union overhead *)(pagepool_start); |