mmap64.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. libc_hidden_proto(mmap)
  15. # if !defined __NR_mmap2 || !defined _syscall6
  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. # define __NR___syscall_mmap2 __NR_mmap2
  34. static __inline__ _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, size_t, len,
  35. int, prot, int, flags, int, fd, 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. # ifdef __USE_FILE_OFFSET64
  50. return __syscall_mmap2(addr, len, prot, flags,
  51. fd, ((__u_quad_t) offset >> MMAP2_PAGE_SHIFT));
  52. # else
  53. return __syscall_mmap2(addr, len, prot, flags,
  54. fd, ((__u_long) offset >> MMAP2_PAGE_SHIFT));
  55. # endif
  56. }
  57. # endif
  58. #endif /* __UCLIBC_HAS_LFS__ */