summaryrefslogtreecommitdiffstats
path: root/usr.bin/truss/amd64-fbsd32.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/truss/amd64-fbsd32.c')
-rw-r--r--usr.bin/truss/amd64-fbsd32.c58
1 files changed, 21 insertions, 37 deletions
diff --git a/usr.bin/truss/amd64-fbsd32.c b/usr.bin/truss/amd64-fbsd32.c
index 7f049a6..f9e435d 100644
--- a/usr.bin/truss/amd64-fbsd32.c
+++ b/usr.bin/truss/amd64-fbsd32.c
@@ -43,9 +43,8 @@ static const char rcsid[] =
*/
#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
#include <sys/syscall.h>
+#include <sys/ptrace.h>
#include <machine/reg.h>
#include <machine/psl.h>
@@ -63,7 +62,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int fd = -1;
static int cpid = -1;
#include "syscalls.h"
@@ -113,26 +111,18 @@ clear_fsc(void) {
void
i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
- char buf[32];
struct reg regs;
int syscall_num;
int i;
unsigned int parm_offset;
struct syscall *sc = NULL;
-
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDWR);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return;
- }
- cpid = trussinfo->pid;
- }
+ struct ptrace_io_desc iorequest;
+ cpid = trussinfo->curthread->tid;
clear_fsc();
- lseek(fd, 0L, 0);
- if (read(fd, &regs, sizeof(regs)) != sizeof(regs)) {
+
+ if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0)
+ {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
@@ -146,13 +136,11 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
syscall_num = regs.r_eax;
switch (syscall_num) {
case SYS_syscall:
- lseek(Procfd, parm_offset, SEEK_SET);
- read(Procfd, &syscall_num, sizeof(int));
+ syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0);
parm_offset += sizeof(int);
break;
case SYS___syscall:
- lseek(Procfd, parm_offset, SEEK_SET);
- read(Procfd, &syscall_num, sizeof(int));
+ syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0);
parm_offset += sizeof(quad_t);
break;
}
@@ -169,15 +157,19 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|| !strcmp(fsc.name, "rfork")
|| !strcmp(fsc.name, "vfork"))))
{
- trussinfo->in_fork = 1;
+ trussinfo->curthread->in_fork = 1;
}
if (nargs == 0)
return;
fsc.args = malloc((1+nargs) * sizeof(unsigned long));
- lseek(Procfd, parm_offset, SEEK_SET);
- if (read(Procfd, fsc.args, nargs * sizeof(unsigned long)) == -1)
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)parm_offset;
+ iorequest.piod_addr = fsc.args;
+ iorequest.piod_len = nargs * sizeof(unsigned long);
+ ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0)
return;
if (fsc.name)
@@ -218,7 +210,7 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
i < (fsc.nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0, trussinfo);
+ fsc.s_args[i] = print_arg(&sc->args[i], fsc.args, 0, trussinfo);
}
}
#if DEBUG
@@ -274,28 +266,20 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
long
i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
- char buf[32];
struct reg regs;
long retval;
int i;
int errorp;
struct syscall *sc;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDONLY);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return (-1);
- }
- cpid = trussinfo->pid;
- }
+ cpid = trussinfo->curthread->tid;
- lseek(fd, 0L, 0);
- if (read(fd, &regs, sizeof(regs)) != sizeof(regs)) {
+ if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0)
+ {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1);
}
+
retval = regs.r_eax;
errorp = !!(regs.r_eflags & PSL_C);
@@ -323,7 +307,7 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
- temp = print_arg(Procfd, &sc->args[i], fsc.args, retval, trussinfo);
+ temp = print_arg(&sc->args[i], fsc.args, retval, trussinfo);
fsc.s_args[i] = temp;
}
}
OpenPOWER on IntegriCloud