Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Create functions ioctl_copyin() and ioctl_copyout(). They ar...
details: https://anonhg.NetBSD.org/src/rev/c8d83eec888b
branches: trunk
changeset: 583906:c8d83eec888b
user: reinoud <reinoud%NetBSD.org@localhost>
date: Sun Aug 28 20:58:14 2005 +0000
description:
Create functions ioctl_copyin() and ioctl_copyout(). They are meant to be
used in ioctl routines to do the right thing when the FKIOCTL flag is
passed to the IOCTL routine indicating its a in-kernel VOP_IOCTL call and
indirect addresses provided in the arguments are to be seen as kernel
adresses rather than userland adresses.
A simple substitution and prepending of the `flags' passed on to the ioctl
handler is enough to DTRT.
diffstat:
distrib/sets/lists/comp/mi | 4 +++-
share/man/man9/Makefile | 5 +++--
share/man/man9/copy.9 | 20 ++++++++++++++++++--
sys/kern/kern_subr.c | 29 +++++++++++++++++++++++++++--
sys/sys/systm.h | 5 ++++-
5 files changed, 55 insertions(+), 8 deletions(-)
diffs (161 lines):
diff -r 3d67e62ecea3 -r c8d83eec888b distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi Sun Aug 28 19:57:25 2005 +0000
+++ b/distrib/sets/lists/comp/mi Sun Aug 28 20:58:14 2005 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.809 2005/08/28 19:37:58 thorpej Exp $
+# $NetBSD: mi,v 1.810 2005/08/28 20:58:14 reinoud Exp $
./etc/mtree/set.comp comp-sys-root
./usr/bin/addr2line comp-debug-bin bfd
./usr/bin/ar comp-util-bin bfd
@@ -9162,6 +9162,8 @@
./usr/share/man/man9/ioasic_intr_evcnt.9 comp-sys-man .man
./usr/share/man/man9/ioasic_submatch.9 comp-sys-man .man
./usr/share/man/man9/ioctl.9 comp-sys-man .man
+./usr/share/man/man9/ioctl_copyin.9 comp-sys-man .man
+./usr/share/man/man9/ioctl_copyout.9 comp-sys-man .man
./usr/share/man/man9/ipkdb.9 comp-sys-man .man
./usr/share/man/man9/ipkdb_connect.9 comp-sys-man .man
./usr/share/man/man9/ipkdb_init.9 comp-sys-man .man
diff -r 3d67e62ecea3 -r c8d83eec888b share/man/man9/Makefile
--- a/share/man/man9/Makefile Sun Aug 28 19:57:25 2005 +0000
+++ b/share/man/man9/Makefile Sun Aug 28 20:58:14 2005 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.174 2005/08/23 09:34:11 yamt Exp $
+# $NetBSD: Makefile,v 1.175 2005/08/28 20:58:14 reinoud Exp $
# Makefile for section 9 (kernel function and variable) manual pages.
@@ -149,7 +149,8 @@
cons.9 cnputc.9
MLINKS+=copy.9 copyin.9 copy.9 copyout.9 copy.9 copystr.9 \
copy.9 copyinstr.9 copy.9 copyoutstr.9 \
- copy.9 copyin_proc.9 copy.9 copyout_proc.9
+ copy.9 copyin_proc.9 copy.9 copyout_proc.9 \
+ copy.9 ioctl_copyin.9 copy.9 ioctl_copyout.9
MLINKS+=cpu_dumpconf.9 cpu_dump.9 cpu_dumpconf.9 cpu_dumpsize.9 \
cpu_dumpconf.9 dumpsys.9
MLINKS+=cpu_fork.9 child_return.9 cpu_fork.9 proc_trampoline.9
diff -r 3d67e62ecea3 -r c8d83eec888b share/man/man9/copy.9
--- a/share/man/man9/copy.9 Sun Aug 28 19:57:25 2005 +0000
+++ b/share/man/man9/copy.9 Sun Aug 28 20:58:14 2005 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: copy.9,v 1.14 2003/04/16 13:35:26 wiz Exp $
+.\" $NetBSD: copy.9,v 1.15 2005/08/28 20:58:14 reinoud Exp $
.\"
.\" Copyright (c) 1996, 2002 Jason R. Thorpe.
.\" All rights reserved.
@@ -32,7 +32,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd July 19, 2002
+.Dd August 28, 2005
.Dt COPY 9
.Os
.Sh NAME
@@ -60,6 +60,10 @@
.Fn copyin_proc "struct proc *p" "const void *uaddr" "void *kaddr" "size_t len"
.Ft int
.Fn copyout_proc "struct proc *p" "const void *kaddr" "void *uaddr" "size_t len"
+.Ft int
+.Fn ioctl_copyin "int ioctlflags" "const void *src" "void *dst" "size_t len"
+.Ft int
+.Fn ioctl_copyout "int ioctlflags" "const void *src" "void *dst" "size_t len"
.Sh DESCRIPTION
The
.Nm
@@ -138,6 +142,18 @@
.Fn copyout ,
except it operates on the address space of the process
.Fa p .
+.It Fn ioctl_copyin
+Like
+.Fn copyin ,
+except it operates on kernel adresses when the FKIOCTL flag is passed in
+.Fa ioctlflags
+from the ioctl call.
+.It Fn ioctl_copyout
+Like
+.Fn copyout ,
+except it operates on kernel adresses when the FKIOCTL flag is passed in
+.Fa ioctlflags
+from the ioctl call.
.El
.Sh RETURN VALUES
The
diff -r 3d67e62ecea3 -r c8d83eec888b sys/kern/kern_subr.c
--- a/sys/kern/kern_subr.c Sun Aug 28 19:57:25 2005 +0000
+++ b/sys/kern/kern_subr.c Sun Aug 28 20:58:14 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_subr.c,v 1.118 2005/07/06 22:30:42 christos Exp $ */
+/* $NetBSD: kern_subr.c,v 1.119 2005/08/28 20:58:14 reinoud Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
@@ -86,7 +86,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.118 2005/07/06 22:30:42 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.119 2005/08/28 20:58:14 reinoud Exp $");
#include "opt_ddb.h"
#include "opt_md.h"
@@ -106,6 +106,7 @@
#include <sys/queue.h>
#include <sys/systrace.h>
#include <sys/ktrace.h>
+#include <sys/fcntl.h>
#include <uvm/uvm_extern.h>
@@ -327,6 +328,30 @@
}
/*
+ * Like copyin(), except it operates on kernel addresses when the FKIOCTL
+ * flag is passed in `ioctlflags' from the ioctl call.
+ */
+int
+ioctl_copyin(int ioctlflags, const void *src, void *dst, size_t len)
+{
+ if (ioctlflags & FKIOCTL)
+ return kcopy(src, dst, len);
+ return copyin(src, dst, len);
+}
+
+/*
+ * Like copyout(), except it operates on kernel addresses when the FKIOCTL
+ * flag is passed in `ioctlflags' from the ioctl call.
+ */
+int
+ioctl_copyout(int ioctlflags, const void *src, void *dst, size_t len)
+{
+ if (ioctlflags & FKIOCTL)
+ return kcopy(src, dst, len);
+ return copyout(src, dst, len);
+}
+
+/*
* General routine to allocate a hash table.
* Allocate enough memory to hold at least `elements' list-head pointers.
* Return a pointer to the allocated space and set *hashmask to a pattern
diff -r 3d67e62ecea3 -r c8d83eec888b sys/sys/systm.h
--- a/sys/sys/systm.h Sun Aug 28 19:57:25 2005 +0000
+++ b/sys/sys/systm.h Sun Aug 28 20:58:14 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: systm.h,v 1.179 2005/06/23 00:30:28 thorpej Exp $ */
+/* $NetBSD: systm.h,v 1.180 2005/08/28 20:58:14 reinoud Exp $ */
/*-
* Copyright (c) 1982, 1988, 1991, 1993
@@ -243,6 +243,9 @@
int copyin_proc(struct proc *, const void *, void *, size_t);
int copyout_proc(struct proc *, const void *, void *, size_t);
+int ioctl_copyin(int ioctlflags, const void *src, void *dst, size_t len);
+int ioctl_copyout(int ioctlflags, const void *src, void *dst, size_t len);
+
int subyte(void *, int);
int suibyte(void *, int);
int susword(void *, short);
Home |
Main Index |
Thread Index |
Old Index