Re: Catching 'out of memory' using pcall()

  • From: Dmitri Shubin <sbn@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 17 Mar 2014 14:35:08 +0400

On 03/13/2014 05:16 PM, Daniel Kolesa wrote:
How about you just override the default LuaJIT allocator from C, keeping track of the amount of allocated memory and then handling it when it tries to go over that? Of course, on x64 you cannot use a custom allocator via lua_newstate because LuaJIT requires use of its own allocator, what you CAN do though is create the state with luaL_newstate, get the original alloc func and data pointer via lua_getallocf and force a new alloc func and data using lua_setallocf (which will keep track of memory AND then call into the original alloc func, passing the original data)

Thanks for suggestion!

Actually we can simply hack luajit sources and check if mmap() call fails.
But I don't understand what we can do next?
How can we unwind stack to some safe state and free memory occupied by this particular lua state?
Can we throw C++ exception, do longjmp() or ?

As I wrote already LJ internal unwinding crashes when trying to throw 'out-of-memory' error.

Other related posts: