mirror of
https://sourceware.org/git/glibc.git
synced 2025-10-26 00:57:39 +03:00
Detect if ld.so not contiguous and handle that case in _dl_find_object. Set l_find_object_processed even for initially loaded link maps, otherwise dlopen of an initially loaded object adds it to _dlfo_loaded_mappings (where maps are expected to be contiguous), in addition to _dlfo_nodelete_mappings. Test elf/tst-link-map-contiguous-ldso iterates over the loader image, reading every word to make sure memory is actually mapped. It only does that if the l_contiguous flag is set for the link map. Otherwise, it finds gaps with mmap and checks that _dl_find_object does not return the ld.so mapping for them. The test elf/tst-link-map-contiguous-main does the same thing for the libc.so shared object. This only works if the kernel loaded the main program because the glibc dynamic loader may fill the gaps with PROT_NONE mappings in some cases, making it contiguous, but accesses to individual words may still fault. Test elf/tst-link-map-contiguous-libc is again slightly different because the dynamic loader always fills the gaps with PROT_NONE mappings, so a different form of probing has to be used. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
46 lines
1.5 KiB
C
46 lines
1.5 KiB
C
/* Check that the entire main program image is readable if contiguous.
|
|
Copyright (C) 2025 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
#include <link.h>
|
|
#include <support/check.h>
|
|
#include <support/xdlfcn.h>
|
|
|
|
static int
|
|
do_test (void)
|
|
{
|
|
struct link_map *l = xdlopen ("", RTLD_NOW);
|
|
if (!l->l_contiguous)
|
|
FAIL_UNSUPPORTED ("main link map is not contiguous");
|
|
|
|
/* This check only works if the kernel loaded the main program. The
|
|
dynamic loader replaces gaps with PROT_NONE mappings, resulting
|
|
in faults. */
|
|
volatile long int *p = (volatile long int *) l->l_map_start;
|
|
volatile long int *end = (volatile long int *) l->l_map_end;
|
|
while (p < end)
|
|
{
|
|
*p;
|
|
++p;
|
|
}
|
|
|
|
xdlclose (l);
|
|
|
|
return 0;
|
|
}
|
|
#include <support/test-driver.c>
|