koute / polkavm

A fast and secure RISC-V based virtual machine
Apache License 2.0
199 stars 44 forks source link

How to polkavm_import/export with non-numeric types? #110

Open xlc opened 2 months ago

xlc commented 2 months ago

Looks like currently only a few numeric types are supported and the ABI is simply pass the arguments via register. This means we can only pass small arguments by value. How can we pass large objects? Or a string or just bunch of bytes?

koute commented 2 months ago

You can pass a pointer to a preallocated chunk of memory and then have the host function write to it. Alternatively if the size of the data is not known you could do it in two steps - first query the host how much memory is needed, have the guest allocate it, and then have the host write to it.

On the guest side there's the derive macro which can be used to define custom marshaling strategies for custom types (e.g. see here for an example.)

xlc commented 2 months ago

thanks. will give it a play and see if I can something working

xlc commented 2 months ago

any plan to update polkavm_import/export macro to support advanced argument passing? or it will stick with registers and then in that case we need another library to abstract the argument marshalling work

koute commented 2 months ago

Depends on what exactly you mean by "advanced argument passing", but in general at least in the short term I'm not planing on expanding its capabilities beyond the basics and concentrate on making the fundamentals really solid.