1 /* Print kernel diagnostics data in ld.so.  Linux version.
2    Copyright (C) 2021-2022 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.  */
24 static void
print_auxv(void)25 print_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 ("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         /* The address of the strings is not useful at all, so print
39            the strings themselvs.  */
40         _dl_diagnostics_print_string ((const char *) av->a_un.a_val);
41       else
42         _dl_printf ("0x%lx", (unsigned long int) av->a_un.a_val);
43       _dl_printf ("\n");
44       ++index;
45     }
46 }
47 
48 /* Print one uname entry.  */
49 static void
print_utsname_entry(const char * field,const char * value)50 print_utsname_entry (const char *field, const char *value)
51 {
52   _dl_printf ("uname.");
53   _dl_diagnostics_print_labeled_string (field, value);
54 }
55 
56 /* Print information from uname, including the kernel version.  */
57 static void
print_uname(void)58 print_uname (void)
59 {
60   struct utsname uts;
61   if (__uname (&uts) == 0)
62     {
63       print_utsname_entry ("sysname", uts.sysname);
64       print_utsname_entry ("nodename", uts.nodename);
65       print_utsname_entry ("release", uts.release);
66       print_utsname_entry ("version", uts.version);
67       print_utsname_entry ("machine", uts.machine);
68       print_utsname_entry ("domainname", uts.domainname);
69     }
70 }
71 
72 void
_dl_diagnostics_kernel(void)73 _dl_diagnostics_kernel (void)
74 {
75   print_auxv ();
76   print_uname ();
77 }
78