File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,12 @@ pub struct DefaultDecoder {
2525 mop : bool ,
2626 version : u32 ,
2727 cfi : CFI ,
28- // use a cache of instructions to avoid decoding the same instruction twice, pc is the key and the instruction is the value
29- instructions_cache : [ ( u64 , u64 ) ; INSTRUCTION_CACHE_SIZE ] ,
28+ // Use a cache of instructions to avoid decoding the same instruction
29+ // twice, pc is the key and the instruction is the value.
30+ //
31+ // Use Vector so that the data is on the heap. Otherwise, if there is
32+ // a vm call chain, it will quickly consume Rust's 2M stack space.
33+ instructions_cache : Vec < ( u64 , u64 ) > ,
3034}
3135
3236impl DefaultDecoder {
@@ -37,7 +41,7 @@ impl DefaultDecoder {
3741 mop,
3842 version,
3943 cfi : CFI :: default ( ) ,
40- instructions_cache : [ ( u64:: MAX , 0 ) ; INSTRUCTION_CACHE_SIZE ] ,
44+ instructions_cache : vec ! [ ( u64 :: MAX as u64 , 0 ) ; INSTRUCTION_CACHE_SIZE ] ,
4145 }
4246 }
4347
@@ -889,7 +893,7 @@ impl InstDecoder for DefaultDecoder {
889893 }
890894
891895 fn reset_instructions_cache ( & mut self ) -> Result < ( ) , Error > {
892- self . instructions_cache = [ ( u64:: MAX , 0 ) ; INSTRUCTION_CACHE_SIZE ] ;
896+ self . instructions_cache = vec ! [ ( u64 :: MAX , 0 ) ; INSTRUCTION_CACHE_SIZE ] ;
893897 Ok ( ( ) )
894898 }
895899}
You can’t perform that action at this time.
0 commit comments