MFhead @ r288954

This commit is contained in:
ngie 2015-10-06 21:43:37 +00:00
parent 8cad7e1c52
commit a6c3db2235
20 changed files with 571 additions and 280 deletions

View File

@ -247,9 +247,11 @@ Checkers.inc.h: ${CLANG_SRCS}/lib/StaticAnalyzer/Checkers/Checkers.td
-I ${CLANG_SRCS}/include -d ${.TARGET:C/\.h$/.d/} -o ${.TARGET} \
${CLANG_SRCS}/lib/StaticAnalyzer/Checkers/Checkers.td
.for dep in ${TGHDRS:C/$/.inc.d/}
. sinclude "${dep}"
.endfor
.if !make(depend)
. for dep in ${TGHDRS:C/$/.inc.d/}
. sinclude "${dep}"
. endfor
.endif
SRCS+= ${TGHDRS:C/$/.inc.h/}
DPSRCS+= ${TGHDRS:C/$/.inc.h/}

View File

@ -398,11 +398,8 @@ MLINKS+= archive_write_set_options.3 archive_write_set_format_option.3
MLINKS+= archive_write_set_options.3 archive_write_set_option.3
MLINKS+= libarchive.3 archive.3
.PHONY: check test clean-test
check test:
cd ${.CURDIR}/test && make obj && make test
clean-test:
cd ${.CURDIR}/test && make clean
.if ${MK_TESTS} != "no"
#SUBDIR+= tests
.endif
.include <bsd.lib.mk>

View File

@ -1,6 +1,6 @@
# $FreeBSD$
LIBARCHIVEDIR= ${.CURDIR}/../../../contrib/libarchive
LIBARCHIVEDIR= ${SRCTOP}/contrib/libarchive
MAN=

View File

@ -63,7 +63,6 @@ CXXFLAGS+= -std=c++11
.endif
LIBADD+= cxxrt
LDFLAGS+= --verbose
INCSGROUPS= STD EXP EXT
STD_HEADERS= __bit_reference\

View File

