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. */
21 #include <sys/types.h>
32 extern char **_dl_argv
;
33 extern char **_environ
;
34 extern size_t _dl_pagesize
;
36 extern void _start (void);
38 int __libc_enable_secure
;
39 int __libc_multiple_libcs
; /* Defining this here avoids the inclusion
43 _dl_sysdep_start (void **start_argptr
,
44 void (*dl_main
) (const ElfW(Phdr
) *phdr
, ElfW(Word
) phnum
,
45 ElfW(Addr
) *user_entry
))
47 const ElfW(Phdr
) *phdr
= NULL
;
49 ElfW(Addr
) user_entry
;
57 user_entry
= (ElfW(Addr
)) &_start
;
58 _dl_argc
= *(long *) start_argptr
;
59 _dl_argv
= (char **) start_argptr
+ 1;
60 _environ
= &_dl_argv
[_dl_argc
+ 1];
61 start_argptr
= (void **) _environ
;
66 #define M(type) (1 << (type))
68 for (av
= (void *) ++start_argptr
;
69 av
->a_type
!= AT_NULL
;
70 seen
|= M ((++av
)->a_type
))
74 phdr
= av
->a_un
.a_ptr
;
77 phnum
= av
->a_un
.a_val
;
80 _dl_pagesize
= av
->a_un
.a_val
;
83 user_entry
= av
->a_un
.a_val
;
92 euid
= av
->a_un
.a_val
;
95 egid
= av
->a_un
.a_val
;
99 /* Linux doesn't provide us with any of these values on the stack
100 when the dynamic linker is run directly as a program. */
102 #define SEE(UID, uid) if ((seen & M (AT_##UID)) == 0) uid = __get##uid ()
109 __libc_enable_secure
= uid
!= euid
|| gid
!= egid
;
111 #ifdef DL_SYSDEP_INIT
115 if (__sbrk (0) == &_end
)
117 /* The dynamic linker was run as a program, and so the initial break
118 starts just after our bss, at &_end. The malloc in dl-minimal.c
119 will consume the rest of this page, so tell the kernel to move the
120 break up that far. When the user program examines its break, it
121 will see this new value and not clobber our data. */
122 size_t pg
= __getpagesize ();
124 __sbrk (pg
- ((&_end
- (void *) 0) & (pg
- 1)));
127 (*dl_main
) (phdr
, phnum
, &user_entry
);
132 _dl_sysdep_start_cleanup (void)
137 /* This is only needed if the system doesn't support MAP_ANON. */
140 _dl_sysdep_open_zero_fill (void)
142 return __open ("/dev/zero", O_RDONLY
);
146 /* Read the whole contents of FILE into new mmap'd space with given
147 protections. *SIZEP gets the size of the file. */
150 _dl_sysdep_read_whole_file (const char *file
, size_t *sizep
, int prot
)
154 int fd
= __open (file
, O_RDONLY
);
157 if (__fxstat (_STAT_VER
, fd
, &st
) < 0)
161 /* Map a copy of the file contents. */
162 result
= __mmap (0, st
.st_size
, prot
,
172 if (result
== (void *) -1)
182 _dl_sysdep_fatal (const char *msg
, ...)
189 size_t len
= strlen (msg
);
190 __write (STDERR_FILENO
, msg
, len
);
191 msg
= va_arg (ap
, const char *);
200 _dl_sysdep_error (const char *msg
, ...)
207 size_t len
= strlen (msg
);
208 __write (STDERR_FILENO
, msg
, len
);
209 msg
= va_arg (ap
, const char *);
216 _dl_sysdep_message (const char *msg
, ...)
223 size_t len
= strlen (msg
);
224 __write (STDOUT_FILENO
, msg
, len
);
225 msg
= va_arg (ap
, const char *);