1/* Print kernel diagnostics data in ld.so. Linux version.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
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 <dl-diagnostics.h>
20#include <ldsodefs.h>
21#include <sys/utsname.h>
22
23/* Dump the auxiliary vector to standard output. */
24static void
25print_auxv (void)
26{
27 /* See _dl_show_auxv. The code below follows the general output
28 format for diagnostic dumps. */
29 unsigned int index = 0;
30 for (ElfW(auxv_t) *av = GLRO(dl_auxv); av->a_type != AT_NULL; ++av)
31 {
32 _dl_printf (fmt: "auxv[0x%x].a_type=0x%lx\n"
33 "auxv[0x%x].a_val",
34 index, (unsigned long int) av->a_type, index);
35 if (av->a_type == AT_EXECFN
36 || av->a_type == AT_PLATFORM
37 || av->a_type == AT_BASE_PLATFORM)
38 {
39 /* The address of the strings is not useful at all, so print
40 the strings themselves. */
41 _dl_printf (fmt: "_string=");
42 _dl_diagnostics_print_string (s: (const char *) av->a_un.a_val);
43 }
44 else
45 _dl_printf (fmt: "=0x%lx", (unsigned long int) av->a_un.a_val);
46 _dl_printf (fmt: "\n");
47 ++index;
48 }
49}
50
51/* Print one uname entry. */
52static void
53print_utsname_entry (const char *field, const char *value)
54{
55 _dl_printf (fmt: "uname.");
56 _dl_diagnostics_print_labeled_string (label: field, s: value);
57}
58
59/* Print information from uname, including the kernel version. */
60static void
61print_uname (void)
62{
63 struct utsname uts;
64 if (__uname (&uts) == 0)
65 {
66 print_utsname_entry (field: "sysname", value: uts.sysname);
67 print_utsname_entry (field: "nodename", value: uts.nodename);
68 print_utsname_entry (field: "release", value: uts.release);
69 print_utsname_entry (field: "version", value: uts.version);
70 print_utsname_entry (field: "machine", value: uts.machine);
71 print_utsname_entry (field: "domainname", value: uts.domainname);
72 }
73}
74
75void
76_dl_diagnostics_kernel (void)
77{
78 print_auxv ();
79 print_uname ();
80}
81

source code of glibc/sysdeps/unix/sysv/linux/dl-diagnostics-kernel.c