免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1125 | 回复: 0
打印 上一主题 下一主题

linux进程地址空间 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-01-13 19:32 |只看该作者 |倒序浏览
  1. #include <linux/module.h>
  2. #include <linux/init.h>

  3. MODULE_LICENSE("GPL");
  4. MODULE_AUTHOR("David Xie");
  5. MODULE_DESCRIPTION("Memory alloc Module");
  6. MODULE_ALIAS("malloc module");

  7. char *buf1 = NULL;
  8. char *buf2 = NULL;


  9. int alloc_init()
  10. {
  11.     buf1 = kmalloc(100,GFP_KERNEL);
  12.     memset(buf1,0,100);
  13.     strcpy(buf1,"<<< --- Kmalloc Mem OK! --- >>>");
  14.     printk("<0>BUF 1 : %s\n",buf1);
  15.     
  16.     buf2 = get_zeroed_page(GFP_KERNEL);
  17.     strcpy(buf2,"<<<--- Get Free Page OK! --- >>>");
  18.     printk("<0>BUF 2 : %s\n",buf2);
  19.     return 0;
  20. }


  21. void alloc_exit()
  22. {
  23.     kfree(buf1);
  24.     free_page(buf2);
  25.     printk("<0><<< --- Module Exit! --->>>\n");
  26. }

  27. module_init(alloc_init);
  28. module_exit(alloc_exit);
  1. ifneq ($(KERNELRELEASE),)

  2. obj-m := alloc_mem.o

  3. else
  4.     
  5. KDIR := /home/guoqian/4-3-1/linux-2.6.29
  6. all:
  7.     make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=arm-linux-
  8. clean:
  9.     rm -f *.ko *.o *.mod.o *.mod.c *.symvers modul*

  10. endif
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP