Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1071666
  • 博文数量: 252
  • 博客积分: 4561
  • 博客等级: 上校
  • 技术积分: 2833
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-15 08:23
文章分类

全部博文(252)

文章存档

2015年(2)

2014年(1)

2013年(1)

2012年(16)

2011年(42)

2010年(67)

2009年(87)

2008年(36)

分类: LINUX

2009-06-01 08:56:20

#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");

阅读(2898) | 评论(0) | 转发(0) |
0

上一篇:练习代码 协议族

下一篇:smtp认证过程

给主人留下些什么吧!~~