使用 mmap64 和 /dev/mem 访问物理内存

static int _STBC_function_open(void)
{
	
	//int fd;
	fdmem = open("/dev/mem", O_RDWR|O_SYNC);  
	if (fdmem == -1)  
	{  
	printf("open dev mem error \n");
	return (-1);  
	}  
	#define KER_STBC_REG_BASE_ADDR			(0xfc040000)

    #define KER_STBC_REG_IPC_ADDR			(KER_STBC_REG_BASE_ADDR + 0x0000)
	//void * tmpres = mmap(NULL, STBC_IPC_MAP_LEN, PROT_READ|PROT_WRITE, MAP_SHARED, fdmem, KER_STBC_REG_IPC_ADDR);  
	void * tmpres = mmap64(NULL, STBC_IPC_MAP_LEN, PROT_READ|PROT_WRITE, MAP_SHARED, fdmem, KER_STBC_REG_IPC_ADDR);   

	
	if( (tmpres == MAP_FAILED) )
	{
		printf("get STBC register user mode address FAIL  %d\n" ,errno);
		return -1;
	}
	else  
	{  
	pstIPCReg=(ST_KER_STBC_IPC_REG*)tmpres;
	printf("ipc Successfull!\n");  
	}  
	

	return 0;

}

你可能感兴趣的:(使用 mmap64 和 /dev/mem 访问物理内存)