microsoft / verona-sandbox

Library sandboxing for the Verona research language and usable in other contexts.
MIT License
12 stars 3 forks source link

Sandboxing a C++ library #3

Open shivrajj1 opened 5 months ago

shivrajj1 commented 5 months ago

I want to sandbox a c++ library using Verona-sandbox. Currently I find myself lacking any example tests to understand how to do so. I want to be able to export the constructors, static, non-static methods of classes defined in the library. Is there a typical way to achieve this using verona-sandbox? I would highly appreciate any help, pointers with regards to this.

mjp41 commented 5 months ago

@davidchisnall is probably the best person to answer questions on this.

davidchisnall commented 5 months ago

Sorry, I don’t seem to get notifications for new issues on this repo anymore.

We don’t currently have macros for doing this. The goal for Verona was that this would be generated with a clang plugin (for simple functions, it’s easy to wrap them).

We can currently expose each library as an object and each function as a method on that object. You could expose classes as nested types within that, but then you start to hit problems. Verona has a region abstraction that lets you have a concept of objects in a sandbox but there is no C++ analogue[1] and so you would need to track ownership manually.

Currently, that requires a fair bit of manual wrapping. In particular, you’d probably want to generate proxy classes in the host environment that forward to instances inside. That’s possible to write by hand, but we don’t have any tooling to generate it (patches welcome!).

[1] My personal journey to the region abstraction started from observing that objects are run-time instances of classes but we have no run-time analogue of a namespace.