Skip to content

Commit

Permalink
fix: rename patch_go to patch_elf (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
weilzkm authored Jun 12, 2024
1 parent cd579f7 commit b0a8989
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/zkmips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn split_elf_into_segs() {
let file =
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
let (mut state, _) = State::load_elf(&file);
state.patch_go(&file);
state.patch_elf(&file);
state.patch_stack(args);

let block_path = match block_no {
Expand Down
12 changes: 11 additions & 1 deletion src/mips_emulator/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl State {
(s, program)
}

pub fn patch_go(&mut self, f: &elf::ElfBytes<AnyEndian>) {
pub fn patch_elf(&mut self, f: &elf::ElfBytes<AnyEndian>) {
let symbols = f
.symbol_table()
.expect("failed to read symbols table, cannot patch program")
Expand All @@ -200,6 +200,7 @@ impl State {
| "github.com/prometheus/client_model/go.init.1"
| "flag.init"
| "runtime.check"
| "runtime.checkfds"
| "_dl_discover_osversion" => {
log::debug!("patch {} at {:X}", name, symbol.st_value);
let r: Vec<u8> = vec![0x03, 0xe0, 0x00, 0x08, 0, 0, 0, 0];
Expand Down Expand Up @@ -560,6 +561,15 @@ impl InstrumentedState {
v1 = MIPS_EBADF;
}
}
} else if a1 == 1 {
// GET_FD
match a0 {
FD_STDIN | FD_STDOUT | FD_STDERR => v0 = a0,
_ => {
v0 = 0xFFffFFff;
v1 = MIPS_EBADF;
}
}
} else {
v0 = 0xFFffFFff;
v1 = MIPS_EBADF;
Expand Down
8 changes: 4 additions & 4 deletions src/mips_emulator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod tests {
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
let (mut state, _) = State::load_elf(&file);

state.patch_go(&file);
state.patch_elf(&file);
state.patch_stack(vec!["aab", "ccd"]);

let mut instrumented_state = InstrumentedState::new(state, String::from(""));
Expand All @@ -80,7 +80,7 @@ mod tests {
let file =
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
let (mut state, _) = State::load_elf(&file);
state.patch_go(&file);
state.patch_elf(&file);
state.patch_stack(vec![]);

let mut instrumented_state = InstrumentedState::new(state, String::from(""));
Expand All @@ -102,7 +102,7 @@ mod tests {
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
let (mut state, _) = State::load_elf(&file);

state.patch_go(&file);
state.patch_elf(&file);
state.patch_stack(vec![]);

let block_path = get_block_path("./test-vectors", "13284491", "");
Expand Down Expand Up @@ -137,7 +137,7 @@ mod tests {
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
let (mut state, _) = State::load_elf(&file);

state.patch_go(&file);
state.patch_elf(&file);
state.patch_stack(vec![]);

let mut instrumented_state = InstrumentedState::new(state, String::from(""));
Expand Down
2 changes: 1 addition & 1 deletion tests/simple_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn split_elf_into_segs(
let file =
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
let (mut state, _) = State::load_elf(&file);
state.patch_go(&file);
state.patch_elf(&file);
state.patch_stack(vec![]);

let block_path = get_block_path(basedir, block_no, "");
Expand Down

0 comments on commit b0a8989

Please sign in to comment.