Skip to content

Commit d59698c

Browse files
committed
Basics of unwinding support for C :)!
1 parent c4629b5 commit d59698c

File tree

5 files changed

+268
-231
lines changed

5 files changed

+268
-231
lines changed

cilly/src/bin/linker/main.rs

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,11 @@ fn main() {
278278
}
279279
}),
280280
);
281-
281+
if *NO_UNWIND {
282+
cilly::builtins::insert_exeception_stub(&mut final_assembly, &mut overrides);
283+
} else {
284+
cilly::builtins::insert_exception(&mut final_assembly, &mut overrides);
285+
};
282286
// Override allocator
283287
if !*C_MODE {
284288
// Get the marshal class
@@ -343,16 +347,16 @@ fn main() {
343347
MethodImpl::MethodBody {
344348
blocks: vec![cilly::BasicBlock::from_v1(
345349
&cilly::basic_block::BasicBlock::new(
346-
vec![cilly::cil_root::V1Root::Throw(
347-
cilly::cil_node::V1Node::NewObj(Box::new(
348-
cilly::cil_node::CallOpArgs {
350+
vec![
351+
cilly::cil_root::V1Root::Throw(cilly::cil_node::V1Node::NewObj(
352+
Box::new(cilly::cil_node::CallOpArgs {
349353
args: Box::new([conv_usize!(arg0)]),
350354
site: asm.alloc_methodref(exception_ctor),
351355
is_pure: IsPure::NOT,
352-
},
353-
)),
354-
)
355-
.into()],
356+
}),
357+
))
358+
.into(),
359+
],
356360
0,
357361
None,
358362
),
@@ -455,7 +459,6 @@ fn main() {
455459
cilly::builtins::math::bitreverse(&mut final_assembly, &mut overrides);
456460

457461
if *C_MODE {
458-
cilly::builtins::insert_exeception_stub(&mut final_assembly, &mut overrides);
459462
externs.insert("__dso_handle", LIBC.clone());
460463
externs.insert("_mm_malloc", LIBC.clone());
461464
externs.insert("_mm_free", LIBC.clone());
@@ -499,7 +502,7 @@ fn main() {
499502
cilly::builtins::instert_threading(&mut final_assembly, &mut overrides);
500503
cilly::builtins::math::math(&mut final_assembly, &mut overrides);
501504
cilly::builtins::simd::simd(&mut final_assembly, &mut overrides);
502-
cilly::builtins::insert_exception(&mut final_assembly, &mut overrides);
505+
503506
cilly::builtins::argc_argv_init(&mut final_assembly, &mut overrides);
504507
}
505508

@@ -648,28 +651,6 @@ fn bootstrap_source(fpath: &Path, output_file_path: &str, jumpstart_cmd: &str) -
648651
config!(NATIVE_PASSTROUGH, bool, false);
649652
config!(ABORT_ON_ERROR, bool, false);
650653
config!(C_MODE, bool, false);
654+
config!(NO_UNWIND, bool, false);
651655
config!(JAVA_MODE, bool, false);
652656
config!(PANIC_MANAGED_BT, bool, false);
653-
/*
654-
lazy_static! {
655-
#[doc = "Tells the linker to not remove any dead code."]pub static ref KEEP_DEAD_CODE:bool = {
656-
std::env::vars().find_map(|(key,value)|if key == stringify!(KEEP_DEAD_CODE){
657-
Some(value)
658-
}else {
659-
None
660-
}).map(|value|match value.as_ref(){
661-
"0"|"false"|"False"|"FALSE" => false,"1"|"true"|"True"|"TRUE" => true,_ => panic!("Boolean enviroment variable {} has invalid value {}",stringify!(KEEP_DEAD_CODE),value),
662-
}).unwrap_or(false)
663-
};
664-
}
665-
lazy_static! {
666-
#[doc = "Tells the codegen to emmit JS source files."]pub static ref JS_MODE:bool = {
667-
std::env::vars().find_map(|(key,value)|if key == stringify!(JS_MODE){
668-
Some(value)
669-
}else {
670-
None
671-
}).map(|value|match value.as_ref(){
672-
"0"|"false"|"False"|"FALSE" => false,"1"|"true"|"True"|"TRUE" => true,_ => panic!("Boolean enviroment variable {} has invalid value {}",stringify!(JS_MODE),value),
673-
}).unwrap_or(false)
674-
};
675-
}*/

cilly/src/v2/c_exporter/c_header.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,3 +928,17 @@ int sigemptyset(void *set);
928928
int sigaction(int sig, void* act,
929929
void* oact);
930930
int sigaltstack(void *new_ss, void* old_ss);
931+
// Unwind support
932+
union System_Exception {void* data_pointer;};
933+
#ifdef UNWIND_SUPPORTED
934+
_Thread_local unionSystem_Exception global_uwnind_exception;
935+
_Thread_local jmp_buf unwind_stack_top;
936+
#define RUST_THROW(arg) global_uwnind_exception = arg; longjump(unwind_stack_top,1);
937+
#define RUST_CATCH if(!setjump(fn_jump_buff)) {unwind_stack_top = fn_jump_buff;
938+
#define RUST_RETHROW if (fn_jump_buff == unwind_stack_top) abort(); longjump(fn_jump_buff);
939+
#else
940+
union System_Exception global_uwnind_exception;
941+
#define RUST_THROW(arg) arg; abort();
942+
#define RUST_CATCH if(true){
943+
#define RUST_RETHROW abort();
944+
#endif

0 commit comments

Comments
 (0)