ptrace.c 697 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <errno.h>
  2. #include <asm/ptrace.h>
  3. #include <asm/unistd.h>
  4. int
  5. ptrace(int request, int pid, int addr, int data)
  6. {
  7. int ret;
  8. int res;
  9. if (request > 0 && request < 4) data = (int)&ret;
  10. __asm__ volatile ("sub.l er0,er0\n\t"
  11. "mov.b %1,r0l\n\t"
  12. "mov.l %2,er1\n\t"
  13. "mov.l %3,er2\n\t"
  14. "mov.l %4,er3\n\t"
  15. "mov.l %5,er4\n\t"
  16. "trapa #0\n\t"
  17. "mov.l er0,%0"
  18. :"=g" (res)
  19. :"i" (__NR_ptrace), "g" (request), "g" (pid),
  20. "g" (addr), "g" (data)
  21. : "er0", "er1", "er2", "er3", "er4");
  22. if (res >= 0) {
  23. if (request > 0 && request < 4) {
  24. __set_errno(0);
  25. return (ret);
  26. }
  27. return (int) res;
  28. }
  29. __set_errno(-res);
  30. return -1;
  31. }