1 /* Operating system specific code for generic dynamic loader functions. Linux.
2 Copyright (C) 2000-2002,2004-2008, 2009 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <kernel-features.h>
22 #include <dl-sysdep.h>
25 #include <hp-timing.h>
29 # define MIN(a,b) (((a)<(b))?(a):(b))
33 /* This is the function used in the dynamic linker to print the fatal error
36 __attribute__ ((__noreturn__
))
37 dl_fatal (const char *str
)
44 #define DL_SYSDEP_OSCHECK(FATAL) \
46 /* Test whether the kernel is new enough. This test is only performed \
47 if the library is not compiled to run on all kernels. */ \
49 int version = _dl_discover_osversion (); \
50 if (__builtin_expect (version >= 0, 1)) \
52 if (__builtin_expect (GLRO(dl_osversion) == 0, 1) \
53 || GLRO(dl_osversion) > version) \
54 GLRO(dl_osversion) = version; \
56 /* Now we can test with the required version. */ \
57 if (__LINUX_KERNEL_VERSION > 0 && version < __LINUX_KERNEL_VERSION) \
58 /* Not sufficent. */ \
59 FATAL ("FATAL: kernel too old\n"); \
61 else if (__LINUX_KERNEL_VERSION > 0) \
62 FATAL ("FATAL: cannot determine kernel version\n"); \
65 static inline uintptr_t __attribute__ ((always_inline
))
66 _dl_setup_stack_chk_guard (void *dl_random
)
69 #ifndef __ASSUME_AT_RANDOM
70 if (__builtin_expect (dl_random
== NULL
, 0))
72 # ifdef ENABLE_STACKGUARD_RANDOMIZE
73 int fd
= __open ("/dev/urandom", O_RDONLY
);
76 ssize_t reslen
= __read (fd
, &ret
, sizeof (ret
));
78 if (reslen
== (ssize_t
) sizeof (ret
))
83 unsigned char *p
= (unsigned char *) &ret
;
84 p
[sizeof (ret
) - 1] = 255;
85 p
[sizeof (ret
) - 2] = '\n';
89 hpt
= (hpt
& 0xffff) << 8;
93 /* Avoid GCC being too smart. */
94 asm ("" : "=r" (stk
) : "r" (p
));
96 #if __BYTE_ORDER == __LITTLE_ENDIAN
97 stk
<<= (__WORDSIZE
- 23);
98 #elif __WORDSIZE == 64
102 /* Avoid GCC being too smart. */
103 p
= (unsigned char *) &errno
;
104 asm ("" : "=r" (stk
) : "r" (p
));
106 #if __BYTE_ORDER == __LITTLE_ENDIAN
107 stk
<<= (__WORDSIZE
- 29);
115 /* We need in the moment only 8 bytes on 32-bit platforms and 16
116 bytes on 64-bit platforms. Therefore we can use the data
117 directly and not use the kernel-provided data to seed a PRNG. */
118 memcpy (&ret
, dl_random
, sizeof (ret
));
122 static inline uintptr_t __attribute__ ((always_inline
))
123 _dl_setup_pointer_guard (void *dl_random
, uintptr_t stack_chk_guard
)
126 #ifndef __ASSUME_AT_RANDOM
127 if (dl_random
== NULL
)
129 ret
= stack_chk_guard
;
130 # ifndef HP_TIMING_NONAVAIL
138 memcpy (&ret
, (char *) dl_random
+ sizeof (ret
), sizeof (ret
));