I am trying to use mprotect for the first reading and then writing.
Here is my code
#include <sys/types.h>
On Linux, the results are shown here:
Here is the result for PROT_WRITE :
$ ./main a = 42 a = 24
and for PROT_READ
$ ./main a = 42 Segmentation fault
On Mac OS X 10.7:
Here is the result for PROT_WRITE :
$ ./main a = 42 a = 24
and for PROT_READ
$ ./main [1] 2878 bus error ./main
Until now, I understand that the behavior of OSX / Linux may be different, but I do not understand why PROT_WRITE does not crash the program when reading a value using printf .
Can someone explain this part?
c
Aif
source share