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.
pull/4493/head
Yonatan Goldschmidt 2019-02-10 00:36:08 +02:00 zatwierdzone przez Damien George
rodzic 812969d615
commit 66f0afc91d
1 zmienionych plików z 3 dodań i 2 usunięć

Wyświetl plik

@ -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;