mmap64.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifdef __USE_FILE_OFFSET64
  23. # undef __USE_FILE_OFFSET64
  24. #endif
  25. # if ! defined __NR_mmap2 || ! defined _syscall6
  26. /*
  27. * This version is a stub that just chops off everything at the mmap 32 bit
  28. * mmap() address space... You will probably need to add in an arch specific
  29. * implementation to override this as there is not a generic way for me to
  30. * implement this particular syscall if your arch lacks _syscall6...
  31. *
  32. */
  33. __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
  34. {
  35. if (offset != (off_t) offset || (offset + len) != (off_t) (offset + len)) {
  36. __set_errno (EINVAL);
  37. return MAP_FAILED;
  38. }
  39. return mmap (addr, len, prot, flags, fd, (off_t) offset);
  40. }
  41. # else
  42. # define __NR___syscall_mmap2 __NR_mmap2
  43. static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr,
  44. size_t, len, int, prot, int, flags, int, fd, off_t, offset);
  45. /* This is always 12, even on architectures where PAGE_SHIFT != 12. */
  46. # ifndef MMAP2_PAGE_SHIFT
  47. # define MMAP2_PAGE_SHIFT 12
  48. # endif
  49. __ptr_t mmap64(__ptr_t addr, size_t len, int prot, int flags, int fd, __off64_t offset)
  50. {
  51. if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
  52. __set_errno (EINVAL);
  53. return MAP_FAILED;
  54. }
  55. return(__syscall_mmap2(addr, len, prot, flags, fd, (off_t) (offset >> MMAP2_PAGE_SHIFT)));
  56. }
  57. # endif
  58. #endif /* __UCLIBC_HAS_LFS__ */