# usleep function makes kernel module doesn't load. Why?



## vyrtosu (Feb 7, 2009)

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 (Feb 7, 2009)

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 (Feb 8, 2009)

mjguzik said:
			
		

> 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 (Feb 8, 2009)

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 (Feb 9, 2009)

```
> man libkern
No manual entry for libkern
> man kern
No manual entry for kern
```

I hate it when that happens.


----------



## danger@ (Feb 10, 2009)

`# ls /usr/share/man/man9` might help...


----------



## Mel_Flynn (Feb 12, 2009)

vyrtosu said:
			
		

> 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 (Feb 12, 2009)

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 (Feb 13, 2009)

The right answer is to use pause function


----------

