ptrace.c 659 B

123456789101112131415161718192021222324252627282930313233
  1. #include <errno.h>
  2. #include <asm/ptrace.h>
  3. #include <sys/syscall.h>
  4. int
  5. ptrace(int request, int pid, int addr, int data)
  6. {
  7. long ret;
  8. long res;
  9. if (request > 0 && request < 4) (long *)data = &ret;
  10. __asm__ volatile ("movel %1,%/d0\n\t"
  11. "movel %2,%/d1\n\t"
  12. "movel %3,%/d2\n\t"
  13. "movel %4,%/d3\n\t"
  14. "movel %5,%/d4\n\t"
  15. "trap #0\n\t"
  16. "movel %/d0,%0"
  17. :"=g" (res)
  18. :"i" (__NR_ptrace), "g" (request), "g" (pid),
  19. "g" (addr), "g" (data) : "%d0", "%d1", "%d2", "%d3", "%d4");
  20. if (res >= 0) {
  21. if (request > 0 && request < 4) {
  22. __set_errno(0);
  23. return (ret);
  24. }
  25. return (int) res;
  26. }
  27. __set_errno(-res);
  28. return -1;
  29. }