@ -1867,6 +1867,8 @@ kinfo_getvmmap_core(struct procstat_core *core, int *cntp)
eb = buf + len;
while (bp < eb) {
kv = (struct kinfo_vmentry *)(uintptr_t)bp;
if (kv->kve_structsize == 0)
break;
bp += kv->kve_structsize;
cnt++;
}
@ -1882,6 +1884,8 @@ kinfo_getvmmap_core(struct procstat_core *core, int *cntp)
/* Pass 2: unpack */
while (bp < eb) {
kv = (struct kinfo_vmentry *)(uintptr_t)bp;
if (kv->kve_structsize == 0)
break;
/* Copy/expand into pre-zeroed buffer */
memcpy(kp, kv, kv->kve_structsize);
/* Advance to next packed record */

View File

@ -44,6 +44,8 @@ kinfo_getvmmap(pid_t pid, int *cntp)
eb = buf + len;
while (bp < eb) {
kv = (struct kinfo_vmentry *)(uintptr_t)bp;
if (kv->kve_structsize == 0)
break;
bp += kv->kve_structsize;
cnt++;
}
@ -59,6 +61,8 @@ kinfo_getvmmap(pid_t pid, int *cntp)
/* Pass 2: unpack */
while (bp < eb) {
kv = (struct kinfo_vmentry *)(uintptr_t)bp;
if (kv->kve_structsize == 0)
break;
/* Copy/expand into pre-zeroed buffer */
memcpy(kp, kv, kv->kve_structsize);
/* Advance to next packed record */

View File

@ -22,7 +22,7 @@
<pubdate>$FreeBSD$</pubdate>
<!-- Last rev: 284814 -->
<!-- Last rev: 288943 -->
<copyright>
<year>2015</year>
@ -457,26 +457,15 @@
<sect2 xml:id="userland-contrib">
<title>Contributed Software</title>
<para revision="258884" contrib="sponsor"
sponsor="&darpa_afrl;">&man.lldb.1; has been updated to
upstream snapshot version r196259.</para>
<para revision="260445">&man.byacc.1; has been updated to
version 20140101.</para>
<para revision="261283"><application>libc++</application> has
been updated to version 3.4.</para>
<para revision="261320"><application>OpenSSH</application> has
been updated to 6.5p1.</para>
<para revision="261344"><application>mdocml</application> has
been updated to version 1.12.3.</para>
<para revision="261991"><application>LLVM</application> and
<application>Clang</application> have been updated to
version 3.4.</para>
<para revision="275718">The <application>binutils</application>
suite of utilities has been updated to include upstream
patches that add new relocations for &arch.powerpc;
@ -595,6 +584,10 @@
<para revision="288303">The &man.nc.1; utility has been updated
to the OpenBSD 5.8 version.</para>
<para revision="288943"><application>LLVM</application> and
<application>Clang</application> have been updated to
version 3.7.0.</para>
</sect2>
<sect2 xml:id="userland-installer">

View File

@ -28,7 +28,7 @@
.\" @(#)core.5 8.3 (Berkeley) 12/11/93
.\" $FreeBSD$
.\"
.Dd September 2, 2015
.Dd October 5, 2015
.Dt CORE 5
.Os
.Sh NAME
@ -130,6 +130,19 @@ All file descriptor information can be preserved by disabling packing.
This potentially wastes up to PATH_MAX bytes per open fd.
Packing is disabled with
.Dl sysctl kern.coredump_pack_fileinfo=0 .
.Pp
Similarly, corefiles are written with vmmap information as an ELF note, which
contains file paths.
By default, they are packed to only use as much space as
needed.
By the same mechanism as for the open files note, these paths can also
change at any time and result in a truncated note.
.Pp
All vmmap information can be preserved by disabling packing.
Like the file information, this potentially wastes up to PATH_MAX bytes per
mapped object.
Packing is disabled with
.Dl sysctl kern.coredump_pack_vmmapinfo=0 .
.Sh EXAMPLES
In order to store all core images in per-user private areas under
.Pa /var/coredumps ,

View File

@ -894,7 +894,6 @@ int intel_gpu_reset(struct drm_device *dev)
case 4:
ret = i965_do_reset(dev);
break;
case 3:
case 2:
ret = i8xx_do_reset(dev);
break;

View File

@ -1959,24 +1959,30 @@ note_procstat_vmmap(void *arg, struct sbuf *sb, size_t *sizep)
{
struct proc *p;
size_t size;
int structsize;
int structsize, vmmap_flags;
if (coredump_pack_vmmapinfo)
vmmap_flags = KERN_VMMAP_PACK_KINFO;
else
vmmap_flags = 0;
p = (struct proc *)arg;
structsize = sizeof(struct kinfo_vmentry);
if (sb == NULL) {
size = 0;
sb = sbuf_new(NULL, NULL, 128, SBUF_FIXEDLEN);
sbuf_set_drain(sb, sbuf_drain_count, &size);
sbuf_bcat(sb, &structsize, sizeof(structsize));
PROC_LOCK(p);
kern_proc_vmmap_out(p, sb);
kern_proc_vmmap_out(p, sb, -1, vmmap_flags);
sbuf_finish(sb);
sbuf_delete(sb);
*sizep = size;
} else {
structsize = sizeof(struct kinfo_vmentry);
sbuf_bcat(sb, &structsize, sizeof(structsize));
PROC_LOCK(p);
kern_proc_vmmap_out(p, sb);
kern_proc_vmmap_out(p, sb, *sizep - sizeof(structsize),
vmmap_flags);
}
}

View File

@ -105,6 +105,11 @@ SYSCTL_INT(_kern, OID_AUTO, coredump_pack_fileinfo, CTLFLAG_RWTUN,
&coredump_pack_fileinfo, 0,
"Enable file path packing in 'procstat -f' coredump notes");
int coredump_pack_vmmapinfo = 1;
SYSCTL_INT(_kern, OID_AUTO, coredump_pack_vmmapinfo, CTLFLAG_RWTUN,
&coredump_pack_vmmapinfo, 0,
"Enable file path packing in 'procstat -v' coredump notes");
static int sysctl_kern_ps_strings(SYSCTL_HANDLER_ARGS);
static int sysctl_kern_usrstack(SYSCTL_HANDLER_ARGS);
static int sysctl_kern_stackprot(SYSCTL_HANDLER_ARGS);

View File

@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
#include <sys/proc.h>
#include <sys/procdesc.h>
#include <sys/pioctl.h>
#include <sys/ptrace.h>
#include <sys/racct.h>
#include <sys/resourcevar.h>
#include <sys/sched.h>
@ -1031,8 +1032,8 @@ fork_return(struct thread *td, struct trapframe *frame)
{
struct proc *p, *dbg;
p = td->td_proc;
if (td->td_dbgflags & TDB_STOPATFORK) {
p = td->td_proc;
sx_xlock(&proctree_lock);
PROC_LOCK(p);
if ((p->p_pptr->p_flag & (P_TRACED | P_FOLLOWFORK)) ==
@ -1049,9 +1050,9 @@ fork_return(struct thread *td, struct trapframe *frame)
p->p_pid, p->p_oppid);
proc_reparent(p, dbg);
sx_xunlock(&proctree_lock);
td->td_dbgflags |= TDB_CHILD;
td->td_dbgflags |= TDB_CHILD | TDB_SCX;
ptracestop(td, SIGSTOP);
td->td_dbgflags &= ~TDB_CHILD;
td->td_dbgflags &= ~(TDB_CHILD | TDB_SCX);
} else {
/*
* ... otherwise clear the request.
@ -1061,6 +1062,18 @@ fork_return(struct thread *td, struct trapframe *frame)
cv_broadcast(&p->p_dbgwait);
}
PROC_UNLOCK(p);
} else if (p->p_flag & P_TRACED) {
/*
* This is the start of a new thread in a traced
* process. Report a system call exit event.
*/
PROC_LOCK(p);
td->td_dbgflags |= TDB_SCX;
_STOPEVENT(p, S_SCX, td->td_dbg_sc_code);
if ((p->p_stops & S_PT_SCX) != 0)
ptracestop(td, SIGTRAP);
td->td_dbgflags &= ~TDB_SCX;
PROC_UNLOCK(p);
}
userret(td, frame);

View File

@ -2252,7 +2252,7 @@ next:;
* Must be called with the process locked and will return unlocked.
*/
int
kern_proc_vmmap_out(struct proc *p, struct sbuf *sb)
kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags)
{
vm_map_entry_t entry, tmp_entry;
struct vattr va;
@ -2276,7 +2276,7 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb)
PRELE(p);
return (ESRCH);
}
kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK);
kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK | M_ZERO);
error = 0;
map = &vm->vm_map;
@ -2411,10 +2411,23 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb)
free(freepath, M_TEMP);
/* Pack record size down */
kve->kve_structsize = offsetof(struct kinfo_vmentry, kve_path) +
strlen(kve->kve_path) + 1;
if ((flags & KERN_VMMAP_PACK_KINFO) != 0)
kve->kve_structsize =
offsetof(struct kinfo_vmentry, kve_path) +
strlen(kve->kve_path) + 1;
else
kve->kve_structsize = sizeof(*kve);
kve->kve_structsize = roundup(kve->kve_structsize,
sizeof(uint64_t));
/* Halt filling and truncate rather than exceeding maxlen */
if (maxlen != -1 && maxlen < kve->kve_structsize) {
error = 0;
vm_map_lock_read(map);
break;
} else if (maxlen != -1)
maxlen -= kve->kve_structsize;
if (sbuf_bcat(sb, kve, kve->kve_structsize) != 0)
error = ENOMEM;
vm_map_lock_read(map);
@ -2447,7 +2460,7 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_ARGS)
sbuf_delete(&sb);
return (error);
}
error = kern_proc_vmmap_out(p, &sb);
error = kern_proc_vmmap_out(p, &sb, -1, KERN_VMMAP_PACK_KINFO);
error2 = sbuf_finish(&sb);
sbuf_delete(&sb);
return (error != 0 ? error : error2);

View File

