Regarding MALLOC_DEFINE related issues in kernel code usage

Shamsher singh meetshamsher at gmail.com
Wed Jul 28 07:02:48 UTC 2021


Hi,
I am using below test.c file (shown as example) in freebsd13 and getting below issues:

For #include <sys/systm.h> and #include <sys/malloc.h>

# cat test.c 
#define _KERNEL
#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> 
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/types.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;
}
[root at FreeBSD_build_machine1 ~/iproot/freebsd/mods/drivers/dell_bios]# cc test.c 
In file included from test.c:4:
In file included from /usr/include/sys/systm.h:179:
/usr/include/sys/kpilite.h:33:10: fatal error: 'offset.inc' file not found
#include "offset.inc"
         ^~~~~~~~~~~~
1 error generated.

If commenting above header then getting issues like:
In file included from /usr/include/sys/malloc.h:43:
In file included from /usr/include/sys/systm.h:179:
/usr/include/sys/kpilite.h:33:10: fatal error: 'offset.inc' file not found
#include “offset.inc"



The MALLOC_DEFINE is defined in malloc.h with macros _KERNEL.
So can’t avoid these above header files.

Can you please suggest me what am I missing here ?

Note: This similar issues I am facing for smbios.

Thanks & regards
Shamsher Singh


More information about the freebsd-questions mailing list