Replies: 1 comment 1 reply
-
Yes the module declares its minimum stack size in a special section: https://docs.rs/polkavm-derive/latest/polkavm_derive/macro.min_stack_size.html
Yes you can use |
Beta Was this translation helpful? Give feedback.
-
There are a few APIs in polkavm related to memory, but as it stands right now, it is hard to understand the full picture.
On one hand this is an embedded target with no global allocator available in Rust target, on the other hand there is
instance.heap_size()
and I'm not sure what it corresponds to exactly.polkatool disassemble
has "Stack size" in it, so my guess it is fixed at link time and heap is growing on top of it (potentially dynamically)?There is also
instance.set_accessible_aux_size()
, but even after looking atMemoryMap
and seeing some additional details it is not clear what it is and how it is used.I have more questions, but probably stop there. What I think would be valuable is to have some visualization and description of different memory sections.
For context I was trying to understand how to correctly write some data structure into VM's memory, then making a function call with a pointer to that data structure, write result into another data structure and then reading it back. I was also thinking about making host calls with some data and getting response back before resuming execution, which is a similar mechanism, but the other way around.
Since all of that is very unsafe, it is really important to understand exactly how things work to do it properly. I understand that I can probably call
sbrk
(which interestingly only supports unsigned integers, so not clear how to reliably not leak memory without a lot of bookkeeping) and write something there, but it gets more complex with return data, etc.Documenting here would be helpful, but ideally integrated into the Rust docs.
Beta Was this translation helpful? Give feedback.
All reactions