Hi, It seems that mprotect(PROT_NONE) isn't actually doing anything on my 2.6.14 au1550 system. Attached is a simple test that allocates 64K (64K aligned), reads/writes the buffer, mprotect(PROT_NONE) the buffer and then attempts to read and write to the buffer a second time. I expected that writing to a PROT_NONE page would result in a segfault, but on the Au1550 the program runs without faulting. Running the same code on x86 (2.6.13) segfaults as expected. Is there some reason why mprotect() wouldn't work on the Au1550, or is this a bug? Thanks, Clem Taylor
#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <sys/mman.h> #include <string.h> #include <errno.h> int main ( int argc, char *argv [ ] ) { int size = 65536, i, ret; unsigned char *buffer; /* allocate 64K, 64K aligned */ buffer = memalign ( size, size ); if ( buffer == NULL ) { fprintf ( stderr, "memalign() failed.\n" ); return 1; } fprintf ( stderr, "buffer=%p size=%d\n", buffer, size ); /* write and read buffer */ memset ( buffer, 0xAA, size ); for ( i = 0; i < 2; i++ ) fprintf ( stderr, "buffer [ %d ] = 0x%02X\n", i, buffer [ i ] ); /* disable reading and writing */ ret = mprotect ( buffer, size, PROT_NONE ); if ( ret != 0 ) { fprintf ( stderr, "mprotect(%p,%d,PROT_NONE) failed: %s\n", buffer, size, strerror ( errno ) ); return 1; } /* write buffer, should segfault */ memset ( buffer, 0x55, size ); /* read buffer, should segfault */ for ( i = 0; i < 2; i++ ) fprintf ( stderr, "buffer [ %d ] = 0x%02X\n", i, buffer [ i ] ); return 0; }