#include<stdio.h>#include<unistd.h>#include<stdlib.h>int A;//全局未初始化变量int B =0;//全局初始化为0的变量int C =2;//全局初始化变量staticint D;//全局静态未初始化变量 staticint E =0;// 全局静态初始化变量0 staticint F =4;//全局静态初始化变量conststaticint G =5;// 全局静态初始化变量conststaticchar H =6;intmain(){int a;//局部未初始化变量int b =0;// 局部初始化为0的变量int c =2;//局部初始化变量staticint d ;//局部静态未初始化变量staticint e =0;//局部静态初始化为0变量staticint f =4;//局部静态初始化变量constint g =5;//局部变量char chr1[]="abcde";//局部字符数值char*cptr ="1";/// cptr在stack上 "1"在常量区int*heap =malloc(sizeof(int)*4);//堆空间printf("PID is %d\n",getpid());printf("int A A_Addr = %p\n",&A);printf("int B B_Addr = %p\n",&B);printf("int C C_Addr = %p\n",&C);printf("int D D_Addr = %p\n",&D);printf("int E E_Addr = %p\n",&E);printf("int F F_Addr = %p\n",&F);printf("int G G_Addr = %p\n",&G);printf("int H H_Addr = %p\n",&H);printf("int a a_Addr = %p\n",&a);printf("int b b_Addr = %p\n",&b);printf("int c c_Addr = %p\n",&c);printf("int d d_Addr = %p\n",&d);printf("int e e_Addr = %p\n",&e);printf("int f f_Addr = %p\n",&f);printf("int g g_Addr = %p\n",&g);printf("int chr1 H_Addr = %p\n",chr1);printf("int cptr H_Addr = %p\n",cptr);printf("int heap H_Addr = %p\n",heap);while(1){getchar();}return0;}
#include<linux/init.h>#include<linux/module.h>#include<linux/device.h>#include<linux/platform_device.h>#include<linux/slab.h>#include<linux/vmalloc.h>#include<linux/mm.h>#include<linux/kthread.h>staticpid_t pid;module_param(pid,int,0644);intprint_vma(void){structtask_struct*task;structmm_struct*mm;structvm_area_struct*vma;printk("begin to print virtual address space\n");
task =pid_task(find_vpid(pid),PIDTYPE_PID);if(task==NULL){return-1;}
mm = task->mm;printk("executable name is %s pid is %d\n",task->comm,task->pid);printk("start code 0x%lx end_code 0x%x\n",mm->start_code,mm->end_code);printk("start data 0x%lx end_code 0x%x\n",mm->start_data,mm->end_code);printk("mmap_base 0x%lx \n",mm->mmap_base);printk("start start_stack 0x%lx\n",mm->start_stack);down_read(&mm->mmap_sem);for(vma=task->mm->mmap;vma;vma=vma->vm_next){printk("0x%lx 0x%lx length is %d",vma->vm_start,vma->vm_end,vma->vm_end-vma->vm_start);if(vma->vm_flags &VM_READ)printk("r");elseprintk(".");if(vma->vm_flags &VM_WRITE)printk("w");elseprintk(".");if(vma->vm_flags &VM_EXEC)printk("x");elseprintk(".");if(vma->vm_flags &VM_SHARED)printk("s");elseprintk(".");printk("\n");}up_read(&mm->mmap_sem);return0;}staticint __init globalmem_platform_init(void){print_vma();return0;}staticvoid __exit globalmem_platform_exit(void){return;}module_init(globalmem_platform_init);module_exit(globalmem_platform_exit);MODULE_LICENSE("GPL");