malloc in kernel

后端 未结 6 2061
南旧
南旧 2020-12-20 13:10

When I try to use malloc in a kernel module I get an error message from the compiler. My code:

res=(ListNode*)malloc(sizeof(ListNode));
<         


        
6条回答
  •  一生所求
    2020-12-20 13:24

    You can't use libraries in the kernel. None whatsoever.

    This means that ANY function you're calling in the kernel needs to be defined in the kernel. Linux does not define a malloc, hence you can't use it.

    There is a memory allocator and a family of memory allocation functions. Read the kernel docs on the memory allocator for more information.

    Incidentially, there are a few functions the kernel defines which are in the standard C library as well; this is for convenience.

    It does, for instance, defined snprintf

提交回复
热议问题