2011-02-17 18:11:09 +01:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include "namespace.h"
|
|
|
|
#include <lib.h>
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
#include <string.h>
|
2011-02-17 18:11:09 +01:00
|
|
|
#include <sys/ptrace.h>
|
|
|
|
|
2013-12-10 18:18:13 +01:00
|
|
|
int ptrace(int req, pid_t pid, void *addr, int data)
|
2011-02-17 18:11:09 +01:00
|
|
|
{
|
|
|
|
message m;
|
|
|
|
|
2013-11-04 22:48:08 +01:00
|
|
|
memset(&m, 0, sizeof(m));
|
|
|
|
m.PM_PTRACE_PID = pid;
|
|
|
|
m.PM_PTRACE_REQ = req;
|
|
|
|
m.PM_PTRACE_ADDR = addr;
|
|
|
|
m.PM_PTRACE_DATA = data;
|
|
|
|
if (_syscall(PM_PROC_NR, PM_PTRACE, &m) < 0) return(-1);
|
2011-02-17 18:11:09 +01:00
|
|
|
|
|
|
|
/* There was no error, but -1 is a legal return value. Clear errno if
|
|
|
|
* necessary to distinguish this case. _syscall has set errno to nonzero
|
|
|
|
* for the error case.
|
|
|
|
*/
|
2013-11-04 22:48:08 +01:00
|
|
|
if (m.PM_PTRACE_DATA == -1) errno = 0;
|
|
|
|
return(m.PM_PTRACE_DATA);
|
2011-02-17 18:11:09 +01:00
|
|
|
}
|