Skip to content

Commit

Permalink
Use _PyRuntime.debug_offsets.runtime_state.interpreters_head
Browse files Browse the repository at this point in the history
  • Loading branch information
benfred committed Oct 23, 2024
1 parent d47072d commit adfcfdd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
7 changes: 0 additions & 7 deletions src/python_bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ pub mod pyruntime {
minor: 11..=12,
..
} => 40,
// TODO: we can get this from the _PyRuntime.debug_offsets.runtime_state.interpreters_head
// way easier than we can get by updating manually, we should take advantagbe of that
Version {
major: 3,
minor: 13,
..
} => 632,
_ => 24,
}
}
Expand Down
27 changes: 26 additions & 1 deletion src/python_process_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,32 @@ where
match version {
Version {
major: 3,
minor: 7..=13,
minor: 13,
..
} => {
if let Some(&addr) = python_info.get_symbol("_PyRuntime") {
// figure out the interpreters_head location using the debug_offsets
let debug_offsets: v3_13_0::_Py_DebugOffsets =
process.copy_struct(addr as usize)?;
let addr = process.copy_struct(
addr as usize + debug_offsets.runtime_state.interpreters_head as usize,
)?;

// Make sure the interpreter addr is valid before returning
match check_interpreter_addresses(&[addr], &*python_info.maps, process, version) {
Ok(addr) => return Ok(addr),
Err(_) => {
warn!(
"Interpreter address from _PyRuntime symbol is invalid {:016x}",
addr
);
}
};
}
}
Version {
major: 3,
minor: 7..=12,
..
} => {
if let Some(&addr) = python_info.get_symbol("_PyRuntime") {
Expand Down

0 comments on commit adfcfdd

Please sign in to comment.