Back to index

glibc  2.9
dl-osinfo.h
Go to the documentation of this file.
00001 /* Operating system specific code for generic dynamic loader functions.  Linux.
00002    Copyright (C) 2000-2002,2004-2007,2008 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <kernel-features.h>
00021 #include <dl-sysdep.h>
00022 #include <fcntl.h>
00023 #include <stdint.h>
00024 
00025 #ifndef MIN
00026 # define MIN(a,b) (((a)<(b))?(a):(b))
00027 #endif
00028 
00029 #ifdef SHARED
00030 /* This is the function used in the dynamic linker to print the fatal error
00031    message.  */
00032 static inline void
00033 __attribute__ ((__noreturn__))
00034 dl_fatal (const char *str)
00035 {
00036   _dl_dprintf (2, str);
00037   _exit (1);
00038 }
00039 #endif
00040 
00041 #define DL_SYSDEP_OSCHECK(FATAL)                                     \
00042   do {                                                               \
00043     /* Test whether the kernel is new enough.  This test is only performed    \
00044        if the library is not compiled to run on all kernels.  */            \
00045                                                                      \
00046     int version = _dl_discover_osversion ();                                \
00047     if (__builtin_expect (version >= 0, 1))                                 \
00048       {                                                                     \
00049        if (__builtin_expect (GLRO(dl_osversion) == 0, 1)                    \
00050            || GLRO(dl_osversion) > version)                                 \
00051          GLRO(dl_osversion) = version;                                      \
00052                                                                      \
00053        /* Now we can test with the required version.  */                    \
00054        if (__LINUX_KERNEL_VERSION > 0 && version < __LINUX_KERNEL_VERSION)   \
00055          /* Not sufficent.  */                                              \
00056          FATAL ("FATAL: kernel too old\n");                                 \
00057       }                                                                     \
00058     else if (__LINUX_KERNEL_VERSION > 0)                             \
00059       FATAL ("FATAL: cannot determine kernel version\n");                   \
00060   } while (0)
00061 
00062 static inline uintptr_t __attribute__ ((always_inline))
00063 _dl_setup_stack_chk_guard (void)
00064 {
00065   uintptr_t ret;
00066 #ifdef ENABLE_STACKGUARD_RANDOMIZE
00067   int fd = __open ("/dev/urandom", O_RDONLY);
00068   if (fd >= 0)
00069     {
00070       ssize_t reslen = __read (fd, &ret, sizeof (ret));
00071       __close (fd);
00072       if (reslen == (ssize_t) sizeof (ret))
00073        return ret;
00074     }
00075 #endif
00076   ret = 0;
00077   unsigned char *p = (unsigned char *) &ret;
00078   p[sizeof (ret) - 1] = 255;
00079   p[sizeof (ret) - 2] = '\n';
00080   return ret;
00081 }