* inet/getrpcbynumber.c (BUFLEN): New macro.
[glibc.git] / sysdeps / generic / dl-sysdep.c
blob9fab0f0922dbc180f72ad13ffbe146566d66b87a
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. */
20 #include <elf.h>
21 #include <sys/types.h>
22 #include <fcntl.h>
23 #include <link.h>
24 #include <unistd.h>
25 #include <stdarg.h>
26 #include <string.h>
29 extern int _dl_argc;
30 extern char **_dl_argv;
31 extern char **_environ;
32 extern void _start (void);
33 extern int _dl_secure;
35 ElfW(Addr)
36 _dl_sysdep_start (void **start_argptr,
37 void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
38 ElfW(Addr) *user_entry))
40 const ElfW(Phdr) *phdr;
41 ElfW(Word) phnum;
42 ElfW(Addr) user_entry;
43 ElfW(auxv_t) *av;
44 uid_t uid, euid;
45 gid_t gid, egid;
46 unsigned int seen;
48 user_entry = (ElfW(Addr)) &_start;
49 _dl_argc = *(long *) start_argptr;
50 _dl_argv = (char **) start_argptr + 1;
51 _environ = &_dl_argv[_dl_argc + 1];
52 start_argptr = (void **) _environ;
53 while (*start_argptr)
54 ++start_argptr;
56 seen = 0;
57 #define M(type) (1 << (type))
59 for (av = (void *) ++start_argptr;
60 av->a_type != AT_NULL;
61 seen |= M ((++av)->a_type))
62 switch (av->a_type)
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;
72 break;
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;
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. */
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);
97 _dl_secure = uid != euid || gid != egid;
99 #ifdef DL_SYSDEP_INIT
100 DL_SYSDEP_INIT;
101 #endif
103 (*dl_main) (phdr, phnum, &user_entry);
104 return user_entry;
107 void
108 _dl_sysdep_start_cleanup (void)
113 _dl_sysdep_open_zero_fill (void)
115 return __open ("/dev/zero", O_RDONLY);
118 void
119 _dl_sysdep_fatal (const char *msg, ...)
121 va_list ap;
123 va_start (ap, msg);
126 size_t len = strlen (msg);
127 __write (STDERR_FILENO, msg, len);
128 msg = va_arg (ap, const char *);
129 } while (msg);
130 va_end (ap);
132 _exit (127);
136 void
137 _dl_sysdep_message (const char *msg, ...)
139 va_list ap;
141 va_start (ap, msg);
144 size_t len = strlen (msg);
145 __write (STDOUT_FILENO, msg, len);
146 msg = va_arg (ap, const char *);
147 } while (msg);
148 va_end (ap);