_mmap.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <unistd.h>
  2. #include <sys/mman.h>
  3. #include <errno.h>
  4. #include <sys/syscall.h>
  5. #define __syscall_clobbers \
  6. "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12"
  7. #define __syscall_return(type) \
  8. return (__sc_err & 0x10000000 ? errno = __sc_ret, __sc_ret = -1 : 0), \
  9. (type) __sc_ret
  10. void * mmap(void *start, size_t length, int prot, int flags, int fd,
  11. off_t offset)
  12. {
  13. unsigned long __sc_ret, __sc_err;
  14. register unsigned long __sc_0 __asm__ ("r0");
  15. register unsigned long __sc_3 __asm__ ("r3");
  16. register unsigned long __sc_4 __asm__ ("r4");
  17. register unsigned long __sc_5 __asm__ ("r5");
  18. register unsigned long __sc_6 __asm__ ("r6");
  19. register unsigned long __sc_7 __asm__ ("r7");
  20. register unsigned long __sc_8 __asm__ ("r8");
  21. __sc_3 = (unsigned long) start;
  22. __sc_4 = (unsigned long) length;
  23. __sc_5 = (unsigned long) prot;
  24. __sc_6 = (unsigned long) flags;
  25. __sc_7 = (unsigned long) fd;
  26. __sc_8 = (unsigned long) offset;
  27. __sc_0 = __NR_mmap;
  28. __asm__ __volatile__
  29. ("sc \n\t"
  30. "mfcr %1 "
  31. : "=&r" (__sc_3), "=&r" (__sc_0)
  32. : "0" (__sc_3), "1" (__sc_0),
  33. "r" (__sc_4),
  34. "r" (__sc_5),
  35. "r" (__sc_6),
  36. "r" (__sc_7),
  37. "r" (__sc_8)
  38. : __syscall_clobbers);
  39. __sc_ret = __sc_3;
  40. __sc_err = __sc_0;
  41. __syscall_return (void *);
  42. }