@@ -62,8 +62,6 @@ pub type DefaultBackend = crate::macos::XhyveVm;
6262pub ( crate ) mod internal {
6363 use std:: sync:: Arc ;
6464
65- use uhyve_interface:: GuestPhysAddr ;
66-
6765 use crate :: {
6866 HypervisorResult ,
6967 vcpu:: VirtualCPU ,
@@ -83,11 +81,7 @@ pub(crate) mod internal {
8381 enable_stats : bool ,
8482 ) -> HypervisorResult < Self :: VCPU > ;
8583
86- fn new (
87- peripherals : Arc < VmPeripherals > ,
88- params : & Params ,
89- guest_addr : GuestPhysAddr ,
90- ) -> HypervisorResult < Self > ;
84+ fn new ( peripherals : Arc < VmPeripherals > , params : & Params ) -> HypervisorResult < Self > ;
9185 }
9286}
9387
@@ -152,6 +146,18 @@ impl<VirtBackend: VirtualizationBackend> UhyveVm<VirtBackend> {
152146 info ! ( "Loading a pre Hermit v0.10.0 kernel" ) ;
153147 }
154148
149+ // Kernels with different Uhyve interface versions may have differing addresses for the
150+ // serial port. As we begun embedding the uhyve-interface version in unikernel images
151+ // much later than v1, but before v2, we assume that all images that don't have a version
152+ // embedded must be v1.
153+ //
154+ // Further, it is used for establishing an appropriate random start addrses for ASLR.
155+ let uhyve_interface_version = object
156+ . uhyve_interface_version ( )
157+ . unwrap_or ( UhyveIfVersion ( 1 ) ) ;
158+
159+ debug ! ( "Detected Uhyve interface version: {uhyve_interface_version}" ) ;
160+
155161 // The memory layout of uhyve looks as follows:
156162 //
157163 // 0x0000_0000 ┌───────────────────┐
@@ -186,11 +192,12 @@ impl<VirtBackend: VirtualizationBackend> UhyveVm<VirtBackend> {
186192 }
187193 ( arch:: RAM_START , GuestPhysAddr :: from ( start_addr) )
188194 } else {
189- let guest_address = if params. aslr {
190- generate_address ( object. mem_size ( ) )
191- } else {
192- arch:: RAM_START
193- } ;
195+ let guest_address = generate_address (
196+ uhyve_interface_version,
197+ params. aslr ,
198+ object. mem_size ( ) ,
199+ memory_size,
200+ ) ;
194201 ( guest_address, ( guest_address + KERNEL_OFFSET ) )
195202 } ;
196203
@@ -266,8 +273,7 @@ impl<VirtBackend: VirtualizationBackend> UhyveVm<VirtBackend> {
266273 serial,
267274 } ) ;
268275
269- let virt_backend =
270- VirtBackend :: BACKEND :: new ( peripherals. clone ( ) , & kernel_info. params , guest_address) ?;
276+ let virt_backend = VirtBackend :: BACKEND :: new ( peripherals. clone ( ) , & kernel_info. params ) ?;
271277
272278 let cpu_count = kernel_info. params . cpu_count . get ( ) ;
273279
@@ -290,14 +296,6 @@ impl<VirtBackend: VirtualizationBackend> UhyveVm<VirtBackend> {
290296
291297 let freq = vcpus[ 0 ] . get_cpu_frequency ( ) ;
292298
293- // Kernels with different Uhyve interface versions may have differing addresses for the
294- // serial port. As we begun embedding the uhyve-interface version in unikernel images
295- // much later than v1, but before v2, we assume that all images that don't have a version
296- // embedded must be v1.
297- let uhyve_interface_version = object
298- . uhyve_interface_version ( )
299- . unwrap_or ( UhyveIfVersion ( 1 ) ) ;
300-
301299 let serial_port = SerialPortBase :: new ( match uhyve_interface_version. 0 {
302300 1 => uhyve_interface:: v1:: HypercallAddress :: Uart as _ ,
303301 2 => uhyve_interface:: v2:: HypercallAddress :: SerialWriteBuffer as _ ,
0 commit comments