Assuming some insane person designs an FPGA to produce a SIGBUS signal occasionally on valid memcpy
accesses to mmap
d addresses, as a weird way to communicate up, what is the best way to reset the application state? A starting point seems to be:
static sigjmp_buf jmpbuf;
...
...
siglongjmp(jmpbuf,signum); // inside signal handler
...
...
if(sigsetjmp(jmpbuf,1)) {
std::cout << "Something bad happened, need to reset" << std::endl;
memory.fixThings(); // **How to recover so memcpy does not hang?**
// special actions
} else {
memory.writeMem(offset, dataPtr, size);
}
...
...
memClass::writeMem(uint32_t offset, void* data, uint32_t sizeBytes) {
memcpy(mmapAddr, offset, data, sizeBytes);
}
What I am running into is the program hanging on the memcpy
after the SIGBUS error. I tried unmap
and mmap
again, and do not get errors from that, but memcpy
on the updated address causes memcpy
to hang.