@ -83,11 +83,12 @@ syscallenter(struct thread *td, struct syscall_args *sa)
if (error == 0) {
STOPEVENT(p, S_SCE, sa->narg);
if (p->p_flag & P_TRACED && p->p_stops & S_PT_SCE) {
if (p->p_flag & P_TRACED) {
PROC_LOCK(p);
td->td_dbg_sc_code = sa->code;
td->td_dbg_sc_narg = sa->narg;
ptracestop((td), SIGTRAP);
if (p->p_stops & S_PT_SCE)
ptracestop((td), SIGTRAP);
PROC_UNLOCK(p);
}
if (td->td_dbgflags & TDB_USERWR) {

View File

@ -84,6 +84,7 @@ int exec_register(const struct execsw *);
int exec_unregister(const struct execsw *);
extern int coredump_pack_fileinfo;
extern int coredump_pack_vmmapinfo;
/*
* note: name##_mod cannot be const storage because the

View File

@ -235,8 +235,6 @@ struct thread {
int td_sqqueue; /* (t) Sleepqueue queue blocked on. */
void *td_wchan; /* (t) Sleep address. */
const char *td_wmesg; /* (t) Reason for sleep. */
int td_lastcpu; /* (t) Last cpu we were on. */
int td_oncpu; /* (t) Which cpu we are on. */
volatile u_char td_owepreempt; /* (k*) Preempt on last critical_exit */
u_char td_tsqueue; /* (t) Turnstile queue blocked on. */
short td_locks; /* (k) Debug: count of non-spin locks */
@ -283,8 +281,6 @@ struct thread {
int td_no_sleeping; /* (k) Sleeping disabled count. */
int td_dom_rr_idx; /* (k) RR Numa domain selection. */
void *td_su; /* (k) FFS SU private */
u_int td_dbg_sc_code; /* (c) Syscall code to debugger. */
u_int td_dbg_sc_narg; /* (c) Syscall arg count to debugger.*/
#define td_endzero td_sigmask
/* Copied during fork1() or create_thread(). */
@ -296,6 +292,8 @@ struct thread {
u_char td_pri_class; /* (t) Scheduling class. */
u_char td_user_pri; /* (t) User pri from estcpu and nice. */
u_char td_base_user_pri; /* (t) Base user pri */
u_int td_dbg_sc_code; /* (c) Syscall code to debugger. */
u_int td_dbg_sc_narg; /* (c) Syscall arg count to debugger.*/
#define td_endcopy td_pcb
/*
@ -335,6 +333,8 @@ struct thread {
struct vm_page **td_ma; /* (k) uio pages held */
int td_ma_cnt; /* (k) size of *td_ma */
void *td_emuldata; /* Emulator state data */
int td_lastcpu; /* (t) Last cpu we were on. */
int td_oncpu; /* (t) Which cpu we are on. */
};
struct mtx *thread_lock_block(struct thread *);

View File

@ -541,6 +541,9 @@ struct kinfo_sigtramp {
/* Flags for kern_proc_filedesc_out. */
#define KERN_FILEDESC_PACK_KINFO 0x00000001U
/* Flags for kern_proc_vmmap_out. */
#define KERN_VMMAP_PACK_KINFO 0x00000001U
struct sbuf;
/*
@ -556,7 +559,8 @@ int kern_proc_filedesc_out(struct proc *p, struct sbuf *sb, ssize_t maxlen,
int flags);
int kern_proc_cwd_out(struct proc *p, struct sbuf *sb, ssize_t maxlen);
int kern_proc_out(struct proc *p, struct sbuf *sb, int flags);
int kern_proc_vmmap_out(struct proc *p, struct sbuf *sb);
int kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen,
int flags);
int vntype_to_kinfo(int vtype);
#endif /* !_KERNEL */

View File

@ -7,6 +7,7 @@ ATF_TESTS_C+= ptrace_test
ATF_TESTS_C+= unix_seqpacket_test
TEST_METADATA.unix_seqpacket_test+= timeout="15"
LDADD.ptrace_test+= -lpthread
LDADD.unix_seqpacket_test+= -lpthread
WARNS?= 5

View File

@ -29,10 +29,12 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/syscall.h>
#include <sys/sysctl.h>
#include <sys/user.h>
#include <sys/wait.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@ -409,12 +411,15 @@ ATF_TC_BODY(ptrace__parent_sees_exit_after_unrelated_debugger, tc)
* debugger is attached to it.
*/
static __dead2 void
follow_fork_parent(void)
follow_fork_parent(bool use_vfork)
{
pid_t fpid, wpid;
int status;
CHILD_REQUIRE((fpid = fork()) != -1);
if (use_vfork)
CHILD_REQUIRE((fpid = vfork()) != -1);
else
CHILD_REQUIRE((fpid = fork()) != -1);
if (fpid == 0)
/* Child */
@ -434,7 +439,7 @@ follow_fork_parent(void)
* child process.
*/
static pid_t
handle_fork_events(pid_t parent)
handle_fork_events(pid_t parent, struct ptrace_lwpinfo *ppl)
{
struct ptrace_lwpinfo pl;
bool fork_reported[2];
@ -469,6 +474,8 @@ handle_fork_events(pid_t parent)
child = wpid;
else
ATF_REQUIRE(child == wpid);
if (ppl != NULL)
ppl[1] = pl;
fork_reported[1] = true;
} else {
ATF_REQUIRE(wpid == parent);
@ -478,6 +485,8 @@ handle_fork_events(pid_t parent)
child = pl.pl_child_pid;
else
ATF_REQUIRE(child == pl.pl_child_pid);
if (ppl != NULL)
ppl[0] = pl;
fork_reported[0] = true;
}
}
@ -499,7 +508,7 @@ ATF_TC_BODY(ptrace__follow_fork_both_attached, tc)
ATF_REQUIRE((fpid = fork()) != -1);
if (fpid == 0) {
trace_me();
follow_fork_parent();
follow_fork_parent(false);
}
/* Parent process. */
@ -516,7 +525,7 @@ ATF_TC_BODY(ptrace__follow_fork_both_attached, tc)
/* Continue the child ignoring the SIGSTOP. */
ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
children[1] = handle_fork_events(children[0]);
children[1] = handle_fork_events(children[0], NULL);
ATF_REQUIRE(children[1] > 0);
ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
@ -555,7 +564,7 @@ ATF_TC_BODY(ptrace__follow_fork_child_detached, tc)
ATF_REQUIRE((fpid = fork()) != -1);
if (fpid == 0) {
trace_me();
follow_fork_parent();
follow_fork_parent(false);
}
/* Parent process. */
@ -572,7 +581,7 @@ ATF_TC_BODY(ptrace__follow_fork_child_detached, tc)
/* Continue the child ignoring the SIGSTOP. */
ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
children[1] = handle_fork_events(children[0]);
children[1] = handle_fork_events(children[0], NULL);
ATF_REQUIRE(children[1] > 0);
ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
@ -606,7 +615,7 @@ ATF_TC_BODY(ptrace__follow_fork_parent_detached, tc)
ATF_REQUIRE((fpid = fork()) != -1);
if (fpid == 0) {
trace_me();
follow_fork_parent();
follow_fork_parent(false);
}
/* Parent process. */
@ -623,7 +632,7 @@ ATF_TC_BODY(ptrace__follow_fork_parent_detached, tc)
/* Continue the child ignoring the SIGSTOP. */
ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
children[1] = handle_fork_events(children[0]);
children[1] = handle_fork_events(children[0], NULL);
ATF_REQUIRE(children[1] > 0);
ATF_REQUIRE(ptrace(PT_DETACH, children[0], (caddr_t)1, 0) != -1);
@ -688,7 +697,7 @@ ATF_TC_BODY(ptrace__follow_fork_both_attached_unrelated_debugger, tc)
ATF_REQUIRE((fpid = fork()) != -1);
if (fpid == 0) {
attach_fork_parent(cpipe);
follow_fork_parent();
follow_fork_parent(false);
}
/* Parent process. */
@ -715,7 +724,7 @@ ATF_TC_BODY(ptrace__follow_fork_both_attached_unrelated_debugger, tc)
/* Signal the fork parent to continue. */
close(cpipe[0]);
children[1] = handle_fork_events(children[0]);
children[1] = handle_fork_events(children[0], NULL);
ATF_REQUIRE(children[1] > 0);
ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
@ -756,7 +765,7 @@ ATF_TC_BODY(ptrace__follow_fork_child_detached_unrelated_debugger, tc)
ATF_REQUIRE((fpid = fork()) != -1);
if (fpid == 0) {
attach_fork_parent(cpipe);
follow_fork_parent();
follow_fork_parent(false);
}
/* Parent process. */
@ -783,7 +792,7 @@ ATF_TC_BODY(ptrace__follow_fork_child_detached_unrelated_debugger, tc)
/* Signal the fork parent to continue. */
close(cpipe[0]);
children[1] = handle_fork_events(children[0]);
children[1] = handle_fork_events(children[0], NULL);
ATF_REQUIRE(children[1] > 0);
ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
@ -819,7 +828,7 @@ ATF_TC_BODY(ptrace__follow_fork_parent_detached_unrelated_debugger, tc)
ATF_REQUIRE((fpid = fork()) != -1);
if (fpid == 0) {
attach_fork_parent(cpipe);
follow_fork_parent();
follow_fork_parent(false);
}
/* Parent process. */
@ -846,7 +855,7 @@ ATF_TC_BODY(ptrace__follow_fork_parent_detached_unrelated_debugger, tc)
/* Signal the fork parent to continue. */
close(cpipe[0]);
children[1] = handle_fork_events(children[0]);
children[1] = handle_fork_events(children[0], NULL);
ATF_REQUIRE(children[1] > 0);
ATF_REQUIRE(ptrace(PT_DETACH, children[0], (caddr_t)1, 0) != -1);
@ -952,6 +961,223 @@ ATF_TC_BODY(ptrace__getppid, tc)
ATF_REQUIRE(WEXITSTATUS(status) == 1);
}
/*
* Verify that pl_syscall_code in struct ptrace_lwpinfo for a new
* child process created via fork() reports the correct value.
*/
ATF_TC_WITHOUT_HEAD(ptrace__new_child_pl_syscall_code_fork);
ATF_TC_BODY(ptrace__new_child_pl_syscall_code_fork, tc)
{
struct ptrace_lwpinfo pl[2];
pid_t children[2], fpid, wpid;
int status;
ATF_REQUIRE((fpid = fork()) != -1);
if (fpid == 0) {
trace_me();
follow_fork_parent(false);
}
/* Parent process. */
children[0] = fpid;
/* The first wait() should report the stop from SIGSTOP. */
wpid = waitpid(children[0], &status, 0);
ATF_REQUIRE(wpid == children[0]);
ATF_REQUIRE(WIFSTOPPED(status));
ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
/* Continue the child ignoring the SIGSTOP. */
ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
/* Wait for both halves of the fork event to get reported. */
children[1] = handle_fork_events(children[0], pl);
ATF_REQUIRE(children[1] > 0);
ATF_REQUIRE((pl[0].pl_flags & PL_FLAG_SCX) != 0);
ATF_REQUIRE((pl[1].pl_flags & PL_FLAG_SCX) != 0);
ATF_REQUIRE(pl[0].pl_syscall_code == SYS_fork);
ATF_REQUIRE(pl[0].pl_syscall_code == pl[1].pl_syscall_code);
ATF_REQUIRE(pl[0].pl_syscall_narg == pl[1].pl_syscall_narg);
ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
/*
* The child can't exit until the grandchild reports status, so the
* grandchild should report its exit first to the debugger.
*/
wpid = wait(&status);
ATF_REQUIRE(wpid == children[1]);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE(WEXITSTATUS(status) == 2);
wpid = wait(&status);
ATF_REQUIRE(wpid == children[0]);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE(WEXITSTATUS(status) == 1);
wpid = wait(&status);
ATF_REQUIRE(wpid == -1);
ATF_REQUIRE(errno == ECHILD);
}
/*
* Verify that pl_syscall_code in struct ptrace_lwpinfo for a new
* child process created via vfork() reports the correct value.
*/
ATF_TC_WITHOUT_HEAD(ptrace__new_child_pl_syscall_code_vfork);
ATF_TC_BODY(ptrace__new_child_pl_syscall_code_vfork, tc)
{
struct ptrace_lwpinfo pl[2];
pid_t children[2], fpid, wpid;
int status;
ATF_REQUIRE((fpid = fork()) != -1);
if (fpid == 0) {
trace_me();
follow_fork_parent(true);
}
/* Parent process. */
children[0] = fpid;
/* The first wait() should report the stop from SIGSTOP. */
wpid = waitpid(children[0], &status, 0);
ATF_REQUIRE(wpid == children[0]);
ATF_REQUIRE(WIFSTOPPED(status));
ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
ATF_REQUIRE(ptrace(PT_FOLLOW_FORK, children[0], NULL, 1) != -1);
/* Continue the child ignoring the SIGSTOP. */
ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
/* Wait for both halves of the fork event to get reported. */
children[1] = handle_fork_events(children[0], pl);
ATF_REQUIRE(children[1] > 0);
ATF_REQUIRE((pl[0].pl_flags & PL_FLAG_SCX) != 0);
ATF_REQUIRE((pl[1].pl_flags & PL_FLAG_SCX) != 0);
ATF_REQUIRE(pl[0].pl_syscall_code == SYS_vfork);
ATF_REQUIRE(pl[0].pl_syscall_code == pl[1].pl_syscall_code);
ATF_REQUIRE(pl[0].pl_syscall_narg == pl[1].pl_syscall_narg);
ATF_REQUIRE(ptrace(PT_CONTINUE, children[0], (caddr_t)1, 0) != -1);
ATF_REQUIRE(ptrace(PT_CONTINUE, children[1], (caddr_t)1, 0) != -1);
/*
* The child can't exit until the grandchild reports status, so the
* grandchild should report its exit first to the debugger.
*/
wpid = wait(&status);
ATF_REQUIRE(wpid == children[1]);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE(WEXITSTATUS(status) == 2);
wpid = wait(&status);
ATF_REQUIRE(wpid == children[0]);
ATF_REQUIRE(WIFEXITED(status));
ATF_REQUIRE(WEXITSTATUS(status) == 1);
wpid = wait(&status);
ATF_REQUIRE(wpid == -1);
ATF_REQUIRE(errno == ECHILD);
}
static void *
simple_thread(void *arg __unused)
{
pthread_exit(NULL);
}
/*
* Verify that pl_syscall_code in struct ptrace_lwpinfo for a new
* thread reports the correct value.
*/
ATF_TC_WITHOUT_HEAD(ptrace__new_child_pl_syscall_code_thread);
ATF_TC_BODY(ptrace__new_child_pl_syscall_code_thread, tc)
{
struct ptrace_lwpinfo pl;
pid_t fpid, wpid;
lwpid_t main;
int status;
ATF_REQUIRE((fpid = fork()) != -1);
if (fpid == 0) {
pthread_t thread;
trace_me();
CHILD_REQUIRE(pthread_create(&thread, NULL, simple_thread,
NULL) == 0);
CHILD_REQUIRE(pthread_join(thread, NULL) == 0);
exit(1);
}
/* The first wait() should report the stop from SIGSTOP. */
wpid = waitpid(fpid, &status, 0);
ATF_REQUIRE(wpid == fpid);
ATF_REQUIRE(WIFSTOPPED(status));
ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
sizeof(pl)) != -1);
main = pl.pl_lwpid;
/*
* Continue the child ignoring the SIGSTOP and tracing all
* system call exits.
*/
ATF_REQUIRE(ptrace(PT_TO_SCX, fpid, (caddr_t)1, 0) != -1);
/*
* Wait for the new thread to arrive. pthread_create() might
* invoke any number of system calls. For now we just wait
* for the new thread to arrive and make sure it reports a
* valid system call code. If ptrace grows thread event
* reporting then this test can be made more precise.
*/
for (;;) {
wpid = waitpid(fpid, &status, 0);
ATF_REQUIRE(wpid == fpid);
ATF_REQUIRE(WIFSTOPPED(status));
ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
sizeof(pl)) != -1);
ATF_REQUIRE((pl.pl_flags & PL_FLAG_SCX) != 0);
ATF_REQUIRE(pl.pl_syscall_code != 0);
if (pl.pl_lwpid != main)
/* New thread seen. */
break;
ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
}
/* Wait for the child to exit. */
ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
for (;;) {
wpid = waitpid(fpid, &status, 0);
ATF_REQUIRE(wpid == fpid);
if (WIFEXITED(status))
break;
ATF_REQUIRE(WIFSTOPPED(status));
ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
}
ATF_REQUIRE(WEXITSTATUS(status) == 1);
wpid = wait(&status);
ATF_REQUIRE(wpid == -1);
ATF_REQUIRE(errno == ECHILD);
}
ATF_TP_ADD_TCS(tp)
{
@ -968,6 +1194,9 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp,
ptrace__follow_fork_parent_detached_unrelated_debugger);
ATF_TP_ADD_TC(tp, ptrace__getppid);
ATF_TP_ADD_TC(tp, ptrace__new_child_pl_syscall_code_fork);
ATF_TP_ADD_TC(tp, ptrace__new_child_pl_syscall_code_vfork);
ATF_TP_ADD_TC(tp, ptrace__new_child_pl_syscall_code_thread);
return (atf_no_error());
}

