Re: Operations inside a module

From: Richard B. Johnson (root@chaos.analogic.com)
Date: Thu Nov 21 2002 - 15:31:58 EST


On Thu, 21 Nov 2002, Matt Young wrote:

> Within the open routine of my module I need to open another device; and the
> write routine needs to write to the other device.
>
> User space system calls seem to be unavailable to module code.
> I know about swapping the DS and ES to fake out other modules; then using
> sys_write etc.
>
> Can my code just include the standard syscall lib and use them from kernel
> space?
>
> My module code would also like to use user space malloc, is this a problem?
>
> Matt
>

This is a FAQ by people who think a module is just some 'C' code that
you hack.

To use open/close/read/write files, you need a process context. You
can make one by creating a kernel thread. The kernel is some protected
code that performs tasks on behalf of the caller, in the context of
the caller. You can't call the kernel from within the kernel, i.e.,
sys-calls because you will never get back. It's like main() calling main()
in user-mode 'C'. And if you "know about swapping DS and ES", as you
state, then you know nothing and shouldn't get near kernel code.

If you need read or write from a device in the kernel, you just
read or write, just put your request in the queue for that device.
Of course if you really mean "files", then your module is broken by
design.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
   Bush : The Fourth Reich of America

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Nov 23 2002 - 22:00:37 EST