Bug 257450 - MALLOC_DEFINE macro error in Freebsd13 OS
Summary: MALLOC_DEFINE macro error in Freebsd13 OS
Status: Closed Not A Bug
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.0-STABLE
Hardware: amd64 Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2021-07-27 13:12 UTC by shamsher
Modified: 2021-07-27 13:20 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description shamsher 2021-07-27 13:12:29 UTC
# 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)
    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.
Comment 1 Mark Johnston freebsd_committer 2021-07-27 13:20:36 UTC
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.