]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/dl-osinfo.h
1 /* Operating system specific code for generic dynamic loader functions. Linux.
2 Copyright (C) 2000-2002,2004-2009,2011 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 #include <kernel-features.h>
20 #include <dl-sysdep.h>
24 #include <not-cancel.h>
27 # define MIN(a,b) (((a)<(b))?(a):(b))
31 /* This is the function used in the dynamic linker to print the fatal error
34 __attribute__ ((__noreturn__
))
35 dl_fatal (const char *str
)
42 #define DL_SYSDEP_OSCHECK(FATAL) \
44 /* Test whether the kernel is new enough. This test is only performed \
45 if the library is not compiled to run on all kernels. */ \
47 int version = _dl_discover_osversion (); \
48 if (__builtin_expect (version >= 0, 1)) \
50 if (__builtin_expect (GLRO(dl_osversion) == 0, 1) \
51 || GLRO(dl_osversion) > version) \
52 GLRO(dl_osversion) = version; \
54 /* Now we can test with the required version. */ \
55 if (__LINUX_KERNEL_VERSION > 0 && version < __LINUX_KERNEL_VERSION) \
56 /* Not sufficent. */ \
57 FATAL ("FATAL: kernel too old\n"); \
59 else if (__LINUX_KERNEL_VERSION > 0) \
60 FATAL ("FATAL: cannot determine kernel version\n"); \
63 static inline uintptr_t __attribute__ ((always_inline
))
64 _dl_setup_stack_chk_guard (void *dl_random
)
69 unsigned char bytes
[sizeof (uintptr_t)];
72 #ifndef __ASSUME_AT_RANDOM
73 if (__builtin_expect (dl_random
== NULL
, 0))
75 const size_t filllen
= sizeof (ret
.bytes
) - 1;
77 # ifdef ENABLE_STACKGUARD_RANDOMIZE
78 int fd
= open_not_cancel_2 ("/dev/urandom", O_RDONLY
);
81 ssize_t reslen
= read_not_cancel (fd
, ret
.bytes
+ 1, filllen
);
82 close_not_cancel_no_status (fd
);
83 if (reslen
== (ssize_t
) filllen
)
87 ret
.bytes
[filllen
- 2] = 255;
88 ret
.bytes
[filllen
- 3] = '\n';
93 /* We need in the moment only 8 bytes on 32-bit platforms and 16
94 bytes on 64-bit platforms. Therefore we can use the data
95 directly and not use the kernel-provided data to seed a PRNG. */
96 memcpy (ret
.bytes
, dl_random
, sizeof (ret
));
97 #if BYTE_ORDER == LITTLE_ENDIAN
99 #elif BYTE_ORDER == BIG_ENDIAN
100 ret
.num
&= ~(0xff << (8 * (sizeof (ret
) - 1)));
102 # error "BYTE_ORDER unknown"
108 static inline uintptr_t __attribute__ ((always_inline
))
109 _dl_setup_pointer_guard (void *dl_random
, uintptr_t stack_chk_guard
)
112 #ifndef __ASSUME_AT_RANDOM
113 if (dl_random
== NULL
)
115 ret
= stack_chk_guard
;
116 # ifndef HP_TIMING_NONAVAIL
124 memcpy (&ret
, (char *) dl_random
+ sizeof (ret
), sizeof (ret
));