/[glibc-bsd]/trunk/glibc-ports/kfreebsd/dl-sysdep.c
ViewVC logotype

Contents of /trunk/glibc-ports/kfreebsd/dl-sysdep.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3756 - (show annotations) (download)
Sat Oct 22 12:29:55 2011 UTC (2 years, 5 months ago) by rmh
File MIME type: text/plain
File size: 7904 byte(s)
Add missing colon.
1 /* Dynamic linker system dependencies for GNU/kFreeBSD.
2 Copyright (C) 1995-1998,2000-2008,2009,2010,2011
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 /* For SHARED, use the generic dynamic linker system interface code. */
22 /* otherwise the code is in dl-support.c */
23
24 #include <string.h>
25 #include <fcntl.h>
26 #include <unistd.h>
27 #include <sys/sysctl.h>
28 #include <ldsodefs.h>
29 #include <kernel-features.h>
30
31 #ifdef SHARED
32 # define _dl_sysdep_start _dl_sysdep_start_ignored_code
33 # define _dl_show_auxv _dl_show_auxv_ignored_code
34 # include <elf/dl-sysdep.c>
35 # include <bits/elf.h>
36 # undef _dl_sysdep_start
37 # undef _dl_show_auxv
38
39 extern const char *_self_program_name_from_auxv attribute_hidden;
40
41 ElfW(Addr)
42 _dl_sysdep_start (void **start_argptr,
43 void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
44 ElfW(Addr) *user_entry, ElfW(auxv_t) *auxv))
45 {
46 const ElfW(Phdr) *phdr = NULL;
47 ElfW(Word) phnum = 0;
48 ElfW(Addr) user_entry;
49 ElfW(auxv_t) *av;
50 uid_t uid = 0;
51 gid_t gid = 0;
52 #ifdef NEED_DL_SYSINFO
53 uintptr_t new_sysinfo = 0;
54 #endif
55
56 __libc_stack_end = DL_STACK_END (start_argptr);
57 DL_FIND_ARG_COMPONENTS (start_argptr, _dl_argc, INTUSE(_dl_argv), _environ,
58 _dl_auxv);
59
60 user_entry = (ElfW(Addr)) ENTRY_POINT;
61 GLRO(dl_platform) = NULL; /* Default to nothing known about the platform. */
62
63 for (av = _dl_auxv; av->a_type != AT_NULL; av++)
64 switch (av->a_type)
65 {
66 case AT_PHDR:
67 phdr = (void *) av->a_un.a_val;
68 break;
69 case AT_PHNUM:
70 phnum = av->a_un.a_val;
71 break;
72 case AT_PAGESZ:
73 GLRO(dl_pagesize) = av->a_un.a_val;
74 break;
75 case AT_ENTRY:
76 user_entry = av->a_un.a_val;
77 break;
78 case AT_EXECPATH:
79 _self_program_name_from_auxv = (char *) av->a_un.a_val;
80 break;
81 #ifdef NEED_DL_BASE_ADDR
82 case AT_BASE:
83 _dl_base_addr = av->a_un.a_val;
84 break;
85 #endif
86 }
87
88 {
89 /* Fill in the values we have not gotten from the kernel through the
90 auxiliary vector. */
91 # undef SEE
92 # define SEE(UID, var, uid) \
93 var ^= __get##uid ()
94 SEE (UID, uid, uid);
95 SEE (EUID, uid, euid);
96 SEE (GID, gid, gid);
97 SEE (EGID, gid, egid);
98
99 /* If one of the two pairs of IDs does not match this is a setuid
100 or setgid run. */
101 INTUSE(__libc_enable_secure) = uid | gid;
102 }
103
104 #ifndef HAVE_AUX_PAGESIZE
105 if (GLRO(dl_pagesize) == 0)
106 GLRO(dl_pagesize) = __getpagesize ();
107 #endif
108
109 #if defined NEED_DL_SYSINFO
110 /* Only set the sysinfo value if we also have the vsyscall DSO. */
111 if (GLRO(dl_sysinfo_dso) != 0 && new_sysinfo)
112 GLRO(dl_sysinfo) = new_sysinfo;
113 #endif
114
115 #ifdef DL_SYSDEP_INIT
116 DL_SYSDEP_INIT;
117 #endif
118
119 #ifdef DL_PLATFORM_INIT
120 DL_PLATFORM_INIT;
121 #endif
122
123 /* Determine the length of the platform name. */
124 if (GLRO(dl_platform) != NULL)
125 GLRO(dl_platformlen) = strlen (GLRO(dl_platform));
126
127 if (__sbrk (0) == _end)
128 /* The dynamic linker was run as a program, and so the initial break
129 starts just after our bss, at &_end. The malloc in dl-minimal.c
130 will consume the rest of this page, so tell the kernel to move the
131 break up that far. When the user program examines its break, it
132 will see this new value and not clobber our data. */
133 __sbrk (GLRO(dl_pagesize)
134 - ((_end - (char *) 0) & (GLRO(dl_pagesize) - 1)));
135
136 /* If this is a SUID program we make sure that FDs 0, 1, and 2 are
137 allocated. If necessary we are doing it ourself. If it is not
138 possible we stop the program. */
139 if (__builtin_expect (INTUSE(__libc_enable_secure), 0))
140 __libc_check_standard_fds ();
141
142 (*dl_main) (phdr, phnum, &user_entry, _dl_auxv);
143 return user_entry;
144 }
145
146 void
147 internal_function
148 _dl_show_auxv (void)
149 {
150 char buf[64];
151 ElfW(auxv_t) *av;
152
153 /* Terminate string. */
154 buf[63] = '\0';
155
156 /* The following code assumes that the AT_* values are encoded
157 starting from 0 with AT_NULL, 1 for AT_IGNORE, and all other values
158 close by (otherwise the array will be too large). In case we have
159 to support a platform where these requirements are not fulfilled
160 some alternative implementation has to be used. */
161 for (av = _dl_auxv; av->a_type != AT_NULL; ++av)
162 {
163 static const struct
164 {
165 const char label[17];
166 enum { unknown = 0, dec, hex, str, ignore } form : 8;
167 } auxvars[] =
168 {
169 [AT_EXECFD - 2] = { "EXECFD: ", dec },
170 [AT_PHDR - 2] = { "PHDR: 0x", hex },
171 [AT_PHENT - 2] = { "PHENT: ", dec },
172 [AT_PHNUM - 2] = { "PHNUM: ", dec },
173 [AT_PAGESZ - 2] = { "PAGESZ: ", dec },
174 [AT_BASE - 2] = { "BASE: 0x", hex },
175 [AT_FLAGS - 2] = { "FLAGS: 0x", hex },
176 [AT_ENTRY - 2] = { "ENTRY: 0x", hex },
177 #ifndef __powerpc__
178 /* For some odd reason these are not in sys/powerpc/include/elf.h. */
179 [AT_NOTELF - 2] = { "NOTELF: ", hex },
180 [AT_UID - 2] = { "UID: ", dec },
181 [AT_EUID - 2] = { "EUID: ", dec },
182 [AT_GID - 2] = { "GID: ", dec },
183 [AT_EGID - 2] = { "EGID: ", dec },
184 #endif
185 [AT_EXECPATH - 2] = { "EXECPATH: ", str },
186 [AT_CANARY - 2] = { "CANARY: 0x", hex },
187 [AT_CANARYLEN - 2] = { "CANARYLEN: ", dec },
188 [AT_OSRELDATE - 2] = { "OSRELDATE: ", dec },
189 [AT_NCPUS - 2] = { "NCPUS: ", dec },
190 [AT_PAGESIZES - 2] = { "PAGESIZES: 0x", hex },
191 [AT_PAGESIZESLEN - 2] = { "PAGESIZESLEN: ", dec },
192 [AT_STACKPROT - 2] = { "STACKPROT: 0x", hex },
193 };
194 unsigned int idx = (unsigned int) (av->a_type - 2);
195
196 if ((unsigned int) av->a_type < 2u || auxvars[idx].form == ignore)
197 continue;
198
199 assert (AT_NULL == 0);
200 assert (AT_IGNORE == 1);
201
202 if (idx < sizeof (auxvars) / sizeof (auxvars[0])
203 && auxvars[idx].form != unknown)
204 {
205 const char *val = (char *) av->a_un.a_val;
206
207 if (__builtin_expect (auxvars[idx].form, dec) == dec)
208 val = _itoa ((unsigned long int) av->a_un.a_val,
209 buf + sizeof buf - 1, 10, 0);
210 else if (__builtin_expect (auxvars[idx].form, hex) == hex)
211 val = _itoa ((unsigned long int) av->a_un.a_val,
212 buf + sizeof buf - 1, 16, 0);
213
214 _dl_printf ("AT_%s%s\n", auxvars[idx].label, val);
215
216 continue;
217 }
218
219 /* Unknown value: print a generic line. */
220 char buf2[17];
221 buf2[sizeof (buf2) - 1] = '\0';
222 const char *val2 = _itoa ((unsigned long int) av->a_un.a_val,
223 buf2 + sizeof buf2 - 1, 16, 0);
224 const char *val = _itoa ((unsigned long int) av->a_type,
225 buf + sizeof buf - 1, 16, 0);
226 _dl_printf ("AT_??? (0x%s): 0x%s\n", val, val2);
227 }
228 }
229 #endif
230
231 int
232 attribute_hidden
233 _dl_discover_osversion (void)
234 {
235 int request[2] = { CTL_KERN, KERN_OSRELDATE };
236 size_t len;
237 int version;
238
239 len = sizeof(version);
240 if (__sysctl (request, 2, &version, &len, NULL, 0) < 0)
241 return -1;
242
243 /*
244 * scheme is: <major><two digit minor>Rxx
245 * 'R' is 0 if release branch or x.0-CURRENT before RELENG_*_0
246 * is created, otherwise 1.
247 */
248
249 /* Convert to the GLIBC versioning system */
250 return ((version / 100000) << 16) /* major */
251 | (((version % 100000) / 1000) << 8) /* minor 0 - 99 */
252 | ((version % 200)); /* subrelease 0 - 199 */
253 }

  ViewVC Help
Powered by ViewVC 1.1.5