Segmentation fault protection: Difference between revisions

Added Wren
No edit summary
(Added Wren)
Line 20:
 
The 6502 uses memory-mapping to interact with external hardware, and reading/writing a memory location you normally shouldn't because your array indexed out of bounds can cause issues with external hardware, and even on some systems can result in a [[wp:Killer_poke|killer poke]] which can damage certain machines such as the Commodore PET. Memory-mapped ports don't work like normal memory; unlike normal memory, even ''reading'' a memory-mapped port can affect its contents, or affect the contents of other ports that are related to that hardware. (This isn't a property of the 6502 itself, but of the hardware connected to it.)
 
=={{header|Wren}}==
In theory and barring bugs in the language's implementation Wren code should never segfault. Array bounds are always checked, memory allocation and reclamation is automatic and there is no support for pointers at all.
 
So the example code below compiles:
<lang ecmascript>var myArray = [1,2, 3, 4, 5, 6]
var myVariable = myArray[500]</lang>
but if you try to run it you get a "Subscript out of bounds" error.
 
However, when Wren is embedded in a C host, segfaults are certainly possible and there is no protection against them whatsoever. As Wren's virtual machine is not re-entrant a common source of segfaults is trying to treat it as if it was!
9,476

edits