关于mprotect()
关于mprotect函数,看到有如下写法:
buf = ( char * )malloc( 1024 + 8191 );
if ( !buf ){
printf( "malloc error\n" );
return;
}
/*
* Align to a multiple of PAGESIZE, assumed to be a power of two
*/
buf = ( char * )( ( ( unsigned int )buf + 8191 ) & ~8191 );
c = buf[77];
buf[77] = c;
printf( "ok\n" );
/*
* Mark the buffer read-only.
*/
if ( mprotect( buf, 1024, PROT_NONE) ){
printf( "mprotect error\n" );
return;
}
/*
* Write error, program dies on SIGSEGV
*/
c = *buf; /* 运行时,这里会core */
这里的:
buf = ( char * )( ( ( unsigned int )buf + 8191 ) & ~8191 );
这条语句,什么意思啊?