[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: direct access to allocator's void *ud
- From: liam mail <liam.list@...>
- Date: Sat, 18 Jun 2011 20:00:43 +0100
On 18 June 2011 18:53, Rebel Neurofog <email@example.com>
>> There's a way to attach a pointer (possibly pointing to structure of
>> several things you will actually use) to lua_State
>> by passing it to lua_newstate () or by setting it with lua_setallocf ().
> Actually I think the correct method for this is to set LUAI_EXTRASPACE in
2. The feature is per-coroutine rather than per global_State.
So using LUAI_EXTRASPACE would lead to unnecessary allocations and
access to main thread's state like ((void*) (G(L)->mainthread) -
Looks like Spartaaaaaa!!!!!!!!!!111...
It is still possible to do this at runtime although I would not recommend it, rather I will just give the evil information. From looking at the source we know that when the allocator is called for the creation of an LG then the state pointer in the allocator is NULL so you can set an allocator and identify this situation adding add extra bytes to the front or back of LG. When the state is closing the L and ptr will be the same.
Here is some output of a runtime hooked version of a Lua program.
inside executable ./lua_hookme
[HOOOKED INFO] lua_newstate_mem_hook
[HOOOKED INFO] Lua 0x0 alloc 0x1001000b0 size 616 byte count: 616
[HOOOKED INFO] lua_close_hook state: 0x1001000b0
[HOOOKED INFO] state 0x1001000b0 cleaned and no leaks
[HOOOKED INFO] Lua 0x1001000b0 free 0x1001000b0 size 616 byte count: 0
[HOOOKED INFO] after hooked function lua_close_hook