TASK_SIZE定义在https://elixir.bootlin.com/linux/v4.16.7/source/arch/arm/include/asm/memory.h#L40中,可以通过以下代码访问。请将其编译为内核模块。
#include <linux/module.h>
#include <linux/memory.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Open Source");
MODULE_DESCRIPTION("Module for TASK_SIZE");
static int __init find_task_size_init(void);
static void __exit find_task_size_exit(void);
static int
__init find_task_size_init(void)
{
printk(KERN_INFO "Memory TASK_SIZE: 0x%lx\n", TASK_SIZE);
return 0;
}
static void
__exit find_task_size_exit(void)
{
printk(KERN_INFO "module exits ok !\n");
}
module_init(find_task_size_init);
module_exit(find_task_size_exit);
Run Code Online (Sandbox Code Playgroud)
ifneq ($(KERNELRELEASE),)
# call from kernel build system
lifo-objs := main.o
obj-m := TASK_SIZE.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
echo $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules
endif
clean:
rm -rf *.o *~ core .depend *.mod.o .*.cmd *.ko *.mod.c .tmp_versions *.markers *.symvers modules.order
depend .depend dep:
$(CC) $(CFLAGS) -M *.c > .depend
ifeq (.depend,$(wildcard .depend))
include .depend
endif
Run Code Online (Sandbox Code Playgroud)
# dmesg -k -w # In the first console shell
[ 2570.156990] Memory TASK_SIZE: 0x7ffffffff000
[ 2573.164671] module exits ok !
Run Code Online (Sandbox Code Playgroud)
# make # In the second console shell
# insmod TASK_SIZE.ko
# rmmod TASK_SIZE
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1604 次 |
| 最近记录: |