实验:设计实验测试内核空间定义的变量和函数地址在3G – 4G之间

1K地址: 1 0000000000(10个0)

1M地址:1 0000000000(10个0)0000000000(10个0)

1G地址:1 0000000000(10个0)0000000000(10个0)0000000000(10个0)

3G地址:11 0000000000    0000000000   0000000000

3G地址:0xcfffffff

3G – 4G地址范围:0xcfffffff– 0xffffffff

 

设计文件内容如下:

show.c内容:

#include <linux/init.h>

#include <linux/kernel.h>

#include <linux/module.h>

 

 

static int a = 1;

int show_hellotest(void)

{

    printk("aadrr = %p, show_test addr = %p !\n",&a,show_hellotest);

 

    return 0;

}

 

hello.c内容:

#include <linux/init.h>

#include <linux/kernel.h>

#include <linux/module.h>

 

extern int show_hellotest(void);

 

static int __init hello_init(void)

{

    printk("helloworld init!\n");

    show_hellotest();

    return 0;

}

 

static void __exit hello_exit(void)

{

    printk("helloworld exit!\n");

}

 

MODULE_LICENSE("GPL");

module_init(hello_init);

module_exit(hello_exit);

 

Makefile内容

ifeq ($(KERNELRELEASE),)

all:

    make -C/lib/modules/$(shell uname -r)/build M=$(shell pwd)

clean:

    rm *.o *.ko*.mod.c modules.order

else

 

obj-m:=helloshow.o

helloshow-y+=hello.o

helloshow-y+=show.o

 

endif

 

执行完make,然后输入sudoinsmod helloshow.ko,再输入dmesg,得到打印如下:

[17946.600413] hello world init!

[17946.600415] a adrr = f9c15000, show_test addr =f9c13000 !


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值