MCPcopy Create free account
hub / github.com/IBM/ACE-RISCV / init

Method init

security-monitor/src/core/memory_layout/mod.rs:102–134  ·  view source on GitHub ↗

TODO: make sure that confidential and non-confidential mem are not bigger than isize?

(
        non_confidential_memory_start: *mut usize, non_confidential_memory_end: *const usize, confidential_memory_start: *mut usize,
        mut confidential_memory_end: *const usize,
    )

Source from the content-addressed store, hash-verified

100 #[rr::returns("res")]
101 // TODO: make sure that confidential and non-confidential mem are not bigger than isize?
102 pub unsafe fn init(
103 non_confidential_memory_start: *mut usize, non_confidential_memory_end: *const usize, confidential_memory_start: *mut usize,
104 mut confidential_memory_end: *const usize,
105 ) -> Result<(ConfidentialMemoryAddress, *const usize), Error> {
106 assert!((non_confidential_memory_start as *const usize) < non_confidential_memory_end);
107 assert!(non_confidential_memory_end <= (confidential_memory_start as *const usize));
108 assert!((confidential_memory_start as *const usize) < confidential_memory_end);
109
110 // We align the start of the confidential memory to the smallest possible page size (4KiB on RISC-V) and make
111 // sure that its size is the multiply of this page size.
112 let smalles_page_size_in_bytes = PageSize::smallest().in_bytes();
113 let confidential_memory_start = ptr_align(confidential_memory_start, smalles_page_size_in_bytes, confidential_memory_end)
114 .map_err(|_| Error::NotEnoughMemory())?;
115 // Let's make sure that the end of the confidential memory is properly aligned. I.e., there are no dangling
116 // bytes after the last page.
117 let memory_size = ptr_byte_offset(confidential_memory_end, confidential_memory_start);
118 let memory_size = usize::try_from(memory_size).map_err(|_| Error::NotEnoughMemory())?;
119 let number_of_pages = memory_size / smalles_page_size_in_bytes;
120 let memory_size_in_bytes = number_of_pages * smalles_page_size_in_bytes;
121 if memory_size > memory_size_in_bytes {
122 // We must modify the end_address because the current one is not a multiply of the smallest page size
123 confidential_memory_end = ptr_byte_add_mut(confidential_memory_start, memory_size_in_bytes, confidential_memory_end)?;
124 }
125
126 MEMORY_LAYOUT.call_once(|| MemoryLayout {
127 non_confidential_memory_start,
128 non_confidential_memory_end,
129 confidential_memory_start,
130 confidential_memory_end,
131 });
132
133 Ok((ConfidentialMemoryAddress::new(confidential_memory_start), confidential_memory_end))
134 }
135
136 /// Offsets an address in the confidential memory by a given number of bytes. Returns an error if the resulting
137 /// address is not in the confidential memory region.

Callers

nothing calls this directly

Calls 4

ptr_alignFunction · 0.85
ptr_byte_offsetFunction · 0.85
ptr_byte_add_mutFunction · 0.85
in_bytesMethod · 0.80

Tested by

no test coverage detected