View File

@ -90,61 +90,137 @@ __FBSDID("$FreeBSD$");
* This should probably be in its own file, sorted alphabetically.
*/
static struct syscall decoded_syscalls[] = {
{ .name = "fcntl", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Fcntl, 1 }, { Fcntlflag, 2 } } },
{ .name = "rfork", .ret_type = 1, .nargs = 1,
.args = { { Rforkflags, 0 } } },
{ .name = "linux_readlink", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Name | OUT, 1 }, { Int, 2 } } },
{ .name = "linux_socketcall", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { LinuxSockArgs, 1 } } },
{ .name = "getpgid", .ret_type = 1, .nargs = 1,
.args = { { Int, 0 } } },
{ .name = "getsid", .ret_type = 1, .nargs = 1,
.args = { { Int, 0 } } },
{ .name = "readlink", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Readlinkres | OUT, 1 }, { Int, 2 } } },
{ .name = "readlinkat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name, 1 }, { Readlinkres | OUT, 2 },
/* Native ABI */
{ .name = "__getcwd", .ret_type = 1, .nargs = 2,
.args = { { Name | OUT, 0 }, { Int, 1 } } },
{ .name = "_umtx_op", .ret_type = 1, .nargs = 5,
.args = { { Ptr, 0 }, { Umtxop, 1 }, { LongHex, 2 }, { Ptr, 3 },
{ Ptr, 4 } } },
{ .name = "accept", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
{ .name = "access", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Accessmode, 1 } } },
{ .name = "bind", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Int, 2 } } },
{ .name = "bindat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 },
{ Int, 3 } } },
{ .name = "lseek", .ret_type = 2, .nargs = 3,
.args = { { Int, 0 }, { QuadHex, 1 + QUAD_ALIGN },
{ Whence, 1 + QUAD_SLOTS + QUAD_ALIGN } } },
{ .name = "linux_lseek", .ret_type = 2, .nargs = 3,
.args = { { Int, 0 }, { Int, 1 }, { Whence, 2 } } },
{ .name = "mmap", .ret_type = 1, .nargs = 6,
.args = { { Ptr, 0 }, { Int, 1 }, { Mprot, 2 }, { Mmapflags, 3 },
{ Int, 4 }, { QuadHex, 5 + QUAD_ALIGN } } },
{ .name = "linux_mkdir", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Int, 1 } } },
{ .name = "mprotect", .ret_type = 1, .nargs = 3,
.args = { { Ptr, 0 }, { Int, 1 }, { Mprot, 2 } } },
{ .name = "open", .ret_type = 1, .nargs = 3,
.args = { { Name | IN, 0 }, { Open, 1 }, { Octal, 2 } } },
{ .name = "openat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name | IN, 1 }, { Open, 2 },
{ Octal, 3 } } },
{ .name = "mkdir", .ret_type = 1, .nargs = 2,
{ .name = "break", .ret_type = 1, .nargs = 1,
.args = { { Ptr, 0 } } },
{ .name = "chdir", .ret_type = 1, .nargs = 1,
.args = { { Name, 0 } } },
{ .name = "chflags", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Hex, 1 } } },
{ .name = "chmod", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Octal, 1 } } },
{ .name = "mkdirat", .ret_type = 1, .nargs = 3,
.args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } },
{ .name = "linux_open", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Hex, 1 }, { Octal, 2 } } },
{ .name = "chown", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } },
{ .name = "chroot", .ret_type = 1, .nargs = 1,
.args = { { Name, 0 } } },
{ .name = "clock_gettime", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Timespec | OUT, 1 } } },
{ .name = "close", .ret_type = 1, .nargs = 1,
.args = { { Int, 0 } } },
{ .name = "connect", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Int, 2 } } },
{ .name = "connectat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 },
{ Int, 3 } } },
{ .name = "eaccess", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Accessmode, 1 } } },
{ .name = "execve", .ret_type = 1, .nargs = 3,
.args = { { Name | IN, 0 }, { ExecArgs | IN, 1 },
{ ExecEnv | IN, 2 } } },
{ .name = "exit", .ret_type = 0, .nargs = 1,
.args = { { Hex, 0 } } },
{ .name = "faccessat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name | IN, 1 }, { Accessmode, 2 },
{ Atflags, 3 } } },
{ .name = "fchmod", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Octal, 1 } } },
{ .name = "fchmodat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Atflags, 3 } } },
{ .name = "fchown", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Int, 1 }, { Int, 2 } } },
{ .name = "fchownat", .ret_type = 1, .nargs = 5,
.args = { { Atfd, 0 }, { Name, 1 }, { Int, 2 }, { Int, 3 },
{ Atflags, 4 } } },
{ .name = "fcntl", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Fcntl, 1 }, { Fcntlflag, 2 } } },
{ .name = "fstat", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Stat | OUT, 1 } } },
{ .name = "fstatat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name | IN, 1 }, { Stat | OUT, 2 },
{ Atflags, 3 } } },
{ .name = "fstatfs", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { StatFs | OUT, 1 } } },
{ .name = "ftruncate", .ret_type = 1, .nargs = 2,
.args = { { Int | IN, 0 }, { QuadHex | IN, 1 + QUAD_ALIGN } } },
{ .name = "futimens", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Timespec2 | IN, 1 } } },
{ .name = "futimes", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Timeval2 | IN, 1 } } },
{ .name = "futimesat", .ret_type = 1, .nargs = 3,
.args = { { Atfd, 0 }, { Name | IN, 1 }, { Timeval2 | IN, 2 } } },
{ .name = "getitimer", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Itimerval | OUT, 2 } } },
{ .name = "getpeername", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
{ .name = "getpgid", .ret_type = 1, .nargs = 1,
.args = { { Int, 0 } } },
{ .name = "getrlimit", .ret_type = 1, .nargs = 2,
.args = { { Resource, 0 }, { Rlimit | OUT, 1 } } },
{ .name = "getrusage", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Rusage | OUT, 1 } } },
{ .name = "getsid", .ret_type = 1, .nargs = 1,
.args = { { Int, 0 } } },
{ .name = "getsockname", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
{ .name = "gettimeofday", .ret_type = 1, .nargs = 2,
.args = { { Timeval | OUT, 0 }, { Ptr, 1 } } },
{ .name = "ioctl", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Ioctl, 1 }, { Hex, 2 } } },
{ .name = "kevent", .ret_type = 1, .nargs = 6,
.args = { { Int, 0 }, { Kevent, 1 }, { Int, 2 }, { Kevent | OUT, 3 },
{ Int, 4 }, { Timespec, 5 } } },
{ .name = "kill", .ret_type = 1, .nargs = 2,
.args = { { Int | IN, 0 }, { Signal | IN, 1 } } },
{ .name = "kldfind", .ret_type = 1, .nargs = 1,
.args = { { Name | IN, 0 } } },
{ .name = "kldfirstmod", .ret_type = 1, .nargs = 1,
.args = { { Int, 0 } } },
{ .name = "kldload", .ret_type = 1, .nargs = 1,
.args = { { Name | IN, 0 } } },
{ .name = "kldnext", .ret_type = 1, .nargs = 1,
.args = { { Int, 0 } } },
{ .name = "kldstat", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Ptr, 1 } } },
{ .name = "kldunload", .ret_type = 1, .nargs = 1,
.args = { { Int, 0 } } },
{ .name = "kse_release", .ret_type = 0, .nargs = 1,
.args = { { Timespec, 0 } } },
{ .name = "lchflags", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Hex, 1 } } },
{ .name = "lchmod", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Octal, 1 } } },
{ .name = "lchown", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } },
{ .name = "link", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Name, 1 } } },
{ .name = "linkat", .ret_type = 1, .nargs = 5,
.args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 },
{ Atflags, 4 } } },
{ .name = "unlink", .ret_type = 1, .nargs = 1,
.args = { { Name, 0 } } },
{ .name = "unlinkat", .ret_type = 1, .nargs = 3,
.args = { { Atfd, 0 }, { Name, 1 }, { Atflags, 2 } } },
{ .name = "chdir", .ret_type = 1, .nargs = 1,
.args = { { Name, 0 } } },
{ .name = "chroot", .ret_type = 1, .nargs = 1,
.args = { { Name, 0 } } },
{ .name = "lseek", .ret_type = 2, .nargs = 3,
.args = { { Int, 0 }, { QuadHex, 1 + QUAD_ALIGN },
{ Whence, 1 + QUAD_SLOTS + QUAD_ALIGN } } },
{ .name = "lstat", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Stat | OUT, 1 } } },
{ .name = "lutimes", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } },
{ .name = "mkdir", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Octal, 1 } } },
{ .name = "mkdirat", .ret_type = 1, .nargs = 3,
.args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 } } },
{ .name = "mkfifo", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Octal, 1 } } },
{ .name = "mkfifoat", .ret_type = 1, .nargs = 3,
@ -153,128 +229,69 @@ static struct syscall decoded_syscalls[] = {
.args = { { Name, 0 }, { Octal, 1 }, { Int, 2 } } },
{ .name = "mknodat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Int, 3 } } },
{ .name = "chmod", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Octal, 1 } } },
{ .name = "fchmod", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Octal, 1 } } },
{ .name = "lchmod", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Octal, 1 } } },
{ .name = "fchmodat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name, 1 }, { Octal, 2 }, { Atflags, 3 } } },
{ .name = "chown", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } },
{ .name = "fchown", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Int, 1 }, { Int, 2 } } },
{ .name = "lchown", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } },
{ .name = "fchownat", .ret_type = 1, .nargs = 5,
.args = { { Atfd, 0 }, { Name, 1 }, { Int, 2 }, { Int, 3 },
{ Atflags, 4 } } },
{ .name = "linux_stat64", .ret_type = 1, .nargs = 3,
.args = { { Name | IN, 0 }, { Ptr | OUT, 1 }, { Ptr | IN, 1 } } },
{ .name = "mmap", .ret_type = 1, .nargs = 6,
.args = { { Ptr, 0 }, { Int, 1 }, { Mprot, 2 }, { Mmapflags, 3 },
{ Int, 4 }, { QuadHex, 5 + QUAD_ALIGN } } },
{ .name = "modfind", .ret_type = 1, .nargs = 1,
.args = { { Name | IN, 0 } } },
{ .name = "mount", .ret_type = 1, .nargs = 4,
.args = { { Name, 0 }, { Name, 1 }, { Int, 2 }, { Ptr, 3 } } },
{ .name = "umount", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Int, 2 } } },
{ .name = "fstat", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Stat | OUT, 1 } } },
{ .name = "fstatat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name | IN, 1 }, { Stat | OUT, 2 },
{ Atflags, 3 } } },
{ .name = "stat", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Stat | OUT, 1 } } },
{ .name = "statfs", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { StatFs | OUT, 1 } } },
{ .name = "fstatfs", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { StatFs | OUT, 1 } } },
{ .name = "lstat", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Stat | OUT, 1 } } },
{ .name = "linux_newstat", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } },
{ .name = "linux_access", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Accessmode, 1 } } },
{ .name = "linux_newfstat", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Ptr | OUT, 1 } } },
{ .name = "write", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 } } },
{ .name = "ioctl", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Ioctl, 1 }, { Hex, 2 } } },
{ .name = "break", .ret_type = 1, .nargs = 1,
.args = { { Ptr, 0 } } },
{ .name = "exit", .ret_type = 0, .nargs = 1,
.args = { { Hex, 0 } } },
{ .name = "access", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Accessmode, 1 } } },
{ .name = "eaccess", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Accessmode, 1 } } },
{ .name = "faccessat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name | IN, 1 }, { Accessmode, 2 },
{ Atflags, 3 } } },
{ .name = "sigaction", .ret_type = 1, .nargs = 3,
.args = { { Signal, 0 }, { Sigaction | IN, 1 },
{ Sigaction | OUT, 2 } } },
{ .name = "accept", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
{ .name = "bind", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Int, 2 } } },
{ .name = "bindat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 },
{ .name = "mprotect", .ret_type = 1, .nargs = 3,
.args = { { Ptr, 0 }, { Int, 1 }, { Mprot, 2 } } },
{ .name = "munmap", .ret_type = 1, .nargs = 2,
.args = { { Ptr, 0 }, { Int, 1 } } },
{ .name = "nanosleep", .ret_type = 1, .nargs = 1,
.args = { { Timespec, 0 } } },
{ .name = "open", .ret_type = 1, .nargs = 3,
.args = { { Name | IN, 0 }, { Open, 1 }, { Octal, 2 } } },
{ .name = "openat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name | IN, 1 }, { Open, 2 },
{ Octal, 3 } } },
{ .name = "pathconf", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Pathconf, 1 } } },
{ .name = "pipe", .ret_type = 1, .nargs = 1,
.args = { { PipeFds | OUT, 0 } } },
{ .name = "pipe2", .ret_type = 1, .nargs = 2,
.args = { { Ptr, 0 }, { Open, 1 } } },
{ .name = "poll", .ret_type = 1, .nargs = 3,
.args = { { Pollfd, 0 }, { Int, 1 }, { Int, 2 } } },
{ .name = "posix_openpt", .ret_type = 1, .nargs = 1,
.args = { { Open, 0 } } },
{ .name = "procctl", .ret_type = 1, .nargs = 4,
.args = { { Idtype, 0 }, { Quad, 1 + QUAD_ALIGN },
{ Procctl, 1 + QUAD_ALIGN + QUAD_SLOTS },
{ Ptr, 2 + QUAD_ALIGN + QUAD_SLOTS } } },
{ .name = "read", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 } } },
{ .name = "readlink", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Readlinkres | OUT, 1 }, { Int, 2 } } },
{ .name = "readlinkat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name, 1 }, { Readlinkres | OUT, 2 },
{ Int, 3 } } },
{ .name = "connect", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Sockaddr | IN, 1 }, { Int, 2 } } },
{ .name = "connectat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Int, 1 }, { Sockaddr | IN, 2 },
{ Int, 3 } } },
{ .name = "getpeername", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
{ .name = "getsockname", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
{ .name = "recvfrom", .ret_type = 1, .nargs = 6,
.args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 }, { Hex, 3 },
{ Sockaddr | OUT, 4 }, { Ptr | OUT, 5 } } },
{ .name = "sendto", .ret_type = 1, .nargs = 6,
.args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 }, { Hex, 3 },
{ Sockaddr | IN, 4 }, { Ptr | IN, 5 } } },
{ .name = "execve", .ret_type = 1, .nargs = 3,
.args = { { Name | IN, 0 }, { ExecArgs | IN, 1 },
{ ExecEnv | IN, 2 } } },
{ .name = "linux_execve", .ret_type = 1, .nargs = 3,
.args = { { Name | IN, 0 }, { ExecArgs | IN, 1 },
{ ExecEnv | IN, 2 } } },
{ .name = "kldload", .ret_type = 1, .nargs = 1,
.args = { { Name | IN, 0 } } },
{ .name = "kldunload", .ret_type = 1, .nargs = 1,
.args = { { Int, 0 } } },
{ .name = "kldfind", .ret_type = 1, .nargs = 1,
.args = { { Name | IN, 0 } } },
{ .name = "kldnext", .ret_type = 1, .nargs = 1,
.args = { { Int, 0 } } },
{ .name = "kldstat", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Ptr, 1 } } },
{ .name = "kldfirstmod", .ret_type = 1, .nargs = 1,
.args = { { Int, 0 } } },
{ .name = "modfind", .ret_type = 1, .nargs = 1,
.args = { { Name | IN, 0 } } },
{ .name = "nanosleep", .ret_type = 1, .nargs = 1,
.args = { { Timespec, 0 } } },
{ .name = "rename", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Name, 1 } } },
{ .name = "renameat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 } } },
{ .name = "rfork", .ret_type = 1, .nargs = 1,
.args = { { Rforkflags, 0 } } },
{ .name = "select", .ret_type = 1, .nargs = 5,
.args = { { Int, 0 }, { Fd_set, 1 }, { Fd_set, 2 }, { Fd_set, 3 },
{ Timeval, 4 } } },
{ .name = "poll", .ret_type = 1, .nargs = 3,
.args = { { Pollfd, 0 }, { Int, 1 }, { Int, 2 } } },
{ .name = "gettimeofday", .ret_type = 1, .nargs = 2,
.args = { { Timeval | OUT, 0 }, { Ptr, 1 } } },
{ .name = "clock_gettime", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Timespec | OUT, 1 } } },
{ .name = "getitimer", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Itimerval | OUT, 2 } } },
{ .name = "sendto", .ret_type = 1, .nargs = 6,
.args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 }, { Hex, 3 },
{ Sockaddr | IN, 4 }, { Ptr | IN, 5 } } },
{ .name = "setitimer", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { Itimerval, 1 }, { Itimerval | OUT, 2 } } },
{ .name = "kse_release", .ret_type = 0, .nargs = 1,
.args = { { Timespec, 0 } } },
{ .name = "kevent", .ret_type = 1, .nargs = 6,
.args = { { Int, 0 }, { Kevent, 1 }, { Int, 2 }, { Kevent | OUT, 3 },
{ Int, 4 }, { Timespec, 5 } } },
{ .name = "setrlimit", .ret_type = 1, .nargs = 2,
.args = { { Resource, 0 }, { Rlimit | IN, 1 } } },
{ .name = "shutdown", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Shutdown, 1 } } },
{ .name = "sigaction", .ret_type = 1, .nargs = 3,
.args = { { Signal, 0 }, { Sigaction | IN, 1 },
{ Sigaction | OUT, 2 } } },
{ .name = "sigpending", .ret_type = 1, .nargs = 1,
.args = { { Sigset | OUT, 0 } } },
{ .name = "sigprocmask", .ret_type = 1, .nargs = 3,
@ -291,63 +308,40 @@ static struct syscall decoded_syscalls[] = {
.args = { { Sigset | IN, 0 }, { Ptr, 1 } } },
{ .name = "sigwaitinfo", .ret_type = 1, .nargs = 2,
.args = { { Sigset | IN, 0 }, { Ptr, 1 } } },
{ .name = "unmount", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Int, 1 } } },
{ .name = "socket", .ret_type = 1, .nargs = 3,
.args = { { Sockdomain, 0 }, { Socktype, 1 }, { Int, 2 } } },
{ .name = "getrusage", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Rusage | OUT, 1 } } },
{ .name = "__getcwd", .ret_type = 1, .nargs = 2,
.args = { { Name | OUT, 0 }, { Int, 1 } } },
{ .name = "shutdown", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Shutdown, 1 } } },
{ .name = "getrlimit", .ret_type = 1, .nargs = 2,
.args = { { Resource, 0 }, { Rlimit | OUT, 1 } } },
{ .name = "setrlimit", .ret_type = 1, .nargs = 2,
.args = { { Resource, 0 }, { Rlimit | IN, 1 } } },
{ .name = "utimes", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } },
{ .name = "lutimes", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } },
{ .name = "futimes", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Timeval2 | IN, 1 } } },
{ .name = "futimesat", .ret_type = 1, .nargs = 3,
.args = { { Atfd, 0 }, { Name | IN, 1 }, { Timeval2 | IN, 2 } } },
{ .name = "futimens", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Timespec2 | IN, 1 } } },
{ .name = "utimensat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name | IN, 1 }, { Timespec2 | IN, 2 },
{ Atflags, 3 } } },
{ .name = "chflags", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Hex, 1 } } },
{ .name = "lchflags", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Hex, 1 } } },
{ .name = "pathconf", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Pathconf, 1 } } },
{ .name = "pipe", .ret_type = 1, .nargs = 1,
.args = { { PipeFds | OUT, 0 } } },
{ .name = "pipe2", .ret_type = 1, .nargs = 2,
.args = { { Ptr, 0 }, { Open, 1 } } },
{ .name = "truncate", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { QuadHex | IN, 1 + QUAD_ALIGN } } },
{ .name = "ftruncate", .ret_type = 1, .nargs = 2,
.args = { { Int | IN, 0 }, { QuadHex | IN, 1 + QUAD_ALIGN } } },
{ .name = "kill", .ret_type = 1, .nargs = 2,
.args = { { Int | IN, 0 }, { Signal | IN, 1 } } },
{ .name = "munmap", .ret_type = 1, .nargs = 2,
.args = { { Ptr, 0 }, { Int, 1 } } },
{ .name = "read", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { BinString | OUT, 1 }, { Int, 2 } } },
{ .name = "rename", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Name, 1 } } },
{ .name = "renameat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name, 1 }, { Atfd, 2 }, { Name, 3 } } },
{ .name = "stat", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Stat | OUT, 1 } } },
{ .name = "statfs", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { StatFs | OUT, 1 } } },
{ .name = "symlink", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Name, 1 } } },
{ .name = "symlinkat", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Atfd, 1 }, { Name, 2 } } },
{ .name = "posix_openpt", .ret_type = 1, .nargs = 1,
.args = { { Open, 0 } } },
{ .name = "sysarch", .ret_type = 1, .nargs = 2,
.args = { { Sysarch, 0 }, { Ptr, 1 } } },
{ .name = "thr_kill", .ret_type = 1, .nargs = 2,
.args = { { Long, 0 }, { Signal, 1 } } },
{ .name = "thr_self", .ret_type = 1, .nargs = 1,
.args = { { Ptr, 0 } } },
{ .name = "truncate", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { QuadHex | IN, 1 + QUAD_ALIGN } } },
#if 0
/* Does not exist */
{ .name = "umount", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Int, 2 } } },
#endif
{ .name = "unlink", .ret_type = 1, .nargs = 1,
.args = { { Name, 0 } } },
{ .name = "unlinkat", .ret_type = 1, .nargs = 3,
.args = { { Atfd, 0 }, { Name, 1 }, { Atflags, 2 } } },
{ .name = "unmount", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Int, 1 } } },
{ .name = "utimensat", .ret_type = 1, .nargs = 4,
.args = { { Atfd, 0 }, { Name | IN, 1 }, { Timespec2 | IN, 2 },
{ Atflags, 3 } } },
{ .name = "utimes", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Timeval2 | IN, 1 } } },
{ .name = "wait4", .ret_type = 1, .nargs = 4,
.args = { { Int, 0 }, { ExitStatus | OUT, 1 }, { Waitoptions, 2 },
{ Rusage | OUT, 3 } } },
@ -357,19 +351,32 @@ static struct syscall decoded_syscalls[] = {
{ Waitoptions, 2 + QUAD_ALIGN + QUAD_SLOTS },
{ Rusage | OUT, 3 + QUAD_ALIGN + QUAD_SLOTS },
{ Ptr, 4 + QUAD_ALIGN + QUAD_SLOTS } } },
{ .name = "procctl", .ret_type = 1, .nargs = 4,
.args = { { Idtype, 0 }, { Quad, 1 + QUAD_ALIGN },
{ Procctl, 1 + QUAD_ALIGN + QUAD_SLOTS },
{ Ptr, 2 + QUAD_ALIGN + QUAD_SLOTS } } },
{ .name = "sysarch", .ret_type = 1, .nargs = 2,
.args = { { Sysarch, 0 }, { Ptr, 1 } } },
{ .name = "_umtx_op", .ret_type = 1, .nargs = 5,
.args = { { Ptr, 0 }, { Umtxop, 1 }, { LongHex, 2 }, { Ptr, 3 },
{ Ptr, 4 } } },
{ .name = "thr_kill", .ret_type = 1, .nargs = 2,
.args = { { Long, 0 }, { Signal, 1 } } },
{ .name = "thr_self", .ret_type = 1, .nargs = 1,
.args = { { Ptr, 0 } } },
{ .name = "write", .ret_type = 1, .nargs = 3,
.args = { { Int, 0 }, { BinString | IN, 1 }, { Int, 2 } } },
/* Linux ABI */
{ .name = "linux_access", .ret_type = 1, .nargs = 2,
.args = { { Name, 0 }, { Accessmode, 1 } } },
{ .name = "linux_execve", .ret_type = 1, .nargs = 3,
.args = { { Name | IN, 0 }, { ExecArgs | IN, 1 },
{ ExecEnv | IN, 2 } } },
{ .name = "linux_lseek", .ret_type = 2, .nargs = 3,
.args = { { Int, 0 }, { Int, 1 }, { Whence, 2 } } },
{ .name = "linux_mkdir", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Int, 1 } } },
{ .name = "linux_newfstat", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { Ptr | OUT, 1 } } },
{ .name = "linux_newstat", .ret_type = 1, .nargs = 2,
.args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } },
{ .name = "linux_open", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Hex, 1 }, { Octal, 2 } } },
{ .name = "linux_readlink", .ret_type = 1, .nargs = 3,
.args = { { Name, 0 }, { Name | OUT, 1 }, { Int, 2 } } },
{ .name = "linux_socketcall", .ret_type = 1, .nargs = 2,
.args = { { Int, 0 }, { LinuxSockArgs, 1 } } },
{ .name = "linux_stat64", .ret_type = 1, .nargs = 3,
.args = { { Name | IN, 0 }, { Ptr | OUT, 1 }, { Ptr | IN, 1 } } },
{ .name = 0 },
};
static STAILQ_HEAD(, syscall) syscalls;