unix/modmachine: Handle repeated /dev/mem open errors.
If opening of /dev/mem has failed an `OSError` is appropriately raised, but
the next time `mem8/16/32` is accessed the invalid file descriptor is used
and the program gets a SIGSEGV.
@@ -57,10 +57,11 @@ uintptr_t mod_machine_mem_get_addr(mp_obj_t addr_o, uint align) {
static uintptr_t last_base = (uintptr_t)-1;
static uintptr_t map_page;
if (!fd) {
- fd = open("/dev/mem", O_RDWR | O_SYNC);
- if (fd == -1) {
+ int _fd = open("/dev/mem", O_RDWR | O_SYNC);
+ if (_fd == -1) {
mp_raise_OSError(errno);
}
+ fd = _fd;
}
uintptr_t cur_base = addr & ~MICROPY_PAGE_MASK;
