is_vmalloc_addr函数总结

#include 
#include 
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

static int *p;  
static int *q;     
int __init s_init(void)
{
	int i, j;
	p = vmalloc(10);
	q = kmalloc(10, GFP_KERNEL);

	i = is_vmalloc_addr(p);
	j = is_vmalloc_addr(q);

	printk("i = %d, j = %d\n", i, j);
	return 0;
}

void __exit s_exit(void)
{
	if(is_vmalloc_addr(p))
		vfree(p);
	else
		kfree(p);
	
	if(is_vmalloc_addr(q))
		vfree(q);
	else
		kfree(q);
}

MODULE_AUTHOR("txj");
MODULE_LICENSE("GPL");

module_init(s_init);
module_exit(s_exit);
# SPDX-License-Identifier: GPL-2.0
obj-m += test.o
test-objs := sys.o

all:
	make -C /usr/src/linux-headers-$(shell uname -r) M=$(shell pwd) modules
clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean

你可能感兴趣的:(linux系统编程与内核编程,linux)