1 /* Check DTAUDIT and vDSO interaction.
2 Copyright (C) 2021-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
25 #include <support/capture_subprocess.h>
26 #include <support/check.h>
27 #include <support/xstdio.h>
28 #include <support/support.h>
32 #define CMDLINE_OPTIONS \
33 { "restart", no_argument, &restart, 1 },
35 static uintptr_t vdso_addr
;
40 fprintf (stderr
, "vdso: %p\n", (void*) vdso_addr
);
45 parse_address (const char *str
)
48 TEST_COMPARE (sscanf (str
, "%p\n", &r
), 1);
53 startswith (const char *str
, const char *pre
)
55 size_t lenpre
= strlen (pre
);
56 size_t lenstr
= strlen (str
);
57 return lenstr
>= lenpre
&& memcmp (pre
, str
, lenpre
) == 0;
61 do_test (int argc
, char *argv
[])
63 vdso_addr
= getauxval (AT_SYSINFO_EHDR
);
65 FAIL_UNSUPPORTED ("getauxval (AT_SYSINFO_EHDR) returned 0");
67 /* We must have either:
68 - One our fource parameters left if called initially:
69 + path to ld.so optional
70 + "--library-path" optional
71 + the library path optional
72 + the application name */
74 return handle_restart ();
78 for (; i
< argc
- 1; i
++)
79 spargv
[i
] = argv
[i
+ 1];
80 spargv
[i
++] = (char *) "--direct";
81 spargv
[i
++] = (char *) "--restart";
84 setenv ("LD_AUDIT", "tst-auditmod22.so", 0);
85 struct support_capture_subprocess result
86 = support_capture_subprogram (spargv
[0], spargv
);
87 support_capture_subprocess_check (&result
, "tst-audit22", 0, sc_allow_stderr
);
89 /* The respawned process should always print the vDSO address (otherwise it
90 will fails as unsupported). However, on some architectures the audit
91 module might see the vDSO with l_addr being 0, meaning a fixed mapping
92 (linux-gate.so). In this case we don't check its value against
93 AT_SYSINFO_EHDR one. */
94 uintptr_t vdso_process
= 0;
95 bool vdso_audit_found
= false;
96 uintptr_t vdso_audit
= 0;
98 FILE *out
= fmemopen (result
.err
.buffer
, result
.err
.length
, "r");
99 TEST_VERIFY (out
!= NULL
);
101 size_t buffer_length
= 0;
102 while (xgetline (&buffer
, &buffer_length
, out
))
104 if (startswith (buffer
, "vdso: "))
105 vdso_process
= parse_address (buffer
+ strlen ("vdso: "));
106 else if (startswith (buffer
, "vdso found: "))
108 vdso_audit
= parse_address (buffer
+ strlen ("vdso found: "));
109 vdso_audit_found
= true;
113 TEST_COMPARE (vdso_audit_found
, true);
115 TEST_COMPARE (vdso_process
, vdso_audit
);
123 #define TEST_FUNCTION_ARGV do_test
124 #include <support/test-driver.c>