PO: Illegal memory access in GC
Hi all, I'm running Project Oberon (current version) on my own simulator for the RISC-5 processor. Yesterday I wanted to try Andreas Pirklbauer's Extended Oberon (btw, excellent explanations - thanks for that), but I ran into the very same error as I did when bringing up the original Project Oberon: "Reading from unknown I/O device 15", which was triggered by a read access to location -4. My simulator does monitor all memory accesses for correctness (out-of-bounds, alignment), which I suspect Peter De Wachter's simulator does not. Otherwise, this error should have shown up at many other sites too. The reason for the illegal memory read lies within the garbage collector in module Kernel.Mod: WHILE pvadr # 0 DO SYSTEM.GET(pvadr, p); SYSTEM.GET(p-4, offadr); IF (p >= heapOrg) & (offadr = 0) THEN ... If after the first GET the pointer p is 0 (NIL), the second GET at p-4 becomes an access to memory location -4. This GET should be guarded by the test "IF (p >= heapOrg) ...", either directly in place, or (better) by separating the compound test in the following IF statement. There is a similar sequence with a dangerous GET a few lines further down: IF offset # -1 THEN (*down*) SYSTEM.GET(pos+offset, r); SYSTEM.GET(r-4, offadr); IF (r >= heapOrg) & (offadr = 0) THEN ... As soon as I inserted the tests, the illegal access was gone and Extended Oberon was running. Best regards, Hellwig
Hello Hellwig, Am 15.05.2020 um 10:42 schrieb Hellwig Geisse:
Hi all,
I'm running Project Oberon (current version) on my own simulator for the RISC-5 processor. Yesterday I wanted to try Andreas Pirklbauer's Extended Oberon (btw, excellent explanations - thanks for that), but I ran into the very same error as I did when bringing up the original Project Oberon: "Reading from unknown I/O device 15", which was triggered by a read access to location -4. My simulator does monitor all memory accesses for correctness (out-of-bounds, alignment), which I suspect Peter De Wachter's simulator does not.
His emulator does not check any alignment or out-of-range accesses, just like the real thing. (In case you ever try any of the modules on Tomas Kral's GitHub, you will probably need to fix a few alignment errors in the code, mostly unaligned SYSTEM.GET integer access). I added alignment checks and out-of-range memory checks (in case you use more than 1MB address space) to my emulators, but for IO read I still implemented the original solution which returns 0 for nonpresent IO devices. And I also used this for probing features in emulators. But I never thought of actually checking if there are any illegal accesses to those IO ports. Nevertheless,
The reason for the illegal memory read lies within the garbage collector in module Kernel.Mod:
WHILE pvadr # 0 DO SYSTEM.GET(pvadr, p); SYSTEM.GET(p-4, offadr); IF (p >= heapOrg) & (offadr = 0) THEN ...
If after the first GET the pointer p is 0 (NIL), the second GET at p-4 becomes an access to memory location -4.
this should of course be fixed, since it may interfere with whatever device will use location -4 in the future. Regards, Michael
participants (2)
-
Hellwig Geisse -
Michael Schierl