mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Operations inside a module
@ 2002-11-21 19:59 Matt Young
  2002-11-21 20:24 ` Rik van Riel
  2002-11-21 20:31 ` Richard B. Johnson
  0 siblings, 2 replies; 3+ messages in thread
From: Matt Young @ 2002-11-21 19:59 UTC (permalink / raw)
  To: linux-kernel

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

  

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Operations inside a module
  2002-11-21 19:59 Operations inside a module Matt Young
@ 2002-11-21 20:24 ` Rik van Riel
  2002-11-21 20:31 ` Richard B. Johnson
  1 sibling, 0 replies; 3+ messages in thread
From: Rik van Riel @ 2002-11-21 20:24 UTC (permalink / raw)
  To: Matt Young; +Cc: linux-kernel

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.

You don't need the system calls, you can just call the in-kernel
functions directly. If one of the functions you want isn't exported
you could either use an exported alternative or export it yourself
by patching your kernel.  However, chances are that if it's not
exported it'll be changed or gone 10 kernels down the line, so you
don't want to use it anyway. ;)

> My module code would also like to use user space malloc, is this a
> problem?

Yes. This is absolutely impossible.

Think of the kernel as a shared library, a shared library that
causes the process that calls a function from it to switch into
supervisor mode.

regards,

Rik
-- 
A: No.
Q: Should I include quotations after my reply?

http://www.surriel.com/		http://distro.conectiva.com/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Operations inside a module
  2002-11-21 19:59 Operations inside a module Matt Young
  2002-11-21 20:24 ` Rik van Riel
@ 2002-11-21 20:31 ` Richard B. Johnson
  1 sibling, 0 replies; 3+ messages in thread
From: Richard B. Johnson @ 2002-11-21 20:31 UTC (permalink / raw)
  To: Matt Young; +Cc: linux-kernel

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-11-21 20:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-21 19:59 Operations inside a module Matt Young
2002-11-21 20:24 ` Rik van Riel
2002-11-21 20:31 ` Richard B. Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®