pub fn spawn(&mut self, func: extern fn()) -> Result<&Arc<RwLock<Context>>> {
        let context_lock = self.new_context()?;
        {
            let mut context = context_lock.write();
            let mut fx = unsafe { Box::from_raw(crate::HEAP_ALLOCATOR.alloc(Layout::from_size_align_unchecked(512, 16)) as *mut [u8; 512]) };
            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>();
            unsafe {
                let offset = stack.len() - mem::size_of::<usize>();
                let func_ptr = stack.as_mut_ptr().offset(offset as isize);
                let cs_ptr = stack.as_mut_ptr().offset((offset - mem::size_of::<usize>()) as isize);
                *(cs_ptr as *mut usize) = 0x23;
                *(func_ptr as *mut usize) = func as usize;
            }
            println!("new thread func:0x{:X}", func as usize);
            context.arch.set_page_table(unsafe { ActivePageTable::address().as_u64() as usize });
            context.arch.set_fx(fx.as_ptr() as usize);
            context.arch.set_stack(stack.as_ptr() as usize + offset);
            context.kfx = Some(fx);
            context.kstack = Some(stack);
            context.unblock();
        }
        Ok(context_lock)
    }
/// Spawn a context from a function.
Spawn a context from a function.
Spawn a context from a function .
pub fn spawn(&mut self, func: extern fn()) -> Result<&Arc<RwLock<Context>>> {
        let context_lock = self.new_context()?;
        {
            let mut context = context_lock.write();
            let mut fx = unsafe { Box::from_raw(crate::HEAP_ALLOCATOR.alloc(Layout::from_size_align_unchecked(512, 16)) as *mut [u8; 512]) };
            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>();
            unsafe {
                let offset = stack.len() - mem::size_of::<usize>();
                let func_ptr = stack.as_mut_ptr().offset(offset as isize);
                let cs_ptr = stack.as_mut_ptr().offset((offset - mem::size_of::<usize>()) as isize);
                *(cs_ptr as *mut usize) = 0x23;
                *(func_ptr as *mut usize) = func as usize;
            }
            println!("new thread func:0x{:X}", func as usize);
            context.arch.set_page_table(unsafe { ActivePageTable::address().as_u64() as usize });
            context.arch.set_fx(fx.as_ptr() as usize);
            context.arch.set_stack(stack.as_ptr() as usize + offset);
            context.kfx = Some(fx);
            context.kstack = Some(stack);
            context.unblock();
        }
        Ok(context_lock)
    }
pub fn spawn ( & mut self , func : extern fn ( ) ) -> Result < & Arc < RwLock < Context > > > { let context_lock = self . new_context ( ) ? ; { let mut context = context_lock . write ( ) ; let mut fx = unsafe { Box :: from_raw ( crate :: HEAP_ALLOCATOR . alloc ( Layout :: from_size_align_unchecked ( 512 , 16 ) ) as * mut [ u8 ; 512 ] ) } ; 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 > ( ) ; unsafe { let offset = stack . len ( ) - mem :: size_of :: < usize > ( ) ; let func_ptr = stack . as_mut_ptr ( ) . offset ( offset as isize ) ; let cs_ptr = stack . as_mut_ptr ( ) . offset ( ( offset - mem :: size_of :: < usize > ( ) ) as isize ) ; * ( cs_ptr as * mut usize ) = 0x23 ; * ( func_ptr as * mut usize ) = func as usize ; } println ! ( " " func as usize ) ; context . arch . set_page_table ( unsafe { ActivePageTable :: address ( ) . as_u64 ( ) as usize } ) ; context . arch . set_fx ( fx . as_ptr ( ) as usize ) ; context . arch . set_stack ( stack . as_ptr ( ) as usize + offset ) ; context . kfx = Some ( fx ) ; context . kstack = Some ( stack ) ; context . unblock ( ) ; } Ok ( context_lock ) }
Spawn a context from a function.
Spawn a context from a function .
&mut self
func
extern fn()
&mut self
func
extern fn()