# cat test.c #include <sys/types.h> #include <sys/module.h> #include <sys/systm.h> #include <sys/param.h> #include <sys/kernel.h> #include <sys/malloc.h> #include <sys/kthread.h> #include <sys/unistd.h> #include <stdlib.h> MALLOC_DEFINE(M_NODE, "NODE1", "test Node"); int main() { int *ptr; ptr = (int*)malloc(sizeof(int), M_NODE ,M_WAITOK) printf("ptr=%p\n",ptr); return 0; } # cc test.c test.c:11:23: error: expected identifier MALLOC_DEFINE(M_NODE, "NODE1", "test Node"); ^ test.c:11:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int] MALLOC_DEFINE(M_NODE, "NODE1", "test Node"); ^ test.c:14:37: error: use of undeclared identifier 'M_NODE' ptr = (int*)malloc(sizeof(int), M_NODE ,M_WAITOK) ^ 1 warning and 2 errors generated.
MALLOC_DEFINE is for the kernel's malloc() implementation, not the userspace malloc(). Note that in sys/malloc.h, _KERNEL needs to be defined for the MALLOC_DEFINE macro to be visible. If you have programming questions, please use the mailing lists (e.g., freebsd-questions, https://lists.freebsd.org/mailman/listinfo/freebsd-questions) or the forums (https://forums.freebsd.org/) to ask, rather than submitting issues to the bug tracker.