MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / allocate

Method allocate

cranelift/jit/src/memory/system.rs:72–93  ·  view source on GitHub ↗
(&mut self, size: usize, align: u64)

Source from the content-addressed store, hash-verified

70 }
71
72 pub(crate) fn allocate(&mut self, size: usize, align: u64) -> io::Result<*mut u8> {
73 let align = usize::try_from(align).expect("alignment too big");
74 if self.position % align != 0 {
75 self.position += align - self.position % align;
76 debug_assert!(self.position % align == 0);
77 }
78
79 if size <= self.current.len - self.position {
80 // TODO: Ensure overflow is not possible.
81 let ptr = unsafe { self.current.ptr.add(self.position) };
82 self.position += size;
83 return Ok(ptr);
84 }
85
86 self.finish_current();
87
88 // TODO: Allocate more at a time.
89 self.current = PtrLen::with_size(size)?;
90 self.position = size;
91
92 Ok(self.current.ptr)
93 }
94
95 /// Set all memory allocated in this `Memory` up to now as readable and executable.
96 pub(crate) fn set_readable_and_executable(

Callers 2

newMethod · 0.45
new_zeroedMethod · 0.45

Calls 4

OkFunction · 0.85
finish_currentMethod · 0.80
expectMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected