]>
Commit | Line | Data |
---|---|---|
78b31cc8 | 1 | /* Test getauxval from a dynamic library after static dlopen. |
6d7e8eda | 2 | Copyright (C) 2021-2023 Free Software Foundation, Inc. |
78b31cc8 FW |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
17 | <https://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #include <dlfcn.h> | |
20 | #include <errno.h> | |
21 | #include <stdio.h> | |
22 | #include <support/check.h> | |
23 | #include <support/xdlfcn.h> | |
24 | #include <sys/auxv.h> | |
25 | ||
26 | unsigned long getauxval_wrapper (unsigned long type, int *errnop); | |
27 | ||
28 | static int | |
29 | do_test (void) | |
30 | { | |
31 | unsigned long outer_random = getauxval (AT_RANDOM); | |
32 | if (outer_random == 0) | |
33 | FAIL_UNSUPPORTED ("getauxval does not support AT_RANDOM"); | |
34 | ||
35 | unsigned long missing_auxv_type; | |
36 | for (missing_auxv_type = AT_RANDOM + 1; ; ++missing_auxv_type) | |
37 | { | |
38 | errno = 0; | |
39 | if (getauxval (missing_auxv_type) == 0 && errno != 0) | |
40 | { | |
41 | TEST_COMPARE (errno, ENOENT); | |
42 | break; | |
43 | } | |
44 | } | |
45 | printf ("info: first missing type: %lu\n", missing_auxv_type); | |
46 | ||
47 | void *handle = xdlopen ("tst-auxvalmod.so", RTLD_LAZY); | |
48 | void *ptr = xdlsym (handle, "getauxval_wrapper"); | |
49 | ||
50 | __typeof__ (getauxval_wrapper) *wrapper = ptr; | |
51 | int inner_errno = 0; | |
52 | unsigned long inner_random = wrapper (AT_RANDOM, &inner_errno); | |
53 | TEST_COMPARE (outer_random, inner_random); | |
54 | ||
55 | inner_errno = 0; | |
56 | TEST_COMPARE (wrapper (missing_auxv_type, &inner_errno), 0); | |
57 | TEST_COMPARE (inner_errno, ENOENT); | |
58 | ||
59 | TEST_COMPARE (getauxval (AT_HWCAP), wrapper (AT_HWCAP, &inner_errno)); | |
60 | TEST_COMPARE (getauxval (AT_HWCAP2), wrapper (AT_HWCAP2, &inner_errno)); | |
61 | ||
62 | xdlclose (handle); | |
63 | return 0; | |
64 | } | |
65 | ||
66 | #include <support/test-driver.c> |