mmap segmentation fault

Maninya M maninya at gmail.com
Thu Apr 12 18:55:33 UTC 2012


Hello,
I want to allocate memory at a specified address location 'a' of size 'b'.
I wrote code below to do it, but I'm getting a seg fault. How can I solve
this?
How can I get the allocated memory at the required address?

int main()
{
unsigned int *addr,*newaddr;
unsigned long a=134516736,a1;
unsigned long b=3895296;
unsigned long flags =6;
a1=(a&0xffff0000);
printf("%x\n",(void *)a);
newaddr=(unsigned int *)mmap((void *)a,b,6,MAP_ANONYMOUS|MAP_FIXED,-1,0);

if(newaddr==MAP_FAILED)
printf("mmap failed");
else
printf("sucess %x",newaddr);
return 0;
}


Output is
8049000
Segmentation fault


-- 
Maninya


More information about the freebsd-hackers mailing list