Skip to content

Commit ea28974

Browse files
committed
Changing Vec<String> of call_stack in thread_context to Vec<(u64, u64)> to run without allocation.
1 parent 0557d26 commit ea28974

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::emu::Emu;
22

33
impl Emu {
4-
pub fn call_stack(&self) -> &Vec<String> {
4+
pub fn call_stack(&self) -> &Vec<(u64, u64)> {
55
&self.threads[self.current_thread_id].call_stack
66
}
77

8-
pub fn call_stack_mut(&mut self) -> &mut Vec<String> {
8+
pub fn call_stack_mut(&mut self) -> &mut Vec<(u64, u64)> {
99
&mut self.threads[self.current_thread_id].call_stack
1010
}
1111
}

crates/libmwemu/src/emu/disassemble.rs renamed to crates/libmwemu/src/emu/disassemble/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use serde::{Deserialize, Serialize};
44

55
// about 10 mb should be on l3 cache
66
// 8192 cache lines,
7-
// 32 instructions for each one,
7+
// 64 instructions for each one,
88
// 40 for the struct (I think we can make it smaller)
9-
const INSTRUCTION_ARRAY_SIZE: usize = 8192 * 32;
9+
const INSTRUCTION_ARRAY_SIZE: usize = 8192 * 64;
1010

11-
// we want the cache size to be store in L1 cache which is lower than 40kb
12-
const CACHE_SIZE: usize = 2048 * 16;
11+
// we want the cache size to be store in L1 cache or L2 cache which is lower than 40kb
12+
const CACHE_SIZE: usize = 2048 * MAX_CACHE_PER_LINE;
1313
const CACHE_MASK: usize = CACHE_SIZE - 1; // Assumes power of 2
14-
const MAX_CACHE_PER_LINE: usize = 16;
14+
const MAX_CACHE_PER_LINE: usize = 32;
1515

1616
// we need INVALID_KEY and INVALID_LEN to be the same as INVALID_LPF_ADDR to optimize for memset
1717
pub const INVALID_LPF_ADDR: u64 = 0xffffffffffffffff;
@@ -146,6 +146,7 @@ impl InstructionCache {
146146
self.flush_cache();
147147
}
148148

149+
// we just need to decode until the call or jump instruction but not the entire one
149150
while decoder.can_decode() && decoder.position() + addition <= max_position {
150151
decoder.decode_out(&mut self.instructions[slot + count]);
151152
let temp = self.instructions[slot + count];

crates/libmwemu/src/emu_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub fn log_emu_state(emu: &mut Emu) {
127127
emu.call_stack().len().min(10)
128128
);
129129
for (i, entry) in emu.call_stack().iter().rev().take(10).enumerate() {
130-
log::error!(" {}: {}", i, entry);
130+
log::error!(" {}: {:x}:call:{:x}", i, entry.0, entry.1);
131131
}
132132
}
133133

crates/libmwemu/src/engine/instructions/call.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ pub fn execute(emu: &mut Emu, ins: &Instruction, instruction_sz: usize, _rep_ste
3535
emu.stack_lvl.push(0);
3636
emu.stack_lvl_idx += 1;
3737
}*/
38-
39-
let call_stack_label = format!("{:x}:call:{:x}", emu.regs().rip, addr);
40-
41-
emu.call_stack_mut().push(call_stack_label);
38+
39+
let rip = emu.regs().rip;
40+
emu.call_stack_mut().push((rip, addr));
4241

4342
if emu.cfg.is_64bits {
4443
if !emu.stack_push64(emu.regs().rip + instruction_sz as u64) {

crates/libmwemu/src/serialization/emu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub struct SerializableEmu {
8282
pub rep: Option<u64>,
8383
pub tick: usize,
8484
pub base: u64,
85-
pub call_stack: Vec<String>,
85+
pub call_stack: Vec<(u64, u64)>,
8686
pub heap_addr: u64,
8787
pub threads: Vec<SerializableThreadContext>,
8888
pub current_thread_id: usize,

crates/libmwemu/src/serialization/thread_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct SerializableThreadContext {
2929
pub tls64: Vec<u64>,
3030
pub fls: Vec<u32>,
3131
pub fs: BTreeMap<u64, u64>,
32-
pub call_stack: Vec<String>,
32+
pub call_stack: Vec<(u64, u64)>, // the first address is the source of the call location and the second address is the destination of the call
3333
}
3434

3535
impl From<&ThreadContext> for SerializableThreadContext {

crates/libmwemu/src/thread_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct ThreadContext {
2424
pub tls64: Vec<u64>,
2525
pub fls: Vec<u32>,
2626
pub fs: BTreeMap<u64, u64>,
27-
pub call_stack: Vec<String>,
27+
pub call_stack: Vec<(u64, u64)>,
2828
}
2929

3030
impl ThreadContext {
@@ -50,7 +50,7 @@ impl ThreadContext {
5050
tls64: Vec::new(),
5151
fls: Vec::new(),
5252
fs: BTreeMap::new(),
53-
call_stack: Vec::new(),
53+
call_stack: Vec::with_capacity(10000),
5454
}
5555
}
5656
}

0 commit comments

Comments
 (0)