Skip to content

Commit 9b61959

Browse files
committed
dysym constants
1 parent 6bf6d22 commit 9b61959

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

lib/truffle/truffle/fiddle_backend.rb

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ def self.convert_native_to_ruby(type, val)
105105
end
106106
end
107107

108+
RTLD_NEXT = Truffle::Config['platform.dlopen.RTLD_NEXT']
109+
RTLD_DEFAULT = Truffle::Config['platform.dlopen.RTLD_DEFAULT']
110+
108111
end
109112

110113
module Fiddle
@@ -234,14 +237,19 @@ def self.[](*args)
234237
RTLD_LAZY = Truffle::Config['platform.dlopen.RTLD_LAZY']
235238
RTLD_NOW = Truffle::Config['platform.dlopen.RTLD_NOW']
236239
RTLD_GLOBAL = Truffle::Config['platform.dlopen.RTLD_GLOBAL']
237-
RTLD_NEXT = Truffle::Config['platform.dlopen.RTLD_NEXT']
238-
RTLD_DEFAULT = Truffle::Config['platform.dlopen.RTLD_DEFAULT']
239240

240241
def initialize(library = nil, flags = RTLD_LAZY | RTLD_GLOBAL)
241242
raise DLError, 'unsupported dlopen flags' if flags != RTLD_LAZY | RTLD_GLOBAL
242-
@handle = Polyglot.eval('nfi', library ? "load #{library}" : 'default')
243-
rescue RuntimeError
244-
raise DLError, "#{library}: cannot open shared object file: No such file or directory"
243+
if library == Truffle::FiddleBackend::RTLD_NEXT
244+
@handle = :rtld_next
245+
else
246+
library = nil if library == Truffle::FiddleBackend::RTLD_DEFAULT
247+
begin
248+
@handle = Polyglot.eval('nfi', library ? "load #{library}" : 'default')
249+
rescue RuntimeError
250+
raise DLError, "#{library}: cannot open shared object file: No such file or directory"
251+
end
252+
end
245253
end
246254

247255
def to_i(*args)
@@ -253,9 +261,13 @@ def close(*args)
253261
end
254262

255263
def sym(name)
256-
sym = @handle[name]
257-
raise DLError, "unknown symbol \"#{name}\"" unless sym
258-
Truffle::Interop.as_pointer(sym)
264+
if :rtld_next == @handle
265+
raise DLError, 'RTLD_NEXT is not supported'
266+
else
267+
sym = @handle[name]
268+
raise DLError, "unknown symbol \"#{name}\"" unless sym
269+
Truffle::Interop.as_pointer(sym)
270+
end
259271
end
260272

261273
alias_method :[], :sym
@@ -272,6 +284,9 @@ def close_enabled?(*args)
272284
raise NotImplementedError
273285
end
274286

287+
DEFAULT = Handle.new(Truffle::FiddleBackend::RTLD_DEFAULT)
288+
NEXT = Handle.new(Truffle::FiddleBackend::RTLD_NEXT)
289+
275290
end
276291

277292
class Pointer

0 commit comments

Comments
 (0)