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

Add support to shadow memory #3184

Open
celinval opened this issue May 15, 2024 · 0 comments
Open

Add support to shadow memory #3184

celinval opened this issue May 15, 2024 · 0 comments
Assignees
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature.

Comments

@celinval
Copy link
Contributor

Requested feature: Add support to shadow memory
Use case: Allow users to extend their code for verification without impacting runtime

Test case:

union Data {
    word: usize,
    byte: u8,
}

impl Data {
    unsafe fn assume_word(&self) -> usize {
        self.word
    }
    unsafe fn assume_byte(&self) -> u8 {
        self.byte
    }
}

struct Memory {
    data: [Data; 1024],
    word: bool,
}

impl Memory {
    unsafe fn read_word(&self, index: usize) -> usize {
        assert!(self.word);
        unsafe { self.data[index].assume_word() }
    }

    unsafe fn read_byte(&self, index: usize) -> u8 {
        assert!(!self.word);
        unsafe { self.data[index].assume_byte() }
    }

    fn new(word: bool) { /* */}
}

#[kani::proof]
fn check_memory() {
    // info
}

Dummy example where users may want to use shadow memory to track how this code is being used. E.g.: Shadow memory could be used to track if the union has been initialized and which type has been used.

@celinval celinval added the [C] Feature / Enhancement A new feature request or enhancement to an existing feature. label May 15, 2024
zhassan-aws added a commit that referenced this issue Jun 4, 2024
Introduces a data structure, `ShadowMem<T>`, with two methods:
```rust
pub fn set<U>(&mut self, ptr: *const U, val: T)
pub fn get<U>(&self, ptr: *const U) -> T
```
for setting and getting values of type `T` associated with the memory location that `ptr` points to.

Towards #3184 

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature.
Projects
None yet
Development

No branches or pull requests

2 participants