_mmap.c 1.0 KB

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