メモリの各ページで単一のメモリアドオンをスキャンして、読み取り可能/読み取り/書き込み可能/なしを確認する小さなプログラムを作成しています。
注: エラーの原因はシグナル処理であるため、コードの一部は示していません。
addysを通過するためのこのwhileループ
char * currAddy;
currAddy = (char*)0x00000000;
while(1){
int readWrite = read_write(currAddy);
printf("Chunk val returned %i\n", readWrite);
if(currAddy == (char*)0xfffff000)
break;
currAddy += pageSize;
}
シグナルを処理するための残りの部分
int read_write (char * currAddy)
{
myRead = 0;
myWrite = 0;
/*
myRead = 0 & myWrite = 0 -> NOT A CHUNK -> RW = -1
myRead = 0 & myWrite = 1 -> NOT POSSIBLE
myRead = 1 & myWrite = 0 -> RW = 0
myRead = 1 & myWrite = 1 -> RW = 1
*/
if (sigsetjmp(jumpbuf, 1) == 0){
//try and read
char test = *currAddy;
myRead = 1;
//try and write
*currAddy = 'a';
myWrite = 1;
}else{
//SIGSEGV while reading
if (myRead == 0)
return -1;
//SIGSEGV while writing
if (myRead == 1 && myWrite == 0)
return 0;
printf("Inside setjmp\n");
}
printf("Below the sigjmp\n");
sleep(1);
//return 1 because we can both read and write to this position
//doesnt appear to run though -- HELP HERE?
return 1;
}
ここで信号が処理されます
void handler (int sig)
{
siglongjmp(jumpbuf, 1);
}
これを実行すると、出力は次のようになります。
Chunk val returned -1
Chunk val returned -1
Chunk val returned -1
Chunk val returned 0
Chunk val returned 0
Below the sigjmp
Inside setjmp
Below the sigjmp
Below the sigjmp
Inside setjmp
Below the sigjmp
Below the sigjmp
Inside setjmp
.........
編集: 1 が返されない理由がわかりませんか? また、「Below the sigjmp」が 2 回表示されるのも奇妙です。どんな助け/ヒントも大歓迎です!