h p
|
Re: align physical memory
|
h p
03/15/2011 11:28 AM
post84003
|
Re: align physical memory
> Hi,
>
> You have to allocate 4KBytes + 0x1000 for your first example. When you get
> physical address just increase it to be multiples of 0x1000:
>
> ptr = (ptr + 0x1000) & ~0xfff;
>
> In general case:
>
> ptr = ptr - (ptr % align) + align;
>
> --
> Respectfully,
> Oleg
>
Hi Oleg,
Thanks for your reply.
But I have not understand your instruction very clearly yet.
Here is my code:
int ret;
int fd_shm;
void * p_shm;
int memsize;
memsize = 4*1024;
fd_shm = shm_open( "/dev/shm/mysharemem", O_RDWR | O_CREAT, 0777 );
if( fd_shm == -1 ) {
printf( "Create share memory failed:%s\n",strerror( errno ) );
return EXIT_FAILURE;
}
/* Set the memory object's size */
ret = shm_ctl(fd_shm,SHMCTL_ANON | SHMCTL_GLOBAL,0,memsize);
if(ret == -1){
printf( "shm_ctl error: %s\n",strerror( errno ) );
close( fd_shm );
shm_unlink( "/dev/shm/mysharemem");
return EXIT_FAILURE;
}
/* Map the memory object */
p_shm = mmap( 0, memsize,
PROT_READ | PROT_WRITE,
MAP_SHARED, fd_shm, 0 );
if( p_shm == MAP_FAILED ) {
printf("mmap failed: %s\n", strerror( errno ) );
close( fd_shm );
shm_unlink( "/dev/shm/mysharemem" );
return EXIT_FAILURE;
}
ret = mem_offset(p_shm, NOFD, memsize, &shm_addr, 0 );
if(ret != 0){
printf("mem_offset failed: %s\n", strerror( errno ) );
close( fd_shm );
shm_unlink( "/dev/shm/mysharemem" );
return EXIT_FAILURE;
}
So, how can I increase this physical address to be multiples of 0x1000?
Regard,
Zodiac.
|
|
|