mmap.c 1.4 KB

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