#include <linux/module.h>
#include <linux/init.h>
#include <asm/atomic.h>
#include <linux/gfp.h>
#include <linux/mm.h>
#include <linux/string.h>
#define err(msg) printk(KERN_ALERT "%s\n", msg)
static int main_init(void)
{
struct page *page;
void *address;
char data[] = "hello linux";
page = alloc_pages(GFP_KERNEL, 0);
if (!page)
{
err("alloc_pages");
return -1;
}
address = page_address(page);
if (!address)
{
err("page_address");
goto err;
}
memcpy(address, data, strlen(data));
printk(KERN_ALERT "%s\n", (char *)address);
free_pages((unsigned long)address, 0);
return 0;
err:
free_pages((unsigned long)page, 0);
return -1;
}
static void main_exit(void)
{
}
module_init(main_init);
module_exit(main_exit);
MODULE_LICENSE("GPL");
alloc_pages()用法
最新推荐文章于 2024-05-01 17:45:45 发布