News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Alien segfaults
Author Message
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #1
RE: Alien segfaults

Actually it looks like it is not possible with alien to query external variables. While the basic functionality is there (alien just uses dlsym), alien lacks the functionality (or maybe I just overlooked it) to dereference the symbols, because it treats all symbols as functions.

Of course, there is always a special trick which could be used to circumvent such stupid limitations. In this case, it is possible to call dlsym directly.

This should demonstrate how it works.


Code:
if not (murgaLua_Version and tonumber(murgaLua_Version) >= 68) then
   require"luarocks.require"
   require"alien"
end

curses=alien.load("/usr/lib/libncurses.so")
getsym=alien.default.dlsym
getsym:types("pointer","pointer","string")
curses.initscr:types("pointer")
curses.endwin:types("int")
curses.initscr()
colons=getsym(nil,"COLS")
lines=getsym(nil,"LINES")
curses.endwin()
print("The terminal has "..alien.toint(colons).." cols and "..alien.toint(lines).." lines")
os.exit()


It is really easy. Since alien uses "RTLD_GLOBAL" to load the library, it is possible to query symbols with dlsym. It isn't even necessary to load libdl.so, since alien already uses it. This works of course only on systems that have "libdl.so" support.

Juergen

01-10-2009 10:36 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
Alien segfaults - jpjacobs - 01-09-2009, 01:41 AM
RE: Alien segfaults - jpjacobs - 01-09-2009, 06:06 AM
RE: Alien segfaults - Juergen - 01-10-2009 10:36 AM
RE: Alien segfaults - jpjacobs - 01-10-2009, 10:06 PM
RE: Alien segfaults - Juergen - 01-11-2009, 03:05 AM
RE: Alien segfaults - jpjacobs - 01-11-2009, 04:40 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: