mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-16 03:20:50 +00:00
more senseful input/context allocation
This commit is contained in:
parent
bcdb942036
commit
1083eaa65d
@ -42,22 +42,32 @@ pub fn init(
|
||||
let allocator = runtime.allocator();
|
||||
|
||||
let descriptor_ptr = allocator.alloc(16)?;
|
||||
let context_ptr = allocator.alloc(context.len() as u32)?;
|
||||
let input_ptr = allocator.alloc(input.len() as u32)?;
|
||||
|
||||
write_u32(&mut context_ptr_slc, context_ptr);
|
||||
write_u32(&mut context_length, context.len() as u32);
|
||||
write_u32(&mut input_ptr_slc, input_ptr);
|
||||
write_u32(&mut input_length, input.len() as u32);
|
||||
|
||||
println!("descriptor_ptr: {}", descriptor_ptr);
|
||||
let memory = env.memory(DEFAULT_MEMORY_INDEX)?;
|
||||
|
||||
if context.len() > 0 {
|
||||
let context_ptr = allocator.alloc(context.len() as u32)?;
|
||||
write_u32(&mut context_ptr_slc, context_ptr);
|
||||
write_u32(&mut context_length, context.len() as u32);
|
||||
memory.set(context_ptr, context)?;
|
||||
println!("context_ptr: {}", context_ptr);
|
||||
}
|
||||
|
||||
if input.len() > 0 {
|
||||
let input_ptr = allocator.alloc(input.len() as u32)?;
|
||||
write_u32(&mut input_ptr_slc, input_ptr);
|
||||
write_u32(&mut input_length, input.len() as u32);
|
||||
memory.set(input_ptr, input)?;
|
||||
println!("input_ptr: {}", input_ptr);
|
||||
}
|
||||
|
||||
memory.set(descriptor_ptr, &context_ptr_slc)?;
|
||||
memory.set(descriptor_ptr+4, &context_length)?;
|
||||
memory.set(descriptor_ptr+8, &input_ptr_slc)?;
|
||||
memory.set(descriptor_ptr+12, &input_length)?;
|
||||
memory.set(context_ptr, context)?;
|
||||
memory.set(input_ptr, input)?;
|
||||
|
||||
println!("descriptor: {:?}", memory.get(descriptor_ptr, 16));
|
||||
|
||||
Ok(descriptor_ptr as i32)
|
||||
}
|
@ -61,9 +61,6 @@ fn main() {
|
||||
// Add module to the programm
|
||||
let module_instance = program.add_module("contract", module).expect("Module to be added successfully");
|
||||
|
||||
// Create allocator
|
||||
runtime.allocator().alloc(5*1024*1024).expect("to allocate 5mb successfully"); // reserve stack space
|
||||
|
||||
// Initialize call descriptor
|
||||
let descriptor = call_args::init(
|
||||
&*program.module("env").expect("env module to exist"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user