2 * Copyright 2010, 2012 Konstantin Belousov <kib@FreeBSD.ORG>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include "namespace.h"
36 #include "un-namespace.h"
37 #include "libc_private.h"
39 extern char **environ;
43 void *__elf_aux_vector;
44 static pthread_once_t aux_vector_once = PTHREAD_ONCE_INIT;
47 init_aux_vector_once(void)
51 sp = (Elf_Addr *)environ;
54 __elf_aux_vector = (Elf_Auxinfo *)sp;
58 __init_elf_aux_vector(void)
61 if (&_DYNAMIC != NULL)
63 _once(&aux_vector_once, init_aux_vector_once);
66 static pthread_once_t aux_once = PTHREAD_ONCE_INIT;
67 static int pagesize, osreldate, canary_len, ncpus, pagesizes_len;
68 static char *canary, *pagesizes;
69 static void *timekeep;
76 for (aux = __elf_aux_vector; aux->a_type != AT_NULL; aux++) {
77 switch (aux->a_type) {
79 canary = (char *)(aux->a_un.a_ptr);
83 canary_len = aux->a_un.a_val;
87 pagesizes = (char *)(aux->a_un.a_ptr);
91 pagesizes_len = aux->a_un.a_val;
95 pagesize = aux->a_un.a_val;
99 osreldate = aux->a_un.a_val;
103 ncpus = aux->a_un.a_val;
107 timekeep = aux->a_un.a_ptr;
114 _elf_aux_info(int aux, void *buf, int buflen)
118 __init_elf_aux_vector();
119 if (__elf_aux_vector == NULL)
121 _once(&aux_once, init_aux);
125 if (canary != NULL && canary_len >= buflen) {
126 memcpy(buf, canary, buflen);
127 memset(canary, 0, canary_len);
134 if (pagesizes != NULL && pagesizes_len >= buflen) {
135 memcpy(buf, pagesizes, buflen);
142 if (buflen == sizeof(int)) {
144 *(int *)buf = pagesize;
152 if (buflen == sizeof(int)) {
153 if (osreldate != 0) {
154 *(int *)buf = osreldate;
162 if (buflen == sizeof(int)) {
172 if (buflen == sizeof(void *)) {
173 if (timekeep != NULL) {
174 *(void **)buf = timekeep;