سؤال

If I map a page as write only:

int* mem_location = (int*)mmap(nullptr, getpagesize(), 
    PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);

cout << "Read @" << mem_location << ". This should segfault: " 
     << *mem_location << endl;

cout << "doesn't though??" << endl;

why doesn't it segfault on read?

هل كانت مفيدة؟

المحلول

See the man page:

On some hardware architectures (e.g., i386), PROT_WRITE implies PROT_READ.

You should not depend on this behavior.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top