Subject: COPYIN/COPYOUT macro problems Re: IOCTL implementation and kernel/userland addresses
To: Frank van der Linden <fvdl@netbsd.org>
From: Reinoud Zandijk <reinoud@netbsd.org>
List: tech-kern
Date: 08/25/2005 18:35:50
--+QahgC5+KEYLbs62
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Dear folks,

picking up an old thread on the added FKIOCTL flag :

On Thu, Feb 17, 2005 at 12:26:36AM +0100, Reinoud Zandijk wrote:
> On Wed, Feb 16, 2005 at 11:37:56PM +0100, Frank van der Linden wrote:
> > On Wed, Feb 16, 2005 at 11:25:39PM +0100, Reinoud Zandijk wrote:
> > > --- sys/fcntl.h 3 Feb 2005 19:20:01 -0000       1.29
> > > +++ sys/fcntl.h 16 Feb 2005 22:21:31 -0000
> > > @@ -124,11 +124,12 @@
> > >  #define        FMARK           0x00001000      /* mark during gc() */
> > >  #define        FDEFER          0x00002000      /* defer for next gc pass */
> > >  #define        FHASLOCK        0x00004000      /* descriptor holds advisory lock */
> > > +#define FKIOCTL                0x80000000
> > >  /* bits to save after open(2) */
> > >  #define        FMASK           
> > > (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FDSYNC|\
> > > -                        FRSYNC|FALTIO)
> > > +                        FRSYNC|FALTIO|FKIOCTL)
> > >  /* bits settable by fcntl(F_SETFL, ...) */
> > So, just add the value for FKIOCTL, and you're done there.


> still remains the point of defining a COPYOUT() and friends macro's ? or a 
> function?

I've defined COPYIN and COPYOUT macros wich allways DTRT for ioctls in the 
following proposed patch :

------------------
diff -u -r1.179 systm.h
--- sys/systm.h 23 Jun 2005 00:30:28 -0000      1.179
+++ sys/systm.h 25 Aug 2005 16:22:28 -0000
@@ -240,6 +240,21 @@
 int    copyin(const void *, void *, size_t);
 int    copyout(const void *, void *, size_t);
 
+#ifdef _KERNEL
+#define COPYIN(ioctlflags, uaddr, kaddr, len)\
+               if ((ioctlflags) & FKIOCTL) {\
+                       memcpy((kaddr), (uaddr), (len));\
+               } else {\
+                       copyin((uaddr), (kaddr), (len));\
+               };
+#define COPYOUT(ioctlflags, kaddr, uaddr, len)\
+               if ((ioctlflags) & FKIOCTL) {\
+                       memcpy((uaddr), (kaddr), (len));\
+               } else {\
+                       copyout((kaddr), (uaddr), (len));\
+               };
+#endif /* KERNEL */
+
 int    copyin_proc(struct proc *, const void *, void *, size_t);
 int    copyout_proc(struct proc *, const void *, void *, size_t);
----------------------

*BUT* a grep in src/sys pointed to the following problems:

arch/pc532/fpu/ieee_handler.c
dist/pf/net/pf_table.c
dist/ipf/netinet/ip_compat.h

all define their own COPYIN() and COPYOUT() macro's.... now what to do?
   a) don't use COPYIN/COPYOUT but use IOCTL_COPYIN and IOCTL_COPYOUT ?
   b) patch somehow pc532/pf/ipf to not use such generic names?
   c) ...

(a) would do justice to the fact that they are only usable for IOCTL flags 
(b) might cause problems with importing newer pf/ipf or are those imports 
mainly scripted?
(c) other suggestions?

Reinoud

--+QahgC5+KEYLbs62
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iQEVAwUBQw3zXoKcNwBDyKpoAQIX7Qf8DN3kM8uBtfzt71u943y0fPxUQegOFCRO
Ps3bXh+vVejrk5uItIpPuJokTKnpxBPwecOyWLzbROPMpjtvXpMMglvCzx/6okvS
YMVcYPaWUDL2/SfcJLgBAmct2oIrnGoj32T00aW3YgsbtsHT0nV8Q4+qKJmRTcal
xgxb9cIw+8OsA1A6aAF0/uvLhu9rVJyDworiUpXhpPkDMrJX8RBZTZoQuf8O8ZeJ
+e3gWw5u8bBdbCwe/4OmSjRT692AMgO7NyyH9eSM6rTPUZMyHOpp1emM/++A9mNj
KDEgbn/ZpCDdrxZxu24la3EN5GufMS3GZBgV/aqlqb4/oOHAjmG67A==
=mGJz
-----END PGP SIGNATURE-----

--+QahgC5+KEYLbs62--