lkml.org 
[lkml]   [2000]   [Sep]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: Function calls not permitted in kernel code
From
[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/

\
 
 \ /
  Last update: 2005-03-22 12:38    [W:0.086 / U:36.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site