Module: FFI::GNUExtensions::DLV

Defined in:
lib/ffi/gnu_extensions.rb

Overview

Override FFI::Library attach functions with support for dlvsym

Instance Method Summary collapse

Instance Method Details

#ffi_lib_versions(versions) ⇒ Array<String>|String

Set the default version(s) for "#attach_function" (GNU only)

Parameters:

  • versions (Array<String>|String)

    the default list of versions to search

Returns:

  • (Array<String>|String)


50
51
52
# File 'lib/ffi/gnu_extensions.rb', line 50

def ffi_lib_versions(versions)
  @versions = versions
end

#find_function_version(cname, version) ⇒ FFI::Pointer, false

use dlvsym to find a function address

Parameters:

  • cname (String|Symbol)

    the function name

  • version (String)

    the version name

Returns:

  • (FFI::Pointer)

    the function address

  • (false)

    if the function/version combination does not exist in any library



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ffi/gnu_extensions.rb', line 99

def find_function_version(cname, version)
  ffi_libraries.map(&:name).each do |l|
    handle = GNUExtensions.dlopen(l, 1)
    next if handle.null?

    addr = GNUExtensions.dlvsym(handle, cname.to_s, version)

    next if addr.null?

    return addr
  end

  false
end