X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2FRuntime.java;h=8b577372a11aa9d2fc589d32d652ed451bab84ef;hb=b5282b0a1a8ca5212c75623610be6d0483fd35bd;hp=bfe1aaba8c3393f582dcd97da78ce458781d1a6c;hpb=ab9be117467f7459965c61e49749b333678b6e4c;p=nestedvm.git diff --git a/src/org/ibex/nestedvm/Runtime.java b/src/org/ibex/nestedvm/Runtime.java index bfe1aab..8b57737 100644 --- a/src/org/ibex/nestedvm/Runtime.java +++ b/src/org/ibex/nestedvm/Runtime.java @@ -1,10 +1,11 @@ +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + // Copyright 2003 Brian Alliet // Based on org.xwt.imp.MIPS by Adam Megacz // Portions Copyright 2003 Adam Megacz -// FEATURE: Add a patch to gcc that enabled -Wall -Werror by default -// FIXME: Get a hotel for IVME :) - package org.ibex.nestedvm; import org.ibex.nestedvm.util.*; @@ -73,8 +74,8 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { public ExecutionException exitException; /** Table containing all open file descriptors. (Entries are null if the fd is not in use */ - FD[] fds = new FD[OPEN_MAX]; // package-private for UnixRuntime - boolean closeOnExec[] = new boolean[OPEN_MAX]; + FD[] fds; // package-private for UnixRuntime + boolean closeOnExec[]; /** Pointer to a SecurityManager for this process */ SecurityManager sm; @@ -105,6 +106,16 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { /** Subclasses should set the CPUState to the state held in state */ protected abstract void setCPUState(CPUState state); + /** True to enabled a few hacks to better support the win32 console */ + final static boolean win32Hacks; + + static { + String os = Platform.getProperty("os.name"); + String prop = Platform.getProperty("nestedvm.win32hacks"); + if(prop != null) { win32Hacks = Boolean.valueOf(prop).booleanValue(); } + else { win32Hacks = os != null && os.toLowerCase().indexOf("windows") != -1; } + } + protected Object clone() throws CloneNotSupportedException { Runtime r = (Runtime) super.clone(); r._byteBuf = null; @@ -122,7 +133,8 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { return r; } - protected Runtime(int pageSize, int totalPages) { + protected Runtime(int pageSize, int totalPages) { this(pageSize, totalPages,false); } + protected Runtime(int pageSize, int totalPages, boolean exec) { if(pageSize <= 0) throw new IllegalArgumentException("pageSize <= 0"); if(totalPages <= 0) throw new IllegalArgumentException("totalPages <= 0"); if((pageSize&(pageSize-1)) != 0) throw new IllegalArgumentException("pageSize not a power of two"); @@ -160,11 +172,16 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { readPages[i] = writePages[i] = new int[pageSize>>2]; } } - - InputStream stdin = Boolean.valueOf(getSystemProperty("nestedvm.textstdin")).booleanValue() ? new TextInputStream(System.in) : System.in; - addFD(new TerminalFD(stdin)); - addFD(new TerminalFD(System.out)); - addFD(new TerminalFD(System.err)); + + if(!exec) { + fds = new FD[OPEN_MAX]; + closeOnExec = new boolean[OPEN_MAX]; + + InputStream stdin = win32Hacks ? new Win32ConsoleIS(System.in) : System.in; + addFD(new TerminalFD(stdin)); + addFD(new TerminalFD(System.out)); + addFD(new TerminalFD(System.err)); + } } /** Copy everything from src to addr initializing uninitialized pages if required. @@ -484,17 +501,16 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { } /** Calls _execute() (subclass's execute()) and catches exceptions */ - // FEATURE: Have these call kill() so we get a pretty message to stdout private void __execute() { try { _execute(); } catch(FaultException e) { if(STDERR_DIAG) e.printStackTrace(); - sys_exit(128+11); // SIGSEGV + exit(128+11,true); // SIGSEGV exitException = e; } catch(ExecutionException e) { if(STDERR_DIAG) e.printStackTrace(); - sys_exit(128+4); // SIGILL + exit(128+4,true); // SIGILL exitException = e; } } @@ -963,11 +979,21 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { /** Hook for subclasses to do something when the process exits */ void _exited() { } - private int sys_exit(int status) { + void exit(int status, boolean fromSignal) { + if(fromSignal && fds[2] != null) { + try { + byte[] msg = getBytes("Process exited on signal " + (status - 128) + "\n"); + fds[2].write(msg,0,msg.length); + } catch(ErrnoException e) { } + } exitStatus = status; for(int i=0;i