mmap.c 853 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (C) 2004-2007 Atmel Corporation
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. */
  8. #include <errno.h>
  9. #include <unistd.h>
  10. #include <sys/mman.h>
  11. #include <sys/syscall.h>
  12. /* libc_hidden_proto(mmap) */
  13. static _syscall6(__ptr_t, mmap2, __ptr_t, addr, size_t, len, int, prot,
  14. int, flags, int, fd, __off_t, pgoff)
  15. __ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
  16. {
  17. unsigned long page_size = sysconf(_SC_PAGESIZE);
  18. unsigned long pgoff;
  19. if (offset & (page_size - 1)) {
  20. __set_errno(EINVAL);
  21. return MAP_FAILED;
  22. }
  23. pgoff = (unsigned long)offset >> (31 - __builtin_clz(page_size));
  24. return mmap2(addr, len, prot, flags, fd, pgoff);
  25. }
  26. libc_hidden_def(mmap)