mirror of
https://github.com/corda/corda.git
synced 2025-01-01 02:36:44 +00:00
intercept SIGSEGV and throw NullPointerExceptions
This commit is contained in:
parent
069a760918
commit
f151d85f4e
4
makefile
4
makefile
@ -28,7 +28,7 @@ src = src
|
||||
classpath = classpath
|
||||
test = test
|
||||
|
||||
input = $(test-build)/Misc.class
|
||||
input = List
|
||||
|
||||
build-cxx = g++
|
||||
build-cc = gcc
|
||||
@ -215,7 +215,7 @@ else
|
||||
flags = -cp $(test-build)
|
||||
endif
|
||||
|
||||
args = $(flags) $(call class-name,$(test-build),$(input))
|
||||
args = $(flags) $(input)
|
||||
|
||||
.PHONY: build
|
||||
build: $(interpreter) $(archive) $(classpath-dep) $(test-dep)
|
||||
|
650
src/compile.cpp
650
src/compile.cpp
File diff suppressed because it is too large
Load Diff
541
src/compiler.cpp
541
src/compiler.cpp
File diff suppressed because it is too large
Load Diff
@ -2,6 +2,7 @@
|
||||
#define COMPILER_H
|
||||
|
||||
#include "system.h"
|
||||
#include "zone.h"
|
||||
|
||||
namespace vm {
|
||||
|
||||
@ -20,18 +21,15 @@ class Promise {
|
||||
|
||||
class Compiler {
|
||||
public:
|
||||
class NullHandler {
|
||||
class TraceHandler {
|
||||
public:
|
||||
virtual ~NullHandler() { }
|
||||
virtual ~TraceHandler() { }
|
||||
|
||||
virtual void handleMaybeNull(Promise* address) = 0;
|
||||
virtual void handleTrace(Promise* address) = 0;
|
||||
};
|
||||
|
||||
virtual ~Compiler() { }
|
||||
|
||||
virtual void setNullHandler(NullHandler*) = 0;
|
||||
|
||||
virtual Promise* machineIp() = 0;
|
||||
virtual Promise* machineIp(unsigned logicalIp) = 0;
|
||||
|
||||
virtual Promise* poolAppend(intptr_t) = 0;
|
||||
@ -44,7 +42,7 @@ class Compiler {
|
||||
int displacement = 0,
|
||||
Operand* index = 0,
|
||||
unsigned scale = 1,
|
||||
bool maybeNull = false) = 0;
|
||||
TraceHandler* traceHandler = 0) = 0;
|
||||
|
||||
virtual Operand* stack() = 0;
|
||||
virtual Operand* base() = 0;
|
||||
@ -58,15 +56,17 @@ class Compiler {
|
||||
virtual Operand* label() = 0;
|
||||
virtual void mark(Operand*) = 0;
|
||||
|
||||
virtual Promise* indirectCall
|
||||
(Operand* address, unsigned argumentCount, ...) = 0;
|
||||
virtual void indirectCall
|
||||
(Operand* address, TraceHandler* traceHandler,
|
||||
unsigned argumentCount, ...) = 0;
|
||||
virtual void indirectCallNoReturn
|
||||
(Operand* address, unsigned argumentCount, ...) = 0;
|
||||
virtual Promise* directCall
|
||||
(Operand* address, TraceHandler* traceHandler,
|
||||
unsigned argumentCount, ...) = 0;
|
||||
virtual void directCall
|
||||
(Operand* address, unsigned argumentCount, ...) = 0;
|
||||
|
||||
virtual void call(Operand*) = 0;
|
||||
virtual void alignedCall(Operand*) = 0;
|
||||
virtual void call(Operand*, TraceHandler*) = 0;
|
||||
virtual void alignedCall(Operand*, TraceHandler*) = 0;
|
||||
virtual void return4(Operand*) = 0;
|
||||
virtual void return8(Operand*) = 0;
|
||||
virtual void ret() = 0;
|
||||
@ -141,7 +141,7 @@ class Compiler {
|
||||
};
|
||||
|
||||
Compiler*
|
||||
makeCompiler(System* system, void* indirectCaller);
|
||||
makeCompiler(System* system, Zone* zone, void* indirectCaller);
|
||||
|
||||
} // namespace vm
|
||||
|
||||
|
@ -55,6 +55,12 @@ void
|
||||
handleSignal(int signal, siginfo_t* info, void* context)
|
||||
{
|
||||
if (signal == SIGSEGV) {
|
||||
sigset_t set;
|
||||
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGSEGV);
|
||||
sigprocmask(SIG_UNBLOCK, &set, 0);
|
||||
|
||||
greg_t* registers
|
||||
= static_cast<ucontext_t*>(context)->uc_mcontext.gregs;
|
||||
|
||||
@ -66,8 +72,10 @@ handleSignal(int signal, siginfo_t* info, void* context)
|
||||
if (not handled) {
|
||||
if (oldSegFaultHandler.sa_flags & SA_SIGINFO) {
|
||||
oldSegFaultHandler.sa_sigaction(signal, info, context);
|
||||
} else {
|
||||
} else if (oldSegFaultHandler.sa_handler) {
|
||||
oldSegFaultHandler.sa_handler(signal);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
92
test/NullPointer.java
Normal file
92
test/NullPointer.java
Normal file
@ -0,0 +1,92 @@
|
||||
public class NullPointer {
|
||||
private int x;
|
||||
private Object y;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// invokeinterface
|
||||
try {
|
||||
((Runnable) null).run();
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// invokevirtual
|
||||
try {
|
||||
((Object) null).toString();
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// arraylength
|
||||
try {
|
||||
int a = ((byte[]) null).length;
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// iaload
|
||||
try {
|
||||
int a = ((byte[]) null)[42];
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// aaload
|
||||
try {
|
||||
Object a = ((Object[]) null)[42];
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// getfield (int)
|
||||
try {
|
||||
int a = ((NullPointer) null).x;
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// getfield (Object)
|
||||
try {
|
||||
Object a = ((NullPointer) null).y;
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// iastore
|
||||
try {
|
||||
((byte[]) null)[42] = 42;
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// aastore
|
||||
try {
|
||||
((Object[]) null)[42] = null;
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// putfield (int)
|
||||
try {
|
||||
((NullPointer) null).x = 42;
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// putfield (Object)
|
||||
try {
|
||||
((NullPointer) null).y = null;
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// monitorenter
|
||||
try {
|
||||
synchronized ((Object) null) {
|
||||
int a = 42;
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user