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

Kernel development, writing drivers, coding, and questions regarding FreeBSD internals.

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

Postby tmulkar » 16 Nov 2011, 09:33

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 [FILE]<string.h>[/FILE], [FILE]<stdlib.h>[/FILE]. I am getting implicit declaration warnings on usage of these functions and compilation won't be through as warning == errorafter inclusion on [FILE]<bsd.kmod.mk>[/FILE]

Can someone help me on this subject?
tmulkar
Junior Member
 
Posts: 3
Joined: 31 Oct 2011, 12:00

Postby caesius » 16 Nov 2011, 11:43

tmulkar wrote: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?

Code: Select all
> 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.
caesius
Member
 
Posts: 277
Joined: 16 Nov 2008, 03:23
Location: New Zealand

Postby SirDice » 16 Nov 2011, 12:53

They are part of the standard C library.

The kernel has no access to any library, including the standard C libraries.
Senior UNIX Engineer at Unix Support Nederland
Experience is something you don't get until just after you need it.
User avatar
SirDice
Old Fart
 
Posts: 16170
Joined: 17 Nov 2008, 16:50
Location: Rotterdam, Netherlands

Postby kpa » 16 Nov 2011, 13:19

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.
kpa
MFC'd
 
Posts: 3393
Joined: 05 Jul 2010, 13:19
Location: People's Technocratic Republic of Finland

Postby trasz@ » 16 Nov 2011, 14:14

Take a look at [FILE]sys/libkern.h[/FILE].
trasz@
Member
 
Posts: 182
Joined: 20 Feb 2008, 22:44
Location: Warszawa, Poland

Postby tmulkar » 16 Nov 2011, 15:02

Well as kpa said kernel has its own library and not dependent on usr lib. I had a look at [FILE]libkern.h[/FILE] 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 "[FILE]stdarg.h[/FILE]"

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?
tmulkar
Junior Member
 
Posts: 3
Joined: 31 Oct 2011, 12:00

Postby trasz@ » 22 Nov 2011, 10:34

Grepping kernel sources for "[FILE]va_list[/FILE]" shows that parts of the kernel use it. Try [FILE]<machine/stdarg.h>[/FILE].
trasz@
Member
 
Posts: 182
Joined: 20 Feb 2008, 22:44
Location: Warszawa, Poland


Return to FreeBSD Development

Who is online

Users browsing this forum: Google [Bot] and 1 guest