From owner-p4-projects@FreeBSD.ORG Sat Oct 20 22:05:14 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 0B57716A41B; Sat, 20 Oct 2007 22:05:14 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ABD1116A418 for ; Sat, 20 Oct 2007 22:05:13 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 98D0313C455 for ; Sat, 20 Oct 2007 22:05:13 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l9KM5Dv3067526 for ; Sat, 20 Oct 2007 22:05:13 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l9KM5Dgr067523 for perforce@freebsd.org; Sat, 20 Oct 2007 22:05:13 GMT (envelope-from jb@freebsd.org) Date: Sat, 20 Oct 2007 22:05:13 GMT Message-Id: <200710202205.l9KM5Dgr067523@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 127850 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Oct 2007 22:05:14 -0000 http://perforce.freebsd.org/chv.cgi?CH=127850 Change 127850 by jb@jb_freebsd1 on 2007/10/20 22:04:17 I plan to create a BSD libproc based on extensions to FreeBSD's ptrace rather than using procfs like Sun does. I won't be using the Solaris libproc API because I can't get Sun to release the whole thing un-encumbered. I'll then hack libdtrace to use our API. For the time being, this library code is just an incomplete hack to allow the working part of DTrace to operate. Expect it to be deleted. Affected files ... .. //depot/projects/dtrace/src/cddl/lib/libproc/Pcontrol.c#2 edit .. //depot/projects/dtrace/src/cddl/lib/libproc/Psymtab.c#2 edit .. //depot/projects/dtrace/src/cddl/lib/libproc/Putil.c#2 edit .. //depot/projects/dtrace/src/cddl/lib/libproc/libproc.h#2 edit .. //depot/projects/dtrace6/src/cddl/lib/libproc/Pcontrol.c#2 edit .. //depot/projects/dtrace6/src/cddl/lib/libproc/Psymtab.c#2 edit .. //depot/projects/dtrace6/src/cddl/lib/libproc/Putil.c#2 edit .. //depot/projects/dtrace6/src/cddl/lib/libproc/libproc.h#2 edit Differences ... ==== //depot/projects/dtrace/src/cddl/lib/libproc/Pcontrol.c#2 (text+ko) ==== @@ -31,7 +31,9 @@ #include #include +#ifdef DOODAD #include +#endif #include #include #include ==== //depot/projects/dtrace/src/cddl/lib/libproc/Psymtab.c#2 (text+ko) ==== @@ -31,7 +31,9 @@ #include #include +#ifdef DOODAD #include +#endif #include #include #include ==== //depot/projects/dtrace/src/cddl/lib/libproc/Putil.c#2 (text+ko) ==== @@ -31,7 +31,9 @@ #include #include +#ifdef DOODAD #include +#endif #include #include #include ==== //depot/projects/dtrace/src/cddl/lib/libproc/libproc.h#2 (text+ko) ==== @@ -38,7 +38,110 @@ * rather than using 'procfs' like on Solaris. */ -#include +#include + +/* + * Control codes (long values) for messages written to ctl and lwpctl files. + */ +#define PCNULL 0L /* null request, advance to next message */ +#define PCSTOP 1L /* direct process or lwp to stop and wait for stop */ +#define PCDSTOP 2L /* direct process or lwp to stop */ +#define PCWSTOP 3L /* wait for process or lwp to stop, no timeout */ +#define PCTWSTOP 4L /* wait for stop, with long millisecond timeout arg */ +#define PCRUN 5L /* make process/lwp runnable, w/ long flags argument */ +#define PCCSIG 6L /* clear current signal from lwp */ +#define PCCFAULT 7L /* clear current fault from lwp */ +#define PCSSIG 8L /* set current signal from siginfo_t argument */ +#define PCKILL 9L /* post a signal to process/lwp, long argument */ +#define PCUNKILL 10L /* delete a pending signal from process/lwp, long arg */ +#define PCSHOLD 11L /* set lwp signal mask from sigset_t argument */ +#define PCSTRACE 12L /* set traced signal set from sigset_t argument */ +#define PCSFAULT 13L /* set traced fault set from fltset_t argument */ +#define PCSENTRY 14L /* set traced syscall entry set from sysset_t arg */ +#define PCSEXIT 15L /* set traced syscall exit set from sysset_t arg */ +#define PCSET 16L /* set modes from long argument */ +#define PCUNSET 17L /* unset modes from long argument */ +#define PCSREG 18L /* set lwp general registers from prgregset_t arg */ +#define PCSFPREG 19L /* set lwp floating-point registers from prfpregset_t */ +#define PCSXREG 20L /* set lwp extra registers from prxregset_t arg */ +#define PCNICE 21L /* set nice priority from long argument */ +#define PCSVADDR 22L /* set %pc virtual address from long argument */ +#define PCWATCH 23L /* set/unset watched memory area from prwatch_t arg */ +#define PCAGENT 24L /* create agent lwp with regs from prgregset_t arg */ +#define PCREAD 25L /* read from the address space via priovec_t arg */ +#define PCWRITE 26L /* write to the address space via priovec_t arg */ +#define PCSCRED 27L /* set process credentials from prcred_t argument */ +#define PCSASRS 28L /* set ancillary state registers from asrset_t arg */ +#define PCSPRIV 29L /* set process privileges from prpriv_t argument */ +#define PCSZONE 30L /* set zoneid from zoneid_t argument */ +#define PCSCREDX 31L /* as PCSCRED but with supplemental groups */ +/* + * PCRUN long operand flags. + */ +#define PRCSIG 0x01 /* clear current signal, if any */ +#define PRCFAULT 0x02 /* clear current fault, if any */ +#define PRSTEP 0x04 /* direct the lwp to single-step */ +#define PRSABORT 0x08 /* abort syscall, if in syscall */ +#define PRSTOP 0x10 /* set directed stop request */ + +typedef struct reg prgregset_t; +typedef struct fpreg prfpregset_t; + +typedef struct lwpstatus { + id_t pr_lwpid; /* lwp id */ + int pr_flags; /* flags */ + int pr_errno; /* errno for failed syscall, 0 if successful */ + short pr_why; /* reason for lwp stop, if stopped */ + short pr_what; /* more detailed reason */ + short pr_cursig; /* current signal, if any */ + prgregset_t + pr_reg; /* general registers */ + prfpregset_t + pr_fpreg; /* floating-point registers */ +} lwpstatus_t; + +typedef struct pstatus { + int pr_flags; /* flags (see below) */ +#define PR_STOPPED 0x00000001 /* lwp is stopped */ +#define PR_ISTOP 0x00000002 /* lwp is stopped on an event of interest */ +#define PR_DSTOP 0x00000004 /* lwp has a stop directive in effect */ +#define PR_STEP 0x00000008 /* lwp has a single-step directive in effect */ +#define PR_ASLEEP 0x00000010 /* lwp is sleeping in a system call */ +#define PR_PCINVAL 0x00000020 /* contents of pr_instr undefined */ +#define PR_ASLWP 0x00000040 /* obsolete flag; never set */ +#define PR_AGENT 0x00000080 /* this lwp is the /proc agent lwp */ +#define PR_DETACH 0x00000100 /* this is a detached lwp */ +#define PR_DAEMON 0x00000200 /* this is a daemon lwp */ +/* The following flags apply to the process, not to an individual lwp */ +#define PR_ISSYS 0x00001000 /* this is a system process */ +#define PR_VFORKP 0x00002000 /* process is the parent of a vfork()d child */ +#define PR_ORPHAN 0x00004000 /* process's process group is orphaned */ +/* The following process flags are modes settable by PCSET/PCUNSET */ +#define PR_FORK 0x00100000 /* inherit-on-fork is in effect */ +#define PR_RLC 0x00200000 /* run-on-last-close is in effect */ +#define PR_KLC 0x00400000 /* kill-on-last-close is in effect */ +#define PR_ASYNC 0x00800000 /* asynchronous-stop is in effect */ +#define PR_MSACCT 0x01000000 /* micro-state usage accounting is in effect */ +#define PR_BPTADJ 0x02000000 /* breakpoint trap pc adjustment is in effect */ +#define PR_PTRACE 0x04000000 /* ptrace-compatibility mode is in effect */ +#define PR_MSFORK 0x08000000 /* micro-state accounting inherited on fork */ +#define PR_IDLE 0x10000000 /* lwp is a cpu's idle thread */ + pid_t pr_pid; /* Process ID. */ + lwpstatus_t + pr_lwp; /* Status of the representative lwp.*/ +} pstatus_t; + +/* + * Reasons for stopping (pr_why). + */ +#define PR_REQUESTED 1 +#define PR_SIGNALLED 2 +#define PR_SYSENTRY 3 +#define PR_SYSEXIT 4 +#define PR_JOBCONTROL 5 +#define PR_FAULTED 6 +#define PR_SUSPENDED 7 +#define PR_CHECKPOINT 8 extern int _libproc_debug; /* set non-zero to enable debugging fprintfs */ ==== //depot/projects/dtrace6/src/cddl/lib/libproc/Pcontrol.c#2 (text+ko) ==== @@ -31,7 +31,9 @@ #include #include +#ifdef DOODAD #include +#endif #include #include #include ==== //depot/projects/dtrace6/src/cddl/lib/libproc/Psymtab.c#2 (text+ko) ==== @@ -31,7 +31,9 @@ #include #include +#ifdef DOODAD #include +#endif #include #include #include ==== //depot/projects/dtrace6/src/cddl/lib/libproc/Putil.c#2 (text+ko) ==== @@ -31,7 +31,9 @@ #include #include +#ifdef DOODAD #include +#endif #include #include #include ==== //depot/projects/dtrace6/src/cddl/lib/libproc/libproc.h#2 (text+ko) ==== @@ -38,7 +38,110 @@ * rather than using 'procfs' like on Solaris. */ -#include +#include + +/* + * Control codes (long values) for messages written to ctl and lwpctl files. + */ +#define PCNULL 0L /* null request, advance to next message */ +#define PCSTOP 1L /* direct process or lwp to stop and wait for stop */ +#define PCDSTOP 2L /* direct process or lwp to stop */ +#define PCWSTOP 3L /* wait for process or lwp to stop, no timeout */ +#define PCTWSTOP 4L /* wait for stop, with long millisecond timeout arg */ +#define PCRUN 5L /* make process/lwp runnable, w/ long flags argument */ +#define PCCSIG 6L /* clear current signal from lwp */ +#define PCCFAULT 7L /* clear current fault from lwp */ +#define PCSSIG 8L /* set current signal from siginfo_t argument */ +#define PCKILL 9L /* post a signal to process/lwp, long argument */ +#define PCUNKILL 10L /* delete a pending signal from process/lwp, long arg */ +#define PCSHOLD 11L /* set lwp signal mask from sigset_t argument */ +#define PCSTRACE 12L /* set traced signal set from sigset_t argument */ +#define PCSFAULT 13L /* set traced fault set from fltset_t argument */ +#define PCSENTRY 14L /* set traced syscall entry set from sysset_t arg */ +#define PCSEXIT 15L /* set traced syscall exit set from sysset_t arg */ +#define PCSET 16L /* set modes from long argument */ +#define PCUNSET 17L /* unset modes from long argument */ +#define PCSREG 18L /* set lwp general registers from prgregset_t arg */ +#define PCSFPREG 19L /* set lwp floating-point registers from prfpregset_t */ +#define PCSXREG 20L /* set lwp extra registers from prxregset_t arg */ +#define PCNICE 21L /* set nice priority from long argument */ +#define PCSVADDR 22L /* set %pc virtual address from long argument */ +#define PCWATCH 23L /* set/unset watched memory area from prwatch_t arg */ +#define PCAGENT 24L /* create agent lwp with regs from prgregset_t arg */ +#define PCREAD 25L /* read from the address space via priovec_t arg */ +#define PCWRITE 26L /* write to the address space via priovec_t arg */ +#define PCSCRED 27L /* set process credentials from prcred_t argument */ +#define PCSASRS 28L /* set ancillary state registers from asrset_t arg */ +#define PCSPRIV 29L /* set process privileges from prpriv_t argument */ +#define PCSZONE 30L /* set zoneid from zoneid_t argument */ +#define PCSCREDX 31L /* as PCSCRED but with supplemental groups */ +/* + * PCRUN long operand flags. + */ +#define PRCSIG 0x01 /* clear current signal, if any */ +#define PRCFAULT 0x02 /* clear current fault, if any */ +#define PRSTEP 0x04 /* direct the lwp to single-step */ +#define PRSABORT 0x08 /* abort syscall, if in syscall */ +#define PRSTOP 0x10 /* set directed stop request */ + +typedef struct reg prgregset_t; +typedef struct fpreg prfpregset_t; + +typedef struct lwpstatus { + id_t pr_lwpid; /* lwp id */ + int pr_flags; /* flags */ + int pr_errno; /* errno for failed syscall, 0 if successful */ + short pr_why; /* reason for lwp stop, if stopped */ + short pr_what; /* more detailed reason */ + short pr_cursig; /* current signal, if any */ + prgregset_t + pr_reg; /* general registers */ + prfpregset_t + pr_fpreg; /* floating-point registers */ +} lwpstatus_t; + +typedef struct pstatus { + int pr_flags; /* flags (see below) */ +#define PR_STOPPED 0x00000001 /* lwp is stopped */ +#define PR_ISTOP 0x00000002 /* lwp is stopped on an event of interest */ +#define PR_DSTOP 0x00000004 /* lwp has a stop directive in effect */ +#define PR_STEP 0x00000008 /* lwp has a single-step directive in effect */ +#define PR_ASLEEP 0x00000010 /* lwp is sleeping in a system call */ +#define PR_PCINVAL 0x00000020 /* contents of pr_instr undefined */ +#define PR_ASLWP 0x00000040 /* obsolete flag; never set */ +#define PR_AGENT 0x00000080 /* this lwp is the /proc agent lwp */ +#define PR_DETACH 0x00000100 /* this is a detached lwp */ +#define PR_DAEMON 0x00000200 /* this is a daemon lwp */ +/* The following flags apply to the process, not to an individual lwp */ +#define PR_ISSYS 0x00001000 /* this is a system process */ +#define PR_VFORKP 0x00002000 /* process is the parent of a vfork()d child */ +#define PR_ORPHAN 0x00004000 /* process's process group is orphaned */ +/* The following process flags are modes settable by PCSET/PCUNSET */ +#define PR_FORK 0x00100000 /* inherit-on-fork is in effect */ +#define PR_RLC 0x00200000 /* run-on-last-close is in effect */ +#define PR_KLC 0x00400000 /* kill-on-last-close is in effect */ +#define PR_ASYNC 0x00800000 /* asynchronous-stop is in effect */ +#define PR_MSACCT 0x01000000 /* micro-state usage accounting is in effect */ +#define PR_BPTADJ 0x02000000 /* breakpoint trap pc adjustment is in effect */ +#define PR_PTRACE 0x04000000 /* ptrace-compatibility mode is in effect */ +#define PR_MSFORK 0x08000000 /* micro-state accounting inherited on fork */ +#define PR_IDLE 0x10000000 /* lwp is a cpu's idle thread */ + pid_t pr_pid; /* Process ID. */ + lwpstatus_t + pr_lwp; /* Status of the representative lwp.*/ +} pstatus_t; + +/* + * Reasons for stopping (pr_why). + */ +#define PR_REQUESTED 1 +#define PR_SIGNALLED 2 +#define PR_SYSENTRY 3 +#define PR_SYSEXIT 4 +#define PR_JOBCONTROL 5 +#define PR_FAULTED 6 +#define PR_SUSPENDED 7 +#define PR_CHECKPOINT 8 extern int _libproc_debug; /* set non-zero to enable debugging fprintfs */