Skip to content

Commit

Permalink
more krusty krab
Browse files Browse the repository at this point in the history
  • Loading branch information
nattthebear committed Jun 22, 2020
1 parent e3dd887 commit 9252557
Show file tree
Hide file tree
Showing 9 changed files with 525 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"editor.insertSpaces": false,
"editor.tabSize": 4,
"search.exclude": {
"waterbox": true
"waterbox/**": true
}
}
5 changes: 5 additions & 0 deletions waterbox/waterboxhost/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"search.exclude": {
"target/**": true
}
}
16 changes: 16 additions & 0 deletions waterbox/waterboxhost/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 waterbox/waterboxhost/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ page_size = "0.4.2"
lazy_static = "1.4.0"
getset = "0.1.1"
parking_lot = "0.10.2"
itertools = "0.9.0"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.8", features = ["memoryapi", "handleapi", "errhandlingapi", "winnt"] }
Expand Down
32 changes: 29 additions & 3 deletions waterbox/waterboxhost/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
#![crate_type = "cdylib"]

use std::io::{Read, Write};
// TODO: Turn this off once we've built the exported public API
#![allow(dead_code)]

use std::io::{Read, Write, Error};

const PAGESIZE: usize = 0x1000;
const PAGEMASK: usize = 0xfff;
const PAGESHIFT: i32 = 12;

mod memory_block;
mod syscall_defs;

pub trait IStateable {
fn save_sate(&mut self, stream: Box<dyn Write>);
fn load_state(&mut self, stream: Box<dyn Read>);
fn save_sate(&mut self, stream: Box<dyn Write>) -> Result<(), Error>;
fn load_state(&mut self, stream: Box<dyn Read>) -> Result<(), Error>;
}

#[derive(Debug, Clone, Copy)]
pub struct AddressRange {
pub start: usize,
pub size: usize,
}
impl AddressRange {
pub fn end(&self) -> usize {
self.start + self.size
}
pub fn contains(&self, addr: usize) -> bool {
addr >= self.start && addr < self.end()
}
/// Unsafe: Pointers are unchecked and lifetime is not connected to the AddressRange
pub unsafe fn slice(&self) -> &'static [u8] {
std::slice::from_raw_parts(self.start as *const u8, self.size)
}
/// Unsafe: Pointers are unchecked and lifetime is not connected to the AddressRange
pub unsafe fn slice_mut(&self) -> &'static mut [u8] {
std::slice::from_raw_parts_mut(self.start as *mut u8, self.size)
}
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 9252557

Please sign in to comment.