From 8a92cd103696a45ebc4e9a828ed889733dd109aa Mon Sep 17 00:00:00 2001 From: Mingkai Li Date: Wed, 16 Aug 2023 12:35:18 +0000 Subject: [PATCH] #7 add revocation tree allocation fail exception code --- riscv/encoding.h | 4 +++- riscv/insns/cs_mrev.h | 3 ++- riscv/insns/cs_split.h | 3 ++- riscv/trap.h | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/riscv/encoding.h b/riscv/encoding.h index 25b62556..063b44c1 100644 --- a/riscv/encoding.h +++ b/riscv/encoding.h @@ -3250,7 +3250,7 @@ #define CAUSE_INSUFFICIENT_CAP_PERMS 0x1b #define CAUSE_CAP_OUT_OF_BOUND 0x1c #define CAUSE_ILLEGAL_OPERAND_VALUE 0x1d -// CAUSE_UNHANDLEABLE_EXCEPTION only used in pure capstone +#define CAUSE_INSUFFICIENT_SYSTEM_RESOURCES 0x1e // #define CAUSE_UNHANDLEABLE_EXCEPTION 0x3f /*end of capstone added exception code*/ #endif @@ -4929,6 +4929,8 @@ DECLARE_CAUSE("unexpected capability type", CAUSE_UNEXPECTED_CAP_TYPE) DECLARE_CAUSE("insufficient capability permissions", CAUSE_INSUFFICIENT_CAP_PERMS) DECLARE_CAUSE("capability out of bound", CAUSE_CAP_OUT_OF_BOUND) DECLARE_CAUSE("illegal operand value", CAUSE_ILLEGAL_OPERAND_VALUE) +DECLARE_CAUSE("insufficient system resources", CAUSE_INSUFFICIENT_SYSTEM_RESOURCES) + // DECLARE_CAUSE("unhandleable exception", CAUSE_UNHANDLEABLE_EXCEPTION) /*end of capstone added exceptions*/ #endif diff --git a/riscv/insns/cs_mrev.h b/riscv/insns/cs_mrev.h index 8d9011ab..0b467ec4 100644 --- a/riscv/insns/cs_mrev.h +++ b/riscv/insns/cs_mrev.h @@ -14,7 +14,8 @@ if (IS_CAP(insn_rd)) UPDATE_RC_DOWN(READ_CAP_NODE(insn_rd)); WRITE_CAP_DUMB(insn_rd, READ_CAP(insn_rs1)); /*update rs1 capability node_id*/ rev_node_id_t mrev_node_id = ALLOCATE_NODE(READ_CAP_NODE(insn_rs1)); -assert(mrev_node_id != REV_NODE_ID_INVALID); // crush if no node available +if (mrev_node_id == REV_NODE_ID_INVALID) + throw trap_capstone_insufficient_system_resources(insn.bits()); READ_CAP(insn_rs1).node_id = mrev_node_id; /*update rd capability type*/ if (NOT_ZERO_REG(insn_rd)) { diff --git a/riscv/insns/cs_split.h b/riscv/insns/cs_split.h index 2b1bec9f..6474dc1e 100644 --- a/riscv/insns/cs_split.h +++ b/riscv/insns/cs_split.h @@ -25,7 +25,8 @@ if (insn_rs1 != insn_rd) { // allocate new node if (NOT_ZERO_REG(insn_rd)) { rev_node_id_t split_node_id = SPLIT_RT(READ_CAP_NODE(insn_rs1)); - assert(split_node_id != REV_NODE_ID_INVALID); // crush if no more node + if (split_node_id == REV_NODE_ID_INVALID) + throw trap_capstone_insufficient_system_resources(insn.bits()); READ_CAP(insn_rd).node_id = split_node_id; READ_CAP(insn_rd).base = tmp_val; READ_CAP(insn_rd).cursor = tmp_val; diff --git a/riscv/trap.h b/riscv/trap.h index 8f885d1e..bec0198a 100644 --- a/riscv/trap.h +++ b/riscv/trap.h @@ -139,5 +139,6 @@ DECLARE_CAPSTONE_TRAP(CAUSE_UNEXPECTED_CAP_TYPE, capstone_unexpected_cap_type) DECLARE_CAPSTONE_TRAP(CAUSE_INSUFFICIENT_CAP_PERMS, capstone_insufficient_cap_perms) DECLARE_CAPSTONE_TRAP(CAUSE_CAP_OUT_OF_BOUND, capstone_cap_out_of_bound) DECLARE_CAPSTONE_TRAP(CAUSE_ILLEGAL_OPERAND_VALUE, capstone_illegal_operand_value) +DECLARE_CAPSTONE_TRAP(CAUSE_INSUFFICIENT_SYSTEM_RESOURCES, capstone_insufficient_system_resources) /*end of transcapstone exceptions*/ #endif