mirror of
https://github.com/rcore-os/rCore.git
synced 2025-01-31 10:04:04 +04:00
Use MaybeUninit for uninitialized
This commit is contained in:
parent
e63f11d199
commit
c67f00d7ca
@ -109,8 +109,8 @@ impl<T: PageTable> CowExt<T> {
|
||||
self.rc_map.write_decrease(&frame);
|
||||
return true;
|
||||
}
|
||||
use core::mem::uninitialized;
|
||||
let mut temp_data: [u8; PAGE_SIZE] = unsafe { uninitialized() };
|
||||
use core::mem::MaybeUninit;
|
||||
let mut temp_data: [u8; PAGE_SIZE] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
temp_data[..].copy_from_slice(self.get_page_slice_mut(addr));
|
||||
|
||||
self.unmap_shared(addr);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
#![feature(alloc)]
|
||||
#![feature(nll)]
|
||||
#![feature(maybe_uninit)]
|
||||
|
||||
// import macros from log
|
||||
use log::*;
|
||||
|
@ -144,10 +144,10 @@ impl MockPageTable {
|
||||
** @retval MockPageTable the mock page table created
|
||||
*/
|
||||
pub fn new() -> Self {
|
||||
use core::mem::uninitialized;
|
||||
use core::mem::MaybeUninit;
|
||||
MockPageTable {
|
||||
entries: [MockEntry::default(); PAGE_COUNT],
|
||||
data: unsafe { uninitialized() },
|
||||
data: unsafe { MaybeUninit::uninitialized().into_initialized() },
|
||||
page_fault_handler: None,
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
use super::Swapper;
|
||||
use alloc::collections::BTreeMap;
|
||||
use core::mem::uninitialized;
|
||||
use core::mem::MaybeUninit;
|
||||
|
||||
const PAGE_SIZE: usize = 4096;
|
||||
|
||||
@ -17,7 +17,7 @@ pub struct MockSwapper {
|
||||
impl Swapper for MockSwapper {
|
||||
fn swap_out(&mut self, data: &[u8]) -> Result<usize, ()> {
|
||||
let id = self.alloc_id();
|
||||
let mut slice: [u8; PAGE_SIZE] = unsafe { uninitialized() };
|
||||
let mut slice: [u8; PAGE_SIZE] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
slice.copy_from_slice(data);
|
||||
self.map.insert(id, slice);
|
||||
Ok(id)
|
||||
@ -27,7 +27,7 @@ impl Swapper for MockSwapper {
|
||||
if !self.map.contains_key(&token) {
|
||||
return Err(());
|
||||
}
|
||||
let mut slice: [u8; PAGE_SIZE] = unsafe { uninitialized() };
|
||||
let mut slice: [u8; PAGE_SIZE] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
slice.copy_from_slice(data);
|
||||
self.map.insert(token, slice);
|
||||
Ok(())
|
||||
@ -64,8 +64,8 @@ mod test {
|
||||
#[test]
|
||||
fn swap_out_in() {
|
||||
let mut swapper = MockSwapper::default();
|
||||
let mut data: [u8; 4096] = unsafe { uninitialized() };
|
||||
let data1: [u8; 4096] = unsafe { uninitialized() };
|
||||
let mut data: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let data1: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let token = swapper.swap_out(&data1).unwrap();
|
||||
swapper.swap_in(token, &mut data).unwrap();
|
||||
assert_data_eq(&data, &data1);
|
||||
@ -74,9 +74,9 @@ mod test {
|
||||
#[test]
|
||||
fn swap_update() {
|
||||
let mut swapper = MockSwapper::default();
|
||||
let mut data: [u8; 4096] = unsafe { uninitialized() };
|
||||
let data1: [u8; 4096] = unsafe { uninitialized() };
|
||||
let data2: [u8; 4096] = unsafe { uninitialized() };
|
||||
let mut data: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let data1: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let data2: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let token = swapper.swap_out(&data1).unwrap();
|
||||
swapper.swap_update(token, &data2).unwrap();
|
||||
swapper.swap_in(token, &mut data).unwrap();
|
||||
@ -86,7 +86,7 @@ mod test {
|
||||
#[test]
|
||||
fn invalid_token() {
|
||||
let mut swapper = MockSwapper::default();
|
||||
let mut data: [u8; 4096] = unsafe { uninitialized() };
|
||||
let mut data: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
assert_eq!(swapper.swap_in(0, &mut data), Err(()));
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ impl PageTableImpl {
|
||||
PageTableImpl {
|
||||
page_table: MappedPageTable::new(table, frame_to_page_table),
|
||||
root_frame: frame,
|
||||
entry: core::mem::uninitialized(),
|
||||
entry: core::mem::MaybeUninit::uninitialized().into_initialized(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -227,7 +227,7 @@ impl PageTableExt for PageTableImpl {
|
||||
PageTableImpl {
|
||||
page_table: MappedPageTable::new(table, frame_to_page_table),
|
||||
root_frame: frame,
|
||||
entry: core::mem::uninitialized(),
|
||||
entry: core::mem::MaybeUninit::uninitialized().into_initialized(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ impl PageTableImpl {
|
||||
PageTableImpl {
|
||||
page_table: TwoLevelPageTable::new(table),
|
||||
root_frame: frame,
|
||||
entry: unsafe { core::mem::uninitialized() },
|
||||
entry: unsafe { core::mem::MaybeUninit::uninitialized().into_initialized() },
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -171,7 +171,7 @@ impl PageTableExt for PageTableImpl {
|
||||
PageTableImpl {
|
||||
page_table: TwoLevelPageTable::new(table),
|
||||
root_frame: frame,
|
||||
entry: unsafe { core::mem::uninitialized() },
|
||||
entry: unsafe { core::mem::MaybeUninit::uninitialized().into_initialized() },
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ impl PageTableImpl {
|
||||
let table = unsafe { &mut *frame_to_page_table(frame) };
|
||||
PageTableImpl(
|
||||
MappedPageTable::new(table, frame_to_page_table),
|
||||
core::mem::uninitialized(),
|
||||
core::mem::MaybeUninit::uninitialized().into_initialized()(),
|
||||
frame,
|
||||
)
|
||||
}
|
||||
@ -217,7 +217,7 @@ impl PageTableExt for PageTableImpl {
|
||||
unsafe {
|
||||
PageTableImpl(
|
||||
MappedPageTable::new(table, frame_to_page_table),
|
||||
core::mem::uninitialized(),
|
||||
core::mem::MaybeUninit::uninitialized().into_initialized()(),
|
||||
frame,
|
||||
)
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#![feature(panic_info_message)]
|
||||
#![feature(global_asm)]
|
||||
#![feature(fnbox)]
|
||||
#![feature(maybe_uninit)]
|
||||
#![deny(unused_must_use)]
|
||||
#![no_std]
|
||||
|
||||
|
@ -21,7 +21,7 @@ use crate::sync::{Condvar, SpinNoIrqLock as Mutex};
|
||||
|
||||
use super::abi::{self, ProcInitInfo};
|
||||
use crate::processor;
|
||||
use core::mem::uninitialized;
|
||||
use core::mem::MaybeUninit;
|
||||
use rcore_fs::vfs::INode;
|
||||
|
||||
pub struct Thread {
|
||||
@ -103,7 +103,7 @@ impl Thread {
|
||||
Box::new(Thread {
|
||||
context: Context::null(),
|
||||
// safety: other fields will never be used
|
||||
..core::mem::uninitialized()
|
||||
..core::mem::MaybeUninit::uninitialized().into_initialized()
|
||||
})
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ impl Thread {
|
||||
) -> Result<(MemorySet, usize, usize), &'static str> {
|
||||
// Read ELF header
|
||||
// 0x3c0: magic number from ld-musl.so
|
||||
let mut data: [u8; 0x3c0] = unsafe { uninitialized() };
|
||||
let mut data: [u8; 0x3c0] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
inode
|
||||
.read_at(0, &mut data)
|
||||
.map_err(|_| "failed to read from INode")?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user