mmap64.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. /*
  43. * Some arches check the size in INLINE_SYSCALL() and barf if it's
  44. * too big (i.e. a 64bit value getting truncated to 32bit).
  45. */
  46. # if __WORDSIZE == 32
  47. uint32_t sysoff;
  48. # else
  49. uint64_t sysoff;
  50. # endif
  51. if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
  52. __set_errno(EINVAL);
  53. return MAP_FAILED;
  54. }
  55. /*
  56. * We know __off64_t is always a signed 64-bit type, but need things
  57. * to be unsigned before doing the shift. If it isn't, we might
  58. * sign extend things and pass in the wrong value. So cast it to
  59. * an unsigned 64-bit value before doing the shift.
  60. */
  61. sysoff = (uint64_t)offset >> MMAP2_PAGE_SHIFT;
  62. return (__ptr_t) INLINE_SYSCALL(mmap2, 6, addr, len, prot, flags, fd, sysoff);
  63. }
  64. # endif
  65. #endif /* __UCLIBC_HAS_LFS__ */