diff --git a/src/context/list.rs b/src/context/list.rs index dc11536..a745955 100644 --- a/src/context/list.rs +++ b/src/context/list.rs @@ -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::(); diff --git a/src/context/mod.rs b/src/context/mod.rs index 9268b14..6b80e0f 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -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);