malloc in kernel

后端 未结 6 2066
南旧
南旧 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:14

    You can imagine it like a three step process:

    1. User space library - malloc()

    2. System call - brk()

    3. Inside Kernel - kmalloc/vmalloc/gfp etc routines of memory manager

    So If you are already at step 3, writing kernel module, then going back wouldn't make sense. So you need to use the kernel routines only for memory allocation.

提交回复
热议问题