1 /* Operating system support for run-time dynamic linker. Generic Unix version.
2 Copyright (C) 1995, 1996, 1997 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 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.
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.
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. */
22 #include <sys/types.h>
28 #include <stdio-common/_itoa.h>
30 #include <dl-machine.h>
33 extern char **_dl_argv;
34 extern char **_environ;
35 extern size_t _dl_pagesize;
36 extern const char *_dl_platform;
37 extern unsigned long _dl_hwcap;
38 extern size_t _dl_platformlen;
40 extern void ENTRY_POINT (void);
42 ElfW(Addr) _dl_base_addr;
44 int __libc_enable_secure;
45 int __libc_multiple_libcs; /* Defining this here avoids the inclusion
47 static ElfW(auxv_t) *_dl_auxv;
50 #ifndef DL_FIND_ARG_COMPONENTS
51 #define DL_FIND_ARG_COMPONENTS(cookie, argc, argv, envp, auxp) \
54 (argc) = *(long *) cookie; \
55 (argv) = (char **) cookie + 1; \
56 (envp) = (argv) + (argc) + 1; \
57 for (_tmp = (void **) (envp); *_tmp; ++_tmp) \
59 (auxp) = (void *) ++_tmp; \
65 _dl_sysdep_start (void **start_argptr,
66 void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
67 ElfW(Addr) *user_entry))
69 const ElfW(Phdr) *phdr = NULL;
71 ElfW(Addr) user_entry;
79 DL_FIND_ARG_COMPONENTS (start_argptr, _dl_argc, _dl_argv, _environ, _dl_auxv);
81 user_entry = (ElfW(Addr)) &ENTRY_POINT;
82 _dl_platform = NULL; /* Default to nothing known about the platform. */
85 #define M(type) (1 << (type))
87 for (av = _dl_auxv; av->a_type != AT_NULL; seen |= M ((++av)->a_type))
91 phdr = av->a_un.a_ptr;
94 phnum = av->a_un.a_val;
97 _dl_pagesize = av->a_un.a_val;
100 user_entry = av->a_un.a_val;
103 _dl_base_addr = av->a_un.a_val;
106 uid = av->a_un.a_val;
109 gid = av->a_un.a_val;
112 euid = av->a_un.a_val;
115 egid = av->a_un.a_val;
118 _dl_platform = av->a_un.a_ptr;
121 _dl_hwcap = av->a_un.a_val;
125 /* Linux doesn't provide us with any of these values on the stack
126 when the dynamic linker is run directly as a program. */
128 #define SEE(UID, uid) if ((seen & M (AT_##UID)) == 0) uid = __get##uid ()
135 __libc_enable_secure = uid != euid || gid != egid;
137 if (_dl_pagesize == 0)
138 _dl_pagesize = __getpagesize ();
140 #ifdef DL_SYSDEP_INIT
144 #ifdef DL_PLATFORM_INIT
148 /* Determine the length of the platform name. */
149 if (_dl_platform != NULL)
150 _dl_platformlen = strlen (_dl_platform);
152 if (__sbrk (0) == &_end)
153 /* The dynamic linker was run as a program, and so the initial break
154 starts just after our bss, at &_end. The malloc in dl-minimal.c
155 will consume the rest of this page, so tell the kernel to move the
156 break up that far. When the user program examines its break, it
157 will see this new value and not clobber our data. */
158 __sbrk (_dl_pagesize - ((&_end - (void *) 0) & (_dl_pagesize - 1)));
160 (*dl_main) (phdr, phnum, &user_entry);
165 _dl_sysdep_start_cleanup (void)
175 /* Terminate string. */
178 for (av = _dl_auxv; av->a_type != AT_NULL; ++av)
182 _dl_sysdep_message ("AT_PHDR: 0x",
183 _itoa_word (av->a_un.a_val, buf + sizeof buf - 1,
188 _dl_sysdep_message ("AT_PHNUM: ",
189 _itoa_word (av->a_un.a_val, buf + sizeof buf - 1,
194 _dl_sysdep_message ("AT_PAGESZ: ",
195 _itoa_word (av->a_un.a_val, buf + sizeof buf - 1,
200 _dl_sysdep_message ("AT_ENTRY: 0x",
201 _itoa_word (av->a_un.a_val, buf + sizeof buf - 1,
206 _dl_sysdep_message ("AT_BASE: 0x",
207 _itoa_word (av->a_un.a_val, buf + sizeof buf - 1,
212 _dl_sysdep_message ("AT_UID: ",
213 _itoa_word (av->a_un.a_val, buf + sizeof buf - 1,
218 _dl_sysdep_message ("AT_GID: ",
219 _itoa_word (av->a_un.a_val, buf + sizeof buf - 1,
224 _dl_sysdep_message ("AT_EUID: ",
225 _itoa_word (av->a_un.a_val, buf + sizeof buf - 1,
230 _dl_sysdep_message ("AT_EGID: ",
231 _itoa_word (av->a_un.a_val, buf + sizeof buf - 1,
236 _dl_sysdep_message ("AT_PLATFORM: ", av->a_un.a_ptr, NULL);
239 _dl_sysdep_message ("AT_HWCAP: ",
240 _itoa_word (av->a_un.a_val, buf + sizeof buf - 1,