2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / dl-osinfo.h
blob5271d4e4de71393dc991d591ff552f81865442bd
1 /* Operating system specific code for generic dynamic loader functions. Linux.
2 Copyright (C) 2000-2002,2004-2007,2008 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 inline 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)
65 uintptr_t ret;
66 #ifdef ENABLE_STACKGUARD_RANDOMIZE
67 int fd = __open ("/dev/urandom", O_RDONLY);
68 if (fd >= 0)
70 ssize_t reslen = __read (fd, &ret, sizeof (ret));
71 __close (fd);
72 if (reslen == (ssize_t) sizeof (ret))
73 return ret;
75 #endif
76 ret = 0;
77 unsigned char *p = (unsigned char *) &ret;
78 p[sizeof (ret) - 1] = 255;
79 p[sizeof (ret) - 2] = '\n';
80 return ret;