• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
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  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include "linker_auxv.h"
30 
31 #include <elf.h>
32 #include <stdio.h>
33 #include <sys/auxv.h>
34 #include <unistd.h>
35 
36 #include <async_safe/log.h>
37 
auxv_name(int at)38 static const char* auxv_name(int at) {
39   switch (at) {
40   case AT_NULL: return "AT_NULL";
41   case AT_IGNORE: return "AT_IGNORE";
42   case AT_EXECFD: return "AT_EXECFD";
43   case AT_PHDR: return "AT_PHDR";
44   case AT_PHENT: return "AT_PHENT";
45   case AT_PHNUM: return "AT_PHNUM";
46   case AT_PAGESZ: return "AT_PAGESZ";
47   case AT_BASE: return "AT_BASE";
48   case AT_FLAGS: return "AT_FLAGS";
49   case AT_ENTRY: return "AT_ENTRY";
50   case AT_NOTELF: return "AT_NOTELF";
51   case AT_UID: return "AT_UID";
52   case AT_EUID: return "AT_EUID";
53   case AT_GID: return "AT_GID";
54   case AT_EGID: return "AT_EGID";
55   case AT_PLATFORM: return "AT_PLATFORM";
56   case AT_HWCAP: return "AT_HWCAP";
57   case AT_CLKTCK: return "AT_CLKTCK";
58   case AT_SECURE: return "AT_SECURE";
59   case AT_BASE_PLATFORM: return "AT_BASE_PLATFORM";
60   case AT_RANDOM: return "AT_RANDOM";
61   case AT_HWCAP2: return "AT_HWCAP2";
62   case AT_RSEQ_FEATURE_SIZE: return "AT_RSEQ_FEATURE_SIZE";
63   case AT_RSEQ_ALIGN: return "AT_RSEQ_ALIGN";
64   case AT_EXECFN: return "AT_EXECFN";
65   case AT_SYSINFO_EHDR: return "AT_SYSINFO_EHDR";
66 #if defined(AT_MINSIGSTKSZ)
67   case AT_MINSIGSTKSZ: return "AT_MINSIGSTKSZ";
68 #endif
69 #if defined(AT_SYSINFO)
70   case AT_SYSINFO: return "AT_SYSINFO";
71 #endif
72 #if defined(AT_L1I_CACHESIZE)
73   case AT_L1I_CACHESIZE: return "AT_L1I_CACHESIZE";
74 #endif
75 #if defined(AT_L1I_CACHEGEOMETRY)
76   case AT_L1I_CACHEGEOMETRY: return "AT_L1I_CACHEGEOMETRY";
77 #endif
78 #if defined(AT_L1D_CACHESIZE)
79   case AT_L1D_CACHESIZE: return "AT_L1D_CACHESIZE";
80 #endif
81 #if defined(AT_L1D_CACHEGEOMETRY)
82   case AT_L1D_CACHEGEOMETRY: return "AT_L1D_CACHEGEOMETRY";
83 #endif
84 #if defined(AT_L2_CACHESIZE)
85   case AT_L2_CACHESIZE: return "AT_L2_CACHESIZE";
86 #endif
87 #if defined(AT_L2_CACHEGEOMETRY)
88   case AT_L2_CACHEGEOMETRY: return "AT_L2_CACHEGEOMETRY";
89 #endif
90 #if defined(AT_L3_CACHESIZE)
91   case AT_L3_CACHESIZE: return "AT_L3_CACHESIZE";
92 #endif
93 #if defined(AT_L3_CACHEGEOMETRY)
94   case AT_L3_CACHEGEOMETRY: return "AT_L3_CACHEGEOMETRY";
95 #endif
96   }
97   static char name[32];
98   snprintf(name, sizeof(name), "AT_??? (%d)", at);
99   return name;
100 }
101 
ld_show_auxv(ElfW (auxv_t)* auxv)102 void ld_show_auxv(ElfW(auxv_t)* auxv) {
103   for (ElfW(auxv_t)* v = auxv; v->a_type != AT_NULL; ++v) {
104     const char* name = auxv_name(v->a_type);
105     long value = v->a_un.a_val;
106     switch (v->a_type) {
107     case AT_SYSINFO_EHDR:
108     case AT_PHDR:
109     case AT_BASE:
110     case AT_ENTRY:
111     case AT_RANDOM:
112       async_safe_format_fd(STDOUT_FILENO, "%-20s %#lx\n", name, value);
113       break;
114     case AT_FLAGS:
115     case AT_HWCAP:
116     case AT_HWCAP2:
117       async_safe_format_fd(STDOUT_FILENO, "%-20s %#lb\n", name, value);
118       break;
119     case AT_EXECFN:
120     case AT_PLATFORM:
121       async_safe_format_fd(STDOUT_FILENO, "%-20s \"%s\"\n", name, reinterpret_cast<char*>(value));
122       break;
123     default:
124       async_safe_format_fd(STDOUT_FILENO, "%-20s %ld\n", name, value);
125       break;
126     }
127   }
128 }
129