#include // for printf() #include // for getpagesize() #include // for mmap() #include #include int main(int argc, char**argv) { // Get the page size. int pageSize = ::getpagesize(); ::printf("pageSize = %d\n", pageSize); // Allocate a page of zeroes in a lonely part of the address space. char* addr = (char*) ::mmap(0, pageSize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); ::printf("addr = %p\n", addr); // Serialize the last few bytes of the page. std::stringstream str; boost::archive::text_oarchive oar(str); oar.save_binary(addr + (pageSize-8), 8); return 0; //These cause an address fault: //oar.save_binary(addr + (pageSize-4), 4); //oar.save_binary(addr + (pageSize-8), 8); //oar.save_binary(addr + (pageSize-16), 16); //oar.save_binary(addr, pageSize); //These don't: //oar.save_binary(addr + (pageSize-9), 8); //oar.save_binary(addr + (pageSize-8), 7); //oar.save_binary(addr + (pageSize-17), 16); //oar.save_binary(addr + (pageSize-16), 15); //oar.save_binary(addr, pageSize-1); }