Skip to content

Commit 0b08ae2

Browse files
committed
Make elf_aux_info() as public libc function.
- Teach elf aux vector functions about newly added AT_HWCAP and AT_HWCAP2 vectors. - Export _elf_aux_info() as new public libc function elf_aux_info(3) The elf_aux_info(3) should be considered as FreeBSD counterpart of glibc getauxval() with more robust interface. Note: We cannot name this new function as getauxval(), with glibc compatible interface. Some ports autodetect its existence and then expects that all Linux specific AT_<*> vectors are defined and implemented. MFC after: 1 month Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D12743
1 parent 904d8c4 commit 0b08ae2

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

lib/libc/gen/Symbol.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ FBSD_1.5 {
398398
devname;
399399
devname_r;
400400
dirname;
401+
elf_aux_info;
401402
fts_children;
402403
fts_close;
403404
fts_get_clientptr;

lib/libc/gen/auxv.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$");
3333
#include <link.h>
3434
#include <pthread.h>
3535
#include <string.h>
36+
#include <sys/auxv.h>
3637
#include "un-namespace.h"
3738
#include "libc_private.h"
3839

@@ -65,8 +66,10 @@ __init_elf_aux_vector(void)
6566

6667
static pthread_once_t aux_once = PTHREAD_ONCE_INIT;
6768
static int pagesize, osreldate, canary_len, ncpus, pagesizes_len;
69+
static int hwcap_present, hwcap2_present;
6870
static char *canary, *pagesizes;
6971
static void *timekeep;
72+
static u_long hwcap, hwcap2;
7073

7174
static void
7275
init_aux(void)
@@ -83,6 +86,16 @@ init_aux(void)
8386
canary_len = aux->a_un.a_val;
8487
break;
8588

89+
case AT_HWCAP:
90+
hwcap_present = 1;
91+
hwcap = (u_long)(aux->a_un.a_val);
92+
break;
93+
94+
case AT_HWCAP2:
95+
hwcap2_present = 1;
96+
hwcap2 = (u_long)(aux->a_un.a_val);
97+
break;
98+
8699
case AT_PAGESIZES:
87100
pagesizes = (char *)(aux->a_un.a_ptr);
88101
break;
@@ -110,6 +123,8 @@ init_aux(void)
110123
}
111124
}
112125

126+
__weak_reference(_elf_aux_info, elf_aux_info);
127+
113128
int
114129
_elf_aux_info(int aux, void *buf, int buflen)
115130
{
@@ -130,14 +145,27 @@ _elf_aux_info(int aux, void *buf, int buflen)
130145
} else
131146
res = ENOENT;
132147
break;
148+
case AT_HWCAP:
149+
if (hwcap_present && buflen == sizeof(u_long)) {
150+
*(u_long *)buf = hwcap;
151+
res = 0;
152+
} else
153+
res = ENOENT;
154+
break;
155+
case AT_HWCAP2:
156+
if (hwcap2_present && buflen == sizeof(u_long)) {
157+
*(u_long *)buf = hwcap2;
158+
res = 0;
159+
} else
160+
res = ENOENT;
161+
break;
133162
case AT_PAGESIZES:
134163
if (pagesizes != NULL && pagesizes_len >= buflen) {
135164
memcpy(buf, pagesizes, buflen);
136165
res = 0;
137166
} else
138167
res = ENOENT;
139168
break;
140-
141169
case AT_PAGESZ:
142170
if (buflen == sizeof(int)) {
143171
if (pagesize != 0) {

sys/sys/auxv.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*-
2+
* Copyright (c) 2017 Michal Meloun
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
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.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24+
* SUCH DAMAGE.
25+
*
26+
* $FreeBSD$
27+
*/
28+
29+
#ifndef _SYS_AUXV_H_
30+
#define _SYS_AUXV_H_
31+
32+
#include <sys/types.h>
33+
#include <machine/elf.h>
34+
35+
int elf_aux_info(int aux, void *buf, int buflen);
36+
37+
#endif /* !_SYS_AUXV_H_ */

0 commit comments

Comments
 (0)