Add missing rustdocs for Windows code

This commit is contained in:
Brandon Fish
2019-11-10 16:03:43 -06:00
parent 82ec5e970a
commit ea3b6fa6d7
2 changed files with 20 additions and 0 deletions

View File

@ -133,14 +133,17 @@ unsafe impl Sync for CodeMemory {}
#[cfg(not(unix))]
impl CodeMemory {
/// Creates a new code memory with the given size.
pub fn new(_size: usize) -> CodeMemory {
unimplemented!("CodeMemory::new");
}
/// Makes this code memory executable.
pub fn make_executable(&self) {
unimplemented!("CodeMemory::make_executable");
}
/// Makes this code memory writable.
pub fn make_writable(&self) {
unimplemented!("CodeMemory::make_writable");
}

View File

@ -12,6 +12,7 @@ use winapi::um::winnt::{
unsafe impl Send for Memory {}
unsafe impl Sync for Memory {}
/// Data for a sized and protected region of memory.
#[derive(Debug)]
pub struct Memory {
ptr: *mut u8,
@ -20,6 +21,7 @@ pub struct Memory {
}
impl Memory {
/// Create a new memory from the given path value and protection.
pub fn with_size_protect(size: usize, protection: Protect) -> Result<Self, String> {
if size == 0 {
return Ok(Self {
@ -52,6 +54,7 @@ impl Memory {
}
}
/// Create a new memory with the given size.
pub fn with_size(size: usize) -> Result<Self, MemoryCreationError> {
if size == 0 {
return Ok(Self {
@ -79,6 +82,7 @@ impl Memory {
}
}
/// Protect this memory with the given range bounds and protection.
pub unsafe fn protect(
&mut self,
range: impl RangeBounds<usize>,
@ -120,6 +124,7 @@ impl Memory {
}
}
/// Split this memory into multiple memories by the given offset.
pub fn split_at(mut self, offset: usize) -> (Memory, Memory) {
let page_size = page_size::get();
if offset % page_size == 0 {
@ -140,22 +145,27 @@ impl Memory {
}
}
/// Gets the size of this memory.
pub fn size(&self) -> usize {
self.size
}
/// Gets a slice for this memory.
pub unsafe fn as_slice(&self) -> &[u8] {
slice::from_raw_parts(self.ptr, self.size)
}
/// Gets a mutable slice for this memory.
pub unsafe fn as_slice_mut(&mut self) -> &mut [u8] {
slice::from_raw_parts_mut(self.ptr, self.size)
}
/// Gets the protect kind of this memory.
pub fn protection(&self) -> Protect {
self.protection
}
/// Gets mutable pointer to the memory.
pub fn as_ptr(&self) -> *mut u8 {
self.ptr
}
@ -192,12 +202,17 @@ impl Clone for Memory {
}
}
/// Kinds of memory protection.
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
#[allow(dead_code)]
pub enum Protect {
/// Read/write/exec allowed.
None,
/// Read only.
Read,
/// Read/write only.
ReadWrite,
/// Read/exec only.
ReadExec,
}
@ -211,6 +226,7 @@ impl Protect {
}
}
/// Returns true if this memory is readable.
pub fn is_readable(self) -> bool {
match self {
Protect::Read | Protect::ReadWrite | Protect::ReadExec => true,
@ -218,6 +234,7 @@ impl Protect {
}
}
/// Returns true if this memory is writable.
pub fn is_writable(self) -> bool {
match self {
Protect::ReadWrite => true,