ptrace.c 906 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 <errno.h>
  7. #include <sys/types.h>
  8. #include <sys/ptrace.h>
  9. #include <sys/syscall.h>
  10. #include <stdarg.h>
  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. }