Dynasm, memory allocation, unsafe, ub?

  1. I am using https://crates.io/crates/dynasm to do dynamic code generation.

  2. The current setup goes something like this:

  • bottom of stack = rust functions
  • rust function invokes dynasm JIT function via "sysv64" abi (works fine)
  • dynasm JIT function, via "sysv64" abi, invokes extedrn "sysv64" fn ... Rust function to allocate memory

Now, it turns out the rust function which allocates memory will need to involve Rust objects (sorry for vagueness, still work in progress).

This 'sandwich' of:

rust host -> dynasm JIT function -> extern rust func (satisfying sysv64 C abi)

is scaring me concerning unsafe / undefined behaviour.

For those who have dealt with this -- advice / documentation ?


The XY problem here is: at the time when Rust invokes the dynasm JIT function, we do NOT know how big the output / return value will be. Thus, as a result, while the dynasm JIT function is running, it may have to ask Rust for memory. This causes the "sandwich" and I am trying to understand potential unsafe / undefined behaviours here.


This is all x86_64 linux. The sysv64 function calling C ABI is not the problem. I am concerned about breaking unsafe / ub guarantees that rustc is assuming.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.