COMPAT_43 and the linuxolator

David P. Reese Jr. daver at gomerbud.com
Mon Aug 18 16:14:42 PDT 2003


In article <200308181532.h7IFW3dG097536 at xxxxxxxxxxxxxxxxxxxx>, Matthew Dillon wrote:
>:[snip]
>:
>:> The trouble is that both the casting to a osockaddr struct and the copyout
>:> happen in the syscall functions.  Thus it sounds like we need to implement
>:> the legacy syscalls in the linux emulation code.
>:
>:[snip]
>:
>:I think I found a worthwhile solution to the problem.  Sorry for the noise.
>:Patches within the week.  Jr. Kernel Hacker in training.
>:
>:-- 
>:   David P. Reese, Jr.                                     daver at xxxxxxxxxxxx
> 
>     I think it's worthwhile to post a quick synopsis of the solution you
>     found.
> 
> 					-Matt

Its kind of a kludge...  Consider the old and new snippets of code that
handle the linux socket ioctls, specifically SIOCGIFADDR.

old snip of src/sys/emulation/linux/linux_ioctl.c:

        case LINUX_SIOCGIFADDR:
                args->cmd = OSIOCGIFADDR;
                error = ioctl((struct ioctl_args *)args);
                break;

What I was moaning about was that the copyout occurs in the native ioctl()
function.  I wanted to change the struct after the ioctl() function
returned, but before the linux syscall returned.  We have the user pointer,
so why cant we just copy back in, modify, and copy back out?

new snip of src/sys/emulation/linux/linux_ioctl.c:

        case LINUX_SIOCGIFADDR:
                args->cmd = SIOCGIFADDR;
                error = ioctl((struct ioctl_args *)args);
                bsd_to_linux_ifreq((struct ifreq *)args->arg);
                break;

The function bsd_to_linux_ifreq() copies the ifreq back in, modifies it
and copies it back out.  Thus, we are using the native syscall code
with an extra copyin-copyout.  Similar solutions seem to have worked for
the other syscalls that depended on COMPAT_43 code.

-- 
   David P. Reese, Jr.                                     daver at xxxxxxxxxxxx





More information about the Kernel mailing list