Use alloc_zeroed when allocating FX.

This commit is contained in:
4lDO2
2022-07-11 13:55:21 +02:00
parent db3b834f19
commit 94578efd1e
2 changed files with 8 additions and 8 deletions

View File

@@ -80,13 +80,11 @@ impl ContextList {
{
let mut context = context_lock.write();
let mut fx = unsafe {
let ptr = crate::ALLOCATOR.alloc(Layout::from_size_align_unchecked(1024, 16)) as *mut [u8; 1024];
// TODO: Alignment must match, the following can be UB. Use AlignedBox.
let ptr = crate::ALLOCATOR.alloc_zeroed(Layout::from_size_align_unchecked(1024, 16)) as *mut [u8; 1024];
if ptr.is_null() { return Err(Error::new(ENOMEM)); }
Box::from_raw(ptr)
};
for b in fx.iter_mut() {
*b = 0;
}
let mut stack = vec![0; 65_536].into_boxed_slice();
let offset = stack.len() - mem::size_of::<usize>();

View File

@@ -57,10 +57,12 @@ pub fn init() {
let mut contexts = contexts_mut();
let context_lock = contexts.new_context().expect("could not initialize first context");
let mut context = context_lock.write();
let mut fx = unsafe { Box::from_raw(crate::ALLOCATOR.alloc(Layout::from_size_align_unchecked(1024, 16)) as *mut [u8; 1024]) };
for b in fx.iter_mut() {
*b = 0;
}
let fx = unsafe {
// TODO: Alignment must match, the following can be UB. Use AlignedBox.
let ptr = crate::ALLOCATOR.alloc_zeroed(Layout::from_size_align_unchecked(1024, 16)) as *mut [u8; 1024];
assert!(!ptr.is_null(), "failed to allocate FX to kmain!");
Box::from_raw(ptr)
};
context.arch.set_fx(fx.as_ptr() as usize);
context.kfx = Some(fx);