# calling kernel space malloc get error



## jchan21 (Apr 12, 2020)

###Here is the errors I am getting. Below the error is the code I wrote, any help would be incredibly appreciated.!! Thanks!
Can someone explained by I am getting implicit warning for malloc and Malloc_Define, I included the header files. I also would like to know how to fix the errors . Thanks.!


```
intkmod.c:20:23: error: expected identifier
MALLOC_DEFINE(M_NODE, "New NODE", "Container Node");
                      ^
intkmod.c:20:1: warning: type specifier missing, defaults to 'int'
      [-Wimplicit-int]
MALLOC_DEFINE(M_NODE, "New NODE", "Container Node");
^
intkmod.c:28:17: warning: implicitly declaring library function 'malloc' with
      type 'void (unsigned long)' [-Wimplicit-function-declaration]
    ptr = (int)malloc(sizeof(int), M_NODE ,M_WAITOK)
                ^
intkmod.c:28:17: note: include the header <stdlib.h> or explicitly provide a
      declaration for 'malloc'
intkmod.c:28:37: error: use of undeclared identifier 'M_NODE'
    ptr = (int*)malloc(sizeof(int), M_NODE ,M_WAITOK)
                                    ^
2 warnings and 2 errors generated.
```


####Here is the code for my file which I include some kernel space files.


```
typedef unsigned long uintfptr_t;

typedef unsigned long intrmask_t;

#include <sys/types.h>
#include <sys/module.h>
#include <sys/systm.h>  /* uprintf /
#include <sys/param.h>  / defines used in kernel.h /
#include <sys/kernel.h> / types used in module initialization /
#include <sys/conf.h>   / cdevsw struct /
#include <sys/uio.h>    / uio struct /
#include <sys/malloc.h>
#include <sys/kthread.h>
#include <sys/unistd.h>//int start();

MALLOC_DEFINE(M_NODE, "New NODE", "Container Node")
int main() {

    int ptr;
    ptr = (int*)malloc(sizeof(int), M_NODE ,M_WAITOK)

    printf("Hello world!\n");
    return 0;
}
```


----------



## jchan21 (Apr 14, 2020)

this is solved


----------



## shamsher (Jul 27, 2021)

May I know how you resolved this? I'm getting the same error on FreeBSD13.


----------



## mark_j (Jul 27, 2021)

Maybe he read the manual page which states:


> In    order to use *MALLOC*_*DEFINE*(), one must include <_sys/param.h_> (instead
> of    <_sys/types.h_>) and <_sys/kernel.h_>.


----------

