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
20 #include <kernel-features.h>
21 #include <dl-sysdep.h>
26 # define MIN(a,b) (((a)<(b))?(a):(b))
30 /* This is the function used in the dynamic linker to print the fatal error
33 __attribute__ ((__noreturn__
))
34 dl_fatal (const char *str
)
41 #define DL_SYSDEP_OSCHECK(FATAL) \
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)) \
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"); \
58 else if (__LINUX_KERNEL_VERSION > 0) \
59 FATAL ("FATAL: cannot determine kernel version\n"); \
62 static inline uintptr_t __attribute__ ((always_inline
))
63 _dl_setup_stack_chk_guard (void)
66 #ifdef ENABLE_STACKGUARD_RANDOMIZE
67 int fd
= __open ("/dev/urandom", O_RDONLY
);
70 ssize_t reslen
= __read (fd
, &ret
, sizeof (ret
));
72 if (reslen
== (ssize_t
) sizeof (ret
))
77 unsigned char *p
= (unsigned char *) &ret
;
78 p
[sizeof (ret
) - 1] = 255;
79 p
[sizeof (ret
) - 2] = '\n';