Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct PDG exclusively on provenance information #1107

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions analysis/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ enum_dispatch = "0.3"
fs-err = "2"
crossbeam-queue = "0.3"
crossbeam-utils = "0.8"
indexmap = { version = "1.9", features = ["serde"] }
14 changes: 9 additions & 5 deletions analysis/runtime/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ pub enum EventKind {

CopyRef,

/// Field projection. Used for operations like `_2 = &(*_1).0`. Nested field
/// accesses like `_4 = &(*_1).x.y.z` are broken into multiple `Node`s, each
/// covering one level.
Field(Pointer, u32),
/// Projection. Used for operations like `_2 = &(*_1).0`.
/// The third value is a "projection index" that points to an element
/// of the projections data structure in the metadata. It is used to
/// disambiguate between different projections with the same pointer,
/// e.g., `(*p).x` and `(*p).x.a` where `a` is at offset 0.
Project(Pointer, Pointer, usize),

Alloc {
size: usize,
Expand Down Expand Up @@ -90,7 +92,9 @@ impl Debug for EventKind {
use EventKind::*;
match *self {
CopyPtr(ptr) => write!(f, "copy(0x{:x})", ptr),
Field(ptr, id) => write!(f, "field(0x{:x}, {})", ptr, id),
Project(ptr, new_ptr, idx) => {
write!(f, "project(0x{:x}, 0x{:x}, [{}])", ptr, new_ptr, idx)
}
Alloc { size, ptr } => {
write!(f, "malloc({}) -> 0x{:x}", size, ptr)
}
Expand Down
4 changes: 2 additions & 2 deletions analysis/runtime/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ pub const HOOK_FUNCTIONS: &[&str] = &[
hook_fn!(offset),
];

pub fn ptr_field(mir_loc: MirLocId, ptr: usize, field_id: u32) {
pub fn ptr_project(mir_loc: MirLocId, ptr: usize, new_ptr: usize, proj_idx: usize) {
RUNTIME.send_event(Event {
mir_loc,
kind: EventKind::Field(ptr, field_id),
kind: EventKind::Project(ptr, new_ptr, proj_idx),
});
}

Expand Down
10 changes: 9 additions & 1 deletion analysis/runtime/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use indexmap::IndexSet;
use std::{
collections::HashMap,
fmt::{self, Debug, Formatter},
Expand All @@ -13,6 +14,7 @@ use crate::mir_loc::{Func, FuncId, MirLoc, MirLocId};
pub struct Metadata {
pub locs: Vec<MirLoc>,
pub functions: HashMap<FuncId, String>,
pub projections: IndexSet<Vec<usize>>,
}

impl Metadata {
Expand Down Expand Up @@ -46,11 +48,17 @@ impl FromIterator<Metadata> for Metadata {
fn from_iter<I: IntoIterator<Item = Metadata>>(iter: I) -> Self {
let mut locs = Vec::new();
let mut functions = HashMap::new();
let mut projections = IndexSet::new();
for metadata in iter {
locs.extend(metadata.locs);
functions.extend(metadata.functions);
projections.extend(metadata.projections);
}
Self {
locs,
functions,
projections,
}
Self { locs, functions }
}
}

Expand Down
Loading
Loading