MCPcopy Create free account
hub / github.com/bytecodealliance/WASI-Virt / stack_alloc

Method stack_alloc

src/data.rs:69–80  ·  view source on GitHub ↗
(&'a mut self, data_len: usize, align: usize)

Source from the content-addressed store, hash-verified

67 }
68
69 fn stack_alloc<'a>(&'a mut self, data_len: usize, align: usize) -> Result<&'a mut [u8]> {
70 if data_len + align > self.stack_ptr {
71 bail!("Out of stack space for file virtualization, use passive segments by decreasing the passive cutoff instead");
72 }
73 let mut new_stack_ptr = self.stack_ptr - data_len;
74 if new_stack_ptr % align != 0 {
75 let padding = align - (self.stack_ptr % align);
76 new_stack_ptr -= padding;
77 }
78 self.stack_ptr = new_stack_ptr;
79 Ok(&mut self.bytes[new_stack_ptr..new_stack_ptr + data_len])
80 }
81
82 pub fn stack_bytes(&mut self, bytes: &[u8]) -> Result<u32> {
83 self.stack_alloc(bytes.len(), 1)?.copy_from_slice(bytes);

Callers 3

stack_bytesMethod · 0.80
write_sliceMethod · 0.80
stringMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected