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;
75 for (aux = __elf_aux_vector; aux->a_type != AT_NULL; aux++) {
76 switch (aux->a_type) {
78 canary = (char *)(aux->a_un.a_ptr);
82 canary_len = aux->a_un.a_val;
86 pagesizes = (char *)(aux->a_un.a_ptr);
90 pagesizes_len = aux->a_un.a_val;
94 pagesize = aux->a_un.a_val;
98 osreldate = aux->a_un.a_val;
102 ncpus = aux->a_un.a_val;
109 _elf_aux_info(int aux, void *buf, int buflen)
113 __init_elf_aux_vector();
114 if (__elf_aux_vector == NULL)
116 _once(&aux_once, init_aux);
120 if (canary != NULL && canary_len >= buflen) {
121 memcpy(buf, canary, buflen);
122 memset(canary, 0, canary_len);
129 if (pagesizes != NULL && pagesizes_len >= buflen) {
130 memcpy(buf, pagesizes, buflen);
137 if (buflen == sizeof(int)) {
139 *(int *)buf = pagesize;
147 if (buflen == sizeof(int)) {
148 if (osreldate != 0) {
149 *(int *)buf = osreldate;
157 if (buflen == sizeof(int)) {