OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [linux/] [dl/] [dl-osinfo.h] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* Operating system specific code  for generic dynamic loader functions.
2
   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
4
 
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.
9
 
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.
14
 
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.  */
19
 
20
#include <string.h>
21
#include <sys/sysctl.h>
22
#include <sys/utsname.h>
23
#include "kernel-features.h"
24
 
25
#ifndef MIN
26
# define MIN(a,b) (((a)<(b))?(a):(b))
27
#endif
28
 
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)
35
{
36
  _dl_dprintf (2, str);
37
  _exit (1);
38
}
39
#endif
40
 
41
 
42
#define DL_SYSDEP_OSCHECK(FATAL) \
43
  do {                                                                        \
44
    /* Test whether the kernel is new enough.  This test is only              \
45
       performed if the library is not compiled to run on all                 \
46
       kernels.  */                                                           \
47
    if (__LINUX_KERNEL_VERSION > 0)                                            \
48
      {                                                                       \
49
        char bufmem[64];                                                      \
50
        char *buf = bufmem;                                                   \
51
        unsigned int version;                                                 \
52
        int parts;                                                            \
53
        char *cp;                                                             \
54
        struct utsname uts;                                                   \
55
                                                                              \
56
        /* Try the uname syscall */                                           \
57
        if (__uname (&uts))                                                   \
58
          {                                                                   \
59
            /* This was not successful.  Now try reading the /proc            \
60
               filesystem.  */                                                \
61
            ssize_t reslen;                                                   \
62
            int fd = __open ("/proc/sys/kernel/osrelease", O_RDONLY);         \
63
            if (fd == -1                                                      \
64
                || (reslen = __read (fd, bufmem, sizeof (bufmem))) <= 0)      \
65
              /* This also didn't work.  We give up since we cannot           \
66
                 make sure the library can actually work.  */                 \
67
              FATAL ("FATAL: cannot determine library version\n");            \
68
            __close (fd);                                                     \
69
            buf[MIN (reslen, (ssize_t) sizeof (bufmem) - 1)] = '\0';          \
70
          }                                                                   \
71
        else                                                                  \
72
          buf = uts.release;                                                  \
73
                                                                              \
74
        /* Now convert it into a number.  The string consists of at most      \
75
           three parts.  */                                                   \
76
        version = 0;                                                           \
77
        parts = 0;                                                             \
78
        cp = buf;                                                             \
79
        while ((*cp >= '0') && (*cp <= '9'))                                  \
80
          {                                                                   \
81
            unsigned int here = *cp++ - '0';                                  \
82
                                                                              \
83
            while ((*cp >= '0') && (*cp <= '9'))                              \
84
              {                                                               \
85
                here *= 10;                                                   \
86
                here += *cp++ - '0';                                          \
87
              }                                                               \
88
                                                                              \
89
            ++parts;                                                          \
90
            version <<= 8;                                                    \
91
            version |= here;                                                  \
92
                                                                              \
93
            if (*cp++ != '.')                                                 \
94
              /* Another part following?  */                                  \
95
              break;                                                          \
96
          }                                                                   \
97
                                                                              \
98
        if (parts < 3)                                                        \
99
          version <<= 8 * (3 - parts);                                        \
100
                                                                              \
101
        /* Now we can test with the required version.  */                     \
102
        if (version < __LINUX_KERNEL_VERSION)                                 \
103
          /* Not sufficent.  */                                               \
104
          FATAL ("FATAL: kernel too old\n");                                  \
105
                                                                              \
106
        _dl_osversion = version;                                              \
107
      }                                                                       \
108
  } while (0)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.