1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'FreeBSD Development' started by tmulkar, Nov 16, 2011.

  1. tmulkar

    tmulkar New Member

    Messages:
    3
    Likes Received:
    0
    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?
     
  2. caesius

    caesius New Member

    Messages:
    279
    Likes Received:
    0
    What do you mean not available for use?

    Code:
    > 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.
     
  3. SirDice

    SirDice Moderator Staff Member Moderator

    Messages:
    17,382
    Likes Received:
    3
    They are part of the standard C library.

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

    kpa Member

    Messages:
    3,998
    Likes Received:
    6
    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.
     
  5. trasz@

    trasz@ New Member Developer

    Messages:
    192
    Likes Received:
    0
    Take a look at sys/libkern.h.
     
  6. tmulkar

    tmulkar New Member

    Messages:
    3
    Likes Received:
    0
    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?
     
  7. trasz@

    trasz@ New Member Developer

    Messages:
    192
    Likes Received:
    0
    Grepping kernel sources for "va_list" shows that parts of the kernel use it. Try <machine/stdarg.h>.