Subject: Re: COPYIN/COPYOUT macro problems Re: IOCTL implementation and kernel/userland addresses
To: Jason Thorpe <thorpej@shagadelic.org>
From: Reinoud Zandijk <reinoud@netbsd.org>
List: tech-kern
Date: 08/25/2005 23:37:09
--df+09Je9rNq3P+GE
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Comming to proposed patch :

Index: sys/sys/systm.h
===================================================================
RCS file: /cvsroot/src/sys/sys/systm.h,v
retrieving revision 1.179
diff -u -r1.179 systm.h
--- sys/sys/systm.h     23 Jun 2005 00:30:28 -0000      1.179
+++ sys/sys/systm.h     25 Aug 2005 21:31:10 -0000
@@ -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    kucopyin(int iskernelspace, const void *src, void *dst, size_t len);
+int    kucopyout(int iskernelspace, const void *src, void *dst, size_t len);
+
 int    subyte(void *, int);
 int    suibyte(void *, int);
 int    susword(void *, short);
Index: sys/kern/kern_subr.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_subr.c,v
retrieving revision 1.118
diff -u -r1.118 kern_subr.c
--- sys/kern/kern_subr.c        6 Jul 2005 22:30:42 -0000       1.118
+++ sys/kern/kern_subr.c        25 Aug 2005 21:31:11 -0000
@@ -327,6 +327,28 @@
 }
 
 /*
+ * Like copyin(), but with flag to specify user or kernel space
+ */
+int
+kucopyin(int iskernelspace, const void *src, void *dst, size_t len)
+{
+       if (iskernelspace)
+               return copyin(src, dst, len);
+       return kcopy(src, dst, len);
+}
+
+/*
+ * Like copyout(), but with flag to specify user of kernel space
+ */
+int
+kucopyout(int iskernelspace, const void *src, void *dst, size_t len)
+{
+       if (iskernelspace)
+               return copyout(src, dst, len);
+       return kcopy(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
Index: share/man/man9/Makefile
===================================================================
RCS file: /cvsroot/src/share/man/man9/Makefile,v
retrieving revision 1.174
diff -u -r1.174 Makefile
--- share/man/man9/Makefile     23 Aug 2005 09:34:11 -0000      1.174
+++ share/man/man9/Makefile     25 Aug 2005 21:31:12 -0000
@@ -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 kucopyin.9 copy.9 kucopyout.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
Index: share/man/man9/copy.9
===================================================================
RCS file: /cvsroot/src/share/man/man9/copy.9,v
retrieving revision 1.14
diff -u -r1.14 copy.9
--- share/man/man9/copy.9       16 Apr 2003 13:35:26 -0000      1.14
+++ share/man/man9/copy.9       25 Aug 2005 21:31:12 -0000
@@ -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 kucopyin "int iskernelspace" "const void *src" "void *dst" "size_t len"
+.Ft int
+.Fn kucopyout "int iskernelspace" "const void *src" "void *dst" "size_t len"
 .Sh DESCRIPTION
 The
 .Nm
@@ -138,6 +142,20 @@
 .Fn copyout ,
 except it operates on the address space of the process
 .Fa p .
+.It Fn kucopyin
+Like
+.Fn copyin ,
+except it operates on either the kernel address space or on user address
+space depending on the
+.Fa iskernelspace
+flag .
+.It Fn kucopyout
+Like
+.Fn copyout ,
+except it operates on either the kernel address space or on user address
+space depending on the
+.Fa iskernelspace
+flag .
 .El
 .Sh RETURN VALUES
 The
------------------------------

leaving offcource kucopyin(struct proc *p,...) and kucopyout(struct proc *p, ...)

but are we not exploding the number of functions this way?

Regards,
Reinoud


--df+09Je9rNq3P+GE
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (NetBSD)

iQEVAwUBQw45+IKcNwBDyKpoAQL0SAf8CAW7It360iAkzr+fBb1ttrqSCI2HpE6F
ZZXGMfIrmxL4m76DubS6ihBwqsoBHhHJwkq4vfs9lpOsgYcz3wShdqG41eLDn9eT
StX/XEWF5B9Ej4FYiXqZ60tKJqFHHC1gT1lDqoi7Hu6WpCFdj60usvxcUmH5loFL
NgnwySmfWCE1iTUw+10EXdDf/GRsGV1T6BNXZQcBrf+0ws6/I3nbqY2OJbu1IHij
IWXZUXOiSgGqrha/qoiMU7j9soc5PL5nNmK/88GNZYl8Xl93XX7oF1GEkTsC4bRO
gfLqgUgJ9kwpAOoE7bPL4992FX30qVFrbIxu6YXYyx4MTGGyI2f9hA==
=pOpZ
-----END PGP SIGNATURE-----

--df+09Je9rNq3P+GE--