]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/generic/dl-sysdep.c
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
;
43 int __libc_enable_secure
;
44 int __libc_multiple_libcs
; /* Defining this here avoids the inclusion
46 static ElfW(auxv_t
) *_dl_auxv
;
49 #ifndef DL_FIND_ARG_COMPONENTS
50 #define DL_FIND_ARG_COMPONENTS(cookie, argc, argv, envp, auxp) \
53 (argc) = *(long *) cookie; \
54 (argv) = (char **) cookie + 1; \
55 (envp) = (argv) + (argc) + 1; \
56 for (_tmp = (void **) (envp); *_tmp; ++_tmp) \
58 (auxp) = (void *) ++_tmp; \
64 _dl_sysdep_start (void **start_argptr
,
65 void (*dl_main
) (const ElfW(Phdr
) *phdr
, ElfW(Word
) phnum
,
66 ElfW(Addr
) *user_entry
))
68 const ElfW(Phdr
) *phdr
= NULL
;
70 ElfW(Addr
) user_entry
;
78 DL_FIND_ARG_COMPONENTS (start_argptr
, _dl_argc
, _dl_argv
, _environ
, _dl_auxv
);
80 user_entry
= (ElfW(Addr
)) &ENTRY_POINT
;
81 _dl_platform
= NULL
; /* Default to nothing known about the platform. */
84 #define M(type) (1 << (type))
86 for (av
= _dl_auxv
; av
->a_type
!= AT_NULL
; seen
|= M ((++av
)->a_type
))
90 phdr
= av
->a_un
.a_ptr
;
93 phnum
= av
->a_un
.a_val
;
96 _dl_pagesize
= av
->a_un
.a_val
;
99 user_entry
= av
->a_un
.a_val
;
102 _dl_base_addr
= av
->a_un
.a_val
;
105 uid
= av
->a_un
.a_val
;
108 gid
= av
->a_un
.a_val
;
111 euid
= av
->a_un
.a_val
;
114 egid
= av
->a_un
.a_val
;
117 _dl_platform
= av
->a_un
.a_ptr
;
120 _dl_hwcap
= av
->a_un
.a_val
;
124 /* Linux doesn't provide us with any of these values on the stack
125 when the dynamic linker is run directly as a program. */
127 #define SEE(UID, uid) if ((seen & M (AT_##UID)) == 0) uid = __get##uid ()
133 __libc_enable_secure
= uid
!= euid
|| gid
!= egid
;
135 if (_dl_pagesize
== 0)
136 _dl_pagesize
= __getpagesize ();
138 #ifdef DL_SYSDEP_INIT
142 #ifdef DL_PLATFORM_INIT
146 /* Determine the length of the platform name. */
147 if (_dl_platform
!= NULL
)
148 _dl_platformlen
= strlen (_dl_platform
);
150 if (__sbrk (0) == &_end
)
151 /* The dynamic linker was run as a program, and so the initial break
152 starts just after our bss, at &_end. The malloc in dl-minimal.c
153 will consume the rest of this page, so tell the kernel to move the
154 break up that far. When the user program examines its break, it
155 will see this new value and not clobber our data. */
156 __sbrk (_dl_pagesize
- ((&_end
- (void *) 0) & (_dl_pagesize
- 1)));
158 (*dl_main
) (phdr
, phnum
, &user_entry
);
163 _dl_sysdep_start_cleanup (void)
173 /* Terminate string. */
176 for (av
= _dl_auxv
; av
->a_type
!= AT_NULL
; ++av
)
180 _dl_sysdep_message ("AT_PHDR: 0x",
181 _itoa_word (av
->a_un
.a_val
, buf
+ sizeof buf
- 1,
186 _dl_sysdep_message ("AT_PHNUM: ",
187 _itoa_word (av
->a_un
.a_val
, buf
+ sizeof buf
- 1,
192 _dl_sysdep_message ("AT_PAGESZ: ",
193 _itoa_word (av
->a_un
.a_val
, buf
+ sizeof buf
- 1,
198 _dl_sysdep_message ("AT_ENTRY: 0x",
199 _itoa_word (av
->a_un
.a_val
, buf
+ sizeof buf
- 1,
204 _dl_sysdep_message ("AT_BASE: 0x",
205 _itoa_word (av
->a_un
.a_val
, buf
+ sizeof buf
- 1,
210 _dl_sysdep_message ("AT_UID: ",
211 _itoa_word (av
->a_un
.a_val
, buf
+ sizeof buf
- 1,
216 _dl_sysdep_message ("AT_GID: ",
217 _itoa_word (av
->a_un
.a_val
, buf
+ sizeof buf
- 1,
222 _dl_sysdep_message ("AT_EUID: ",
223 _itoa_word (av
->a_un
.a_val
, buf
+ sizeof buf
- 1,
228 _dl_sysdep_message ("AT_EGID: ",
229 _itoa_word (av
->a_un
.a_val
, buf
+ sizeof buf
- 1,
234 _dl_sysdep_message ("AT_PLATFORM: ", av
->a_un
.a_ptr
, NULL
);
237 _dl_sysdep_message ("AT_HWCAP: ",
238 _itoa_word (av
->a_un
.a_val
, buf
+ sizeof buf
- 1,