Put vfs bits of ktrace into kern_ktrace_vfs.c per convention.
This commit is contained in:
parent
a639bb644d
commit
b4e2514736
@ -1,4 +1,4 @@
|
|||||||
# $NetBSD: files,v 1.1081 2013/10/15 15:13:17 skrll Exp $
|
# $NetBSD: files,v 1.1082 2013/12/09 16:45:23 pooka Exp $
|
||||||
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
|
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
|
||||||
|
|
||||||
version 20100430
|
version 20100430
|
||||||
@ -1505,6 +1505,7 @@ file kern/kern_idle.c
|
|||||||
file kern/kern_hook.c
|
file kern/kern_hook.c
|
||||||
file kern/kern_kthread.c
|
file kern/kern_kthread.c
|
||||||
file kern/kern_ktrace.c ktrace
|
file kern/kern_ktrace.c ktrace
|
||||||
|
file kern/kern_ktrace_vfs.c ktrace
|
||||||
file kern/kern_ksyms.c ksyms | ddb | modular needs-flag
|
file kern/kern_ksyms.c ksyms | ddb | modular needs-flag
|
||||||
file kern/kern_lock.c
|
file kern/kern_lock.c
|
||||||
file kern/kern_lwp.c
|
file kern/kern_lwp.c
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: kern_ktrace.c,v 1.163 2013/09/16 09:25:56 martin Exp $ */
|
/* $NetBSD: kern_ktrace.c,v 1.164 2013/12/09 16:45:23 pooka Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
||||||
@ -61,14 +61,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.163 2013/09/16 09:25:56 martin Exp $");
|
__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.164 2013/12/09 16:45:23 pooka Exp $");
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
#include <sys/proc.h>
|
#include <sys/proc.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/namei.h>
|
|
||||||
#include <sys/vnode.h>
|
|
||||||
#include <sys/kernel.h>
|
#include <sys/kernel.h>
|
||||||
#include <sys/kthread.h>
|
#include <sys/kthread.h>
|
||||||
#include <sys/ktrace.h>
|
#include <sys/ktrace.h>
|
||||||
@ -131,7 +129,6 @@ struct ktr_desc {
|
|||||||
static int ktealloc(struct ktrace_entry **, void **, lwp_t *, int,
|
static int ktealloc(struct ktrace_entry **, void **, lwp_t *, int,
|
||||||
size_t);
|
size_t);
|
||||||
static void ktrwrite(struct ktr_desc *, struct ktrace_entry *);
|
static void ktrwrite(struct ktr_desc *, struct ktrace_entry *);
|
||||||
static int ktrace_common(lwp_t *, int, int, int, file_t **);
|
|
||||||
static int ktrops(lwp_t *, struct proc *, int, int,
|
static int ktrops(lwp_t *, struct proc *, int, int,
|
||||||
struct ktr_desc *);
|
struct ktr_desc *);
|
||||||
static int ktrsetchildren(lwp_t *, struct proc *, int, int,
|
static int ktrsetchildren(lwp_t *, struct proc *, int, int,
|
||||||
@ -221,23 +218,6 @@ ktd_logerr(struct proc *p, int error)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline int
|
|
||||||
ktrenter(lwp_t *l)
|
|
||||||
{
|
|
||||||
|
|
||||||
if ((l->l_pflag & LP_KTRACTIVE) != 0)
|
|
||||||
return 1;
|
|
||||||
l->l_pflag |= LP_KTRACTIVE;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
ktrexit(lwp_t *l)
|
|
||||||
{
|
|
||||||
|
|
||||||
l->l_pflag &= ~LP_KTRACTIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ktrace_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
|
ktrace_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
|
||||||
void *arg0, void *arg1, void *arg2, void *arg3)
|
void *arg0, void *arg1, void *arg2, void *arg3)
|
||||||
@ -1190,75 +1170,6 @@ sys_fktrace(struct lwp *l, const struct sys_fktrace_args *uap, register_t *retva
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* ktrace system call
|
|
||||||
*/
|
|
||||||
/* ARGSUSED */
|
|
||||||
int
|
|
||||||
sys_ktrace(struct lwp *l, const struct sys_ktrace_args *uap, register_t *retval)
|
|
||||||
{
|
|
||||||
/* {
|
|
||||||
syscallarg(const char *) fname;
|
|
||||||
syscallarg(int) ops;
|
|
||||||
syscallarg(int) facs;
|
|
||||||
syscallarg(int) pid;
|
|
||||||
} */
|
|
||||||
struct vnode *vp = NULL;
|
|
||||||
file_t *fp = NULL;
|
|
||||||
struct pathbuf *pb;
|
|
||||||
struct nameidata nd;
|
|
||||||
int error = 0;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (ktrenter(l))
|
|
||||||
return EAGAIN;
|
|
||||||
|
|
||||||
if (KTROP(SCARG(uap, ops)) != KTROP_CLEAR) {
|
|
||||||
/*
|
|
||||||
* an operation which requires a file argument.
|
|
||||||
*/
|
|
||||||
error = pathbuf_copyin(SCARG(uap, fname), &pb);
|
|
||||||
if (error) {
|
|
||||||
ktrexit(l);
|
|
||||||
return (error);
|
|
||||||
}
|
|
||||||
NDINIT(&nd, LOOKUP, FOLLOW, pb);
|
|
||||||
if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0) {
|
|
||||||
pathbuf_destroy(pb);
|
|
||||||
ktrexit(l);
|
|
||||||
return (error);
|
|
||||||
}
|
|
||||||
vp = nd.ni_vp;
|
|
||||||
pathbuf_destroy(pb);
|
|
||||||
VOP_UNLOCK(vp);
|
|
||||||
if (vp->v_type != VREG) {
|
|
||||||
vn_close(vp, FREAD|FWRITE, l->l_cred);
|
|
||||||
ktrexit(l);
|
|
||||||
return (EACCES);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* This uses up a file descriptor slot in the
|
|
||||||
* tracing process for the duration of this syscall.
|
|
||||||
* This is not expected to be a problem.
|
|
||||||
*/
|
|
||||||
if ((error = fd_allocfile(&fp, &fd)) != 0) {
|
|
||||||
vn_close(vp, FWRITE, l->l_cred);
|
|
||||||
ktrexit(l);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
fp->f_flag = FWRITE;
|
|
||||||
fp->f_type = DTYPE_VNODE;
|
|
||||||
fp->f_ops = &vnops;
|
|
||||||
fp->f_data = (void *)vp;
|
|
||||||
vp = NULL;
|
|
||||||
}
|
|
||||||
error = ktrace_common(l, SCARG(uap, ops), SCARG(uap, facs),
|
|
||||||
SCARG(uap, pid), &fp);
|
|
||||||
if (KTROP(SCARG(uap, ops)) != KTROP_CLEAR)
|
|
||||||
fd_abort(curproc, fp, fd);
|
|
||||||
return (error);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
ktrops(lwp_t *curl, struct proc *p, int ops, int facs,
|
ktrops(lwp_t *curl, struct proc *p, int ops, int facs,
|
||||||
struct ktr_desc *ktd)
|
struct ktr_desc *ktd)
|
||||||
|
147
sys/kern/kern_ktrace_vfs.c
Normal file
147
sys/kern/kern_ktrace_vfs.c
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
/* $NetBSD: kern_ktrace_vfs.c,v 1.1 2013/12/09 16:45:23 pooka Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
|
* by Andrew Doran.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||||
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)kern_ktrace.c 8.5 (Berkeley) 5/14/95
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__KERNEL_RCSID(0, "$NetBSD: kern_ktrace_vfs.c,v 1.1 2013/12/09 16:45:23 pooka Exp $");
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/systm.h>
|
||||||
|
#include <sys/file.h>
|
||||||
|
#include <sys/filedesc.h>
|
||||||
|
#include <sys/namei.h>
|
||||||
|
#include <sys/vnode.h>
|
||||||
|
#include <sys/kernel.h>
|
||||||
|
#include <sys/ktrace.h>
|
||||||
|
#include <sys/kauth.h>
|
||||||
|
|
||||||
|
#include <sys/mount.h>
|
||||||
|
#include <sys/syscallargs.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ktrace system call, the part of the ktrace framework that
|
||||||
|
* explicitly interacts with VFS
|
||||||
|
*/
|
||||||
|
/* ARGSUSED */
|
||||||
|
int
|
||||||
|
sys_ktrace(struct lwp *l, const struct sys_ktrace_args *uap, register_t *retval)
|
||||||
|
{
|
||||||
|
/* {
|
||||||
|
syscallarg(const char *) fname;
|
||||||
|
syscallarg(int) ops;
|
||||||
|
syscallarg(int) facs;
|
||||||
|
syscallarg(int) pid;
|
||||||
|
} */
|
||||||
|
struct vnode *vp = NULL;
|
||||||
|
file_t *fp = NULL;
|
||||||
|
struct pathbuf *pb;
|
||||||
|
struct nameidata nd;
|
||||||
|
int error = 0;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (ktrenter(l))
|
||||||
|
return EAGAIN;
|
||||||
|
|
||||||
|
if (KTROP(SCARG(uap, ops)) != KTROP_CLEAR) {
|
||||||
|
/*
|
||||||
|
* an operation which requires a file argument.
|
||||||
|
*/
|
||||||
|
error = pathbuf_copyin(SCARG(uap, fname), &pb);
|
||||||
|
if (error) {
|
||||||
|
ktrexit(l);
|
||||||
|
return (error);
|
||||||
|
}
|
||||||
|
NDINIT(&nd, LOOKUP, FOLLOW, pb);
|
||||||
|
if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0) {
|
||||||
|
pathbuf_destroy(pb);
|
||||||
|
ktrexit(l);
|
||||||
|
return (error);
|
||||||
|
}
|
||||||
|
vp = nd.ni_vp;
|
||||||
|
pathbuf_destroy(pb);
|
||||||
|
VOP_UNLOCK(vp);
|
||||||
|
if (vp->v_type != VREG) {
|
||||||
|
vn_close(vp, FREAD|FWRITE, l->l_cred);
|
||||||
|
ktrexit(l);
|
||||||
|
return (EACCES);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* This uses up a file descriptor slot in the
|
||||||
|
* tracing process for the duration of this syscall.
|
||||||
|
* This is not expected to be a problem.
|
||||||
|
*/
|
||||||
|
if ((error = fd_allocfile(&fp, &fd)) != 0) {
|
||||||
|
vn_close(vp, FWRITE, l->l_cred);
|
||||||
|
ktrexit(l);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
fp->f_flag = FWRITE;
|
||||||
|
fp->f_type = DTYPE_VNODE;
|
||||||
|
fp->f_ops = &vnops;
|
||||||
|
fp->f_data = (void *)vp;
|
||||||
|
vp = NULL;
|
||||||
|
}
|
||||||
|
error = ktrace_common(l, SCARG(uap, ops), SCARG(uap, facs),
|
||||||
|
SCARG(uap, pid), &fp);
|
||||||
|
if (KTROP(SCARG(uap, ops)) != KTROP_CLEAR)
|
||||||
|
fd_abort(curproc, fp, fd);
|
||||||
|
return (error);
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: ktrace.h,v 1.59 2012/02/19 21:06:58 rmind Exp $ */
|
/* $NetBSD: ktrace.h,v 1.60 2013/12/09 16:45:23 pooka Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1988, 1993
|
* Copyright (c) 1988, 1993
|
||||||
@ -298,6 +298,25 @@ void ktr_execarg(const void *, size_t);
|
|||||||
void ktr_execenv(const void *, size_t);
|
void ktr_execenv(const void *, size_t);
|
||||||
void ktr_execfd(int, u_int);
|
void ktr_execfd(int, u_int);
|
||||||
|
|
||||||
|
int ktrace_common(lwp_t *, int, int, int, file_t **);
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
ktrenter(lwp_t *l)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ((l->l_pflag & LP_KTRACTIVE) != 0)
|
||||||
|
return 1;
|
||||||
|
l->l_pflag |= LP_KTRACTIVE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ktrexit(lwp_t *l)
|
||||||
|
{
|
||||||
|
|
||||||
|
l->l_pflag &= ~LP_KTRACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
ktrpoint(int fac)
|
ktrpoint(int fac)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user