Sponsored Content
Top Forums Programming can a linux kernel module call libc functions? Post 302573888 by otheus on Wednesday 16th of November 2011 03:29:00 AM
Old 11-16-2011
Quote:
But, what makes the kernel can not call syscalls which inside itself?
(If you received mail of this post, it was premature. Disregards)

Linux (AFAIK) does not support a 're-entrant' model. Once you're inside the kernel, you can't thread a new process, or go again into the kernel (you're already there). Allowing a module to do a syscall would make things incredibly complicated and would more than often result in a deadlock or worse -- a infinite recursive loop, filling up the stack.

Some UNIX's (Solaris 2.5+) are re-entrant and theoretically could support a kernel module making a syscall, but again, the problems are similar - extreme care has to be taken to ensure that bad things dont happen.

If you want to have a kernel module do some nifty things, the common practice is to have it communicate with a userland process via a pipe or ioctl. That is, make your module act as a dummy device driver which fills the dummy device with data that it wants to send to the userland process. The userland process is then blocking-read on this device and acts appropriately when the data is available.

There is also the issue of calling symantics. On most devices (ie, CPUs), invoking a system call involves setting registers and triggering an interrupt, which the kernel then handles. If your code is running in the Kernel, this interrupt has to be masked to prevent another system call from interrupting the currently executing one. (Unless you're a re-entrant kernel like Solaris; then your code has to be re-entrant too). In other instances, the system call entry point is through a specific CPU instruction -- one which requires a mode bit to indicate the currently executing process is in "userland" mode. Once the control is handed to the kernel, the kernel sets that bit accordingly, so once again, the CPU wont let a kernel thread invoke a kernel thread.

Last edited by otheus; 11-16-2011 at 04:40 AM.. Reason: first response was already answered by corona
 

10 More Discussions You Might Find Interesting

1. Linux

Making Socket System Call From Linux Kernel Module?

Hi Everyone! How can we make a socket() system call from a linux module executing in kernel space? If any one knows, kindly tell me. It will be great. I want to use the socket interface in linux kernel space for sending raw packets over the network. Hamayun (0 Replies)
Discussion started by: mian_m_hamayun
0 Replies

2. Programming

kernel-kernel call communication

hi all! i have developed a mechanism in system.c to count how many times each kernel call is called. The results are held in an array in system.c . What i want to do is to create a new kernel call which will print this array. I need help in passing the array from system.c to the new kernel call. ... (5 Replies)
Discussion started by: aureliano
5 Replies

3. SuSE

max number of slabs per kernel module (kernel 2.6.17, suse)

Hi All, Is there a max number of slabs that can be used per kernel module? I'm having a tough time finding out that kind of information, but the array 'node_zonelists' (mmzone.h) has a size of 5. I just want to avoid buffer overruns and other bad stuff. Cheers, Brendan (4 Replies)
Discussion started by: Brendan Kennedy
4 Replies

4. UNIX for Dummies Questions & Answers

Linux kernel module parameters

Hi, Does anyone know if it is possible to know the current value of a kernel module parameters after the module is loaded. Are the values of the parameters advertised at some /proc or /sys location ? The only thing I know is modinfo, that actually looks a the module .ko and gives a... (3 Replies)
Discussion started by: macL
3 Replies

5. Linux

How to convert Linux Kernel built-in module into a loadable module

Hi all, I am working on USB data monitoring on Fedora Core 9. Kernel 2.6.25 has a built-in module (the one that isn't loadable, but compiles and links statically with the kernel during compilation) to snoop USB data. It is in <kernel_source_code>/drivers/usb/mon/. I need to know if I can... (0 Replies)
Discussion started by: anitemp
0 Replies

6. Red Hat

Export functions in kernel module to user Programs

Hi all, I just started working on kernel modules. One query i'm not able to resolve how i can use call any of my function(take example testfunc() ) defined in my loadable kernel module (take example : test.ko) I want to export kernel module functions to user programs. Consider i have... (0 Replies)
Discussion started by: er.tarun.9986
0 Replies

7. Programming

Make cannot generate .ko linux kernel module

cannot generate .ko file on my linux, although it can generate module.symvers. But when I copy .c file and Makefile to another linux computer, there's no problem. The strange thing is: make is successfuly executed, and returned 0; make output: make -C /lib/modules/2.6.18-92.el5xen/build ... (4 Replies)
Discussion started by: vistastar
4 Replies

8. UNIX for Advanced & Expert Users

Get pointer for existing device class (struct class) in Linux kernel module

Hi all! I am trying to register a device in an existing device class, but I am having trouble getting the pointer to an existing class. I can create a class in a module, get the pointer to it and then use it to register the device with: *cl = class_create(THIS_MODULE, className);... (0 Replies)
Discussion started by: hdaniel@ualg.pt
0 Replies

9. Linux

Unload kernel module at boot time (Debian Wheezy 7.2, 3.2.0-4-686-pae kernel)

Hi everyone, I am trying to prevent the ehci_hcd kernel module to load at boot time. Here's what I've tried so far: 1) Add the following line to /etc/modprobe.d/blacklist.conf (as suggested here): 2) Blacklisted the module by adding the following string to 3) Tried to blacklist the module... (0 Replies)
Discussion started by: gacanepa
0 Replies

10. Shell Programming and Scripting

Call functions from other scripts

i have a file that contains functions and i want the functions to be available in another script. of course, the ideal situation here would be to put the functions in the same script, but i dont own these scripts. so I have to call the functions file from a different script. how do i... (3 Replies)
Discussion started by: SkySmart
3 Replies
XPT(4)							   BSD Kernel Interfaces Manual 						    XPT(4)

NAME
xpt -- CAM transport layer interface SYNOPSIS
None. DESCRIPTION
The xpt driver provides a way for userland applications to issue certain CAM CCBs to the kernel. Since the xpt driver allows direct access to the CAM subsystem, system administrators should exercise caution when granting access to this driver. If used improperly, this driver can allow userland applications to crash a machine or cause data loss. KERNEL CONFIGURATION
There is no kernel configuration required for the xpt driver. It is enabled when SCSI support is enabled in the kernel. There is one instance of the xpt driver per CAM transport layer instance. Since there is currently only one CAM transport layer, there will only be one instance of this driver. IOCTLS
CAMIOCOMMAND This ioctl takes certain kinds of CAM CCBs and passes them through to the CAM transport layer for action. Only the following CCB types are supported: XPT_SCAN_BUS XPT_RESET_BUS XPT_SCAN_LUN XPT_ENG_INQ XPT_ENG_EXEC XPT_DEBUG XPT_DEV_MATCH XPT_PATH_INQ The above CCBs are the only ones supported since it makes more sense to send them through a generic passthrough device rather than a passthrough device tied to a particular underlying SCSI device. CAMGETPASSTHRU This ioctl takes an XPT_GDEVLIST CCB, and returns the passthrough device corresponding to the device in question. FILES
/dev/xpt0 Character device node for the xpt driver. DIAGNOSTICS
None. SEE ALSO
cam(3), cam_cdbparse(3), pass(4), camcontrol(8) HISTORY
The CAM transport layer driver first appeared in FreeBSD 3.0. AUTHORS
Kenneth Merry <ken@FreeBSD.org> BSD
October 10, 1998 BSD
All times are GMT -4. The time now is 02:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy