]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/dl-osinfo.h
1 /* Operating system specific code for generic dynamic loader functions.
2 Copyright (C) 2000 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <sys/sysctl.h>
21 #include "kernel-features.h"
24 # define MIN(a,b) (((a)<(b))?(a):(b))
27 /* There is no prototype for __sysctl in that file. */
28 extern int __sysctl (int *name
, int nlen
, void *oldval
,
29 size_t *oldlenp
, void *newval
, size_t newlen
);
33 /* This is the function used in the dynamic linker to print the fatal error
36 __attribute__ ((__noreturn__
))
37 dl_fatal (const char *str
)
39 _dl_sysdep_output (2, str
, NULL
);
45 #define DL_SYSDEP_OSCHECK(FATAL) \
47 /* Test whether the kernel is new enough. This test is only \
48 performed if the library is not compiled to run on all \
50 if (__LINUX_KERNEL_VERSION > 0) \
52 static const int sysctl_args[] = { CTL_KERN, KERN_OSRELEASE }; \
54 size_t reslen = sizeof (buf); \
55 unsigned int version; \
59 /* Try reading the number using `sysctl' first. */ \
60 if (__sysctl ((int *) sysctl_args, \
61 sizeof (sysctl_args) / sizeof (sysctl_args[0]), \
62 buf, &reslen, NULL, 0) < 0) \
64 /* This was not successful. Now try reading the /proc \
66 int fd = __open ("/proc/sys/kernel/osrelease", O_RDONLY); \
68 || (reslen = __read (fd, buf, sizeof (buf))) <= 0) \
69 /* This also didn't work. We give up since we cannot \
70 make sure the library can actually work. */ \
71 FATAL ("FATAL: cannot determine library version\n"); \
75 buf[MIN (reslen, sizeof (buf) - 1)] = '\0'; \
77 /* Now convert it into a number. The string consists of at most \
82 while ((*cp >= '0') && (*cp <= '9')) \
84 unsigned int here = *cp++ - '0'; \
86 while ((*cp >= '0') && (*cp <= '9')) \
89 here += *cp++ - '0'; \
97 /* Another part following? */ \
102 version <<= 8 * (3 - parts); \
104 /* Now we can test with the required version. */ \
105 if (version < __LINUX_KERNEL_VERSION) \
106 /* Not sufficent. */ \
107 FATAL ("FATAL: kernel too old\n"); \