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. # if !defined __NR_mmap2
  15. /*
  16. * This version is a stub that just chops off everything at the mmap 32 bit
  17. * mmap() address space... You will probably need to add in an arch specific
  18. * implementation to override this as there is not a generic way for me to
  19. * implement this particular syscall if your arch lacks _syscall6...
  20. *
  21. */
  22. __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
  23. {
  24. if (offset != (off_t) offset ||
  25. (offset + len) != (off_t) (offset + len)) {
  26. __set_errno(EINVAL);
  27. return MAP_FAILED;
  28. }
  29. return mmap(addr, len, prot, flags, fd, (off_t) offset);
  30. }
  31. # else
  32. # define __NR___syscall_mmap2 __NR_mmap2
  33. static __inline__ _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr,
  34. size_t, len, int, prot, int, flags, int, fd,
  35. 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__ */