videobuf2相关的videobuf-vmalloc.c中vmalloc内存相关知识(中)

近日游玩看了videobuf2相关的videobuf-vmalloc.c,有些想法,特写下.
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>


int A;           //全局未初始化变量
int B = 0;       //全局初始化为0的变量
int C = 2;       //全局初始化变量


static int D;   //全局静态未初始化变量 
static int E = 0; // 全局静态初始化变量0 
static int F = 4; //全局静态初始化变量
const static int G = 5; // 全局静态初始化变量
const static char H = 6;





int main()
{
   int a; //局部未初始化变量
   int b = 0;// 局部初始化为0的变量
   int c = 2; //局部初始化变量
   static int d ; //局部静态未初始化变量
   static int e = 0; //局部静态初始化为0变量
   static int f = 4; //局部静态初始化变量
   const  int 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();
   }
   
   return 0;
}
#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>


static pid_t pid;

module_param(pid,int,0644);


int print_vma(void)
{
	struct task_struct*task;
	struct mm_struct*mm;
	struct vm_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");
		else 
			  printk(".");
		  
		if(vma->vm_flags &VM_WRITE)
		  printk("w");
		else 
		  printk(".");
	  
	   if(vma->vm_flags &VM_EXEC)
		  printk("x");
		else 
		  printk(".");
	  
	   if(vma->vm_flags &VM_SHARED)
		  printk("s");
		else 
		  printk(".");
	  
		printk("\n");
	}
	
	up_read(&mm->mmap_sem);
	
	return 0;
	
}


static int __init globalmem_platform_init(void)
{
	print_vma();
	return 0;  
	
}

static void __exit globalmem_platform_exit(void)
{  
    
	return ;	
}

module_init(globalmem_platform_init);
module_exit(globalmem_platform_exit);
MODULE_LICENSE("GPL");

在这里插入图片描述在这里插入图片描述在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

今天少内耗10点半睡觉和今天早晚运动

老铁的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值