Date: Thu, 12 Apr 2012 21:37:09 +0200 From: Jilles Tjoelker <jilles@stack.nl> To: Maninya M <maninya@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: mmap segmentation fault Message-ID: <20120412193709.GA7521@stack.nl> In-Reply-To: <CAC46K3=LbSYFqCPSXO%2BwhZK6mpTwW9YQXWDqq5UwBzPQGAFeVg@mail.gmail.com> References: <CAC46K3=LbSYFqCPSXO%2BwhZK6mpTwW9YQXWDqq5UwBzPQGAFeVg@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Apr 13, 2012 at 12:25:32AM +0530, Maninya M wrote: > 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 If this is i386, you're mapping onto the executable itself. If you really want to map something there, you will have to move your code somewhere else or manipulate your executable to contain a suitable memory area at the required address. Try, for example, procstat -v $$ -- Jilles Tjoelker
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120412193709.GA7521>