implemented SIGSEGV

This commit is contained in:
minjaesong
2021-04-23 15:19:20 +09:00
parent 04cafea3c5
commit 48fd10aeed
4 changed files with 29 additions and 8 deletions

1
assets/disk0/segfault.js Normal file
View File

@@ -0,0 +1 @@
sys.poke(66666,66);

View File

@@ -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;
}

View File

@@ -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;