Re: Function calls not permitted in kernel code

From: Peter Samuelson (peter@cadcamlab.org)
Date: Wed Sep 20 2000 - 07:40:44 EST


[Mark James]
> That is, can a kernel module open and read files or sockets, call
> libc functions, start processes?

* Read files/sockets: you need a process context. That means if you
  are running in an interrupt you are SOL and if you are in an existing
  process context, the context owner might get upset with you for
  playing with its fd table without its knowledge. So the only safe
  way is to spawn a kernel thread; see below.

* libc: absolutely not. The kernel has its own set of provided
  functions, some of which look suspiciously like libc functions, but
  your selection is very limited. Look in your lib/ directory to see
  what is available.

* start processes: yes, if you must. Grep for the kernel_thread()
  function. Watch for the pitfalls (study existing usage). If you
  want to run a userspace program, see kernel/kmod.c for an example.

> are the options to:
>
> (1) Get a user process to do the work, communicating
> with the kernel via /proc or some other way.
>
> (2) Doing things really low-level through kernel calls
> (such as injecting skbs into TCP/IP code).

(1), in general. /proc files are a popular kludge, and /dev files with
custom ioctl() calls are almost as popular.

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



This archive was generated by hypermail 2b29 : Sat Sep 23 2000 - 21:00:23 EST