Skip to content

Commit

Permalink
Cosmetic changes and soundness bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Nov 29, 2019
1 parent 15eb11c commit 1c8edcb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
max_width = 79
wrap_comments = true
error_on_line_overflow = false
fn_args_density = "Compressed"
fn_args_layout = "Compressed"
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,17 @@ impl<T> SliceDeque<T> {
/// assert_eq!(s.len(), cap - len);
/// // We can write to them and for example bump the tail of
/// // the deque:
/// s[0] = 4;
/// s[1] = 5;
/// s[0] = std::mem::MaybeUninit::new(4);
/// s[1] = std::mem::MaybeUninit::new(5);
/// }
/// d.move_tail(2);
/// }
/// assert_eq!(d, sdeq![1, 2, 3, 4, 5]);
/// # }
/// ```
pub unsafe fn tail_head_slice(&mut self) -> &mut [T] {
pub unsafe fn tail_head_slice(&mut self) -> &mut [mem::MaybeUninit<T>] {
let ptr = self.as_mut_slice().as_mut_ptr().add(self.len());
slice::from_raw_parts_mut(ptr, self.capacity() - self.len())
slice::from_raw_parts_mut(ptr as _, self.capacity() - self.len())
}

/// Attempts to reserve capacity for inserting at least `additional`
Expand Down Expand Up @@ -5717,7 +5717,7 @@ mod tests {

for i in 0..slice.len() {
// segfault:
slice[i] = 0;
slice[i] = mem::MaybeUninit::new(0);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/mirrored/linux.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Non-racy linux-specific mirrored memory allocation.
use libc::{
c_char, c_int, c_long, c_uint, c_void, close, ftruncate, mkstemp, mmap,
munmap, off_t, size_t, sysconf, ENOSYS, unlink,
MAP_FAILED, MAP_FIXED, MAP_SHARED, PROT_READ, PROT_WRITE, _SC_PAGESIZE,
munmap, off_t, size_t, sysconf, unlink, ENOSYS, MAP_FAILED, MAP_FIXED,
MAP_SHARED, PROT_READ, PROT_WRITE, _SC_PAGESIZE,
};

#[cfg(any(target_os = "android", target_os = "openbsd"))]
Expand Down
13 changes: 7 additions & 6 deletions src/mirrored/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ pub fn allocate_mirrored(size: usize) -> Result<*mut u8, AllocError> {

// Get an object handle to the first memory region:
let mut memory_object_size = half_size as memory_object_size_t;
let mut object_handle: mem_entry_name_port_t = mem::uninitialized();
let mut object_handle =
mem::MaybeUninit::<mem_entry_name_port_t>::uninit();
let parent_handle: mem_entry_name_port_t = 0;
let r: kern_return_t = mach_make_memory_entry_64(
task,
&mut memory_object_size as *mut memory_object_size_t,
addr as memory_object_offset_t,
VM_PROT_READ | VM_PROT_WRITE,
&mut object_handle as *mut mem_entry_name_port_t,
object_handle.as_mut_ptr(),
parent_handle,
);

Expand All @@ -115,8 +116,8 @@ pub fn allocate_mirrored(size: usize) -> Result<*mut u8, AllocError> {

// Map the first half to the second half using the object handle:
let mut to = (addr as *mut u8).add(half_size) as mach_vm_address_t;
let mut current_prot: vm_prot_t = mem::uninitialized();
let mut out_prot: vm_prot_t = mem::uninitialized();
let mut current_prot = mem::MaybeUninit::<vm_prot_t>::uninit();
let mut out_prot = mem::MaybeUninit::<vm_prot_t>::uninit();
let r: kern_return_t = mach_vm_remap(
task,
&mut to as *mut mach_vm_address_t,
Expand All @@ -126,8 +127,8 @@ pub fn allocate_mirrored(size: usize) -> Result<*mut u8, AllocError> {
task,
addr,
/* copy: */ 0 as boolean_t,
&mut current_prot as *mut vm_prot_t,
&mut out_prot as *mut vm_prot_t,
current_prot.as_mut_ptr(),
out_prot.as_mut_ptr(),
VM_INHERIT_NONE,
);

Expand Down
11 changes: 2 additions & 9 deletions src/mirrored/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,12 @@ pub(crate) use self::sysv::{
};

#[cfg(all(
any(target_os = "linux",
target_os = "android",
target_os = "openbsd"
),
any(target_os = "linux", target_os = "android", target_os = "openbsd"),
not(feature = "unix_sysv")
))]
mod linux;
#[cfg(all(
any(
target_os = "linux",
target_os = "android",
target_os = "openbsd"
),
any(target_os = "linux", target_os = "android", target_os = "openbsd"),
not(feature = "unix_sysv")
))]
pub(crate) use self::linux::{
Expand Down
5 changes: 3 additions & 2 deletions src/mirrored/winapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ use super::AllocError;
/// size (64k vs 4k), so determining the page size here is not necessary.
pub fn allocation_granularity() -> usize {
unsafe {
let mut system_info: SYSTEM_INFO = mem::uninitialized();
GetSystemInfo(&mut system_info as LPSYSTEM_INFO);
let mut system_info = mem::MaybeUninit::<SYSTEM_INFO>::uninit();
GetSystemInfo(system_info.as_mut_ptr() as LPSYSTEM_INFO);
let system_info = system_info.assume_init();
let allocation_granularity =
system_info.dwAllocationGranularity as usize;
let page_size = system_info.dwPageSize as usize;
Expand Down

0 comments on commit 1c8edcb

Please sign in to comment.