2 ms·
> 2. the callee side must be able to express on-stack by-value structs, many (most?) managed languages don't I think the FFI could well express this. Just gene
by fulafel 11y ago
> 2. the callee side must be able to express on-stack by-value structs, many (most?) managed languages don't
I think the FFI could well express this. Just generate
a C thunk that converts the value from the stack to
a suitable representation.
> 3. and finally the layout (and size) of the struct must be deterministic
The layout and padding of structs is deterministic in all C
environments I know of since they end up as part of ABIs.
> Depending on the callee's implementation that may be too late already, there is absolutely no guarantee the data will even go through the FFI without being released
So you make a C FFI call from a safe language to libfoo.so function void foo(char *jsondata) and before the callee returns your safe runtime yanks the data from under it in another thread?
Yeah, you would also need the caller's FFI to guarantee against this to get safety. In absence of such guarantees you should stick to only passing pass-by-value structures!
- masklinn 11y ago> I think the FFI could well express this. Just generate a C thunk that converts the value from the stack to a suitable representation. Oh definitely, I'm just saying not all of them do (if you follow the link, the Ruby/MRI, CPython and Node FFIs all provide for that at least on the caller side) > So you make a C FFI call from a safe language to libfoo.so function void foo(char *jsondata) and before the callee returns your safe runtime yanks the data from under it in another thread? Yup, could happen with a concurrent GC kicking it at an inconvenient time, or with a refcounting GC. > Yeah, you would also need the FFI to guarantee against this to get safety. I'm not sure it could (without caller cooperation), best I can see is offer side-channels to "leak" memory (allocate non-managed memory and copy stuff into it) or recommend that you keep an internal strong reference of some sort (e.g. a global list/set).