From 5ffdfecdc2215032e852a499c82bb9c8f8724391 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Fri, 7 Feb 2014 14:24:56 -0700 Subject: [PATCH 1/5] remove vm from code paths, to match namespacing --- include/avian/{vm => }/codegen/architecture.h | 0 include/avian/{vm => }/codegen/assembler.h | 6 +++--- include/avian/{vm => }/codegen/compiler.h | 2 +- include/avian/{vm => }/codegen/lir-ops.inc.cpp | 0 include/avian/{vm => }/codegen/lir.h | 0 include/avian/{vm => }/codegen/promise.h | 0 include/avian/{vm => }/codegen/registers.h | 0 include/avian/{vm => }/codegen/runtime.h | 0 include/avian/{vm => }/codegen/targets.h | 0 include/avian/{vm => }/heap/heap.h | 2 +- include/avian/{vm => }/system/system.h | 0 makefile | 4 ++-- src/avian/alloc-vector.h | 2 +- src/avian/finder.h | 2 +- src/avian/lzma-util.h | 2 +- src/avian/lzma.h | 2 +- src/avian/machine.h | 4 ++-- src/avian/process.h | 2 +- src/avian/processor.h | 4 ++-- src/avian/zone.h | 2 +- src/codegen/compiler.cpp | 8 ++++---- src/codegen/compiler/context.cpp | 2 +- src/codegen/compiler/context.h | 4 ++-- src/codegen/compiler/frame.cpp | 2 +- src/codegen/compiler/regalloc.h | 6 +++--- src/codegen/compiler/site.h | 2 +- src/codegen/compiler/value.h | 6 +++--- src/codegen/registers.cpp | 2 +- src/codegen/target/arm/assembler.cpp | 6 +++--- src/codegen/target/arm/block.h | 4 ++-- src/codegen/target/arm/context.h | 4 ++-- src/codegen/target/arm/encode.h | 4 ++-- src/codegen/target/arm/fixup.h | 4 ++-- src/codegen/target/arm/multimethod.h | 4 ++-- src/codegen/target/arm/registers.h | 4 ++-- src/codegen/target/powerpc/assembler.cpp | 6 +++--- src/codegen/target/powerpc/context.h | 2 +- src/codegen/target/x86/assembler.cpp | 12 ++++++------ src/codegen/target/x86/block.cpp | 2 +- src/codegen/target/x86/block.h | 2 +- src/codegen/target/x86/context.h | 6 +++--- src/codegen/target/x86/detect.h | 2 +- src/codegen/target/x86/encode.cpp | 4 ++-- src/codegen/target/x86/encode.h | 2 +- src/codegen/target/x86/fixup.cpp | 2 +- src/codegen/target/x86/fixup.h | 2 +- src/codegen/target/x86/multimethod.cpp | 2 +- src/codegen/target/x86/multimethod.h | 2 +- src/codegen/target/x86/operations.cpp | 4 ++-- src/codegen/target/x86/operations.h | 2 +- src/codegen/targets.cpp | 2 +- src/compile.cpp | 12 ++++++------ src/finder.cpp | 2 +- src/heap/heap.cpp | 4 ++-- src/interpret.cpp | 2 +- src/main.cpp | 2 +- src/{vm => }/system/posix.cpp | 2 +- src/{vm => }/system/windows.cpp | 2 +- src/tools/audit-codegen/main.cpp | 12 ++++++------ src/tools/bootimage-generator/main.cpp | 6 +++--- unittest/codegen/assembler-test.cpp | 12 ++++++------ unittest/codegen/registers-test.cpp | 2 +- 62 files changed, 104 insertions(+), 104 deletions(-) rename include/avian/{vm => }/codegen/architecture.h (100%) rename include/avian/{vm => }/codegen/assembler.h (96%) rename include/avian/{vm => }/codegen/compiler.h (99%) rename include/avian/{vm => }/codegen/lir-ops.inc.cpp (100%) rename include/avian/{vm => }/codegen/lir.h (100%) rename include/avian/{vm => }/codegen/promise.h (100%) rename include/avian/{vm => }/codegen/registers.h (100%) rename include/avian/{vm => }/codegen/runtime.h (100%) rename include/avian/{vm => }/codegen/targets.h (100%) rename include/avian/{vm => }/heap/heap.h (98%) rename include/avian/{vm => }/system/system.h (100%) rename src/{vm => }/system/posix.cpp (99%) rename src/{vm => }/system/windows.cpp (99%) diff --git a/include/avian/vm/codegen/architecture.h b/include/avian/codegen/architecture.h similarity index 100% rename from include/avian/vm/codegen/architecture.h rename to include/avian/codegen/architecture.h diff --git a/include/avian/vm/codegen/assembler.h b/include/avian/codegen/assembler.h similarity index 96% rename from include/avian/vm/codegen/assembler.h rename to include/avian/codegen/assembler.h index 1c541a4796..efece1ab14 100644 --- a/include/avian/vm/codegen/assembler.h +++ b/include/avian/codegen/assembler.h @@ -11,11 +11,11 @@ #ifndef AVIAN_CODEGEN_ASSEMBLER_H #define AVIAN_CODEGEN_ASSEMBLER_H -#include +#include #include "avian/zone.h" -#include -#include +#include +#include namespace avian { namespace codegen { diff --git a/include/avian/vm/codegen/compiler.h b/include/avian/codegen/compiler.h similarity index 99% rename from include/avian/vm/codegen/compiler.h rename to include/avian/codegen/compiler.h index 25de4024f3..99fc426408 100644 --- a/include/avian/vm/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -11,7 +11,7 @@ #ifndef AVIAN_CODEGEN_COMPILER_H #define AVIAN_CODEGEN_COMPILER_H -#include +#include #include "avian/zone.h" #include "assembler.h" diff --git a/include/avian/vm/codegen/lir-ops.inc.cpp b/include/avian/codegen/lir-ops.inc.cpp similarity index 100% rename from include/avian/vm/codegen/lir-ops.inc.cpp rename to include/avian/codegen/lir-ops.inc.cpp diff --git a/include/avian/vm/codegen/lir.h b/include/avian/codegen/lir.h similarity index 100% rename from include/avian/vm/codegen/lir.h rename to include/avian/codegen/lir.h diff --git a/include/avian/vm/codegen/promise.h b/include/avian/codegen/promise.h similarity index 100% rename from include/avian/vm/codegen/promise.h rename to include/avian/codegen/promise.h diff --git a/include/avian/vm/codegen/registers.h b/include/avian/codegen/registers.h similarity index 100% rename from include/avian/vm/codegen/registers.h rename to include/avian/codegen/registers.h diff --git a/include/avian/vm/codegen/runtime.h b/include/avian/codegen/runtime.h similarity index 100% rename from include/avian/vm/codegen/runtime.h rename to include/avian/codegen/runtime.h diff --git a/include/avian/vm/codegen/targets.h b/include/avian/codegen/targets.h similarity index 100% rename from include/avian/vm/codegen/targets.h rename to include/avian/codegen/targets.h diff --git a/include/avian/vm/heap/heap.h b/include/avian/heap/heap.h similarity index 98% rename from include/avian/vm/heap/heap.h rename to include/avian/heap/heap.h index 51b9808b08..bd09c881f8 100644 --- a/include/avian/vm/heap/heap.h +++ b/include/avian/heap/heap.h @@ -11,7 +11,7 @@ #ifndef HEAP_H #define HEAP_H -#include +#include #include "avian/allocator.h" namespace vm { diff --git a/include/avian/vm/system/system.h b/include/avian/system/system.h similarity index 100% rename from include/avian/vm/system/system.h rename to include/avian/system/system.h diff --git a/makefile b/makefile index 0adfb9b2f8..0781e3b0b4 100755 --- a/makefile +++ b/makefile @@ -1108,7 +1108,7 @@ vm-depends := $(generated-code) \ $(shell find src include -name '*.h' -or -name '*.inc.cpp') vm-sources = \ - $(src)/vm/system/$(system).cpp \ + $(src)/system/$(system).cpp \ $(src)/finder.cpp \ $(src)/machine.cpp \ $(src)/util.cpp \ @@ -1239,7 +1239,7 @@ boot-object = $(build)/boot.o generator-depends := $(wildcard $(src)/*.h) generator-sources = \ $(src)/tools/type-generator/main.cpp \ - $(src)/vm/system/$(build-system).cpp \ + $(src)/system/$(build-system).cpp \ $(src)/finder.cpp ifneq ($(lzma),) diff --git a/src/avian/alloc-vector.h b/src/avian/alloc-vector.h index 88a544f010..fe486a11ca 100644 --- a/src/avian/alloc-vector.h +++ b/src/avian/alloc-vector.h @@ -11,7 +11,7 @@ #ifndef VECTOR_H #define VECTOR_H -#include +#include #include "avian/target.h" #include diff --git a/src/avian/finder.h b/src/avian/finder.h index 08d2c061ca..ff5a3db917 100644 --- a/src/avian/finder.h +++ b/src/avian/finder.h @@ -12,7 +12,7 @@ #define FINDER_H #include "avian/common.h" -#include +#include #include "avian/allocator.h" namespace vm { diff --git a/src/avian/lzma-util.h b/src/avian/lzma-util.h index 304c892f08..29aa97c0ab 100644 --- a/src/avian/lzma-util.h +++ b/src/avian/lzma-util.h @@ -13,7 +13,7 @@ #include "avian/lzma.h" #include "C/Types.h" -#include +#include #include "avian/allocator.h" namespace vm { diff --git a/src/avian/lzma.h b/src/avian/lzma.h index 859d361eef..5cdde89989 100644 --- a/src/avian/lzma.h +++ b/src/avian/lzma.h @@ -11,7 +11,7 @@ #ifndef LZMA_H #define LZMA_H -#include +#include #include "avian/allocator.h" namespace vm { diff --git a/src/avian/machine.h b/src/avian/machine.h index a2d05facd8..f466979216 100644 --- a/src/avian/machine.h +++ b/src/avian/machine.h @@ -13,8 +13,8 @@ #include "avian/common.h" #include "java-common.h" -#include -#include +#include +#include #include "avian/finder.h" #include "avian/processor.h" #include "avian/constants.h" diff --git a/src/avian/process.h b/src/avian/process.h index 6ebed9e6b1..a808b08759 100644 --- a/src/avian/process.h +++ b/src/avian/process.h @@ -12,7 +12,7 @@ #define PROCESS_H #include "avian/common.h" -#include +#include #include "avian/machine.h" #include "avian/constants.h" diff --git a/src/avian/processor.h b/src/avian/processor.h index 6c0740c1bd..40e02f43aa 100644 --- a/src/avian/processor.h +++ b/src/avian/processor.h @@ -12,8 +12,8 @@ #define PROCESSOR_H #include "avian/common.h" -#include -#include +#include +#include #include "bootimage.h" #include "avian/heapwalk.h" #include "avian/zone.h" diff --git a/src/avian/zone.h b/src/avian/zone.h index 753e40fcf8..e21841f2ea 100644 --- a/src/avian/zone.h +++ b/src/avian/zone.h @@ -11,7 +11,7 @@ #ifndef ZONE_H #define ZONE_H -#include +#include #include "avian/allocator.h" #include diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 07a0890951..f6ae9d0b89 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -12,10 +12,10 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "codegen/compiler/regalloc.h" #include "codegen/compiler/context.h" diff --git a/src/codegen/compiler/context.cpp b/src/codegen/compiler/context.cpp index 116c452ec8..57245f684b 100644 --- a/src/codegen/compiler/context.cpp +++ b/src/codegen/compiler/context.cpp @@ -11,7 +11,7 @@ #include "codegen/compiler/context.h" #include "codegen/compiler/resource.h" -#include +#include namespace avian { namespace codegen { diff --git a/src/codegen/compiler/context.h b/src/codegen/compiler/context.h index 61a5e7bee8..ede8da5513 100644 --- a/src/codegen/compiler/context.h +++ b/src/codegen/compiler/context.h @@ -11,8 +11,8 @@ #ifndef AVIAN_CODEGEN_COMPILER_CONTEXT_H #define AVIAN_CODEGEN_COMPILER_CONTEXT_H -#include -#include +#include +#include #include #include "regalloc.h" diff --git a/src/codegen/compiler/frame.cpp b/src/codegen/compiler/frame.cpp index 12a29577a3..1732395484 100644 --- a/src/codegen/compiler/frame.cpp +++ b/src/codegen/compiler/frame.cpp @@ -13,7 +13,7 @@ #include "codegen/compiler/context.h" #include "codegen/compiler/frame.h" -#include +#include namespace avian { namespace codegen { diff --git a/src/codegen/compiler/regalloc.h b/src/codegen/compiler/regalloc.h index 17163ae906..0ac60dd1a2 100644 --- a/src/codegen/compiler/regalloc.h +++ b/src/codegen/compiler/regalloc.h @@ -13,8 +13,8 @@ #include "avian/common.h" -#include -#include +#include +#include namespace avian { @@ -108,4 +108,4 @@ pickTarget(Context* c, Read* read, bool intersectRead, } // namespace codegen } // namespace avian -#endif // AVIAN_CODEGEN_COMPILER_REGALLOC_H \ No newline at end of file +#endif // AVIAN_CODEGEN_COMPILER_REGALLOC_H diff --git a/src/codegen/compiler/site.h b/src/codegen/compiler/site.h index 50e80a547d..461ff14f21 100644 --- a/src/codegen/compiler/site.h +++ b/src/codegen/compiler/site.h @@ -11,7 +11,7 @@ #ifndef AVIAN_CODEGEN_COMPILER_SITE_H #define AVIAN_CODEGEN_COMPILER_SITE_H -#include +#include #include "codegen/compiler/value.h" #include "codegen/compiler/context.h" diff --git a/src/codegen/compiler/value.h b/src/codegen/compiler/value.h index e9ff43f19b..364621cf1d 100644 --- a/src/codegen/compiler/value.h +++ b/src/codegen/compiler/value.h @@ -11,8 +11,8 @@ #ifndef AVIAN_CODEGEN_COMPILER_VALUE_H #define AVIAN_CODEGEN_COMPILER_VALUE_H -#include -#include +#include +#include namespace avian { namespace codegen { @@ -81,4 +81,4 @@ Value* value(Context* c, lir::ValueType type, Site* site = 0, Site* target = 0); } // namespace codegen } // namespace avian -#endif // AVIAN_CODEGEN_COMPILER_VALUE_H \ No newline at end of file +#endif // AVIAN_CODEGEN_COMPILER_VALUE_H diff --git a/src/codegen/registers.cpp b/src/codegen/registers.cpp index 7a8d5daad2..aeca098591 100644 --- a/src/codegen/registers.cpp +++ b/src/codegen/registers.cpp @@ -8,7 +8,7 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include +#include namespace avian { namespace codegen { diff --git a/src/codegen/target/arm/assembler.cpp b/src/codegen/target/arm/assembler.cpp index 2ef6db5b6e..41b18c2d9b 100644 --- a/src/codegen/target/arm/assembler.cpp +++ b/src/codegen/target/arm/assembler.cpp @@ -10,9 +10,9 @@ #include -#include -#include -#include +#include +#include +#include #include "context.h" #include "block.h" diff --git a/src/codegen/target/arm/block.h b/src/codegen/target/arm/block.h index 8fa1aec1d3..e4117a1147 100644 --- a/src/codegen/target/arm/block.h +++ b/src/codegen/target/arm/block.h @@ -11,8 +11,8 @@ #ifndef AVIAN_CODEGEN_ASSEMBLER_ARM_BLOCK_H #define AVIAN_CODEGEN_ASSEMBLER_ARM_BLOCK_H -#include -#include +#include +#include namespace avian { namespace codegen { diff --git a/src/codegen/target/arm/context.h b/src/codegen/target/arm/context.h index 19c45acc16..791ac3ebf7 100644 --- a/src/codegen/target/arm/context.h +++ b/src/codegen/target/arm/context.h @@ -11,8 +11,8 @@ #ifndef AVIAN_CODEGEN_ASSEMBLER_ARM_CONTEXT_H #define AVIAN_CODEGEN_ASSEMBLER_ARM_CONTEXT_H -#include -#include +#include +#include #include "avian/alloc-vector.h" namespace vm { diff --git a/src/codegen/target/arm/encode.h b/src/codegen/target/arm/encode.h index 857148b837..38abbfe8c7 100644 --- a/src/codegen/target/arm/encode.h +++ b/src/codegen/target/arm/encode.h @@ -11,8 +11,8 @@ #ifndef AVIAN_CODEGEN_ASSEMBLER_ARM_ENCODE_H #define AVIAN_CODEGEN_ASSEMBLER_ARM_ENCODE_H -#include -#include +#include +#include namespace avian { namespace codegen { diff --git a/src/codegen/target/arm/fixup.h b/src/codegen/target/arm/fixup.h index 2a5cf8cf28..c82495a881 100644 --- a/src/codegen/target/arm/fixup.h +++ b/src/codegen/target/arm/fixup.h @@ -13,8 +13,8 @@ #include "avian/target.h" -#include -#include +#include +#include #include "avian/alloc-vector.h" namespace vm { diff --git a/src/codegen/target/arm/multimethod.h b/src/codegen/target/arm/multimethod.h index 9e0ef50827..01f90731a7 100644 --- a/src/codegen/target/arm/multimethod.h +++ b/src/codegen/target/arm/multimethod.h @@ -11,8 +11,8 @@ #ifndef AVIAN_CODEGEN_ASSEMBLER_ARM_MULTIMETHOD_H #define AVIAN_CODEGEN_ASSEMBLER_ARM_MULTIMETHOD_H -#include -#include +#include +#include #define CAST1(x) reinterpret_cast(x) #define CAST2(x) reinterpret_cast(x) diff --git a/src/codegen/target/arm/registers.h b/src/codegen/target/arm/registers.h index 50695b6af3..cb3b3bec8d 100644 --- a/src/codegen/target/arm/registers.h +++ b/src/codegen/target/arm/registers.h @@ -11,8 +11,8 @@ #ifndef AVIAN_CODEGEN_ASSEMBLER_ARM_REGISTERS_H #define AVIAN_CODEGEN_ASSEMBLER_ARM_REGISTERS_H -#include -#include +#include +#include namespace avian { namespace codegen { diff --git a/src/codegen/target/powerpc/assembler.cpp b/src/codegen/target/powerpc/assembler.cpp index 20f85bb778..cff041d38c 100644 --- a/src/codegen/target/powerpc/assembler.cpp +++ b/src/codegen/target/powerpc/assembler.cpp @@ -8,9 +8,9 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include -#include -#include +#include +#include +#include #include "avian/alloc-vector.h" #include diff --git a/src/codegen/target/powerpc/context.h b/src/codegen/target/powerpc/context.h index e4bd0a0147..d0467f759b 100644 --- a/src/codegen/target/powerpc/context.h +++ b/src/codegen/target/powerpc/context.h @@ -11,7 +11,7 @@ #ifndef AVIAN_CODEGEN_ASSEMBLER_POWERPC_CONTEXT_H #define AVIAN_CODEGEN_ASSEMBLER_POWERPC_CONTEXT_H -#include +#include #include "avian/alloc-vector.h" #ifdef powerpc diff --git a/src/codegen/target/x86/assembler.cpp b/src/codegen/target/x86/assembler.cpp index 0c064c652d..83519bb083 100644 --- a/src/codegen/target/x86/assembler.cpp +++ b/src/codegen/target/x86/assembler.cpp @@ -22,13 +22,13 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#include +#include #include "context.h" #include "block.h" diff --git a/src/codegen/target/x86/block.cpp b/src/codegen/target/x86/block.cpp index a7660ee99a..3043a99b86 100644 --- a/src/codegen/target/x86/block.cpp +++ b/src/codegen/target/x86/block.cpp @@ -10,7 +10,7 @@ #include "block.h" -#include +#include namespace avian { namespace codegen { diff --git a/src/codegen/target/x86/block.h b/src/codegen/target/x86/block.h index 82ecfc5e56..a9c179a5e6 100644 --- a/src/codegen/target/x86/block.h +++ b/src/codegen/target/x86/block.h @@ -11,7 +11,7 @@ #ifndef AVIAN_CODEGEN_ASSEMBLER_X86_BLOCK_H #define AVIAN_CODEGEN_ASSEMBLER_X86_BLOCK_H -#include +#include namespace avian { namespace codegen { diff --git a/src/codegen/target/x86/context.h b/src/codegen/target/x86/context.h index f51b3d8ff0..79e94a2211 100644 --- a/src/codegen/target/x86/context.h +++ b/src/codegen/target/x86/context.h @@ -19,10 +19,10 @@ #include "avian/alloc-vector.h" -#include -#include +#include +#include -#include +#include namespace vm { class System; diff --git a/src/codegen/target/x86/detect.h b/src/codegen/target/x86/detect.h index 3478c3fee1..afeca7e17d 100644 --- a/src/codegen/target/x86/detect.h +++ b/src/codegen/target/x86/detect.h @@ -11,7 +11,7 @@ #ifndef AVIAN_CODEGEN_ASSEMBLER_X86_DETECT_H #define AVIAN_CODEGEN_ASSEMBLER_X86_DETECT_H -#include +#include namespace avian { namespace codegen { diff --git a/src/codegen/target/x86/encode.cpp b/src/codegen/target/x86/encode.cpp index ec6ea9fe8f..16762d00d9 100644 --- a/src/codegen/target/x86/encode.cpp +++ b/src/codegen/target/x86/encode.cpp @@ -14,8 +14,8 @@ #include #include -#include -#include +#include +#include #include "context.h" #include "encode.h" diff --git a/src/codegen/target/x86/encode.h b/src/codegen/target/x86/encode.h index 1f3c4a3c4d..3546095686 100644 --- a/src/codegen/target/x86/encode.h +++ b/src/codegen/target/x86/encode.h @@ -15,7 +15,7 @@ #include "avian/common.h" -#include +#include #include "registers.h" diff --git a/src/codegen/target/x86/fixup.cpp b/src/codegen/target/x86/fixup.cpp index 4862f82eba..73f9736712 100644 --- a/src/codegen/target/x86/fixup.cpp +++ b/src/codegen/target/x86/fixup.cpp @@ -16,7 +16,7 @@ #include "avian/zone.h" #include -#include +#include #include "context.h" #include "fixup.h" diff --git a/src/codegen/target/x86/fixup.h b/src/codegen/target/x86/fixup.h index b2f904715a..395c916d8e 100644 --- a/src/codegen/target/x86/fixup.h +++ b/src/codegen/target/x86/fixup.h @@ -13,7 +13,7 @@ #include -#include +#include namespace vm { class System; diff --git a/src/codegen/target/x86/multimethod.cpp b/src/codegen/target/x86/multimethod.cpp index ff5084ed5a..661ee8e99f 100644 --- a/src/codegen/target/x86/multimethod.cpp +++ b/src/codegen/target/x86/multimethod.cpp @@ -12,7 +12,7 @@ #include -#include +#include #include "context.h" #include "operations.h" diff --git a/src/codegen/target/x86/multimethod.h b/src/codegen/target/x86/multimethod.h index a965d57bde..8c41fd448c 100644 --- a/src/codegen/target/x86/multimethod.h +++ b/src/codegen/target/x86/multimethod.h @@ -13,7 +13,7 @@ #include "avian/common.h" -#include +#include namespace avian { namespace codegen { diff --git a/src/codegen/target/x86/operations.cpp b/src/codegen/target/x86/operations.cpp index f7a03e952f..38740d0294 100644 --- a/src/codegen/target/x86/operations.cpp +++ b/src/codegen/target/x86/operations.cpp @@ -15,8 +15,8 @@ #include -#include -#include +#include +#include #include "context.h" #include "encode.h" diff --git a/src/codegen/target/x86/operations.h b/src/codegen/target/x86/operations.h index 6b2d7d5c14..7dd1b785fe 100644 --- a/src/codegen/target/x86/operations.h +++ b/src/codegen/target/x86/operations.h @@ -13,7 +13,7 @@ #include "avian/common.h" -#include +#include #include "context.h" diff --git a/src/codegen/targets.cpp b/src/codegen/targets.cpp index 30e914ae81..1e9ad6f007 100644 --- a/src/codegen/targets.cpp +++ b/src/codegen/targets.cpp @@ -10,7 +10,7 @@ #include "avian/common.h" -#include +#include #include "avian/environment.h" diff --git a/src/compile.cpp b/src/compile.cpp index 2d1703b7f4..87a303f96f 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -15,12 +15,12 @@ #include "avian/target.h" #include "avian/arch.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/src/finder.cpp b/src/finder.cpp index eb64d92c08..aa45a2d1a5 100644 --- a/src/finder.cpp +++ b/src/finder.cpp @@ -8,7 +8,7 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include +#include #include #include #include diff --git a/src/heap/heap.cpp b/src/heap/heap.cpp index aaf9909f6b..c3f0199329 100644 --- a/src/heap/heap.cpp +++ b/src/heap/heap.cpp @@ -8,8 +8,8 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include -#include +#include +#include #include "avian/common.h" #include "avian/arch.h" diff --git a/src/interpret.cpp b/src/interpret.cpp index feac47591f..91627ab2ab 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -9,7 +9,7 @@ details. */ #include "avian/common.h" -#include +#include #include "avian/constants.h" #include "avian/machine.h" #include "avian/processor.h" diff --git a/src/main.cpp b/src/main.cpp index c5c6af839d..20d4685fce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,7 +13,7 @@ #include "string.h" #include "jni.h" -#include +#include #include "avian/finder.h" #include diff --git a/src/vm/system/posix.cpp b/src/system/posix.cpp similarity index 99% rename from src/vm/system/posix.cpp rename to src/system/posix.cpp index b2531ff05f..9167fb8124 100644 --- a/src/vm/system/posix.cpp +++ b/src/system/posix.cpp @@ -49,7 +49,7 @@ #include "dirent.h" #include "sched.h" #include "avian/arch.h" -#include +#include #include diff --git a/src/vm/system/windows.cpp b/src/system/windows.cpp similarity index 99% rename from src/vm/system/windows.cpp rename to src/system/windows.cpp index f7b364131d..3f3c94e934 100644 --- a/src/vm/system/windows.cpp +++ b/src/system/windows.cpp @@ -24,7 +24,7 @@ #undef min #include "avian/arch.h" -#include +#include #include #if defined(WINAPI_FAMILY) diff --git a/src/tools/audit-codegen/main.cpp b/src/tools/audit-codegen/main.cpp index 3b462a3126..12c05ede3b 100644 --- a/src/tools/audit-codegen/main.cpp +++ b/src/tools/audit-codegen/main.cpp @@ -8,16 +8,16 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include +#include // since we aren't linking against libstdc++, we must implement this // ourselves: diff --git a/src/tools/bootimage-generator/main.cpp b/src/tools/bootimage-generator/main.cpp index e8fc477abd..3442877626 100644 --- a/src/tools/bootimage-generator/main.cpp +++ b/src/tools/bootimage-generator/main.cpp @@ -8,14 +8,14 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include +#include #include "avian/heapwalk.h" #include "avian/common.h" #include "avian/machine.h" #include "avian/util.h" #include -#include -#include +#include +#include #include "avian/target.h" #include #include diff --git a/unittest/codegen/assembler-test.cpp b/unittest/codegen/assembler-test.cpp index deab7695c8..f5176b7388 100644 --- a/unittest/codegen/assembler-test.cpp +++ b/unittest/codegen/assembler-test.cpp @@ -11,14 +11,14 @@ #include #include "avian/common.h" -#include -#include +#include +#include #include "avian/target.h" -#include -#include -#include -#include +#include +#include +#include +#include #include "test-harness.h" diff --git a/unittest/codegen/registers-test.cpp b/unittest/codegen/registers-test.cpp index 8502ee973a..d961dcaf44 100644 --- a/unittest/codegen/registers-test.cpp +++ b/unittest/codegen/registers-test.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "test-harness.h" From 730dade53eebc4bc00723598bff2a53389f139eb Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Fri, 21 Feb 2014 17:06:17 -0700 Subject: [PATCH 2/5] break out signal handling from System --- include/avian/system/signal.h | 67 ++++++ include/avian/system/system.h | 11 +- makefile | 2 + src/avian/machine.h | 1 + src/avian/processor.h | 6 +- src/compile.cpp | 63 +++--- src/interpret.cpp | 20 +- src/jnienv.cpp | 4 +- src/main.cpp | 2 +- src/system/posix.cpp | 151 +++---------- src/system/posix/signal.cpp | 207 ++++++++++++++++++ src/system/windows.cpp | 196 +---------------- src/system/windows/signal.cpp | 279 +++++++++++++++++++++++++ src/tools/audit-codegen/main.cpp | 2 +- src/tools/bootimage-generator/main.cpp | 4 +- src/tools/type-generator/main.cpp | 2 +- unittest/codegen/assembler-test.cpp | 2 +- 17 files changed, 649 insertions(+), 370 deletions(-) create mode 100644 include/avian/system/signal.h create mode 100644 src/system/posix/signal.cpp create mode 100644 src/system/windows/signal.cpp diff --git a/include/avian/system/signal.h b/include/avian/system/signal.h new file mode 100644 index 0000000000..d9314415be --- /dev/null +++ b/include/avian/system/signal.h @@ -0,0 +1,67 @@ +/* Copyright (c) 2008-2013, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#ifndef AVIAN_SYSTEM_SIGNAL_H +#define AVIAN_SYSTEM_SIGNAL_H + +namespace avian { +namespace system { + +// Registrar for unix-like "signals" (implemented with structured exceptions on windows). +// TODO: remove dependence on generated code having a well-known "thread" +// register. Use a thread-local variable instead. +class SignalRegistrar { + public: + class Handler { + public: + // This function receives state information about the paused thread. + // Returns whether to resume execution after the failure point. + virtual bool handleSignal(void** ip, + void** frame, + void** stack, + void** thread) = 0; + }; + + SignalRegistrar(); + ~SignalRegistrar(); + + // Register a handler for segfault signals. + // After this method call, any segfault exceptions (mostly null pointer + // dereference, but generally access to any non-mapped memory) will be handled + // by the given handler. Pass null (0) to unregister a handler. + // Returns true upon success, false upon failure + bool handleSegFault(Handler* handler); + + // Register a handler for divide-by-zero signals. + // After this method call, any divide-by-zero exceptions will be handled by + // the given handler. Pass null (0) to unregister a handler. + // Returns true upon success, false upon failure + bool handleDivideByZero(Handler* handler); + + // Set the directory that a crash dump will be written to should an unhandled + // exception be thrown. + // Note: this only currently does anything on windows. + // TODO: move this out of this class, into a separate "CrashDumper" class or + // somesuch. + void setCrashDumpDirectory(const char* crashDumpDirectory); + + // This is internal, implementation-specific data. It's declared in the + // specific implementation. + struct Data; + + private: + + Data* data; +}; + +} // namespace system +} // namespace avian + +#endif diff --git a/include/avian/system/system.h b/include/avian/system/system.h index 014b288a60..2427fd1f57 100644 --- a/include/avian/system/system.h +++ b/include/avian/system/system.h @@ -98,12 +98,6 @@ class System : public avian::util::Aborter { virtual void disposeAll() = 0; }; - class SignalHandler { - public: - virtual bool handleSignal(void** ip, void** frame, void** stack, - void** thread) = 0; - }; - class MonitorResource { public: MonitorResource(System::Thread* t, System::Monitor* m): t(t), m(m) { @@ -131,8 +125,7 @@ class System : public avian::util::Aborter { virtual Status make(Mutex**) = 0; virtual Status make(Monitor**) = 0; virtual Status make(Local**) = 0; - virtual Status handleSegFault(SignalHandler* handler) = 0; - virtual Status handleDivideByZero(SignalHandler* handler) = 0; + virtual Status visit(Thread* thread, Thread* target, ThreadVisitor* visitor) = 0; virtual uint64_t call(void* function, uintptr_t* arguments, uint8_t* types, @@ -193,7 +186,7 @@ sysAbort(System* s) // #endif // not NDEBUG AVIAN_EXPORT System* -makeSystem(const char* crashDumpDirectory); +makeSystem(); } // namespace vm diff --git a/makefile b/makefile index 0781e3b0b4..269bdc03d9 100755 --- a/makefile +++ b/makefile @@ -1109,6 +1109,7 @@ vm-depends := $(generated-code) \ vm-sources = \ $(src)/system/$(system).cpp \ + $(src)/system/$(system)/signal.cpp \ $(src)/finder.cpp \ $(src)/machine.cpp \ $(src)/util.cpp \ @@ -1240,6 +1241,7 @@ generator-depends := $(wildcard $(src)/*.h) generator-sources = \ $(src)/tools/type-generator/main.cpp \ $(src)/system/$(build-system).cpp \ + $(src)/system/$(build-system)/signal.cpp \ $(src)/finder.cpp ifneq ($(lzma),) diff --git a/src/avian/machine.h b/src/avian/machine.h index f466979216..e1cca45ad2 100644 --- a/src/avian/machine.h +++ b/src/avian/machine.h @@ -14,6 +14,7 @@ #include "avian/common.h" #include "java-common.h" #include +#include #include #include "avian/finder.h" #include "avian/processor.h" diff --git a/src/avian/processor.h b/src/avian/processor.h index 40e02f43aa..94ad8b7d0e 100644 --- a/src/avian/processor.h +++ b/src/avian/processor.h @@ -208,8 +208,10 @@ class Processor { } }; -Processor* -makeProcessor(System* system, Allocator* allocator, bool useNativeFeatures); +Processor* makeProcessor(System* system, + Allocator* allocator, + const char* crashDumpDirectory, + bool useNativeFeatures); } // namespace vm diff --git a/src/compile.cpp b/src/compile.cpp index 87a303f96f..f716fe4e1f 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -43,6 +43,7 @@ vmJumpAndInvoke(void* thread, void* function, void* stack, unsigned frameSize); using namespace avian::codegen; +using namespace avian::system; namespace { @@ -8366,7 +8367,7 @@ invoke(Thread* thread, object method, ArgumentList* arguments) return r; } -class SignalHandler: public System::SignalHandler { +class SignalHandler: public SignalRegistrar::Handler { public: SignalHandler(Machine::Type type, Machine::Root root, unsigned fixedSize): m(0), type(type), root(root), fixedSize(fixedSize) { } @@ -8501,24 +8502,27 @@ class MyProcessor: public Processor { Thunk table; }; - MyProcessor(System* s, Allocator* allocator, bool useNativeFeatures): - s(s), - allocator(allocator), - roots(0), - bootImage(0), - heapImage(0), - codeImage(0), - codeImageSize(0), - segFaultHandler(Machine::NullPointerExceptionType, - Machine::NullPointerException, - FixedSizeOfNullPointerException), - divideByZeroHandler(Machine::ArithmeticExceptionType, - Machine::ArithmeticException, - FixedSizeOfArithmeticException), - codeAllocator(s, 0, 0), - callTableSize(0), - useNativeFeatures(useNativeFeatures), - compilationHandlers(0) + MyProcessor(System* s, + Allocator* allocator, + const char* crashDumpDirectory, + bool useNativeFeatures) + : s(s), + allocator(allocator), + roots(0), + bootImage(0), + heapImage(0), + codeImage(0), + codeImageSize(0), + segFaultHandler(Machine::NullPointerExceptionType, + Machine::NullPointerException, + FixedSizeOfNullPointerException), + divideByZeroHandler(Machine::ArithmeticExceptionType, + Machine::ArithmeticException, + FixedSizeOfArithmeticException), + codeAllocator(s, 0, 0), + callTableSize(0), + useNativeFeatures(useNativeFeatures), + compilationHandlers(0) { thunkTable[compileMethodIndex] = voidPointer(local::compileMethod); thunkTable[compileVirtualMethodIndex] = voidPointer(compileVirtualMethod); @@ -8540,6 +8544,8 @@ class MyProcessor: public Processor { // table. thunkTable[dummyIndex] = reinterpret_cast (static_cast(UINT64_C(0x5555555555555555))); + + signals.setCrashDumpDirectory(crashDumpDirectory); } virtual Thread* @@ -8924,7 +8930,9 @@ class MyProcessor: public Processor { compilationHandlers->dispose(allocator); - s->handleSegFault(0); + signals.handleSegFault(0); + signals.handleDivideByZero(0); + signals.setCrashDumpDirectory(0); allocator->free(this, sizeof(*this)); } @@ -9116,12 +9124,10 @@ class MyProcessor: public Processor { #endif segFaultHandler.m = t->m; - expect(t, t->m->system->success - (t->m->system->handleSegFault(&segFaultHandler))); + expect(t, signals.handleSegFault(&segFaultHandler)); divideByZeroHandler.m = t->m; - expect(t, t->m->system->success - (t->m->system->handleDivideByZero(÷ByZeroHandler))); + expect(t, signals.handleDivideByZero(÷ByZeroHandler)); } virtual void callWithCurrentContinuation(Thread* t, object receiver) { @@ -9173,6 +9179,7 @@ class MyProcessor: public Processor { } System* s; + SignalRegistrar signals; Allocator* allocator; object roots; BootImage* bootImage; @@ -10285,11 +10292,13 @@ codeAllocator(MyThread* t) namespace vm { -Processor* -makeProcessor(System* system, Allocator* allocator, bool useNativeFeatures) +Processor* makeProcessor(System* system, + Allocator* allocator, + const char* crashDumpDirectory, + bool useNativeFeatures) { return new (allocator->allocate(sizeof(local::MyProcessor))) - local::MyProcessor(system, allocator, useNativeFeatures); + local::MyProcessor(system, allocator, crashDumpDirectory, useNativeFeatures); } } // namespace vm diff --git a/src/interpret.cpp b/src/interpret.cpp index 91627ab2ab..7ab3ce98a7 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -10,6 +10,7 @@ #include "avian/common.h" #include +#include #include "avian/constants.h" #include "avian/machine.h" #include "avian/processor.h" @@ -20,6 +21,7 @@ #include using namespace vm; +using namespace avian::system; namespace local { @@ -2959,9 +2961,11 @@ invoke(Thread* t, object method) class MyProcessor: public Processor { public: - MyProcessor(System* s, Allocator* allocator): - s(s), allocator(allocator) - { } + MyProcessor(System* s, Allocator* allocator, const char* crashDumpDirectory) + : s(s), allocator(allocator) + { + signals.setCrashDumpDirectory(crashDumpDirectory); + } virtual vm::Thread* makeThread(Machine* m, object javaThread, vm::Thread* parent) @@ -3260,21 +3264,25 @@ class MyProcessor: public Processor { virtual void dispose() { allocator->free(this, sizeof(*this)); + signals.setCrashDumpDirectory(0); } System* s; Allocator* allocator; + SignalRegistrar signals; }; } // namespace namespace vm { -Processor* -makeProcessor(System* system, Allocator* allocator, bool) +Processor* makeProcessor(System* system, + Allocator* allocator, + const char* crashDumpDirectory, + bool) { return new (allocator->allocate(sizeof(local::MyProcessor))) - local::MyProcessor(system, allocator); + local::MyProcessor(system, allocator, crashDumpDirectory); } } // namespace vm diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 66f2f2ef5c..1dcd9e6769 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -3878,7 +3878,7 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) if (classpath == 0) classpath = "."; - System* s = makeSystem(crashDumpDirectory); + System* s = makeSystem(); Heap* h = makeHeap(s, heapLimit); Classpath* c = makeClasspath(s, h, javaHome, embedPrefix); @@ -3913,7 +3913,7 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) Finder* af = makeFinder(s, h, classpath, bootLibrary); if(bootLibrary) free(bootLibrary); - Processor* p = makeProcessor(s, h, true); + Processor* p = makeProcessor(s, h, crashDumpDirectory, true); const char** properties = static_cast (h->allocate(sizeof(const char*) * propertyCount)); diff --git a/src/main.cpp b/src/main.cpp index 20d4685fce..b1a1be458d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,7 +59,7 @@ mainClass(const char* jar) { using namespace vm; - System* system = makeSystem(0); + System* system = makeSystem(); class MyAllocator: public Allocator { public: diff --git a/src/system/posix.cpp b/src/system/posix.cpp index 9167fb8124..2d3825325b 100644 --- a/src/system/posix.cpp +++ b/src/system/posix.cpp @@ -78,29 +78,14 @@ class MutexResource { const int InvalidSignal = -1; const int VisitSignal = SIGUSR1; const unsigned VisitSignalIndex = 0; -const int SegFaultSignal = SIGSEGV; -const unsigned SegFaultSignalIndex = 1; const int InterruptSignal = SIGUSR2; -const unsigned InterruptSignalIndex = 2; -#ifdef __APPLE__ -const int AltSegFaultSignal = SIGBUS; -#else -const int AltSegFaultSignal = InvalidSignal; -#endif -const unsigned AltSegFaultSignalIndex = 3; +const unsigned InterruptSignalIndex = 1; const int PipeSignal = SIGPIPE; -const unsigned PipeSignalIndex = 4; -const int DivideByZeroSignal = SIGFPE; -const unsigned DivideByZeroSignalIndex = 5; +const unsigned PipeSignalIndex = 2; -const int signals[] = { VisitSignal, - SegFaultSignal, - InterruptSignal, - AltSegFaultSignal, - PipeSignal, - DivideByZeroSignal }; +const int signals[] = {VisitSignal, InterruptSignal, PipeSignal}; -const unsigned SignalCount = 6; +const unsigned SignalCount = 3; class MySystem; MySystem* system; @@ -123,7 +108,7 @@ pathOfExecutable(System* s, const char** retBuf, unsigned* size) CFURLRef url = CFBundleCopyExecutableURL(bundle); CFStringRef path = CFURLCopyPath(url); path = CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault, - path, CFSTR("")); + path, CFSTR("")); CFIndex pathSize = CFStringGetMaximumSizeOfFileSystemRepresentation(path); char* buffer = reinterpret_cast(allocate(s, pathSize)); if (CFStringGetFileSystemRepresentation(path, buffer, pathSize)) { @@ -606,32 +591,27 @@ class MySystem: public System { expect(this, system == 0); system = this; - memset(handlers, 0, sizeof(handlers)); - - registerHandler(&nullHandler, InterruptSignalIndex); - registerHandler(&nullHandler, PipeSignalIndex); - registerHandler(&nullHandler, VisitSignalIndex); + expect(this, registerHandler(InterruptSignalIndex)); + expect(this, registerHandler(VisitSignalIndex)); + expect(this, registerHandler(PipeSignalIndex)); expect(this, make(&visitLock) == 0); } - int registerHandler(System::SignalHandler* handler, int index) { - if (handler) { - handlers[index] = handler; + // Returns true on success, false on failure + bool unregisterHandler(int index) { + return sigaction(signals[index], oldHandlers + index, 0) == 0; + } - struct sigaction sa; - memset(&sa, 0, sizeof(struct sigaction)); - sigemptyset(&(sa.sa_mask)); - sa.sa_flags = SA_SIGINFO; - sa.sa_sigaction = handleSignal; - - return sigaction(signals[index], &sa, oldHandlers + index); - } else if (handlers[index]) { - handlers[index] = 0; - return sigaction(signals[index], oldHandlers + index, 0); - } else { - return 1; - } + // Returns true on success, false on failure + bool registerHandler(int index) { + struct sigaction sa; + memset(&sa, 0, sizeof(struct sigaction)); + sigemptyset(&(sa.sa_mask)); + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = handleSignal; + + return sigaction(signals[index], &sa, oldHandlers + index) == 0; } virtual void* tryAllocate(unsigned sizeInBytes) { @@ -701,18 +681,6 @@ class MySystem: public System { return 0; } - virtual Status handleSegFault(SignalHandler* handler) { - Status s = registerHandler(handler, SegFaultSignalIndex); - if (s == 0 and AltSegFaultSignal != InvalidSignal) { - return registerHandler(handler, AltSegFaultSignalIndex); - } - return s; - } - - virtual Status handleDivideByZero(SignalHandler* handler) { - return registerHandler(handler, DivideByZeroSignalIndex); - } - virtual Status visit(System::Thread* st UNUSED, System::Thread* sTarget, ThreadVisitor* visitor) { @@ -937,19 +905,14 @@ class MySystem: public System { virtual void dispose() { visitLock->dispose(); - registerHandler(0, InterruptSignalIndex); - registerHandler(0, VisitSignalIndex); - registerHandler(0, PipeSignalIndex); + expect(this, unregisterHandler(InterruptSignalIndex)); + expect(this, unregisterHandler(VisitSignalIndex)); + expect(this, unregisterHandler(PipeSignalIndex)); system = 0; ::free(this); } - class NullSignalHandler: public SignalHandler { - virtual bool handleSignal(void**, void**, void**, void**) { return false; } - } nullHandler; - - SignalHandler* handlers[SignalCount]; struct sigaction oldHandlers[SignalCount]; ThreadVisitor* threadVisitor; @@ -957,27 +920,16 @@ class MySystem: public System { System::Monitor* visitLock; }; -void -handleSignal(int signal, siginfo_t*, void* context) +void handleSignal(int signal, siginfo_t*, void* context) { ucontext_t* c = static_cast(context); void* ip = reinterpret_cast(IP_REGISTER(c)); void* stack = reinterpret_cast(STACK_REGISTER(c)); - void* thread = reinterpret_cast(THREAD_REGISTER(c)); void* link = reinterpret_cast(LINK_REGISTER(c)); -#ifdef FRAME_REGISTER - void* frame = reinterpret_cast(FRAME_REGISTER(c)); -#else - void* frame = 0; -#endif - - unsigned index; switch (signal) { case VisitSignal: { - index = VisitSignalIndex; - system->threadVisitor->visit(ip, stack, link); System::Thread* t = system->visitTarget; @@ -987,57 +939,6 @@ handleSignal(int signal, siginfo_t*, void* context) system->visitLock->notifyAll(t); } break; - case SegFaultSignal: - case AltSegFaultSignal: - case DivideByZeroSignal: { - switch (signal) { - case SegFaultSignal: - index = SegFaultSignalIndex; - break; - - case AltSegFaultSignal: - index = AltSegFaultSignalIndex; - break; - - case DivideByZeroSignal: - index = DivideByZeroSignalIndex; - break; - - default: - abort(); - } - - bool jump = system->handlers[index]->handleSignal - (&ip, &frame, &stack, &thread); - - if (jump) { - // I'd like to use setcontext here (and get rid of the - // sigprocmask call), but it doesn't work on my Linux x86_64 - // system, and I can't tell from the documentation if it's even - // supposed to work. - - sigset_t set; - sigemptyset(&set); - sigaddset(&set, signal); - pthread_sigmask(SIG_UNBLOCK, &set, 0); - - vmJump(ip, frame, stack, thread, 0, 0); - } - } break; - - case InterruptSignal: { - index = InterruptSignalIndex; - } break; - - case PipeSignal: { - index = PipeSignalIndex; - } break; - - default: abort(); - } - - switch (signal) { - case VisitSignal: case InterruptSignal: case PipeSignal: break; @@ -1052,7 +953,7 @@ handleSignal(int signal, siginfo_t*, void* context) namespace vm { AVIAN_EXPORT System* -makeSystem(const char*) +makeSystem() { return new (malloc(sizeof(MySystem))) MySystem(); } diff --git a/src/system/posix/signal.cpp b/src/system/posix/signal.cpp new file mode 100644 index 0000000000..54e117e365 --- /dev/null +++ b/src/system/posix/signal.cpp @@ -0,0 +1,207 @@ +/* Copyright (c) 2008-2013, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#include "signal.h" +#include "sys/types.h" +#ifdef __APPLE__ +#include "CoreFoundation/CoreFoundation.h" +#include "sys/ucontext.h" +#undef assert +#elif defined(__ANDROID__) +#include /* for sigcontext */ +#include /* for stack_t */ +typedef struct ucontext { + unsigned long uc_flags; + struct ucontext* uc_link; + stack_t uc_stack; + struct sigcontext uc_mcontext; + unsigned long uc_sigmask; +} ucontext_t; +#else +#if defined __FreeBSD__ +#include "limits.h" +#endif +#include "ucontext.h" +#endif + +#include "avian/arch.h" +#include +#include + +namespace avian { +namespace system { + +namespace posix { + + +const int InvalidSignal = -1; +const int SegFaultSignal = SIGSEGV; +const unsigned SegFaultSignalIndex = 0; +#ifdef __APPLE__ +const int AltSegFaultSignal = SIGBUS; +#else +const int AltSegFaultSignal = InvalidSignal; +#endif +const unsigned AltSegFaultSignalIndex = 1; +const int DivideByZeroSignal = SIGFPE; +const unsigned DivideByZeroSignalIndex = 2; + +const int signals[] + = {SegFaultSignal, AltSegFaultSignal, DivideByZeroSignal}; + +const unsigned SignalCount = 3; + +} + +struct SignalRegistrar::Data { + Handler* handlers[posix::SignalCount]; + struct sigaction oldHandlers[posix::SignalCount]; + + bool registerHandler(Handler* handler, int index); + + Data() + { + if(instance) { + abort(); + } + + instance = this; + } + + ~Data() + { + instance = 0; + } + + static SignalRegistrar::Data* instance; +}; + +SignalRegistrar::Data* SignalRegistrar::Data::instance = 0; + +namespace posix { + +using namespace vm; + +void handleSignal(int signal, siginfo_t*, void* context) +{ + ucontext_t* c = static_cast(context); + + void* ip = reinterpret_cast(IP_REGISTER(c)); + void* stack = reinterpret_cast(STACK_REGISTER(c)); + void* thread = reinterpret_cast(THREAD_REGISTER(c)); +#ifdef FRAME_REGISTER + void* frame = reinterpret_cast(FRAME_REGISTER(c)); +#else + void* frame = 0; +#endif + + unsigned index; + + switch (signal) { + case SegFaultSignal: + case AltSegFaultSignal: + case DivideByZeroSignal: { + switch (signal) { + case SegFaultSignal: + index = SegFaultSignalIndex; + break; + + case AltSegFaultSignal: + index = AltSegFaultSignalIndex; + break; + + case DivideByZeroSignal: + index = DivideByZeroSignalIndex; + break; + + default: + abort(); + } + + bool jump + = SignalRegistrar::Data::instance->handlers[index]->handleSignal(&ip, &frame, &stack, &thread); + + if (jump) { + // I'd like to use setcontext here (and get rid of the + // sigprocmask call), but it doesn't work on my Linux x86_64 + // system, and I can't tell from the documentation if it's even + // supposed to work. + + sigset_t set; + sigemptyset(&set); + sigaddset(&set, signal); + pthread_sigmask(SIG_UNBLOCK, &set, 0); + + vmJump(ip, frame, stack, thread, 0, 0); + } + } break; + + default: + abort(); + } +} + +} // namespace posix + +SignalRegistrar::SignalRegistrar() +{ + data = new (malloc(sizeof(Data))) Data(); +} + +SignalRegistrar::~SignalRegistrar() +{ + data->~Data(); + free(data); +} + +bool SignalRegistrar::Data::registerHandler(Handler* handler, int index) +{ + if (handler) { + handlers[index] = handler; + + struct sigaction sa; + memset(&sa, 0, sizeof(struct sigaction)); + sigemptyset(&(sa.sa_mask)); + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = posix::handleSignal; + + return sigaction(posix::signals[index], &sa, oldHandlers + index) == 0; + } else if (handlers[index]) { + handlers[index] = 0; + return sigaction(posix::signals[index], oldHandlers + index, 0) == 0; + } else { + return false; + } +} + +bool SignalRegistrar::handleSegFault(Handler* handler) +{ + if(!data->registerHandler(handler, posix::SegFaultSignalIndex)) { + return false; + } + if (posix::AltSegFaultSignal != posix::InvalidSignal) { + return data->registerHandler(handler, posix::AltSegFaultSignalIndex); + } else { + return true; + } +} + +bool SignalRegistrar::handleDivideByZero(Handler* handler) +{ + return data->registerHandler(handler, posix::DivideByZeroSignalIndex); +} + +void SignalRegistrar::setCrashDumpDirectory(const char*) +{ + // Do nothing, not currently supported on posix +} + +} // namespace system +} // namespace avian diff --git a/src/system/windows.cpp b/src/system/windows.cpp index 3f3c94e934..53280049c9 100644 --- a/src/system/windows.cpp +++ b/src/system/windows.cpp @@ -10,7 +10,6 @@ #include "sys/stat.h" #include "windows.h" -#include "sys/timeb.h" #ifdef _MSC_VER # define S_ISREG(x) ((x) & _S_IFREG) @@ -115,11 +114,6 @@ class MutexResource { HANDLE m; }; -const unsigned SegFaultIndex = 0; -const unsigned DivideByZeroIndex = 1; - -const unsigned HandlerCount = 2; - class MySystem; MySystem* system; @@ -626,68 +620,15 @@ class MySystem: public System { System::Library* next_; }; - MySystem(const char* crashDumpDirectory): -#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - oldHandler(0), -#endif - crashDumpDirectory(crashDumpDirectory) + MySystem() { expect(this, system == 0); system = this; - memset(handlers, 0, sizeof(handlers)); - mutex = CreateMutex(0, false, 0); assert(this, mutex); } - bool findHandler() { - for (unsigned i = 0; i < HandlerCount; ++i) { - if (handlers[i]) return true; - } - return false; - } - - int registerHandler(System::SignalHandler* handler, int index) { - if (handler) { - handlers[index] = handler; - -#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - if (oldHandler == 0) { -# ifdef ARCH_x86_32 - oldHandler = SetUnhandledExceptionFilter(handleException); -# elif defined ARCH_x86_64 - AddVectoredExceptionHandler(1, handleException); - oldHandler = reinterpret_cast(1); -# endif - } -#else - #pragma message("TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx") -#endif - - return 0; - } else if (handlers[index]) { - handlers[index] = 0; - - if (not findHandler()) { -#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -# ifdef ARCH_x86_32 - SetUnhandledExceptionFilter(oldHandler); - oldHandler = 0; -# elif defined ARCH_x86_64 - // do nothing, handlers are never "unregistered" anyway -# endif -#else - #pragma message("TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx") -#endif - } - - return 0; - } else { - return 1; - } - } - virtual void* tryAllocate(unsigned sizeInBytes) { return malloc(sizeInBytes); } @@ -746,14 +687,6 @@ class MySystem: public System { return 0; } - virtual Status handleSegFault(SignalHandler* handler) { - return registerHandler(handler, SegFaultIndex); - } - - virtual Status handleDivideByZero(SignalHandler* handler) { - return registerHandler(handler, DivideByZeroIndex); - } - virtual Status visit(System::Thread* st UNUSED, System::Thread* sTarget, ThreadVisitor* visitor) { @@ -1020,139 +953,16 @@ class MySystem: public System { } HANDLE mutex; - SignalHandler* handlers[HandlerCount]; -#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - LPTOP_LEVEL_EXCEPTION_FILTER oldHandler; -#endif - const char* crashDumpDirectory; }; -#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - -#pragma pack(push,4) -struct MINIDUMP_EXCEPTION_INFORMATION { - DWORD thread; - LPEXCEPTION_POINTERS exception; - BOOL exceptionInCurrentAddressSpace; -}; -#pragma pack(pop) - -struct MINIDUMP_USER_STREAM_INFORMATION; -struct MINIDUMP_CALLBACK_INFORMATION; - -enum MINIDUMP_TYPE { - MiniDumpNormal = 0, - MiniDumpWithFullMemory = 2 -}; - -typedef BOOL (*MiniDumpWriteDumpType) -(HANDLE processHandle, - DWORD processId, - HANDLE file, - MINIDUMP_TYPE type, - const MINIDUMP_EXCEPTION_INFORMATION* exception, - const MINIDUMP_USER_STREAM_INFORMATION* userStream, - const MINIDUMP_CALLBACK_INFORMATION* callback); - -void -dump(LPEXCEPTION_POINTERS e, const char* directory) -{ - HINSTANCE dbghelp = LoadLibrary("dbghelp.dll"); - - if (dbghelp) { - MiniDumpWriteDumpType MiniDumpWriteDump = reinterpret_cast - (GetProcAddress(dbghelp, "MiniDumpWriteDump")); - - if (MiniDumpWriteDump) { - char name[MAX_PATH]; - _timeb tb; - FTIME(&tb); - vm::snprintf(name, MAX_PATH, "%s\\crash-%" LLD ".mdmp", directory, - (static_cast(tb.time) * 1000) - + static_cast(tb.millitm)); - - HANDLE file = CreateFile - (name, FILE_WRITE_DATA, 0, 0, CREATE_ALWAYS, 0, 0); - - if (file != INVALID_HANDLE_VALUE) { - MINIDUMP_EXCEPTION_INFORMATION exception - = { GetCurrentThreadId(), e, true }; - - MiniDumpWriteDump - (GetCurrentProcess(), - GetCurrentProcessId(), - file, - MiniDumpWithFullMemory, - &exception, - 0, - 0); - - CloseHandle(file); - } - } - - FreeLibrary(dbghelp); - } -} - -LONG CALLBACK -handleException(LPEXCEPTION_POINTERS e) -{ - System::SignalHandler* handler = 0; - if (e->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { - handler = system->handlers[SegFaultIndex]; - } else if (e->ExceptionRecord->ExceptionCode == EXCEPTION_INT_DIVIDE_BY_ZERO) - { - handler = system->handlers[DivideByZeroIndex]; - } - - if (handler) { -#ifdef ARCH_x86_32 - void* ip = reinterpret_cast(e->ContextRecord->Eip); - void* base = reinterpret_cast(e->ContextRecord->Ebp); - void* stack = reinterpret_cast(e->ContextRecord->Esp); - void* thread = reinterpret_cast(e->ContextRecord->Ebx); -#elif defined ARCH_x86_64 - void* ip = reinterpret_cast(e->ContextRecord->Rip); - void* base = reinterpret_cast(e->ContextRecord->Rbp); - void* stack = reinterpret_cast(e->ContextRecord->Rsp); - void* thread = reinterpret_cast(e->ContextRecord->Rbx); -#endif - - bool jump = handler->handleSignal(&ip, &base, &stack, &thread); - -#ifdef ARCH_x86_32 - e->ContextRecord->Eip = reinterpret_cast(ip); - e->ContextRecord->Ebp = reinterpret_cast(base); - e->ContextRecord->Esp = reinterpret_cast(stack); - e->ContextRecord->Ebx = reinterpret_cast(thread); -#elif defined ARCH_x86_64 - e->ContextRecord->Rip = reinterpret_cast(ip); - e->ContextRecord->Rbp = reinterpret_cast(base); - e->ContextRecord->Rsp = reinterpret_cast(stack); - e->ContextRecord->Rbx = reinterpret_cast(thread); -#endif - - if (jump) { - return EXCEPTION_CONTINUE_EXECUTION; - } else if (system->crashDumpDirectory) { - dump(e, system->crashDumpDirectory); - } - } - - return EXCEPTION_CONTINUE_SEARCH; -} - -#endif - } // namespace namespace vm { AVIAN_EXPORT System* -makeSystem(const char* crashDumpDirectory) +makeSystem() { - return new (malloc(sizeof(MySystem))) MySystem(crashDumpDirectory); + return new (malloc(sizeof(MySystem))) MySystem(); } } // namespace vm diff --git a/src/system/windows/signal.cpp b/src/system/windows/signal.cpp new file mode 100644 index 0000000000..343788f371 --- /dev/null +++ b/src/system/windows/signal.cpp @@ -0,0 +1,279 @@ +/* Copyright (c) 2008-2013, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#include "windows.h" +#include "sys/timeb.h" + +#ifdef _MSC_VER +#define FTIME _ftime_s +#else +#define FTIME _ftime +#endif + +#ifndef WINAPI_FAMILY + +#ifndef WINAPI_PARTITION_DESKTOP +#define WINAPI_PARTITION_DESKTOP 1 +#endif + +#ifndef WINAPI_FAMILY_PARTITION +#define WINAPI_FAMILY_PARTITION(x) (x) +#endif + +#endif + +#include +#include + +namespace avian { +namespace system { + +namespace windows { +const unsigned SegFaultIndex = 0; +const unsigned DivideByZeroIndex = 1; + +const unsigned HandlerCount = 2; + +} // namespace windows + +struct SignalRegistrar::Data { + Handler* handlers[windows::HandlerCount]; + const char* crashDumpDirectory; + +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + LPTOP_LEVEL_EXCEPTION_FILTER oldHandler; +#endif + + Data() : crashDumpDirectory(0), +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + oldHandler(0) +#endif + { + if (instance) { + abort(); + } + instance = this; + memset(handlers, 0, sizeof(handlers)); + } + + ~Data() + { + instance = 0; + } + + bool registerHandler(Handler* handler, int index); + + bool findHandler() { + for (unsigned i = 0; i < windows::HandlerCount; ++i) { + if (handlers[i]) return true; + } + return false; + } + + static SignalRegistrar::Data* instance; +}; + +SignalRegistrar::Data* SignalRegistrar::Data::instance = 0; + +namespace windows { + +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + +#pragma pack(push, 4) +struct MINIDUMP_EXCEPTION_INFORMATION { + DWORD thread; + LPEXCEPTION_POINTERS exception; + BOOL exceptionInCurrentAddressSpace; +}; +#pragma pack(pop) + +struct MINIDUMP_USER_STREAM_INFORMATION; +struct MINIDUMP_CALLBACK_INFORMATION; + +enum MINIDUMP_TYPE { + MiniDumpNormal = 0, + MiniDumpWithFullMemory = 2 +}; + +typedef BOOL (*MiniDumpWriteDumpType)(HANDLE processHandle, + DWORD processId, + HANDLE file, + MINIDUMP_TYPE type, + const MINIDUMP_EXCEPTION_INFORMATION + * exception, + const MINIDUMP_USER_STREAM_INFORMATION + * userStream, + const MINIDUMP_CALLBACK_INFORMATION + * callback); + +#endif + +void dump(LPEXCEPTION_POINTERS e, const char* directory) +{ + HINSTANCE dbghelp = LoadLibrary("dbghelp.dll"); + + if (dbghelp) { + MiniDumpWriteDumpType MiniDumpWriteDump = reinterpret_cast + (GetProcAddress(dbghelp, "MiniDumpWriteDump")); + + if (MiniDumpWriteDump) { + char name[MAX_PATH]; + _timeb tb; + FTIME(&tb); + vm::snprintf(name, + MAX_PATH, + "%s\\crash-%" LLD ".mdmp", + directory, + (static_cast(tb.time) * 1000) + static_cast + (tb.millitm)); + + HANDLE file + = CreateFile(name, FILE_WRITE_DATA, 0, 0, CREATE_ALWAYS, 0, 0); + + if (file != INVALID_HANDLE_VALUE) { + MINIDUMP_EXCEPTION_INFORMATION exception + = {GetCurrentThreadId(), e, true}; + + MiniDumpWriteDump(GetCurrentProcess(), + GetCurrentProcessId(), + file, + MiniDumpWithFullMemory, + &exception, + 0, + 0); + + CloseHandle(file); + } + } + + FreeLibrary(dbghelp); + } +} + +LONG CALLBACK handleException(LPEXCEPTION_POINTERS e) +{ + SignalRegistrar::Handler* handler = 0; + if (e->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { + handler = SignalRegistrar::Data::instance->handlers[SegFaultIndex]; + } else if (e->ExceptionRecord->ExceptionCode + == EXCEPTION_INT_DIVIDE_BY_ZERO) { + handler = SignalRegistrar::Data::instance->handlers[DivideByZeroIndex]; + } + + if (handler) { +#ifdef ARCH_x86_32 + void* ip = reinterpret_cast(e->ContextRecord->Eip); + void* base = reinterpret_cast(e->ContextRecord->Ebp); + void* stack = reinterpret_cast(e->ContextRecord->Esp); + void* thread = reinterpret_cast(e->ContextRecord->Ebx); +#elif defined ARCH_x86_64 + void* ip = reinterpret_cast(e->ContextRecord->Rip); + void* base = reinterpret_cast(e->ContextRecord->Rbp); + void* stack = reinterpret_cast(e->ContextRecord->Rsp); + void* thread = reinterpret_cast(e->ContextRecord->Rbx); +#endif + + bool jump = handler->handleSignal(&ip, &base, &stack, &thread); + +#ifdef ARCH_x86_32 + e->ContextRecord->Eip = reinterpret_cast(ip); + e->ContextRecord->Ebp = reinterpret_cast(base); + e->ContextRecord->Esp = reinterpret_cast(stack); + e->ContextRecord->Ebx = reinterpret_cast(thread); +#elif defined ARCH_x86_64 + e->ContextRecord->Rip = reinterpret_cast(ip); + e->ContextRecord->Rbp = reinterpret_cast(base); + e->ContextRecord->Rsp = reinterpret_cast(stack); + e->ContextRecord->Rbx = reinterpret_cast(thread); +#endif + + if (jump) { + return EXCEPTION_CONTINUE_EXECUTION; + } else if (SignalRegistrar::Data::instance->crashDumpDirectory) { + dump(e, SignalRegistrar::Data::instance->crashDumpDirectory); + } + } + + return EXCEPTION_CONTINUE_SEARCH; +} + +} // namespace windows + +SignalRegistrar::SignalRegistrar() +{ + data = new (malloc(sizeof(Data))) Data(); +} + +SignalRegistrar::~SignalRegistrar() +{ + data->~Data(); + free(data); +} + +bool SignalRegistrar::Data::registerHandler(Handler* handler, int index) +{ + if (handler) { + handlers[index] = handler; + +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + if (oldHandler == 0) { +#ifdef ARCH_x86_32 + oldHandler = SetUnhandledExceptionFilter(windows::handleException); +#elif defined ARCH_x86_64 + AddVectoredExceptionHandler(1, windows::handleException); + oldHandler = reinterpret_cast(1); +#endif + } +#else +#pragma message( \ + "TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx") +#endif + + return true; + } else if (handlers[index]) { + handlers[index] = 0; + + if (not findHandler()) { +#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +#ifdef ARCH_x86_32 + SetUnhandledExceptionFilter(oldHandler); + oldHandler = 0; +#elif defined ARCH_x86_64 +// do nothing, handlers are never "unregistered" anyway +#endif +#else +#pragma message( \ + "TODO: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.unhandledexception(v=vs.105).aspx") +#endif + } + + return true; + } else { + return false; + } +} + +bool SignalRegistrar::handleSegFault(Handler* handler) +{ + return data->registerHandler(handler, windows::SegFaultIndex); +} + +bool SignalRegistrar::handleDivideByZero(Handler* handler) +{ + return data->registerHandler(handler, windows::DivideByZeroIndex); +} + +void SignalRegistrar::setCrashDumpDirectory(const char* crashDumpDirectory) +{ + data->crashDumpDirectory = crashDumpDirectory; +} + +} // namespace system +} // namespace avian diff --git a/src/tools/audit-codegen/main.cpp b/src/tools/audit-codegen/main.cpp index 12c05ede3b..270d0c6348 100644 --- a/src/tools/audit-codegen/main.cpp +++ b/src/tools/audit-codegen/main.cpp @@ -34,7 +34,7 @@ public: Architecture* arch; BasicEnv(): - s(makeSystem(0)), + s(makeSystem()), heap(makeHeap(s, 32 * 1024)), arch(makeArchitectureNative(s, true)) { diff --git a/src/tools/bootimage-generator/main.cpp b/src/tools/bootimage-generator/main.cpp index 3442877626..3d7cf47788 100644 --- a/src/tools/bootimage-generator/main.cpp +++ b/src/tools/bootimage-generator/main.cpp @@ -1899,11 +1899,11 @@ main(int ac, const char** av) Arguments args(ac, av); // args.dump(); - System* s = makeSystem(0); + System* s = makeSystem(); Heap* h = makeHeap(s, HeapCapacity * 2); Classpath* c = makeClasspath(s, h, AVIAN_JAVA_HOME, AVIAN_EMBED_PREFIX); Finder* f = makeFinder(s, h, args.classpath, 0); - Processor* p = makeProcessor(s, h, false); + Processor* p = makeProcessor(s, h, 0, false); // todo: currently, the compiler cannot compile code with jumps or // calls spanning more than the maximum size of an immediate value diff --git a/src/tools/type-generator/main.cpp b/src/tools/type-generator/main.cpp index 8171bd560b..a08a5be3ff 100644 --- a/src/tools/type-generator/main.cpp +++ b/src/tools/type-generator/main.cpp @@ -1941,7 +1941,7 @@ main(int ac, char** av) local::usageAndExit(av[0]); } - System* system = makeSystem(0); + System* system = makeSystem(); class MyAllocator: public Allocator { public: diff --git a/unittest/codegen/assembler-test.cpp b/unittest/codegen/assembler-test.cpp index f5176b7388..8908fb3a67 100644 --- a/unittest/codegen/assembler-test.cpp +++ b/unittest/codegen/assembler-test.cpp @@ -33,7 +33,7 @@ public: Architecture* arch; BasicEnv(): - s(makeSystem(0)), + s(makeSystem()), heap(makeHeap(s, 32 * 1024)), arch(makeArchitectureNative(s, true)) { From ca7d51edb31e76e200b43f2a44ec16628fba9f05 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Fri, 21 Feb 2014 23:03:25 -0700 Subject: [PATCH 3/5] add crash function to match the semantics of System::abort --- include/avian/system/signal.h | 7 +++++++ src/system/posix.cpp | 5 +++-- src/system/posix/signal.cpp | 11 ++++++++--- src/system/windows.cpp | 5 ++--- src/system/windows/signal.cpp | 13 ++++++++++++- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/avian/system/signal.h b/include/avian/system/signal.h index d9314415be..15581ec7d3 100644 --- a/include/avian/system/signal.h +++ b/include/avian/system/signal.h @@ -11,9 +11,16 @@ #ifndef AVIAN_SYSTEM_SIGNAL_H #define AVIAN_SYSTEM_SIGNAL_H +#include + namespace avian { namespace system { +// Crash the process. +// On posix, the just calls abort. On windows, we dereference a null pointer in +// order to trigger the crash dump logic. +NO_RETURN void crash(); + // Registrar for unix-like "signals" (implemented with structured exceptions on windows). // TODO: remove dependence on generated code having a well-known "thread" // register. Use a thread-local variable instead. diff --git a/src/system/posix.cpp b/src/system/posix.cpp index 2d3825325b..a27090453d 100644 --- a/src/system/posix.cpp +++ b/src/system/posix.cpp @@ -49,8 +49,9 @@ #include "dirent.h" #include "sched.h" #include "avian/arch.h" -#include +#include +#include #include @@ -899,7 +900,7 @@ class MySystem: public System { } virtual void abort() { - ::abort(); + avian::system::crash(); } virtual void dispose() { diff --git a/src/system/posix/signal.cpp b/src/system/posix/signal.cpp index 54e117e365..67c17055d4 100644 --- a/src/system/posix/signal.cpp +++ b/src/system/posix/signal.cpp @@ -69,7 +69,7 @@ struct SignalRegistrar::Data { Data() { if(instance) { - abort(); + crash(); } instance = this; @@ -122,7 +122,7 @@ void handleSignal(int signal, siginfo_t*, void* context) break; default: - abort(); + crash(); } bool jump @@ -144,12 +144,17 @@ void handleSignal(int signal, siginfo_t*, void* context) } break; default: - abort(); + crash(); } } } // namespace posix +NO_RETURN void crash() +{ + abort(); +} + SignalRegistrar::SignalRegistrar() { data = new (malloc(sizeof(Data))) Data(); diff --git a/src/system/windows.cpp b/src/system/windows.cpp index 53280049c9..bf3b2eae39 100644 --- a/src/system/windows.cpp +++ b/src/system/windows.cpp @@ -24,6 +24,7 @@ #include "avian/arch.h" #include +#include #include #if defined(WINAPI_FAMILY) @@ -941,9 +942,7 @@ class MySystem: public System { } virtual void abort() { - // trigger an EXCEPTION_ACCESS_VIOLATION, which we will catch and - // generate a debug dump for - *static_cast(0) = 0; + avian::system::crash(); } virtual void dispose() { diff --git a/src/system/windows/signal.cpp b/src/system/windows/signal.cpp index 343788f371..22bd9cc286 100644 --- a/src/system/windows/signal.cpp +++ b/src/system/windows/signal.cpp @@ -57,7 +57,7 @@ struct SignalRegistrar::Data { #endif { if (instance) { - abort(); + crash(); } instance = this; memset(handlers, 0, sizeof(handlers)); @@ -260,6 +260,17 @@ bool SignalRegistrar::Data::registerHandler(Handler* handler, int index) } } +NO_RETURN void crash() +{ + // trigger an EXCEPTION_ACCESS_VIOLATION, which we will catch and + // generate a debug dump for + *static_cast(0) = 0; + + // Some (all?) compilers don't realize that we can't possibly continue past + // the above statement. + abort(); +} + bool SignalRegistrar::handleSegFault(Handler* handler) { return data->registerHandler(handler, windows::SegFaultIndex); From bc9f7d2f8760d00303ae13be0b24bf246f249b85 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Fri, 21 Feb 2014 23:23:01 -0700 Subject: [PATCH 4/5] refactor SignalRegistrar interface --- include/avian/system/signal.h | 26 ++++++++++++++-------- src/compile.cpp | 8 +++---- src/system/posix/signal.cpp | 41 ++++++++++++++++++++++++++--------- src/system/windows/signal.cpp | 18 ++++++++------- 4 files changed, 62 insertions(+), 31 deletions(-) diff --git a/include/avian/system/signal.h b/include/avian/system/signal.h index 15581ec7d3..590ab7a44f 100644 --- a/include/avian/system/signal.h +++ b/include/avian/system/signal.h @@ -36,21 +36,29 @@ class SignalRegistrar { void** thread) = 0; }; + enum Signal { + // "Segmentation fault" exceptions (mostly null pointer dereference, but + // generally access to any non-mapped memory) + SegFault, + + DivideByZero, + }; + SignalRegistrar(); ~SignalRegistrar(); - // Register a handler for segfault signals. - // After this method call, any segfault exceptions (mostly null pointer - // dereference, but generally access to any non-mapped memory) will be handled - // by the given handler. Pass null (0) to unregister a handler. + // Register a handler for the given signal. + // After this method call, anytime the given signal is raised, it will be + // handled by the given handler. // Returns true upon success, false upon failure - bool handleSegFault(Handler* handler); + bool registerHandler(Signal signal, Handler* handler); - // Register a handler for divide-by-zero signals. - // After this method call, any divide-by-zero exceptions will be handled by - // the given handler. Pass null (0) to unregister a handler. + // Unregister a handler for the given signal. + // After this method call, the given signal will no longer be handled (or, + // rather, it go back to being handled by whatever was registered to handle it + // before us). // Returns true upon success, false upon failure - bool handleDivideByZero(Handler* handler); + bool unregisterHandler(Signal signal); // Set the directory that a crash dump will be written to should an unhandled // exception be thrown. diff --git a/src/compile.cpp b/src/compile.cpp index f716fe4e1f..0f41e6c73a 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -8930,8 +8930,8 @@ class MyProcessor: public Processor { compilationHandlers->dispose(allocator); - signals.handleSegFault(0); - signals.handleDivideByZero(0); + signals.unregisterHandler(SignalRegistrar::SegFault); + signals.unregisterHandler(SignalRegistrar::DivideByZero); signals.setCrashDumpDirectory(0); allocator->free(this, sizeof(*this)); @@ -9124,10 +9124,10 @@ class MyProcessor: public Processor { #endif segFaultHandler.m = t->m; - expect(t, signals.handleSegFault(&segFaultHandler)); + expect(t, signals.registerHandler(SignalRegistrar::SegFault, &segFaultHandler)); divideByZeroHandler.m = t->m; - expect(t, signals.handleDivideByZero(÷ByZeroHandler)); + expect(t, signals.registerHandler(SignalRegistrar::DivideByZero, ÷ByZeroHandler)); } virtual void callWithCurrentContinuation(Thread* t, object receiver) { diff --git a/src/system/posix/signal.cpp b/src/system/posix/signal.cpp index 67c17055d4..bd4581697d 100644 --- a/src/system/posix/signal.cpp +++ b/src/system/posix/signal.cpp @@ -186,21 +186,42 @@ bool SignalRegistrar::Data::registerHandler(Handler* handler, int index) } } -bool SignalRegistrar::handleSegFault(Handler* handler) +bool SignalRegistrar::registerHandler(Signal signal, Handler* handler) { - if(!data->registerHandler(handler, posix::SegFaultSignalIndex)) { - return false; - } - if (posix::AltSegFaultSignal != posix::InvalidSignal) { - return data->registerHandler(handler, posix::AltSegFaultSignalIndex); - } else { - return true; + switch(signal) { + case SegFault: + if(!data->registerHandler(handler, posix::SegFaultSignalIndex)) { + return false; + } + if (posix::AltSegFaultSignal != posix::InvalidSignal) { + return data->registerHandler(handler, posix::AltSegFaultSignalIndex); + } else { + return true; + } + case DivideByZero: + return data->registerHandler(handler, posix::DivideByZeroSignalIndex); + default: + crash(); } } -bool SignalRegistrar::handleDivideByZero(Handler* handler) +bool SignalRegistrar::unregisterHandler(Signal signal) { - return data->registerHandler(handler, posix::DivideByZeroSignalIndex); + switch(signal) { + case SegFault: + if(!data->registerHandler(0, posix::SegFaultSignalIndex)) { + return false; + } + if (posix::AltSegFaultSignal != posix::InvalidSignal) { + return data->registerHandler(0, posix::AltSegFaultSignalIndex); + } else { + return true; + } + case DivideByZero: + return data->registerHandler(0, posix::DivideByZeroSignalIndex); + default: + crash(); + } } void SignalRegistrar::setCrashDumpDirectory(const char*) diff --git a/src/system/windows/signal.cpp b/src/system/windows/signal.cpp index 22bd9cc286..7477d10037 100644 --- a/src/system/windows/signal.cpp +++ b/src/system/windows/signal.cpp @@ -36,8 +36,6 @@ namespace avian { namespace system { namespace windows { -const unsigned SegFaultIndex = 0; -const unsigned DivideByZeroIndex = 1; const unsigned HandlerCount = 2; @@ -161,10 +159,10 @@ LONG CALLBACK handleException(LPEXCEPTION_POINTERS e) { SignalRegistrar::Handler* handler = 0; if (e->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { - handler = SignalRegistrar::Data::instance->handlers[SegFaultIndex]; + handler = SignalRegistrar::Data::instance->handlers[SignalRegistrar::SegFault]; } else if (e->ExceptionRecord->ExceptionCode == EXCEPTION_INT_DIVIDE_BY_ZERO) { - handler = SignalRegistrar::Data::instance->handlers[DivideByZeroIndex]; + handler = SignalRegistrar::Data::instance->handlers[SignalRegistrar::DivideByZero]; } if (handler) { @@ -219,6 +217,10 @@ SignalRegistrar::~SignalRegistrar() bool SignalRegistrar::Data::registerHandler(Handler* handler, int index) { + if(index != SegFault && index != DivideByZero) { + crash(); + } + if (handler) { handlers[index] = handler; @@ -271,14 +273,14 @@ NO_RETURN void crash() abort(); } -bool SignalRegistrar::handleSegFault(Handler* handler) +bool SignalRegistrar::registerHandler(Signal signal, Handler* handler) { - return data->registerHandler(handler, windows::SegFaultIndex); + return data->registerHandler(handler, signal); } -bool SignalRegistrar::handleDivideByZero(Handler* handler) +bool SignalRegistrar::unregisterHandler(Signal signal) { - return data->registerHandler(handler, windows::DivideByZeroIndex); + return data->registerHandler(0, signal); } void SignalRegistrar::setCrashDumpDirectory(const char* crashDumpDirectory) From 3bd00f19bcbf192dd53248dde407d9694bdc6a3d Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sat, 22 Feb 2014 15:35:12 -0700 Subject: [PATCH 5/5] fix remote-test functionality for windows --- makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index 269bdc03d9..c03a64c785 100755 --- a/makefile +++ b/makefile @@ -90,6 +90,12 @@ ifneq (,$(filter mingw32 cygwin,$(build-platform))) path-separator = ; endif +target-path-separator = : + +ifeq ($(platform),windows) + target-path-separator = ; +endif + library-path-variable = LD_LIBRARY_PATH ifeq ($(build-platform),darwin) @@ -1527,7 +1533,7 @@ endif $(build)/run-tests.sh: $(test-classes) makefile $(build)/extra-dir/multi-classpath-test.txt $(build)/test/multi-classpath-test.txt echo 'cd $$(dirname $$0)' > $(@) echo "sh ./test.sh 2>/dev/null \\" >> $(@) - echo "$(shell echo $(library-path) | sed 's|$(build)|\.|g') ./$(name)-unittest${exe-suffix} ./$(notdir $(test-executable)) $(mode) \"-Djava.library.path=. -cp test$(path-separator)extra-dir\" \\" >> $(@) + echo "$(shell echo $(library-path) | sed 's|$(build)|\.|g') ./$(name)-unittest${exe-suffix} ./$(notdir $(test-executable)) $(mode) \"-Djava.library.path=. -cp test$(target-path-separator)extra-dir\" \\" >> $(@) echo "$(call class-names,$(test-build),$(filter-out $(test-support-classes), $(test-classes))) \\" >> $(@) echo "$(continuation-tests) $(tail-tests)" >> $(@)