mmap.c 823 B

1234567891011121314151617181920212223242526272829303132
  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. static _syscall6(__ptr_t, mmap2, __ptr_t, addr, size_t, len, int, prot,
  13. int, flags, int, fd, __off_t, pgoff)
  14. __ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
  15. {
  16. unsigned long page_size = sysconf(_SC_PAGESIZE);
  17. unsigned long pgoff;
  18. if (offset & (page_size - 1)) {
  19. __set_errno(EINVAL);
  20. return MAP_FAILED;
  21. }
  22. pgoff = (unsigned long)offset >> (31 - __builtin_clz(page_size));
  23. return mmap2(addr, len, prot, flags, fd, pgoff);
  24. }
  25. libc_hidden_def(mmap)