MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / allocate

Method allocate

vm-allocator/src/address.rs:166–194  ·  view source on GitHub ↗

Allocates a range of addresses from the managed region. Returns `Some(allocated_address)` when successful, or `None` if an area of `size` can't be allocated or if alignment isn't a power of two.

(
        &mut self,
        address: Option<GuestAddress>,
        size: GuestUsize,
        align_size: Option<GuestUsize>,
    )

Source from the content-addressed store, hash-verified

164 /// when successful, or `None` if an area of `size` can't be allocated or if alignment isn't
165 /// a power of two.
166 pub fn allocate(
167 &mut self,
168 address: Option<GuestAddress>,
169 size: GuestUsize,
170 align_size: Option<GuestUsize>,
171 ) -> Option<GuestAddress> {
172 if size == 0 {
173 return None;
174 }
175
176 let alignment = align_size.unwrap_or(4);
177 if !alignment.is_power_of_two() {
178 return None;
179 }
180
181 let new_addr = match address {
182 Some(req_address) => match self.available_range(req_address, size, alignment) {
183 Ok(addr) => addr,
184 Err(_) => {
185 return None;
186 }
187 },
188 None => self.first_available_range(size, alignment)?,
189 };
190
191 self.ranges.insert(new_addr, size);
192
193 Some(new_addr)
194 }
195
196 /// Free an already allocated address range.
197 /// We can only free a range if it matches exactly an already allocated range.

Callers 11

allocate_barsMethod · 0.80
allocate_barsMethod · 0.80
allocate_barsMethod · 0.80
allocate_barsMethod · 0.80
move_barMethod · 0.80
hotplug_ram_regionMethod · 0.80
allocate_io_addressesMethod · 0.80
allocate_barsMethod · 0.80

Calls 3

available_rangeMethod · 0.80
first_available_rangeMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected