PDA

View Full Version : usleep function makes kernel module doesn't load. Why?


vyrtosu
February 7th, 2009, 22:55
I an writing kernel module using this article:

http://www.freesoftwaremagazine.com/articles/writing_a_kernel_module_for_freebsd

I have actually two problems. When I try to include file #include <stdio.h> or any other like unistd e.t.r. It doesn't see them and tells that there are no such file. But it is a lie.

And second problem is that when I try to use in my kernel code function usleep it compiles well but i just cant load this module. It tells that file is not found. But its not true.

What should I change comparing to the info indicated in the article to use function like sleep f.ex. (for now it tells me that this function is unknown). And why it doesn't sees standard include files?

Thanks in advance.

mjguzik
February 8th, 2009, 00:00
In the kernel you can't use anything depending on libc, as it belongs to userland. After getting that 'file not found' check dmesg, linker puts diagnostic information there.

vyrtosu
February 8th, 2009, 12:52
In the kernel you can't use anything depending on libc, as it belongs to userland. After getting that 'file not found' check dmesg, linker puts diagnostic information there.

Thanks great for your answer. Could you please then indicate me where can I find the list of functions that I can use in my kernel?

mjguzik
February 8th, 2009, 13:52
9th section of manpages, various headers from /usr/include/sys, reading the code to know how to do things. Also note that some useful functions like strlcat, strclcpy and so on are available in libkern library.

kamikaze
February 9th, 2009, 11:50
> man libkern
No manual entry for libkern
> man kern
No manual entry for kern

I hate it when that happens.

danger@
February 10th, 2009, 01:17
ls /usr/share/man/man9 might help...

Mel_Flynn
February 12th, 2009, 10:01
And second problem is that when I try to use in my kernel code function usleep it compiles well but i just cant load this module. It tells that file is not found. But its not true.


# sysctl kern.module_path
kern.module_path: /boot/kernel;/boot/modules

mjguzik
February 12th, 2009, 10:09
That's not the case. If the kernel linker fails to resolve a symbol, appropriate message is printed to the console (something like "link_elf: symbol foo undefined") and errno is set to ENOENT, thus 'No such file or directory'.

vyrtosu
February 13th, 2009, 09:18
The right answer is to use pause function