mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-08 04:01:51 +09:00
implemented SIGSEGV
This commit is contained in:
@@ -10,6 +10,10 @@ import java.io.OutputStream
|
||||
import java.util.*
|
||||
import kotlin.math.ceil
|
||||
|
||||
|
||||
class ErrorIllegalAccess(vm: VM, addr: Long) : RuntimeException("Segmentation fault at 0x${addr.toString(16).padStart(8, '0')} on VM id ${vm.id}")
|
||||
|
||||
|
||||
/**
|
||||
* A class representing an instance of a Virtual Machine
|
||||
*/
|
||||
@@ -20,9 +24,6 @@ class VM(
|
||||
val roms: Array<VMProgramRom?> // first ROM must contain the BIOS
|
||||
) {
|
||||
|
||||
class ErrorIllegalAccess(val addr: Long) : RuntimeException("Segmentation fault at 0x${addr.toString(16).padStart(8, '0')}")
|
||||
|
||||
|
||||
val id = java.util.Random().nextInt()
|
||||
|
||||
val memsize = minOf(USER_SPACE_SIZE, _memsize.toLong())
|
||||
@@ -117,10 +118,10 @@ class VM(
|
||||
internal fun poke(addr: Long, value: Byte) {
|
||||
val (memspace, offset) = translateAddr(addr)
|
||||
if (memspace == null)
|
||||
throw ErrorIllegalAccess(addr)
|
||||
throw ErrorIllegalAccess(this, addr)
|
||||
else if (memspace is UnsafePtr) {
|
||||
if (addr >= memspace.size)
|
||||
throw ErrorIllegalAccess(addr)
|
||||
throw ErrorIllegalAccess(this, addr)
|
||||
else
|
||||
memspace.set(offset, value)
|
||||
}
|
||||
@@ -134,7 +135,7 @@ class VM(
|
||||
null
|
||||
else if (memspace is UnsafePtr) {
|
||||
if (addr >= memspace.size)
|
||||
throw ErrorIllegalAccess(addr)
|
||||
throw ErrorIllegalAccess(this, addr)
|
||||
else
|
||||
memspace.get(offset)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user