# Can we use stdlib.h, string.h in kernel module ?



## tmulkar (Nov 16, 2011)

Hello All, 

I am asking very tivial question here. I wish to port a kernel module from Linux to FreeBSD. While porting I came accross various standard library routins which are not available for usage in FreeBSD kernel <string.h>, <stdlib.h>. I am getting implicit declaration warnings on usage of these functions and compilation won't be through as warning == errorafter inclusion on <bsd.kmod.mk>

Can someone help me on this subject?


----------



## caesius (Nov 16, 2011)

tmulkar said:
			
		

> Hello All,
> While porting I came accross various standard library routins which are not availalbe for usage in FreeBSD kernel <string.h>, <stdlib.h>



What do you mean not available for use?


```
> grep -r stdlib.h /usr/src/sys                                                    
./amd64/amd64/bpf_jit_machdep.c:#include <stdlib.h>
./boot/ficl/ficl.c:#include <stdlib.h>
./boot/ficl/fileaccess.c:#include <stdlib.h>
./boot/ficl/float.c:#include <stdlib.h>
[snipped]
```

Looks like it's used plenty.


----------



## SirDice (Nov 16, 2011)

They are part of the standard C library. 

The kernel has no access to any library, including the standard C libraries.


----------



## kpa (Nov 16, 2011)

As far as I know the kernel has its own standard C library that is standalone and does not depend on the userland C library.


----------



## trasz@ (Nov 16, 2011)

Take a look at sys/libkern.h.


----------



## tmulkar (Nov 16, 2011)

Well as kpa said kernel has its own library and not dependent on usr lib. I had a look at libkern.h but not all functions are defined here. For the time being I have defined some of the functions in my module itself as I am not sure why they are not included in kernel. But now I am facing same issue with "stdarg.h"

Is it true that FreeBSD kernel code does not use variable argument type fucntions and that's why we don't have them in kernel library?


----------



## trasz@ (Nov 22, 2011)

Grepping kernel sources for "va_list" shows that parts of the kernel use it.  Try <machine/stdarg.h>.


----------

