mmap64.c 2.1 KB

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