mmap64.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. /* Massivly hacked up for uClibc by Erik Andersen */
  7. #include <_lfs_64.h>
  8. #ifdef __UCLIBC_HAS_LFS__
  9. #include <errno.h>
  10. #include <unistd.h>
  11. #include <sys/mman.h>
  12. #include <sys/syscall.h>
  13. #include <bits/uClibc_page.h>
  14. /* libc_hidden_proto(mmap) */
  15. # if !defined __NR_mmap2 || !defined _syscall6
  16. /*
  17. * This version is a stub that just chops off everything at the mmap 32 bit
  18. * mmap() address space... You will probably need to add in an arch specific
  19. * implementation to override this as there is not a generic way for me to
  20. * implement this particular syscall if your arch lacks _syscall6...
  21. *
  22. */
  23. __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
  24. {
  25. if (offset != (off_t) offset ||
  26. (offset + len) != (off_t) (offset + len)) {
  27. __set_errno(EINVAL);
  28. return MAP_FAILED;
  29. }
  30. return mmap(addr, len, prot, flags, fd, (off_t) offset);
  31. }
  32. # else
  33. # define __NR___syscall_mmap2 __NR_mmap2
  34. static __inline__ _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr,
  35. size_t, len, int, prot, int, flags, int, fd,
  36. off_t, offset)
  37. /* Some architectures always use 12 as page shift for mmap2() eventhough the
  38. * real PAGE_SHIFT != 12. Other architectures use the same value as
  39. * PAGE_SHIFT...
  40. */
  41. # ifndef MMAP2_PAGE_SHIFT
  42. # define MMAP2_PAGE_SHIFT 12
  43. # endif
  44. __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
  45. {
  46. if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
  47. __set_errno(EINVAL);
  48. return MAP_FAILED;
  49. }
  50. # ifdef __USE_FILE_OFFSET64
  51. return __syscall_mmap2(addr, len, prot, flags,
  52. fd, ((__u_quad_t) offset >> MMAP2_PAGE_SHIFT));
  53. # else
  54. return __syscall_mmap2(addr, len, prot, flags,
  55. fd, ((__u_long) offset >> MMAP2_PAGE_SHIFT));
  56. # endif
  57. }
  58. # endif
  59. #endif /* __UCLIBC_HAS_LFS__ */