Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to cr.h? #16

Open
Neopallium opened this issue Mar 28, 2019 · 5 comments
Open

Switch to cr.h? #16

Neopallium opened this issue Mar 28, 2019 · 5 comments

Comments

@Neopallium
Copy link
Contributor

I have created the start of a Rust wrapper for cr.h:
https://github.com/Neopallium/cr-rs

Right now I am planning on a host-side and guest-side sys crates, since two different libraries need to be crated. Might be able to use features to keep it as one library that can be compiled as either side as needed.

Right now a basic host example compiles and can load the libbasic_guest.so from cr.h samples.

The only problem I see right now is that cr.h doesn't provide access to the library handle. The cr-sys crate could patch in a function to return the library handle.

@emoon
Copy link
Owner

emoon commented Mar 28, 2019

Awesome! Great work

@fungos
Copy link

fungos commented Mar 28, 2019

@Neopallium Hi, great work with that, looks amazing! If you think any of your changes to cr.h would be better upstream, please do open PRs and we can get it sorted out to help making cr-rs a reality faster!

@Neopallium
Copy link
Contributor Author

FYI, the cr-sys crate can now build/run basic host & guest side code.

Missing:

  • userdata pointer. Maybe change cr-sys::Plugin to cr-sys::Plugin<T>
  • enums. Right now they are just raw ints.
  • guest-side wrapper for cr_main.
  • Allow host-side to get the raw library handle or get a symbol from the library.

@fungos Thanks for the great work in cr.h

@Neopallium
Copy link
Contributor Author

Publish the first version of cr-sys (raw bindings) and cr (safe bindings). Reloading is working. Both crates have example host/guest.

@fungos Rollback worked after a crash (de-reference null pointer). Be reloading a new version seems causes a setjmp/longjmp loop. Also saw some invalid reads in the data section code in cr.h.

Might have to catch crashes in the Rust cr_main wrapper and tell cr.h, but I am not sure how to catch panics/faults in Rust.

setjmp/longjmp might not work well with Rust. I remember reading that Lua VM bindings were having issues with handling Lua errors, which uses setjmp/longjmp too.

@Neopallium
Copy link
Contributor Author

FYI, fixed the rollback + reload issue. Also Rust panics are caught and trigger a rollback.

It seems setjmp/longjmp can work to recover from segfaults from unsafe Rust code, since it doesn't get caught by std::panic::catch_unwind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants