ptrace.c 873 B

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