mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-12 00:21:20 +00:00
Add illegal arithmetic runtime error
This commit is contained in:
@ -70,6 +70,7 @@ public:
|
||||
IncorrectCallIndirectSignature = 1,
|
||||
MemoryOutOfBounds = 2,
|
||||
CallIndirectOOB = 3,
|
||||
IllegalArithmetic = 4,
|
||||
Unknown,
|
||||
};
|
||||
|
||||
@ -98,6 +99,12 @@ private:
|
||||
case Type::MemoryOutOfBounds:
|
||||
out << "memory access out-of-bounds";
|
||||
break;
|
||||
case Type::CallIndirectOOB:
|
||||
out << "call_indirect out-of-bounds";
|
||||
break;
|
||||
case Type::IllegalArithmetic:
|
||||
out << "illegal arithmetic operation";
|
||||
break;
|
||||
case Type::Unknown:
|
||||
default:
|
||||
out << "unknown";
|
||||
@ -142,7 +149,6 @@ extern "C" {
|
||||
}
|
||||
|
||||
[[noreturn]] void throw_trap(WasmTrap::Type ty) {
|
||||
std::cout << "throwing trap: " << ty << std::endl;
|
||||
throw WasmTrap(ty);
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,8 @@ enum WasmTrapType {
|
||||
Unreachable = 0,
|
||||
IncorrectCallIndirectSignature = 1,
|
||||
MemoryOutOfBounds = 2,
|
||||
CallIndirectOOB = 3,
|
||||
IllegalArithmetic = 4,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
@ -407,6 +409,12 @@ impl ProtectedCaller for LLVMProtectedCaller {
|
||||
WasmTrapType::MemoryOutOfBounds => RuntimeError::Trap {
|
||||
msg: "memory out-of-bounds access".into(),
|
||||
},
|
||||
WasmTrapType::CallIndirectOOB => RuntimeError::Trap {
|
||||
msg: "call_indirect out-of-bounds".into(),
|
||||
},
|
||||
WasmTrapType::IllegalArithmetic => RuntimeError::Trap {
|
||||
msg: "illegal arithmetic operation".into(),
|
||||
},
|
||||
WasmTrapType::Unknown => RuntimeError::Trap {
|
||||
msg: "unknown trap".into(),
|
||||
},
|
||||
|
@ -122,6 +122,8 @@ pub fn parse_function_bodies(
|
||||
|
||||
generate_trampolines(info, &signatures, &module, &context, &builder, &intrinsics);
|
||||
|
||||
println!("done generating ir");
|
||||
|
||||
let pass_manager = PassManager::create_for_module();
|
||||
// pass_manager.add_verifier_pass();
|
||||
pass_manager.add_function_inlining_pass();
|
||||
@ -131,11 +133,13 @@ pub fn parse_function_bodies(
|
||||
pass_manager.add_aggressive_inst_combiner_pass();
|
||||
pass_manager.add_merged_load_store_motion_pass();
|
||||
// pass_manager.add_sccp_pass();
|
||||
pass_manager.add_gvn_pass();
|
||||
// pass_manager.add_new_gvn_pass();
|
||||
// pass_manager.add_gvn_pass();
|
||||
pass_manager.add_new_gvn_pass();
|
||||
pass_manager.add_aggressive_dce_pass();
|
||||
pass_manager.run_on_module(&module);
|
||||
|
||||
println!("done optimizing ir");
|
||||
|
||||
// module.print_to_stderr();
|
||||
|
||||
Ok((module, intrinsics))
|
||||
@ -2116,7 +2120,7 @@ fn trap_if_zero_or_overflow(
|
||||
builder.position_at_end(&should_trap_block);
|
||||
builder.build_call(
|
||||
intrinsics.throw_trap,
|
||||
&[intrinsics.trap_memory_oob],
|
||||
&[intrinsics.trap_illegal_arithmetic],
|
||||
"throw",
|
||||
);
|
||||
builder.build_unreachable();
|
||||
@ -2158,7 +2162,7 @@ fn trap_if_zero(
|
||||
builder.position_at_end(&should_trap_block);
|
||||
builder.build_call(
|
||||
intrinsics.throw_trap,
|
||||
&[intrinsics.trap_memory_oob],
|
||||
&[intrinsics.trap_illegal_arithmetic],
|
||||
"throw",
|
||||
);
|
||||
builder.build_unreachable();
|
||||
|
@ -97,6 +97,7 @@ pub struct Intrinsics {
|
||||
pub trap_call_indirect_sig: BasicValueEnum,
|
||||
pub trap_call_indirect_oob: BasicValueEnum,
|
||||
pub trap_memory_oob: BasicValueEnum,
|
||||
pub trap_illegal_arithmetic: BasicValueEnum,
|
||||
|
||||
// VM intrinsics.
|
||||
pub memory_grow_dynamic_local: FunctionValue,
|
||||
@ -295,6 +296,7 @@ impl Intrinsics {
|
||||
trap_call_indirect_sig: i32_ty.const_int(1, false).as_basic_value_enum(),
|
||||
trap_call_indirect_oob: i32_ty.const_int(3, false).as_basic_value_enum(),
|
||||
trap_memory_oob: i32_ty.const_int(2, false).as_basic_value_enum(),
|
||||
trap_illegal_arithmetic: i32_ty.const_int(4, false).as_basic_value_enum(),
|
||||
|
||||
// VM intrinsics.
|
||||
memory_grow_dynamic_local: module.add_function(
|
||||
|
Reference in New Issue
Block a user