1 /* Operating system support for run-time dynamic linker. Generic Unix version.
2 Copyright (C) 1995, 96 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
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
21 #include <sys/types.h>
32 extern char **_dl_argv
;
33 extern char **_environ
;
34 extern void _start (void);
36 int __libc_enable_secure
;
39 _dl_sysdep_start (void **start_argptr
,
40 void (*dl_main
) (const ElfW(Phdr
) *phdr
, ElfW(Word
) phnum
,
41 ElfW(Addr
) *user_entry
))
43 const ElfW(Phdr
) *phdr
;
45 ElfW(Addr
) user_entry
;
51 user_entry
= (ElfW(Addr
)) &_start
;
52 _dl_argc
= *(long *) start_argptr
;
53 _dl_argv
= (char **) start_argptr
+ 1;
54 _environ
= &_dl_argv
[_dl_argc
+ 1];
55 start_argptr
= (void **) _environ
;
60 #define M(type) (1 << (type))
62 for (av
= (void *) ++start_argptr
;
63 av
->a_type
!= AT_NULL
;
64 seen
|= M ((++av
)->a_type
))
68 phdr
= av
->a_un
.a_ptr
;
71 phnum
= av
->a_un
.a_val
;
74 user_entry
= av
->a_un
.a_val
;
83 euid
= av
->a_un
.a_val
;
86 egid
= av
->a_un
.a_val
;
90 /* Linux doesn't provide us with any of these values on the stack
91 when the dynamic linker is run directly as a program. */
93 #define SEE(UID, uid) if ((seen & M (AT_##UID)) == 0) uid = __get##uid ()
100 __libc_enable_secure
= uid
!= euid
|| gid
!= egid
;
102 #ifdef DL_SYSDEP_INIT
106 (*dl_main
) (phdr
, phnum
, &user_entry
);
111 _dl_sysdep_start_cleanup (void)
116 /* This is only needed if the system doesn't support MAP_ANON. */
119 _dl_sysdep_open_zero_fill (void)
121 return __open ("/dev/zero", O_RDONLY
);
125 /* Read the whole contents of FILE into new mmap'd space with given
126 protections. *SIZEP gets the size of the file. */
129 _dl_sysdep_read_whole_file (const char *file
, size_t *sizep
, int prot
)
133 int fd
= __open (file
, O_RDONLY
);
136 if (__fstat (fd
, &st
) < 0)
140 /* Map a copy of the file contents. */
141 result
= __mmap (0, st
.st_size
, prot
,
151 if (result
== (void *) -1)
161 _dl_sysdep_fatal (const char *msg
, ...)
168 size_t len
= strlen (msg
);
169 __write (STDERR_FILENO
, msg
, len
);
170 msg
= va_arg (ap
, const char *);
179 _dl_sysdep_message (const char *msg
, ...)
186 size_t len
= strlen (msg
);
187 __write (STDOUT_FILENO
, msg
, len
);
188 msg
= va_arg (ap
, const char *);