mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
implemented SIGSEGV
This commit is contained in:
1
assets/disk0/segfault.js
Normal file
1
assets/disk0/segfault.js
Normal file
@@ -0,0 +1 @@
|
||||
sys.poke(66666,66);
|
||||
@@ -6,6 +6,13 @@ function InterruptedException(m) {
|
||||
InterruptedException.prototype = Object.create(Error.prototype);
|
||||
InterruptedException.prototype.name = 'InterruptedException';
|
||||
InterruptedException.prototype.constructor = InterruptedException;
|
||||
function IllegalAccessException(m) {
|
||||
this.message = m;
|
||||
this.stack = (new Error()).stack;
|
||||
};
|
||||
IllegalAccessException.prototype = Object.create(Error.prototype);
|
||||
IllegalAccessException.prototype.name = 'IllegalAccessException';
|
||||
IllegalAccessException.prototype.constructor = IllegalAccessException;
|
||||
class SIG {
|
||||
constructor(name, number) {
|
||||
this.name = "SIG" + name;
|
||||
@@ -155,9 +162,12 @@ var execApp = (cmdsrc, args) => {
|
||||
return status;
|
||||
}
|
||||
catch (e) {
|
||||
serial.printerr(`app execution interrupted -- ${e}\n${e.stack}`);
|
||||
serial.printerr(`app execution interrupted -- ${e}\n${e.stack || "(stack trace unavailable)"}`);
|
||||
//serial.printerr(Object.entries(e));
|
||||
if (e instanceof InterruptedException)
|
||||
return SIGTERM;
|
||||
else if (e instanceof IllegalAccessException || `${e}`.startsWith("net.torvald.tsvm.ErrorIllegalAccess"))
|
||||
return SIGSEGV;
|
||||
else
|
||||
return (undefined == status) ? 0 : status;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ shell.coreutils = {
|
||||
}
|
||||
},
|
||||
dir: function(args) {
|
||||
var pathstr = (args[1] !== undefined) ? args[1] : "\\"+shell_pwd.join("\\");
|
||||
var pathstr = (args[1] !== undefined) ? args[1] : shell.getPwdString();
|
||||
|
||||
// check if path is valid
|
||||
var pathOpened = filesystem.open(CURRENT_DRIVE, pathstr, 'R');
|
||||
@@ -309,6 +309,15 @@ shell.coreutils = {
|
||||
var port = filesystem._toPorts(CURRENT_DRIVE)[0]
|
||||
com.sendMessage(port, "LIST");
|
||||
println(com.pullMessage(port));
|
||||
},
|
||||
cat: function(args) {
|
||||
var pathstr = (args[1] !== undefined) ? args[1] : shell.getPwdString();
|
||||
|
||||
var pathOpened = filesystem.open(CURRENT_DRIVE, pathstr, 'R');
|
||||
if (!pathOpened) { printerrln("File not found"); return; }
|
||||
let contents = filesystem.readAll(CURRENT_DRIVE);
|
||||
// TODO just print out what's there
|
||||
print(contents);
|
||||
}
|
||||
};
|
||||
shell.coreutils.chdir = shell.coreutils.cd;
|
||||
|
||||
@@ -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