]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/generic/dl-sysdep.c
Tue Jun 11 19:13:04 1996 Richard Henderson <rth@tamu.edu>
[thirdparty/glibc.git] / sysdeps / generic / dl-sysdep.c
CommitLineData
d66e34cd 1/* Operating system support for run-time dynamic linker. Generic Unix version.
bfc04a9f 2Copyright (C) 1995, 96 Free Software Foundation, Inc.
d66e34cd
RM
3This file is part of the GNU C Library.
4
5The GNU C Library is free software; you can redistribute it and/or
6modify it under the terms of the GNU Library General Public License as
7published by the Free Software Foundation; either version 2 of the
8License, or (at your option) any later version.
9
10The GNU C Library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13Library General Public License for more details.
14
15You should have received a copy of the GNU Library General Public
16License along with the GNU C Library; see the file COPYING.LIB. If
17not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18Cambridge, MA 02139, USA. */
19
20#include <elf.h>
21#include <sys/types.h>
22#include <fcntl.h>
23#include <link.h>
439d1d45 24#include <unistd.h>
8d6468d0
RM
25#include <stdarg.h>
26#include <string.h>
27
439d1d45
RM
28
29extern int _dl_argc;
30extern char **_dl_argv;
31extern char **_environ;
60478656 32extern void _start (void);
bfc04a9f 33extern int _dl_secure;
d66e34cd 34
8d6468d0 35ElfW(Addr)
d66e34cd 36_dl_sysdep_start (void **start_argptr,
8d6468d0
RM
37 void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
38 ElfW(Addr) *user_entry))
d66e34cd 39{
8d6468d0
RM
40 const ElfW(Phdr) *phdr;
41 ElfW(Word) phnum;
42 ElfW(Addr) user_entry;
43 ElfW(auxv_t) *av;
d66e34cd
RM
44 uid_t uid, euid;
45 gid_t gid, egid;
b0d20a87 46 unsigned int seen;
d66e34cd 47
8d6468d0
RM
48 user_entry = (ElfW(Addr)) &_start;
49 _dl_argc = *(long *) start_argptr;
24906b43 50 _dl_argv = (char **) start_argptr + 1;
d66e34cd
RM
51 _environ = &_dl_argv[_dl_argc + 1];
52 start_argptr = (void **) _environ;
53 while (*start_argptr)
54 ++start_argptr;
55
b0d20a87
RM
56 seen = 0;
57#define M(type) (1 << (type))
58
59 for (av = (void *) ++start_argptr;
60 av->a_type != AT_NULL;
61 seen |= M ((++av)->a_type))
d66e34cd
RM
62 switch (av->a_type)
63 {
64 case AT_PHDR:
65 phdr = av->a_un.a_ptr;
66 break;
67 case AT_PHNUM:
68 phnum = av->a_un.a_val;
69 break;
70 case AT_ENTRY:
71 user_entry = av->a_un.a_val;
60478656 72 break;
d66e34cd
RM
73 case AT_UID:
74 uid = av->a_un.a_val;
75 break;
76 case AT_GID:
77 gid = av->a_un.a_val;
78 break;
79 case AT_EUID:
80 euid = av->a_un.a_val;
81 break;
82 case AT_EGID:
83 egid = av->a_un.a_val;
84 break;
85 }
86
b0d20a87
RM
87 /* Linux doesn't provide us with any of these values on the stack
88 when the dynamic linker is run directly as a program. */
89
90#define SEE(UID, uid) if ((seen & M (AT_##UID)) == 0) uid = __get##uid ()
91 SEE (UID, uid);
92 SEE (GID, gid);
93 SEE (EUID, euid);
94 SEE (EGID, egid);
95
96
d66e34cd
RM
97 _dl_secure = uid != euid || gid != egid;
98
376fd36e
RM
99#ifdef DL_SYSDEP_INIT
100 DL_SYSDEP_INIT;
101#endif
102
d66e34cd 103 (*dl_main) (phdr, phnum, &user_entry);
24906b43 104 return user_entry;
d66e34cd
RM
105}
106
a5a81fec
RM
107void
108_dl_sysdep_start_cleanup (void)
109{
110}
111
d66e34cd
RM
112int
113_dl_sysdep_open_zero_fill (void)
114{
564210fe 115 return __open ("/dev/zero", O_RDONLY);
d66e34cd
RM
116}
117
d66e34cd
RM
118void
119_dl_sysdep_fatal (const char *msg, ...)
120{
121 va_list ap;
122
123 va_start (ap, msg);
124 do
125 {
126 size_t len = strlen (msg);
564210fe 127 __write (STDERR_FILENO, msg, len);
d66e34cd
RM
128 msg = va_arg (ap, const char *);
129 } while (msg);
130 va_end (ap);
131
132 _exit (127);
133}
6a76c115
RM
134
135
136void
137_dl_sysdep_message (const char *msg, ...)
138{
139 va_list ap;
140
141 va_start (ap, msg);
142 do
143 {
144 size_t len = strlen (msg);
564210fe 145 __write (STDOUT_FILENO, msg, len);
6a76c115
RM
146 msg = va_arg (ap, const char *);
147 } while (msg);
148 va_end (ap);
149}