Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@larskanis
Copy link
Member

Since libffi introduced static trampolines in commit libffi/libffi@9ba5592 , it's necessary to use ffi_prep_cif() and ffi_prep_closure_loc() instead of our own optimized trampoline. Otherwise all functions attached to a FFI::Library module result in a segfault.

Using ffi's (classic or static) trampolines is somewhat slower than our optimized ones, but they are still faster than the alternative ruby code like this:

module FFI
  class Function < Pointer
    def attach(mod, name)
      this = self
      body = -> *args, &block do
        this.call(*args, &block)
      end
      mod.define_method(name, body)
      mod.define_singleton_method(name, body)
      self
    end
  end
end

Fixes #989

larskanis and others added 2 commits April 14, 2023 17:08
This is because libffi changed the way how closures are allocated to static trampolines.
`codeloc` is an opaque pointer now, to the internal `struct tramp` struct - and not to executable code.
The executable code of trampolines is static and no longer written or writable at runtime.
@larskanis larskanis merged commit 54651da into ffi:master Apr 16, 2023
@larskanis larskanis deleted the update-libffi branch April 16, 2023 19:31
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

Successfully merging this pull request may close these issues.

ruby-ffi segfaults with latest libffi on x86_64-linux

1 participant