diff options
author | Yonatan Goldschmidt <yon.goldschmidt@gmail.com> | 2019-02-10 00:36:08 +0200 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-02-12 15:29:11 +1100 |
commit | 66f0afc91d22bb414d8247b795ce37743bd3f39d (patch) | |
tree | 3b593f561d5022e252b4210e7d75338bbc98ded8 | |
parent | 812969d615e130bef7e525553dbb7b01c27191ea (diff) |
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.
-rw-r--r-- | ports/unix/modmachine.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/ports/unix/modmachine.c b/ports/unix/modmachine.c index 48dddec0a..e2c44f94c 100644 --- a/ports/unix/modmachine.c +++ b/ports/unix/modmachine.c @@ -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; |