mmap64.c 2.0 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. # if !defined __NR_mmap2
  15. /*
  16. * This version is a stub that just chops off everything at the mmap 32 bit
  17. * mmap() address space... You will probably need to add in an arch specific
  18. * implementation to override this as there is not a generic way for me to
  19. * implement this particular syscall if your arch lacks _syscall6...
  20. *
  21. */
  22. __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
  23. {
  24. if (offset != (off_t) offset ||
  25. (offset + len) != (off_t) (offset + len)) {
  26. __set_errno(EINVAL);
  27. return MAP_FAILED;
  28. }
  29. return mmap(addr, len, prot, flags, fd, (off_t) offset);
  30. }
  31. # else
  32. # define __NR___syscall_mmap2 __NR_mmap2
  33. static __inline__ _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr,
  34. size_t, len, int, prot, int, flags, int, fd,
  35. off_t, offset)
  36. /* Some architectures always use 12 as page shift for mmap2() eventhough the
  37. * real PAGE_SHIFT != 12. Other architectures use the same value as
  38. * PAGE_SHIFT...
  39. */
  40. # ifndef MMAP2_PAGE_SHIFT
  41. # define MMAP2_PAGE_SHIFT 12
  42. # endif
  43. __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
  44. {
  45. if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
  46. __set_errno(EINVAL);
  47. return MAP_FAILED;
  48. }
  49. /*
  50. * We know __off64_t is always a signed 64-bit type, but need things
  51. * to be unsigned before doing the shift. If it isn't, we might
  52. * sign extend things and pass in the wrong value. So cast it to
  53. * an unsigned 64-bit value before doing the shift.
  54. */
  55. return __syscall_mmap2(addr, len, prot, flags, fd,
  56. ((uint64_t)offset >> MMAP2_PAGE_SHIFT));
  57. }
  58. # endif
  59. #endif /* __UCLIBC_HAS_LFS__ */