elf: Use errcode instead of (unset) errno in rtld_chain_load
[glibc.git] / elf / dl-main.h
blobd3820e00631438784773332fb7c7e2a932ccfc8d
1 /* Information collection during ld.so startup.
2 Copyright (C) 1995-2021 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/>. */
19 #ifndef _DL_MAIN
20 #define _DL_MAIN
22 #include <ldsodefs.h>
23 #include <limits.h>
24 #include <stdlib.h>
26 /* Length limits for names and paths, to protect the dynamic linker,
27 particularly when __libc_enable_secure is active. */
28 #ifdef NAME_MAX
29 # define SECURE_NAME_LIMIT NAME_MAX
30 #else
31 # define SECURE_NAME_LIMIT 255
32 #endif
33 #ifdef PATH_MAX
34 # define SECURE_PATH_LIMIT PATH_MAX
35 #else
36 # define SECURE_PATH_LIMIT 1024
37 #endif
39 /* Strings containing colon-separated lists of audit modules. */
40 struct audit_list
42 /* Array of strings containing colon-separated path lists. Each
43 audit module needs its own namespace, so pre-allocate the largest
44 possible list. */
45 const char *audit_strings[DL_NNS];
47 /* Number of entries added to audit_strings. */
48 size_t length;
50 /* Index into the audit_strings array (for the iteration phase). */
51 size_t current_index;
53 /* Tail of audit_strings[current_index] which still needs
54 processing. */
55 const char *current_tail;
57 /* Scratch buffer for returning a name which is part of the strings
58 in audit_strings. */
59 char fname[SECURE_NAME_LIMIT];
62 /* This is a list of all the modes the dynamic loader can be in. */
63 enum rtld_mode
65 rtld_mode_normal, rtld_mode_list, rtld_mode_verify, rtld_mode_trace,
66 rtld_mode_list_tunables, rtld_mode_list_diagnostics, rtld_mode_help,
69 /* Aggregated state information extracted from environment variables
70 and the ld.so command line. */
71 struct dl_main_state
73 struct audit_list audit_list;
75 /* The library search path. */
76 const char *library_path;
78 /* Where library_path comes from. LD_LIBRARY_PATH or --library-path. */
79 const char *library_path_source;
81 /* The list preloaded objects from LD_PRELOAD. */
82 const char *preloadlist;
84 /* The preload list passed as a command argument. */
85 const char *preloadarg;
87 /* Additional glibc-hwcaps subdirectories to search first.
88 Colon-separated list. */
89 const char *glibc_hwcaps_prepend;
91 /* Mask for the internal glibc-hwcaps subdirectories.
92 Colon-separated list. */
93 const char *glibc_hwcaps_mask;
95 enum rtld_mode mode;
97 /* True if any of the debugging options is enabled. */
98 bool any_debug;
100 /* True if information about versions has to be printed. */
101 bool version_info;
104 /* Helper function to invoke _dl_init_paths with the right arguments
105 from *STATE. */
106 static inline void
107 call_init_paths (const struct dl_main_state *state)
109 _dl_init_paths (state->library_path, state->library_path_source,
110 state->glibc_hwcaps_prepend, state->glibc_hwcaps_mask);
113 /* Print ld.so usage information and exit. */
114 _Noreturn void _dl_usage (const char *argv0, const char *wrong_option)
115 attribute_hidden;
117 /* Print ld.so version information and exit. */
118 _Noreturn void _dl_version (void) attribute_hidden;
120 /* Print ld.so --help output and exit. */
121 _Noreturn void _dl_help (const char *argv0, struct dl_main_state *state)
122 attribute_hidden;
124 /* Print a diagnostics dump. */
125 _Noreturn void _dl_print_diagnostics (char **environ) attribute_hidden;
127 #endif /* _DL_MAIN */