@@ -62,7 +62,7 @@ use super::{
62
62
use crate :: hypervisor:: hypervisor_handler:: HypervisorHandler ;
63
63
use crate :: hypervisor:: HyperlightExit ;
64
64
use crate :: mem:: ptr:: { GuestPtr , RawPtr } ;
65
- use crate :: sandbox:: sandbox_builder:: { MemoryRegionFlags , SandboxMemorySections } ;
65
+ use crate :: sandbox:: sandbox_builder:: { MemoryRegionFlags , SandboxMemorySections , STACK_ALIGNMENT } ;
66
66
#[ cfg( gdb) ]
67
67
use crate :: HyperlightError ;
68
68
use crate :: { log_then_return, new_error, Result } ;
@@ -489,13 +489,17 @@ impl Hypervisor for HypervLinuxDriver {
489
489
) ?;
490
490
491
491
// The guest may have chosen a different stack region. If so, we drop usage of our tmp stack.
492
- let hyperlight_peb = self . mem_sections . read_hyperlight_peb ( ) ?;
492
+ let mut hyperlight_peb = self . mem_sections . read_hyperlight_peb ( ) ?;
493
493
494
494
if let Some ( guest_stack_data) = & hyperlight_peb. get_guest_stack_data_region ( ) {
495
495
if guest_stack_data. offset . is_some ( ) {
496
496
// If we got here, it means the guest has set up a new stack
497
497
let rsp = hyperlight_peb. get_top_of_guest_stack_data ( ) ;
498
- self . orig_rsp = GuestPtr :: try_from ( RawPtr :: from ( rsp) ) ?;
498
+ self . orig_rsp = GuestPtr :: try_from ( RawPtr :: from ( rsp - STACK_ALIGNMENT ) ) ?;
499
+
500
+ // Need to update the min stack address from tmp_stack address to the new stack
501
+ hyperlight_peb. min_stack_address = hyperlight_peb. calculate_min_stack_address ( ) ;
502
+ self . mem_sections . write_hyperlight_peb ( hyperlight_peb) ?;
499
503
}
500
504
}
501
505
@@ -730,67 +734,3 @@ impl Drop for HypervLinuxDriver {
730
734
}
731
735
}
732
736
}
733
-
734
- // TODO(danbugs:297): bring back
735
- // #[cfg(test)]
736
- // mod tests {
737
- // use super::*;
738
- // use crate::mem::memory_region::MemoryRegionVecBuilder;
739
- // use crate::mem::shared_mem::{ExclusiveSharedMemory, SharedMemory};
740
- //
741
- // #[rustfmt::skip]
742
- // const CODE: [u8; 12] = [
743
- // 0xba, 0xf8, 0x03, /* mov $0x3f8, %dx */
744
- // 0x00, 0xd8, /* add %bl, %al */
745
- // 0x04, b'0', /* add $'0', %al */
746
- // 0xee, /* out %al, (%dx) */
747
- // /* send a 0 to indicate we're done */
748
- // 0xb0, b'\0', /* mov $'\0', %al */
749
- // 0xee, /* out %al, (%dx) */
750
- // 0xf4, /* HLT */
751
- // ];
752
- //
753
- // fn shared_mem_with_code(
754
- // code: &[u8],
755
- // mem_size: usize,
756
- // load_offset: usize,
757
- // ) -> Result<Box<ExclusiveSharedMemory>> {
758
- // if load_offset > mem_size {
759
- // log_then_return!(
760
- // "code load offset ({}) > memory size ({})",
761
- // load_offset,
762
- // mem_size
763
- // );
764
- // }
765
- // let mut shared_mem = ExclusiveSharedMemory::new(mem_size)?;
766
- // shared_mem.copy_from_slice(code, load_offset)?;
767
- // Ok(Box::new(shared_mem))
768
- // }
769
- //
770
- // #[test]
771
- // fn create_driver() {
772
- // if !super::is_hypervisor_present() {
773
- // return;
774
- // }
775
- // const MEM_SIZE: usize = 0x3000;
776
- // let gm = shared_mem_with_code(CODE.as_slice(), MEM_SIZE, 0).unwrap();
777
- // let rsp_ptr = GuestPtr::try_from(0).unwrap();
778
- // let pml4_ptr = GuestPtr::try_from(0).unwrap();
779
- // let entrypoint_ptr = GuestPtr::try_from(0).unwrap();
780
- // let mut regions = MemoryRegionVecBuilder::new(0, gm.base_addr());
781
- // regions.push_page_aligned(
782
- // MEM_SIZE,
783
- // MemoryRegionFlags::READ | MemoryRegionFlags::WRITE | MemoryRegionFlags::EXECUTE,
784
- // crate::mem::memory_region::MemoryRegionType::Code,
785
- // );
786
- // super::HypervLinuxDriver::new(
787
- // regions.build(),
788
- // entrypoint_ptr,
789
- // rsp_ptr,
790
- // pml4_ptr,
791
- // #[cfg(gdb)]
792
- // None,
793
- // )
794
- // .unwrap();
795
- // }
796
- // }
0 commit comments