elf: Extract command-line/environment variables state from rtld.c
[platform/upstream/glibc.git] / elf / dl-main.h
1 /* Information collection during ld.so startup.
2    Copyright (C) 1995-2020 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 #ifndef _DL_MAIN
20 #define _DL_MAIN
21
22 #include <limits.h>
23
24 /* Length limits for names and paths, to protect the dynamic linker,
25    particularly when __libc_enable_secure is active.  */
26 #ifdef NAME_MAX
27 # define SECURE_NAME_LIMIT NAME_MAX
28 #else
29 # define SECURE_NAME_LIMIT 255
30 #endif
31 #ifdef PATH_MAX
32 # define SECURE_PATH_LIMIT PATH_MAX
33 #else
34 # define SECURE_PATH_LIMIT 1024
35 #endif
36
37 /* Strings containing colon-separated lists of audit modules.  */
38 struct audit_list
39 {
40   /* Array of strings containing colon-separated path lists.  Each
41      audit module needs its own namespace, so pre-allocate the largest
42      possible list.  */
43   const char *audit_strings[DL_NNS];
44
45   /* Number of entries added to audit_strings.  */
46   size_t length;
47
48   /* Index into the audit_strings array (for the iteration phase).  */
49   size_t current_index;
50
51   /* Tail of audit_strings[current_index] which still needs
52      processing.  */
53   const char *current_tail;
54
55   /* Scratch buffer for returning a name which is part of the strings
56      in audit_strings.  */
57   char fname[SECURE_NAME_LIMIT];
58 };
59
60 /* This is a list of all the modes the dynamic loader can be in.  */
61 enum rtld_mode
62   {
63     rtld_mode_normal, rtld_mode_list, rtld_mode_verify, rtld_mode_trace,
64   };
65
66 /* Aggregated state information extracted from environment variables
67    and the ld.so command line.  */
68 struct dl_main_state
69 {
70   struct audit_list audit_list;
71
72   /* The library search path.  */
73   const char *library_path;
74
75   /* The list preloaded objects from LD_PRELOAD.  */
76   const char *preloadlist;
77
78   /* The preload list passed as a command argument.  */
79   const char *preloadarg;
80
81   enum rtld_mode mode;
82
83   /* True if any of the debugging options is enabled.  */
84   bool any_debug;
85
86   /* True if information about versions has to be printed.  */
87   bool version_info;
88 };
89
90 /* Helper function to invoke _dl_init_paths with the right arguments
91    from *STATE.  */
92 static inline void
93 call_init_paths (const struct dl_main_state *state)
94 {
95   _dl_init_paths (state->library_path);
96 }
97
98 #endif /* _DL_MAIN */