mmap64.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <stdint.h>
  11. #include <unistd.h>
  12. #include <sys/mman.h>
  13. #include <sys/syscall.h>
  14. #include <bits/uClibc_page.h>
  15. # if !defined __NR_mmap2
  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. /* Some architectures always use 12 as page shift for mmap2() eventhough the
  34. * real PAGE_SHIFT != 12. Other architectures use the same value as
  35. * PAGE_SHIFT...
  36. */
  37. # ifndef MMAP2_PAGE_SHIFT
  38. # define MMAP2_PAGE_SHIFT 12
  39. # endif
  40. __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
  41. {
  42. if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
  43. __set_errno(EINVAL);
  44. return MAP_FAILED;
  45. }
  46. /*
  47. * We know __off64_t is always a signed 64-bit type, but need things
  48. * to be unsigned before doing the shift. If it isn't, we might
  49. * sign extend things and pass in the wrong value. So cast it to
  50. * an unsigned 64-bit value before doing the shift.
  51. */
  52. return (__ptr_t) INLINE_SYSCALL(mmap2, 6, addr, len, prot, flags, fd,
  53. ((uint64_t)offset >> MMAP2_PAGE_SHIFT));
  54. }
  55. # endif
  56. #endif /* __UCLIBC_HAS_LFS__ */