From dbfda580a7e1b6a38ca4f4d934e79a11096fbf82 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 23 Apr 2021 21:57:02 +0900 Subject: [PATCH] SIGTERM simulation by hitting SHIFT-CTRL-T-R --- assets/disk0/infinite.js | 4 +++ assets/disk0/inttest.js | 2 +- assets/disk0/tvdos/TVDOS.SYS | 19 ++--------- assets/disk0/tvdos/bin/command.js | 32 +++++++++++-------- .../tsvm/peripheral/CharacterLCDdisplay.kt | 2 ++ src/net/torvald/tsvm/peripheral/IOSpace.kt | 14 ++++++++ 6 files changed, 42 insertions(+), 31 deletions(-) create mode 100644 assets/disk0/infinite.js diff --git a/assets/disk0/infinite.js b/assets/disk0/infinite.js new file mode 100644 index 0000000..65d21fa --- /dev/null +++ b/assets/disk0/infinite.js @@ -0,0 +1,4 @@ +while (true) { + print(((Math.random() * 2)|0) ? '\\' : '/'); + sys.spin(); +} \ No newline at end of file diff --git a/assets/disk0/inttest.js b/assets/disk0/inttest.js index 4ddf188..8460474 100644 --- a/assets/disk0/inttest.js +++ b/assets/disk0/inttest.js @@ -1 +1 @@ -throw new InterruptedException("lol"); +throw new InterruptedException(); diff --git a/assets/disk0/tvdos/TVDOS.SYS b/assets/disk0/tvdos/TVDOS.SYS index b9dbc29..6da8ace 100644 --- a/assets/disk0/tvdos/TVDOS.SYS +++ b/assets/disk0/tvdos/TVDOS.SYS @@ -163,7 +163,7 @@ let injectIntChk = (s, n) => { let k = s .replace(/while *\([^\n]+\) *{/, "$& "+n+"();") .replace(/for *\([^\n]+\) *{/, "$& "+n+"();"); - serial.println(k); + //serial.println(k); return k; } @@ -178,22 +178,7 @@ var execApp = (cmdsrc, args) => { `var _appStub=function(exec_args){${injectIntChk(cmdsrc, intchkFunName)}\n};` + `_appStub`); // making 'exec_args' a app-level global - var status = 0; - - try { - status = execAppPrg(args); - return status; - } - catch (e) { - 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; - } + return execAppPrg(args); } /////////////////////////////////////////////////////////////////////////////// diff --git a/assets/disk0/tvdos/bin/command.js b/assets/disk0/tvdos/bin/command.js index 7ec061a..87469ba 100644 --- a/assets/disk0/tvdos/bin/command.js +++ b/assets/disk0/tvdos/bin/command.js @@ -447,7 +447,8 @@ if (goInteractive) { var cmdbuf = ""; while (true) { - var key = con.getch(); + let key = con.getch(); + let gotError = false; // printable chars if (key >= 32 && key <= 126) { @@ -466,22 +467,27 @@ if (goInteractive) { try { errorlevel = 0; // reset the number errorlevel = shell.execute(cmdbuf); - let rawE = errorlevel; - - if (errorlevel instanceof SIG) - errorlevel = errorlevel.name; - else if (errorlevel == undefined || (typeof errorlevel.trim == "function" && errorlevel.trim().length == 0) || isNaN(errorlevel)) - errorlevel = 0; - - serial.printerr(`errorlevel: ${errorlevel} (raw: ${rawE})`); } catch (e) { - printerrln("\n"+(e.stack || e)); - //if (errorlevel === 0 || isNaN(errorlevel)) { - // errorlevel = 1; // generic failure - //} + gotError = true; + + serial.printerr(`[command.js] program quit with ${e}:\n${e.stack || '(stack trace unavailable)'}`); + + if (`${e}`.startsWith("InterruptedException")) + errorlevel = SIGTERM.name; + else if (e instanceof IllegalAccessException || `${e}`.startsWith("net.torvald.tsvm.ErrorIllegalAccess")) + errorlevel = SIGSEGV.name; + // exception catched means something went wrong, so if errorlevel is found to be zero, force set to 1. + else + errorlevel = 1; } finally { + // sometimes no-error program may return nothing as the errorlevel; force set to 0 then. + if (!gotError && (errorlevel == undefined || (typeof errorlevel.trim == "function" && errorlevel.trim().length == 0) || isNaN(errorlevel))) + errorlevel = 0; + + serial.printerr(`errorlevel: ${errorlevel}`); + if (cmdbuf.trim().length > 0) cmdHistory.push(cmdbuf); diff --git a/src/net/torvald/tsvm/peripheral/CharacterLCDdisplay.kt b/src/net/torvald/tsvm/peripheral/CharacterLCDdisplay.kt index be69254..49683b9 100644 --- a/src/net/torvald/tsvm/peripheral/CharacterLCDdisplay.kt +++ b/src/net/torvald/tsvm/peripheral/CharacterLCDdisplay.kt @@ -70,6 +70,8 @@ class CharacterLCDdisplay(vm: VM) : GraphicsAdapter(vm, AdapterConfig( } } + + fun currentTimeInMills(): Long { vm.poke(-69, -1) var r = 0L diff --git a/src/net/torvald/tsvm/peripheral/IOSpace.kt b/src/net/torvald/tsvm/peripheral/IOSpace.kt index ff9a2c3..7c9d8cb 100644 --- a/src/net/torvald/tsvm/peripheral/IOSpace.kt +++ b/src/net/torvald/tsvm/peripheral/IOSpace.kt @@ -252,6 +252,20 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor { RTClatched = false rtc = vm.worldInterface.currentTimeInMills() } + + // SIGTERM key combination: Ctrl+Shift+T+R + vm.stopDown = Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT) && + Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT) && + Gdx.input.isKeyPressed(Input.Keys.T) && + Gdx.input.isKeyPressed(Input.Keys.R) + if (vm.stopDown) println("[VM-${vm.id}] SIGTERM requested") + + // RESET key combination: Ctrl+Shift+R+S + vm.resetDown = Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT) && + Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT) && + Gdx.input.isKeyPressed(Input.Keys.R) && + Gdx.input.isKeyPressed(Input.Keys.S) + if (vm.resetDown) println("[VM-${vm.id}] RESET requested") } override fun touchUp(p0: Int, p1: Int, p2: Int, p3: Int): Boolean {