|
Packit Service |
82fcde |
/* Dynamic linker system dependencies for Linux.
|
|
Packit Service |
82fcde |
Copyright (C) 1995-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License as published by the Free Software Foundation; either
|
|
Packit Service |
82fcde |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library; if not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Linux needs some special initialization, but otherwise uses
|
|
Packit Service |
82fcde |
the generic dynamic linker system interface code. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <string.h>
|
|
Packit Service |
82fcde |
#include <fcntl.h>
|
|
Packit Service |
82fcde |
#include <unistd.h>
|
|
Packit Service |
82fcde |
#include <sys/param.h>
|
|
Packit Service |
82fcde |
#include <sys/utsname.h>
|
|
Packit Service |
82fcde |
#include <ldsodefs.h>
|
|
Packit Service |
82fcde |
#include <not-cancel.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#ifdef SHARED
|
|
Packit Service |
82fcde |
# define DL_SYSDEP_INIT frob_brk ()
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static inline void
|
|
Packit Service |
82fcde |
frob_brk (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
__brk (0); /* Initialize the break. */
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
# include <elf/dl-sysdep.c>
|
|
Packit Service |
82fcde |
#endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
int
|
|
Packit Service |
82fcde |
attribute_hidden
|
|
Packit Service |
82fcde |
_dl_discover_osversion (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
#if defined NEED_DL_SYSINFO_DSO && defined SHARED
|
|
Packit Service |
82fcde |
if (GLRO(dl_sysinfo_map) != NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* If the kernel-supplied DSO contains a note indicating the kernel's
|
|
Packit Service |
82fcde |
version, we don't need to call uname or parse any strings. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static const struct
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
ElfW(Nhdr) hdr;
|
|
Packit Service |
82fcde |
char vendor[8];
|
|
Packit Service |
82fcde |
} expected_note = { { sizeof "Linux", sizeof (ElfW(Word)), 0 }, "Linux" };
|
|
Packit Service |
82fcde |
const ElfW(Phdr) *const phdr = GLRO(dl_sysinfo_map)->l_phdr;
|
|
Packit Service |
82fcde |
const ElfW(Word) phnum = GLRO(dl_sysinfo_map)->l_phnum;
|
|
Packit Service |
82fcde |
for (uint_fast16_t i = 0; i < phnum; ++i)
|
|
Packit Service |
82fcde |
if (phdr[i].p_type == PT_NOTE)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
const ElfW(Addr) start = (phdr[i].p_vaddr
|
|
Packit Service |
82fcde |
+ GLRO(dl_sysinfo_map)->l_addr);
|
|
Packit Service |
82fcde |
const ElfW(Nhdr) *note = (const void *) start;
|
|
Packit Service |
82fcde |
while ((ElfW(Addr)) (note + 1) - start < phdr[i].p_memsz)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (!memcmp (note, &expected_note, sizeof expected_note))
|
|
Packit Service |
82fcde |
return *(const ElfW(Word) *) ((const void *) note
|
|
Packit Service |
82fcde |
+ sizeof expected_note);
|
|
Packit Service |
82fcde |
#define ROUND(len) (((len) + sizeof note->n_type - 1) & -sizeof note->n_type)
|
|
Packit Service |
82fcde |
note = ((const void *) (note + 1)
|
|
Packit Service |
82fcde |
+ ROUND (note->n_namesz) + ROUND (note->n_descsz));
|
|
Packit Service |
82fcde |
#undef ROUND
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
#endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
char bufmem[64];
|
|
Packit Service |
82fcde |
char *buf = bufmem;
|
|
Packit Service |
82fcde |
unsigned int version;
|
|
Packit Service |
82fcde |
int parts;
|
|
Packit Service |
82fcde |
char *cp;
|
|
Packit Service |
82fcde |
struct utsname uts;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Try the uname system call. */
|
|
Packit Service |
82fcde |
if (__uname (&uts))
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* This was not successful. Now try reading the /proc filesystem. */
|
|
Packit Service |
82fcde |
int fd = __open64_nocancel ("/proc/sys/kernel/osrelease", O_RDONLY);
|
|
Packit Service |
82fcde |
if (fd < 0)
|
|
Packit Service |
82fcde |
return -1;
|
|
Packit Service |
82fcde |
ssize_t reslen = __read_nocancel (fd, bufmem, sizeof (bufmem));
|
|
Packit Service |
82fcde |
__close_nocancel (fd);
|
|
Packit Service |
82fcde |
if (reslen <= 0)
|
|
Packit Service |
82fcde |
/* This also didn't work. We give up since we cannot
|
|
Packit Service |
82fcde |
make sure the library can actually work. */
|
|
Packit Service |
82fcde |
return -1;
|
|
Packit Service |
82fcde |
buf[MIN (reslen, (ssize_t) sizeof (bufmem) - 1)] = '\0';
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
buf = uts.release;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Now convert it into a number. The string consists of at most
|
|
Packit Service |
82fcde |
three parts. */
|
|
Packit Service |
82fcde |
version = 0;
|
|
Packit Service |
82fcde |
parts = 0;
|
|
Packit Service |
82fcde |
cp = buf;
|
|
Packit Service |
82fcde |
while ((*cp >= '0') && (*cp <= '9'))
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
unsigned int here = *cp++ - '0';
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
while ((*cp >= '0') && (*cp <= '9'))
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
here *= 10;
|
|
Packit Service |
82fcde |
here += *cp++ - '0';
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
++parts;
|
|
Packit Service |
82fcde |
version <<= 8;
|
|
Packit Service |
82fcde |
version |= here;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (*cp++ != '.' || parts == 3)
|
|
Packit Service |
82fcde |
/* Another part following? */
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (parts < 3)
|
|
Packit Service |
82fcde |
version <<= 8 * (3 - parts);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return version;
|
|
Packit Service |
82fcde |
}
|