mmap giving Permission Denied error

ratheesh kannoth ratheesh.ksz at gmail.com
Sat Sep 21 09:47:24 EDT 2013


MAP_FIXED could be trying to get a map from  0.


Pls remove this flag and try.


On Sat, Sep 21, 2013 at 6:55 PM, Ravi Teja <ravi2j at gmail.com> wrote:

> Hello all,
>
> I tried mmap'ing to address zero after setting */proc/sys/vm/mmap_min_addr
> * to* 0*, but mmap is giving Permission Denied error.
>
> My C code is as below -
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/mman.h>
>
> int main(void)
> {
> int *ptr = NULL;
>  ptr =
> mmap(0,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0);
> if(ptr == MAP_FAILED)
>  {
> perror("Error in mapping\n");
> exit(1);
>  }
> printf("After mmap\n");
> *ptr = 16;
> printf("Contents of address 0x%x is :: %d\n",ptr,*ptr);
>  return 0;
> }
>
> Am I doing anything wrong here?
>
> Thank you in advance.
>
> Regards,
> Ravi Teja
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130921/99c57118/attachment.html 


More information about the Kernelnewbies mailing list