]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/generic/dl-cache.h
(CACHEMAGIC_VERSION_NEW): New value.
[thirdparty/glibc.git] / sysdeps / generic / dl-cache.h
1 /* Support for reading /etc/ld.so.cache files written by Linux ldconfig.
2 Copyright (C) 1999, 2000 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #include <stdint.h>
21
22 #ifndef _DL_CACHE_DEFAULT_ID
23 # define _DL_CACHE_DEFAULT_ID 3
24 #endif
25
26 #ifndef _dl_cache_check_flags
27 # define _dl_cache_check_flags(flags) \
28 ((flags) == 1 || (flags) == _DL_CACHE_DEFAULT_ID)
29 #endif
30
31 #ifndef LD_SO_CACHE
32 # define LD_SO_CACHE SYSCONFDIR "/ld.so.cache"
33 #endif
34
35 #define CACHEMAGIC "ld.so-1.7.0"
36
37 /* libc5 and glibc 2.0/2.1 use the same format. For glibc 2.2 another
38 format has been added in a compatible way:
39 The beginning of the string table is used for the new table:
40 old_magic
41 nlibs
42 libs[0]
43 ...
44 libs[nlibs-1]
45 pad, new magic needs to be aligned
46 - this is string[0] for the old format
47 new magic - this is string[0] for the new format
48 newnlibs
49 ...
50 newlibs[0]
51 ...
52 newlibs[newnlibs-1]
53 string 1
54 string 2
55 ...
56 */
57 struct file_entry
58 {
59 int flags; /* This is 1 for an ELF library. */
60 unsigned int key, value; /* String table indices. */
61 };
62
63 struct cache_file
64 {
65 char magic[sizeof CACHEMAGIC - 1];
66 unsigned int nlibs;
67 struct file_entry libs[0];
68 };
69
70 #define CACHEMAGIC_NEW "glibc-ld.so.cache"
71 #define CACHE_VERSION "1.1"
72 #define CACHEMAGIC_VERSION_NEW CACHEMAGIC_NEW CACHE_VERSION "1.1"
73
74
75 struct file_entry_new
76 {
77 int32_t flags; /* This is 1 for an ELF library. */
78 uint32_t key, value; /* String table indices. */
79 uint32_t __unused; /* Align next field always on 8 byte boundary. */
80 uint64_t hwcap; /* Hwcap entry. */
81 };
82
83 struct cache_file_new
84 {
85 char magic[sizeof CACHEMAGIC_NEW - 1];
86 char version[sizeof CACHE_VERSION - 1];
87 uint32_t nlibs; /* Number of entries. */
88 uint32_t len_strings; /* Size of string table. */
89 uint32_t unused[5]; /* Leave space for future extensions
90 and align to 8 byte boundary. */
91 struct file_entry_new libs[0]; /* Entries describing libraries. */
92 /* After this the string table of size len_strings is found. */
93 };
94
95 /* Used to align cache_file_new. */
96 #define ALIGN_CACHE(addr) \
97 (((addr) + __alignof__ (struct cache_file_new) -1) \
98 & (~(__alignof__ (struct cache_file_new) - 1)))
99
100 static int
101 _dl_cache_libcmp (const char *p1, const char *p2)
102 {
103 while (*p1 != '\0')
104 {
105 if (*p1 >= '0' && *p1 <= '9')
106 {
107 if (*p2 >= '0' && *p2 <= '9')
108 {
109 /* Must compare this numerically. */
110 int val1;
111 int val2;
112
113 val1 = *p1++ - '0';
114 val2 = *p2++ - '0';
115 while (*p1 >= '0' && *p1 <= '9')
116 val1 = val1 * 10 + *p1++ - '0';
117 while (*p2 >= '0' && *p2 <= '9')
118 val2 = val2 * 10 + *p2++ - '0';
119 if (val1 != val2)
120 return val1 - val2;
121 }
122 else
123 return 1;
124 }
125 else if (*p2 >= '0' && *p2 <= '9')
126 return -1;
127 else if (*p1 != *p2)
128 return *p1 - *p2;
129 else
130 {
131 ++p1;
132 ++p2;
133 }
134 }
135 return *p1 - *p2;
136 }