dynamic_reload icon indicating copy to clipboard operation
dynamic_reload copied to clipboard

Switch to cr.h?

Open Neopallium opened this issue 6 years ago • 5 comments

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.

Neopallium avatar Mar 28 '19 18:03 Neopallium

Awesome! Great work

emoon avatar Mar 28 '19 18:03 emoon

@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!

fungos avatar Mar 28 '19 23:03 fungos

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 avatar Mar 29 '19 04:03 Neopallium

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 avatar Mar 29 '19 12:03 Neopallium

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.

Neopallium avatar Mar 30 '19 14:03 Neopallium