Update poll.h header for POSIX 2008.
[glibc.git] / sysdeps / unix / sysv / linux / dl-osinfo.h
blobdf07869bc5d795c9da96fcf59f5015d1d6d3e252
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
18 02111-1307 USA. */
20 #include <kernel-features.h>
21 #include <dl-sysdep.h>
22 #include <fcntl.h>
23 #include <stdint.h>
25 #ifndef MIN
26 # define MIN(a,b) (((a)<(b))?(a):(b))
27 #endif
29 #ifdef SHARED
30 /* This is the function used in the dynamic linker to print the fatal error
31 message. */
32 static void
33 __attribute__ ((__noreturn__))
34 dl_fatal (const char *str)
36 _dl_dprintf (2, str);
37 _exit (1);
39 #endif
41 #define DL_SYSDEP_OSCHECK(FATAL) \
42 do { \
43 /* Test whether the kernel is new enough. This test is only performed \
44 if the library is not compiled to run on all kernels. */ \
46 int version = _dl_discover_osversion (); \
47 if (__builtin_expect (version >= 0, 1)) \
48 { \
49 if (__builtin_expect (GLRO(dl_osversion) == 0, 1) \
50 || GLRO(dl_osversion) > version) \
51 GLRO(dl_osversion) = version; \
53 /* Now we can test with the required version. */ \
54 if (__LINUX_KERNEL_VERSION > 0 && version < __LINUX_KERNEL_VERSION) \
55 /* Not sufficent. */ \
56 FATAL ("FATAL: kernel too old\n"); \
57 } \
58 else if (__LINUX_KERNEL_VERSION > 0) \
59 FATAL ("FATAL: cannot determine kernel version\n"); \
60 } while (0)
62 static inline uintptr_t __attribute__ ((always_inline))
63 _dl_setup_stack_chk_guard (void *dl_random)
65 uintptr_t ret;
66 #ifndef __ASSUME_AT_RANDOM
67 if (__builtin_expect (dl_random == NULL, 0))
69 # ifdef ENABLE_STACKGUARD_RANDOMIZE
70 int fd = __open ("/dev/urandom", O_RDONLY);
71 if (fd >= 0)
73 ssize_t reslen = __read (fd, &ret, sizeof (ret));
74 __close (fd);
75 if (reslen == (ssize_t) sizeof (ret))
76 return ret;
78 # endif
79 ret = 0;
80 unsigned char *p = (unsigned char *) &ret;
81 p[sizeof (ret) - 1] = 255;
82 p[sizeof (ret) - 2] = '\n';
84 else
85 #endif
86 /* We need in the moment only 8 bytes on 32-bit platforms and 16
87 bytes on 64-bit platforms. Therefore we can use the data
88 directly and not use the kernel-provided data to seed a PRNG. */
89 memcpy (&ret, dl_random, sizeof (ret));
90 return ret;
93 static inline uintptr_t __attribute__ ((always_inline))
94 _dl_setup_pointer_guard (void *dl_random, uintptr_t stack_chk_guard)
96 uintptr_t ret;
97 #ifndef __ASSUME_AT_RANDOM
98 if (dl_random == NULL)
100 ret = stack_chk_guard;
101 # ifndef HP_TIMING_NONAVAIL
102 hp_timing_t now;
103 HP_TIMING_NOW (now);
104 ret ^= now;
105 # endif
107 else
108 #endif
109 memcpy (&ret, (char *) dl_random + sizeof (ret), sizeof (ret));
110 return ret;