1 /* Dynamic linker system dependencies for Linux.
2 Copyright (C) 1995-2014 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 Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 /* Linux needs some special initialization, but otherwise uses
20 the generic dynamic linker system interface code. */
26 #include <sys/utsname.h>
28 #include <kernel-features.h>
31 # define DL_SYSDEP_INIT frob_brk ()
36 __brk (0); /* Initialize the break. */
39 # include <elf/dl-sysdep.c>
45 _dl_discover_osversion (void)
47 #if defined NEED_DL_SYSINFO_DSO && defined SHARED
48 if (GLRO(dl_sysinfo_map
) != NULL
)
50 /* If the kernel-supplied DSO contains a note indicating the kernel's
51 version, we don't need to call uname or parse any strings. */
57 } expected_note
= { { sizeof "Linux", sizeof (ElfW(Word
)), 0 }, "Linux" };
58 const ElfW(Phdr
) *const phdr
= GLRO(dl_sysinfo_map
)->l_phdr
;
59 const ElfW(Word
) phnum
= GLRO(dl_sysinfo_map
)->l_phnum
;
60 for (uint_fast16_t i
= 0; i
< phnum
; ++i
)
61 if (phdr
[i
].p_type
== PT_NOTE
)
63 const ElfW(Addr
) start
= (phdr
[i
].p_vaddr
64 + GLRO(dl_sysinfo_map
)->l_addr
);
65 const ElfW(Nhdr
) *note
= (const void *) start
;
66 while ((ElfW(Addr
)) (note
+ 1) - start
< phdr
[i
].p_memsz
)
68 if (!memcmp (note
, &expected_note
, sizeof expected_note
))
69 return *(const ElfW(Word
) *) ((const void *) note
70 + sizeof expected_note
);
71 #define ROUND(len) (((len) + sizeof note->n_type - 1) & -sizeof note->n_type)
72 note
= ((const void *) (note
+ 1)
73 + ROUND (note
->n_namesz
) + ROUND (note
->n_descsz
));
87 /* Try the uname system call. */
90 /* This was not successful. Now try reading the /proc filesystem. */
91 int fd
= __open ("/proc/sys/kernel/osrelease", O_RDONLY
);
94 ssize_t reslen
= __read (fd
, bufmem
, sizeof (bufmem
));
97 /* This also didn't work. We give up since we cannot
98 make sure the library can actually work. */
100 buf
[MIN (reslen
, (ssize_t
) sizeof (bufmem
) - 1)] = '\0';
105 /* Now convert it into a number. The string consists of at most
110 while ((*cp
>= '0') && (*cp
<= '9'))
112 unsigned int here
= *cp
++ - '0';
114 while ((*cp
>= '0') && (*cp
<= '9'))
124 if (*cp
++ != '.' || parts
== 3)
125 /* Another part following? */
130 version
<<= 8 * (3 - parts
);
135 /* Mask every signal, returning the previous sigmask in OLD. */
138 _dl_mask_all_signals (sigset_t
*old
)
145 /* This function serves as a replacement to pthread_sigmask, which
146 isn't available from within the dynamic linker since it would require
147 linking with libpthread. We duplicate some of the functionality here
148 to avoid requiring libpthread. This isn't quite identical to
149 pthread_sigmask in that we do not mask internal signals used for
150 cancellation and setxid handling. This disables asynchronous
151 cancellation for the duration the signals are disabled, but it's a
152 small window, and prevents any problems with the use of TLS variables
153 in the signal handlers that would have executed. */
155 /* It's very important we don't touch errno here, as that's TLS; since this
156 gets called from get_tls_addr we might end up recursing. */
158 INTERNAL_SYSCALL_DECL (err
);
160 ret
= INTERNAL_SYSCALL (rt_sigprocmask
, err
, 4, SIG_SETMASK
, &new, old
,
166 /* Return sigmask to what it was before a call to _dl_mask_all_signals. */
169 _dl_unmask_signals (sigset_t
*old
)
172 INTERNAL_SYSCALL_DECL (err
);
174 ret
= INTERNAL_SYSCALL (rt_sigprocmask
, err
, 4, SIG_SETMASK
, old
, NULL
,