I am trying to go over the memory addresses and see different accessibility of the contiguous memory areas, which are: read-only, read&write and no accessibility. I also have a signal handler that takes care of segmentation fault so the program can continue running.
char* currentAdd;
char readBuf;
for (unsigned int i = 0; i < 0xffffffff, i+=PAGE_SIZE){
currentAdd = (char*)i;
jmpVar = sigsetjmp(env,1); // don't worry about this, it's handled properly
if(jmpVar == 0){
currentMode = MEM_RO;
readBuf = *currentAdd; // always a segmentation fault
// it can never try writing!!
currentMode = MEM_RW;
*currentAdd = readBuf;
}
else{
...
}
}
my program never goes past (readBuf = *currentAdd;), which is sometimes expected but not always. Did I do something wrong?
I tried to start from i=1, to prevent what some people suggested but still it keeps giving me the segmentation fault.
question from:
https://stackoverflow.com/questions/66057393/dereferencing-a-char-always-gives-segmentation-fault 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…