mlua icon indicating copy to clipboard operation
mlua copied to clipboard

[Question]Why luajit feature not support memory_limit

Open iiibui opened this issue 4 years ago • 3 comments

Related code: https://github.com/khvzak/mlua/blob/cfb5d3fd45a810e5cde6811b039d154241d1444c/src/lua.rs#L332-L399

fn allocator include luajit feature, but it is not used when new lua state.

iiibui avatar Jan 08 '22 15:01 iiibui

It's quite interesting question.

Mostly because In Lua 5.1/JIT lua_pushcfunction api call can trigger memory errors. Our protection mechanism to intercept Lua exceptions heavy relies on resilient lua_pushcfunction call. There is a way how to fail it and trigger uncought exception that would crash the program -- is enable memory limits for 5.1/JIT. In Lua >= 5.2 this function never triggers memory errors.

Unfortunately I don't see a simple way how to enable memory limits in Lua 5.1/JIT 🤔

khvzak avatar Jan 08 '22 21:01 khvzak

Thank you for your reply.

It's a little complicated for me, maybe I should use unsafe rust to call luajit c api directly😢

iiibui avatar Jan 16 '22 13:01 iiibui

maybe I should use unsafe rust to call luajit c api directly

it does not matter actually, you would get crash unless wrap it to lua_cpcall.

khvzak avatar Jan 16 '22 21:01 khvzak

I believe I found a good workaround, so memory limits will be supported for any Lua in v0.9

khvzak avatar Mar 26 '23 00:03 khvzak