mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-25 12:11:10 +00:00
5a82c74822
Also, change sources.redhat.com to sourceware.org. This patch was automatically generated by running the following shell script, which uses GNU sed, and which avoids modifying files imported from upstream: sed -ri ' s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g ' \ $(find $(git ls-files) -prune -type f \ ! -name '*.po' \ ! -name 'ChangeLog*' \ ! -path COPYING ! -path COPYING.LIB \ ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \ ! -path manual/texinfo.tex ! -path scripts/config.guess \ ! -path scripts/config.sub ! -path scripts/install-sh \ ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \ ! -path INSTALL ! -path locale/programs/charmap-kw.h \ ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \ ! '(' -name configure \ -execdir test -f configure.ac -o -f configure.in ';' ')' \ ! '(' -name preconfigure \ -execdir test -f preconfigure.ac ';' ')' \ -print) and then by running 'make dist-prepare' to regenerate files built from the altered files, and then executing the following to cleanup: chmod a+x sysdeps/unix/sysv/linux/riscv/configure # Omit irrelevant whitespace and comment-only changes, # perhaps from a slightly-different Autoconf version. git checkout -f \ sysdeps/csky/configure \ sysdeps/hppa/configure \ sysdeps/riscv/configure \ sysdeps/unix/sysv/linux/csky/configure # Omit changes that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines git checkout -f \ sysdeps/powerpc/powerpc64/ppc-mcount.S \ sysdeps/unix/sysv/linux/s390/s390-64/syscall.S # Omit change that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
120 lines
3.2 KiB
C
120 lines
3.2 KiB
C
/* BZ #18877, BZ #21270, and BZ #24699 mmap offset test.
|
|
|
|
Copyright (C) 2015-2019 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 <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <sys/mman.h>
|
|
#include <mmap_info.h>
|
|
|
|
#include <support/check.h>
|
|
|
|
static int fd;
|
|
static long int page_shift;
|
|
static char fname[] = "/tmp/tst-mmap-offset-XXXXXX";
|
|
|
|
static void
|
|
do_prepare (int argc, char **argv)
|
|
{
|
|
fd = mkstemp64 (fname);
|
|
if (fd < 0)
|
|
FAIL_EXIT1 ("mkstemp failed");
|
|
|
|
if (unlink (fname))
|
|
FAIL_EXIT1 ("unlink failed");
|
|
|
|
long sz = sysconf(_SC_PAGESIZE);
|
|
if (sz == -1)
|
|
sz = 4096L;
|
|
page_shift = ffs (sz) - 1;
|
|
}
|
|
|
|
#define PREPARE do_prepare
|
|
|
|
|
|
/* Check if negative offsets are handled correctly by mmap. */
|
|
static int
|
|
do_test_bz18877 (void)
|
|
{
|
|
const int prot = PROT_READ | PROT_WRITE;
|
|
const int flags = MAP_SHARED;
|
|
const unsigned long length = 0x10000;
|
|
const unsigned long offset = 0xace00000;
|
|
const unsigned long size = offset + length;
|
|
void *addr;
|
|
|
|
if (ftruncate64 (fd, size))
|
|
FAIL_RET ("ftruncate64 failed");
|
|
|
|
addr = mmap (NULL, length, prot, flags, fd, offset);
|
|
if (MAP_FAILED == addr)
|
|
FAIL_RET ("mmap failed");
|
|
|
|
/* This memcpy is likely to SIGBUS if mmap has messed up with offset. */
|
|
memcpy (addr, fname, sizeof (fname));
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Check if invalid offset are handled correctly by mmap. */
|
|
static int
|
|
do_test_large_offset (void)
|
|
{
|
|
/* For architectures with sizeof (off_t) < sizeof (off64_t) mmap is
|
|
implemented with __SYS_mmap2 syscall and the offset is represented in
|
|
multiples of page size. For offset larger than
|
|
'1 << (page_shift + 8 * sizeof (off_t))' (that is, 1<<44 on system with
|
|
page size of 4096 bytes) the system call silently truncates the offset.
|
|
For this case glibc mmap implementation returns EINVAL. */
|
|
const int prot = PROT_READ | PROT_WRITE;
|
|
const int flags = MAP_SHARED;
|
|
const int64_t offset = 1ULL << (page_shift + 8 * sizeof (uint32_t));
|
|
const size_t length = 4096;
|
|
|
|
void *addr = mmap64 (NULL, length, prot, flags, fd, offset);
|
|
if (mmap64_maximum_offset (page_shift) < UINT64_MAX)
|
|
{
|
|
if ((addr != MAP_FAILED) && (errno != EINVAL))
|
|
FAIL_RET ("mmap succeed");
|
|
}
|
|
else
|
|
{
|
|
if (addr == MAP_FAILED)
|
|
FAIL_RET ("mmap failed");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
do_test (void)
|
|
{
|
|
int ret = 0;
|
|
|
|
ret += do_test_bz18877 ();
|
|
ret += do_test_large_offset ();
|
|
|
|
return ret;
|
|
}
|
|
|
|
#include <support/test-driver.c>
|