RE: how to use the function copyout()

From: Norbert Koch (NKoch_at_demig.de)
Date: 07/25/05

  • Next message: Matthew N. Dodd: "RE: how to use the function copyout()"
    To: "Giorgos Keramidas" <keramida@freebsd.org>, "Felix-KM" <Felix-KM@yandex.ru>
    Date: Mon, 25 Jul 2005 16:58:55 +0200
    
    

    >
    > > So if I get it right, it's impossible in FreeBSD to gain access to
    > > 64KB of user's program memory with ioctl?
    > >
    > > My situation is this - I have a device driver for Linux. My task is
    > > port it as it is (1:1) into FreeBSD.
    > >
    > > In the Linux driver Ioctl is realized with the macroses _put_user
    > > _get_user all over it. As I understand in FreeBSD their analogues are
    > > functions described in store(9), copy(9) and fetch(9).
    > >
    > > So the problem is that in my user program an array short unsigned int
    > > Data[32768] is defined. I need to gain access to the array(to each
    > > element of it) from device driver with Ioctl handler.
    > >
    > > Is it possible to do? If yes, then how it can be done?
    >
    > A better alternative that doesn't involve copying huge amounts of data
    > from userlevel to kernel space and vice versa is probably to pass just
    > the address of the area with an ioctl() and then map the appropriate
    > pages from the address space of the user process to an area where the
    > kernel can access the data directly?

    I think that could work (only an idea, not tested):

    struct Region
    {
      void * p;
      size_t s;
    };

    #define IOBIG _IOWR ('b', 123, struct Region)

    userland:

      char data[1000];
      struct Region r;

      r.p = data;
      r.s = sizeof data;
      int error = ioctl (fd, IOBIG, &r);

    kernel:
      int my_ioctl(..., caddr_t data, ...)
      {
        ...
        char data[1000];
        ...
        return copyout(data, ((struct Region *) data)->p, ((struct Region *)
    data)->s);
      }

    Have a try and tell us if it works.

    Norbert

    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: Matthew N. Dodd: "RE: how to use the function copyout()"

    Relevant Pages

    • Re: Trap number: how a system software recognise it?
      ... MINIX has no concept of "device recognition". ... discuss how to implement a new device driver - not so much documentation ... > driver code at the kernel space to perform the low level instructions. ... User program issues readlibc function to read some bytes from ...
      (comp.os.linux.misc)
    • Re: Trap number: how a system software recognise it?
      ... MINIX has no concept of "device recognition". ... discuss how to implement a new device driver - not so much documentation ... > driver code at the kernel space to perform the low level instructions. ... User program issues readlibc function to read some bytes from ...
      (comp.os.linux.development.system)
    • RE: printf internals
      ... Subject: printf internals ... I tried strace on a regular system. ... Kernel boots fine to a point where it starts accessing ramdisk and ... I wanted to trace down the path from user program to the kernel and see ...
      (Linux-Kernel)
    • Re: [RFC] frandom - fast random generator module
      ... |> are in the kernel, ... |> is a bitch in shell scripts;-) ... Not to mention that to get entropy the user program will have to ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: virus or some other malware in a movie file
      ... once you get the buffer vulnerability you can ... completely gain access to a system "IF" the Context ... into kernel or much better to patch kernel code, ... plain text in a application working with AACS ...
      (microsoft.public.win32.programmer.kernel)