ptrace.c 964 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 <sys/syscall.h>
  7. #include <sys/types.h>
  8. #include <sys/ptrace.h>
  9. #include <stdarg.h>
  10. #if defined __NR_ptrace && defined __USE_BSD && defined __USE_MISC
  11. #define __NR___syscall_ptrace __NR_ptrace
  12. static __inline__ _syscall4(long, __syscall_ptrace, enum __ptrace_request, request,
  13. __kernel_pid_t, pid, void*, addr, void*, data);
  14. long int
  15. ptrace (enum __ptrace_request request, ...)
  16. {
  17. long int res, ret;
  18. va_list ap;
  19. pid_t pid;
  20. void *addr, *data;
  21. va_start (ap, request);
  22. pid = va_arg (ap, pid_t);
  23. addr = va_arg (ap, void *);
  24. data = va_arg (ap, void *);
  25. va_end (ap);
  26. if (request > 0 && request < 4)
  27. data = &ret;
  28. res = __syscall_ptrace(request, pid, addr, data);
  29. if (res >= 0 && request > 0 && request < 4) {
  30. __set_errno(0);
  31. return ret;
  32. }
  33. return res;
  34. }
  35. #endif