Subject: Re: COPYIN/COPYOUT macro problems Re: IOCTL implementation and kernel/userland addresses
To: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
From: Jason Thorpe <thorpej@shagadelic.org>
List: tech-kern
Date: 08/25/2005 11:44:19
On Aug 25, 2005, at 11:01 AM, YAMAMOTO Takashi wrote:

>> +#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 */
>
> - don't discard return values.
> - why memcpy rather than kcopy?
> - is there any benefits to use macros?  why not functions?

Exactly, this should be implemented as ioctl_copyin() and  
ioctl_copyout() functions that redirect to the appropriate other  
functions.  Macros like this are EVIL.

> - do you have any plan for non-vnode ioctls?
>
> YAMAMOTO Takashi

-- thorpej