mmap.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * mmap() for uClibc
  4. *
  5. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <sys/syscall.h>
  10. #include <unistd.h>
  11. #include <sys/mman.h>
  12. #include <bits/uClibc_page.h>
  13. #ifdef __NR_mmap
  14. #ifdef __UCLIBC_MMAP_HAS_6_ARGS__
  15. _syscall6(void *, mmap, void *, start, size_t, length,
  16. int, prot, int, flags, int, fd, off_t, offset)
  17. #else
  18. # define __NR__mmap __NR_mmap
  19. static __inline__ _syscall1(__ptr_t, _mmap, unsigned long *, buffer)
  20. __ptr_t mmap(__ptr_t addr, size_t len, int prot,
  21. int flags, int fd, __off_t offset)
  22. {
  23. unsigned long buffer[6];
  24. buffer[0] = (unsigned long) addr;
  25. buffer[1] = (unsigned long) len;
  26. buffer[2] = (unsigned long) prot;
  27. buffer[3] = (unsigned long) flags;
  28. buffer[4] = (unsigned long) fd;
  29. buffer[5] = (unsigned long) offset;
  30. return (__ptr_t) _mmap(buffer);
  31. }
  32. #endif
  33. libc_hidden_def(mmap)
  34. #elif defined(__NR_mmap2)
  35. #define __NR___syscall_mmap2 __NR_mmap2
  36. static __inline__ _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr,
  37. size_t, len, int, prot, int, flags, int, fd, off_t, offset)
  38. /* Some architectures always use 12 as page shift for mmap2() eventhough the
  39. * real PAGE_SHIFT != 12. Other architectures use the same value as
  40. * PAGE_SHIFT...
  41. */
  42. # ifndef MMAP2_PAGE_SHIFT
  43. # define MMAP2_PAGE_SHIFT 12
  44. # endif
  45. __ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
  46. {
  47. if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
  48. __set_errno(EINVAL);
  49. return MAP_FAILED;
  50. }
  51. return __syscall_mmap2(addr, len, prot, flags, fd, offset >> MMAP2_PAGE_SHIFT);
  52. }
  53. libc_hidden_def(mmap)
  54. #endif