@@ -1768,3 +1768,83 @@ fn interrupt_cancel_delete_race() {
17681768 handle. join ( ) . unwrap ( ) ;
17691769 }
17701770}
1771+
1772+ /// Compile-time regression guard for public visibility of memory
1773+ /// region types.
1774+ ///
1775+ /// This test MUST live in an integration test (not a unit test)
1776+ /// because integration tests are compiled as separate crates and can
1777+ /// only access items marked `pub`. A unit test inside the crate
1778+ /// would also see `pub(crate)` items, defeating the purpose.
1779+ ///
1780+ /// If any of these types or fields revert to `pub(crate)`, this test
1781+ /// will fail to **compile** — catching the regression before CI even
1782+ /// runs the test binary.
1783+ #[ test]
1784+ fn memory_region_types_are_publicly_accessible ( ) {
1785+ use hyperlight_host:: mem:: memory_region:: {
1786+ HostGuestMemoryRegion , MemoryRegion_ , MemoryRegionFlags , MemoryRegionKind , MemoryRegionType ,
1787+ } ;
1788+
1789+ // This test is a compile-time guard. If it compiles, it passes.
1790+ // Every line below would cause a compile error if the referenced
1791+ // type, variant, or field reverted to pub(crate).
1792+
1793+ // MemoryRegionType enum and all its variants are pub
1794+ let _rt = MemoryRegionType :: Code ;
1795+ let _rt = MemoryRegionType :: InitData ;
1796+ let _rt = MemoryRegionType :: Peb ;
1797+ let _rt = MemoryRegionType :: Heap ;
1798+ let _rt = MemoryRegionType :: Scratch ;
1799+ let _rt = MemoryRegionType :: Snapshot ;
1800+ let _rt = MemoryRegionType :: MappedFile ;
1801+
1802+ // MemoryRegionFlags is pub and combinable
1803+ let _flags = MemoryRegionFlags :: READ | MemoryRegionFlags :: WRITE | MemoryRegionFlags :: EXECUTE ;
1804+
1805+ // SurrogateMapping enum and MemoryRegionType::surrogate_mapping()
1806+ // are pub (Windows only).
1807+ #[ cfg( target_os = "windows" ) ]
1808+ {
1809+ use hyperlight_host:: mem:: memory_region:: SurrogateMapping ;
1810+
1811+ let mapping = MemoryRegionType :: MappedFile . surrogate_mapping ( ) ;
1812+ let _: SurrogateMapping = mapping;
1813+ let _ = SurrogateMapping :: SandboxMemory ;
1814+ let _ = SurrogateMapping :: ReadOnlyFile ;
1815+ }
1816+
1817+ // MemoryRegion_ struct and all its fields are pub (struct literal
1818+ // construction requires every field to be pub).
1819+ #[ cfg( not( target_os = "windows" ) ) ]
1820+ {
1821+ let base: <HostGuestMemoryRegion as MemoryRegionKind >:: HostBaseType = 0x1000 ;
1822+ let _region = MemoryRegion_ :: < HostGuestMemoryRegion > {
1823+ guest_region : 0x1000 ..0x2000 ,
1824+ host_region : base..<HostGuestMemoryRegion as MemoryRegionKind >:: add ( base, 0x1000 ) ,
1825+ flags : MemoryRegionFlags :: READ ,
1826+ region_type : MemoryRegionType :: Code ,
1827+ } ;
1828+ }
1829+
1830+ #[ cfg( target_os = "windows" ) ]
1831+ {
1832+ use hyperlight_host:: hypervisor:: wrappers:: HandleWrapper ;
1833+ use hyperlight_host:: mem:: memory_region:: HostRegionBase ;
1834+ use windows:: Win32 :: Foundation :: HANDLE ;
1835+
1836+ let host_base = HostRegionBase {
1837+ from_handle : HandleWrapper :: from ( HANDLE ( std:: ptr:: null_mut ( ) ) ) ,
1838+ handle_base : 0x1000 ,
1839+ handle_size : 0x1000 ,
1840+ offset : 0 ,
1841+ } ;
1842+ let _region = MemoryRegion_ :: < HostGuestMemoryRegion > {
1843+ guest_region : 0x1000 ..0x2000 ,
1844+ host_region : host_base
1845+ ..<HostGuestMemoryRegion as MemoryRegionKind >:: add ( host_base, 0x1000 ) ,
1846+ flags : MemoryRegionFlags :: READ ,
1847+ region_type : MemoryRegionType :: Code ,
1848+ } ;
1849+ }
1850+ }
0 commit comments