Re: ffi.load and clib_extname

  • From: Mike Pall <mike-1403@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 7 Mar 2014 10:49:12 +0100

Daurnimator wrote:
> I wanted to keep using ffi abilities like cdef to declare functions. Is
> this functionality possible to retain somehow?

Umm, how many functions do you need from the VDSO? One? Two?

Anyway ... use a function pointer:

local ffi = require("ffi")
ffi.cdef[[
void *dlopen(const char *filename, int flag);
void *dlsym(void *handle, const char *symbol);
typedef long time_t;
typedef time_t (*__vdso_time)(time_t *t);
]]
local vdso = ffi.C.dlopen("linux-vdso.so.1", 1)
local time = ffi.cast("__vdso_time", ffi.C.dlsym(vdso, "__vdso_time"))
print(time(nil))

--Mike

Other related posts: