mmap64.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 <features.h>
  8. #include <errno.h>
  9. #include <unistd.h>
  10. #include <sys/mman.h>
  11. #ifdef __UCLIBC_HAS_LFS__
  12. libc_hidden_proto(mmap)
  13. #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS != 64
  14. # undef _FILE_OFFSET_BITS
  15. # define _FILE_OFFSET_BITS 64
  16. #endif
  17. #ifndef __USE_LARGEFILE64
  18. # define __USE_LARGEFILE64 1
  19. #endif
  20. /* We absolutely do _NOT_ want interfaces silently
  21. * renamed under us or very bad things will happen...
  22. */
  23. #ifdef __USE_FILE_OFFSET64
  24. # undef __USE_FILE_OFFSET64
  25. #endif
  26. # if !defined __NR_mmap2 || !defined _syscall6
  27. /*
  28. * This version is a stub that just chops off everything at the mmap 32 bit
  29. * mmap() address space... You will probably need to add in an arch specific
  30. * implementation to override this as there is not a generic way for me to
  31. * implement this particular syscall if your arch lacks _syscall6...
  32. *
  33. */
  34. __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
  35. {
  36. if (offset != (off_t) offset ||
  37. (offset + len) != (off_t) (offset + len)) {
  38. __set_errno(EINVAL);
  39. return MAP_FAILED;
  40. }
  41. return mmap(addr, len, prot, flags, fd, (off_t) offset);
  42. }
  43. # else
  44. # define __NR___syscall_mmap2 __NR_mmap2
  45. static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
  46. int, prot, int, flags, int, fd, off_t, offset);
  47. /* Some architectures always use 12 as page shift for mmap2() eventhough the
  48. * real PAGE_SHIFT != 12. Other architectures use the same value as
  49. * PAGE_SHIFT...
  50. */
  51. # ifndef MMAP2_PAGE_SHIFT
  52. # define MMAP2_PAGE_SHIFT 12
  53. # endif
  54. __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
  55. {
  56. if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
  57. __set_errno(EINVAL);
  58. return MAP_FAILED;
  59. }
  60. return __syscall_mmap2(addr, len, prot, flags, fd, (off_t) (offset >> MMAP2_PAGE_SHIFT));
  61. }
  62. # endif
  63. #endif /* __UCLIBC_HAS_LFS__ */