void my_signal_handler2(int signum) { ::signal(signum, SIG_DFL); void** f = static_cast<void**>(g_region.get_address()); *f = reinterpret_cast<void*>(1); // Setting flag that shared memory now constains stacktrace. boost::stacktrace::safe_dump_to(f + 1, g_region.get_size() - sizeof(void*)); ::raise(SIGABRT); }
int run_4(const char* argv[]) { using namespace boost::interprocess; { shared_memory_object shm_obj(open_only, "shared_memory", read_write); shm_obj.swap(g_shm); } { mapped_region m(g_shm, read_write, 0, shared_memory_size); m.swap(g_region); } //[getting_started_on_program_restart_shmem void** f = static_cast<void**>(g_region.get_address()); if (*f) { // Checking if memory constains stacktrace. boost::stacktrace::stacktrace st = boost::stacktrace::stacktrace::from_dump(f + 1, g_region.get_size() - sizeof(bool)); std::cout << "Previous run crashed and left trace in shared memory:\n" << st << std::endl; *f = 0; /*<-*/ shared_memory_object::remove("shared_memory"); if (std::string(argv[0]).find("noop") == std::string::npos) { if (!st) { return 43; } } else { if (st) { return 44; } } } else { return 42; /*->*/ } //] return 0; }
int run_3(const char* /*argv*/[]) { using namespace boost::interprocess; { shared_memory_object shm_obj(open_or_create, "shared_memory", read_write); shm_obj.swap(g_shm); } g_shm.truncate(shared_memory_size); { mapped_region m(g_shm, read_write, 0, shared_memory_size); m.swap(g_region); } void** f = static_cast<void**>(g_region.get_address()); *f = 0; ::signal(SIGSEGV, &my_signal_handler2); ::signal(SIGABRT, &my_signal_handler2); foo(5); return 31; }
boost::fusion::map<headers::content_length> generate_body(OutputIterator sink, const boost::interprocess::mapped_region & region) { sink = boost::asio::buffer(region.get_address(), region.get_size()); return boost::fusion::map<headers::content_length>(headers::content_length(region.get_size()));; }