Skip to content

Commit 85189c3

Browse files
committed
ptrace stuff
1 parent 21b3b5e commit 85189c3

File tree

7 files changed

+1017
-32
lines changed

7 files changed

+1017
-32
lines changed

Cargo.lock

Lines changed: 163 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ libc = "0.2"
4040
libffi = "4.0.0"
4141
libloading = "0.8"
4242
nix = { version = "0.30.1", features = ["mman", "ptrace", "signal"] }
43+
ipc-channel = "0.19.0"
44+
serde = { version = "1.0.219", features = ["derive"] }
45+
46+
[target.'cfg(all(unix, any(target_arch = "x86", target_arch = "x86_64")))'.dependencies]
47+
iced-x86 = "1.21.0"
4348

4449
[target.'cfg(target_family = "windows")'.dependencies]
4550
windows-sys = { version = "0.59", features = [

src/alloc_addresses/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,13 +465,26 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
465465
/// This overapproximates the modifications which external code might make to memory:
466466
/// We set all reachable allocations as initialized, mark all reachable provenances as exposed
467467
/// and overwrite them with `Provenance::WILDCARD`.
468-
fn prepare_exposed_for_native_call(&mut self) -> InterpResult<'tcx> {
468+
fn prepare_exposed_for_native_call(&mut self, _paranoid: bool) -> InterpResult<'tcx> {
469469
let this = self.eval_context_mut();
470470
// We need to make a deep copy of this list, but it's fine; it also serves as scratch space
471471
// for the search within `prepare_for_native_call`.
472472
let exposed: Vec<AllocId> =
473473
this.machine.alloc_addresses.get_mut().exposed.iter().copied().collect();
474-
this.prepare_for_native_call(exposed)
474+
this.prepare_for_native_call(exposed /*, paranoid*/)
475+
}
476+
477+
/// Makes use of information obtained about memory accesses during FFI to determine which
478+
/// provenances should be exposed. Note that if `prepare_exposed_for_native_call` was not
479+
/// called before the FFI (with `paranoid` set to false) then some of the writes may be
480+
/// lost!
481+
#[cfg(all(unix, any(target_arch = "x86", target_arch = "x86_64")))]
482+
fn apply_events(&mut self, _events: crate::shims::trace::MemEvents) -> InterpResult<'tcx> {
483+
let this = self.eval_context_mut();
484+
let _exposed: Vec<AllocId> =
485+
this.machine.alloc_addresses.get_mut().exposed.iter().copied().collect();
486+
interp_ok(())
487+
//this.apply_accesses(exposed, events.reads, events.writes)
475488
}
476489
}
477490

src/discrete_alloc.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ impl MachineAlloc {
5353
}
5454

5555
/// Returns a vector of page addresses managed by the allocator.
56-
#[expect(dead_code)]
5756
pub fn pages() -> Vec<u64> {
5857
let alloc = ALLOCATOR.lock().unwrap();
5958
alloc.pages.clone().into_iter().map(|p| p.addr().to_u64()).collect()
@@ -225,7 +224,6 @@ impl MachineAlloc {
225224
///
226225
/// SAFETY: Accessing memory after this point will result in a segfault
227226
/// unless it is first unprotected.
228-
#[expect(dead_code)]
229227
pub unsafe fn prepare_ffi() -> Result<(), nix::errno::Errno> {
230228
let mut alloc = ALLOCATOR.lock().unwrap();
231229
unsafe {
@@ -238,7 +236,6 @@ impl MachineAlloc {
238236
/// Deprotects all owned memory by setting it to RW. Erroring here is very
239237
/// likely unrecoverable, so it may panic if applying those permissions
240238
/// fails.
241-
#[expect(dead_code)]
242239
pub fn unprep_ffi() {
243240
let mut alloc = ALLOCATOR.lock().unwrap();
244241
let default_flags = ProtFlags::PROT_READ | ProtFlags::PROT_WRITE;

src/shims/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub mod os_str;
1919
pub mod panic;
2020
pub mod time;
2121
pub mod tls;
22+
#[cfg(all(unix, any(target_arch = "x86", target_arch = "x86_64")))]
23+
pub mod trace;
2224

2325
pub use self::files::FdTable;
2426
pub use self::unix::{DirTable, EpollInterestTable};

0 commit comments

Comments
 (0)