<div dir="ltr">Hello all,<div><br></div><div>I tried mmap'ing to address zero after setting <b>/proc/sys/vm/mmap_min_addr</b> to<b> 0</b>, but mmap is giving Permission Denied error.</div><div><br></div><div>My C code is as below - </div>
<div><br></div><div><div>#include <stdio.h></div><div>#include <stdlib.h></div><div>#include <sys/mman.h></div><div><br></div><div>int main(void)</div><div>{</div><div><span class="" style="white-space:pre">        </span>int *ptr = NULL;</div>
<div><span class="" style="white-space:pre">        </span>ptr = mmap(0,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0);</div><div><span class="" style="white-space:pre">        </span>if(ptr == MAP_FAILED)</div><div>
<span class="" style="white-space:pre">        </span>{</div><div><span class="" style="white-space:pre">                </span>perror("Error in mapping\n");</div><div><span class="" style="white-space:pre">                </span>exit(1);</div><div>
<span class="" style="white-space:pre">        </span>}</div><div><span class="" style="white-space:pre">        </span>printf("After mmap\n");</div><div><span class="" style="white-space:pre">        </span>*ptr = 16;</div><div><span class="" style="white-space:pre">        </span>printf("Contents of address 0x%x is :: %d\n",ptr,*ptr);</div>
<div><span class="" style="white-space:pre">        </span>return 0;</div><div>}</div></div><div><br></div><div>Am I doing anything wrong here?</div><div><br></div><div>Thank you in advance.</div><div><br></div><div>Regards,</div>
<div>Ravi Teja</div></div>