hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame sysdeps/unix/sysv/linux/mmap64.c

Packit 6c4009
/* mmap - map files or devices into memory.  Linux version.
Packit 6c4009
   Copyright (C) 1999-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Jakub Jelinek <jakub@redhat.com>, 1999.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <sys/mman.h>
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
#include <mmap_internal.h>
Packit 6c4009
Packit 6c4009
/* To avoid silent truncation of offset when using mmap2, do not accept
Packit 6c4009
   offset larger than 1 << (page_shift + off_t bits).  For archictures with
Packit 6c4009
   32 bits off_t and page size of 4096 it would be 1^44.  */
Packit 6c4009
#define MMAP_OFF_HIGH_MASK \
Packit 6c4009
  ((-(MMAP2_PAGE_UNIT << 1) << (8 * sizeof (off_t) - 1)))
Packit 6c4009
Packit 6c4009
#define MMAP_OFF_MASK (MMAP_OFF_HIGH_MASK | MMAP_OFF_LOW_MASK)
Packit 6c4009
Packit 6c4009
/* An architecture may override this.  */
Packit 6c4009
#ifndef MMAP_PREPARE
Packit 6c4009
# define MMAP_PREPARE(addr, len, prot, flags, fd, offset)
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
void *
Packit 6c4009
__mmap64 (void *addr, size_t len, int prot, int flags, int fd, off64_t offset)
Packit 6c4009
{
Packit 6c4009
  MMAP_CHECK_PAGE_UNIT ();
Packit 6c4009
Packit 6c4009
  if (offset & MMAP_OFF_MASK)
Packit 6c4009
    return (void *) INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
Packit 6c4009
Packit 6c4009
  MMAP_PREPARE (addr, len, prot, flags, fd, offset);
Packit 6c4009
#ifdef __NR_mmap2
Packit 6c4009
  return (void *) MMAP_CALL (mmap2, addr, len, prot, flags, fd,
Packit 6c4009
			     (off_t) (offset / MMAP2_PAGE_UNIT));
Packit 6c4009
#else
Packit 6c4009
  return (void *) MMAP_CALL (mmap, addr, len, prot, flags, fd, offset);
Packit 6c4009
#endif
Packit 6c4009
}
Packit 6c4009
weak_alias (__mmap64, mmap64)
Packit 6c4009
libc_hidden_def (__mmap64)
Packit 6c4009
Packit 6c4009
#ifdef __OFF_T_MATCHES_OFF64_T
Packit 6c4009
weak_alias (__mmap64, mmap)
Packit 6c4009
weak_alias (__mmap64, __mmap)
Packit 6c4009
libc_hidden_def (__mmap)
Packit 6c4009
#endif