xref: /minix3/minix/lib/libc/sys/ptrace.c (revision 5dd8da10c5368f1f7c641252b24203c14ed8d051)
1433d6423SLionel Sambuc #include <sys/cdefs.h>
2433d6423SLionel Sambuc #include "namespace.h"
3433d6423SLionel Sambuc #include <lib.h>
4433d6423SLionel Sambuc 
5433d6423SLionel Sambuc #include <string.h>
6433d6423SLionel Sambuc #include <sys/ptrace.h>
7433d6423SLionel Sambuc 
ptrace(int req,pid_t pid,void * addr,int data)8433d6423SLionel Sambuc int ptrace(int req, pid_t pid, void *addr, int data)
9433d6423SLionel Sambuc {
10433d6423SLionel Sambuc   message m;
11433d6423SLionel Sambuc 
12433d6423SLionel Sambuc   memset(&m, 0, sizeof(m));
13433d6423SLionel Sambuc   m.m_lc_pm_ptrace.pid = pid;
14433d6423SLionel Sambuc   m.m_lc_pm_ptrace.req = req;
15*5dd8da10SDavid van Moolenbroek   m.m_lc_pm_ptrace.addr = (vir_bytes)addr;
16433d6423SLionel Sambuc   m.m_lc_pm_ptrace.data = data;
17433d6423SLionel Sambuc   if (_syscall(PM_PROC_NR, PM_PTRACE, &m) < 0) return(-1);
18433d6423SLionel Sambuc 
19433d6423SLionel Sambuc   /* There was no error, but -1 is a legal return value.  Clear errno if
20433d6423SLionel Sambuc    * necessary to distinguish this case.  _syscall has set errno to nonzero
21433d6423SLionel Sambuc    * for the error case.
22433d6423SLionel Sambuc    */
23433d6423SLionel Sambuc   if (m.m_pm_lc_ptrace.data == -1) errno = 0;
24433d6423SLionel Sambuc   return(m.m_pm_lc_ptrace.data);
25433d6423SLionel Sambuc }
26