Skip to content

Implement custom slab allocator for LuaJIT with memory reservation - #33

Open
GEEKiDoS wants to merge 5 commits into
esuo1198:Refactorfrom
GEEKiDoS:Refactor
Open

Implement custom slab allocator for LuaJIT with memory reservation#33
GEEKiDoS wants to merge 5 commits into
esuo1198:Refactorfrom
GEEKiDoS:Refactor

Conversation

@GEEKiDoS

@GEEKiDoS GEEKiDoS commented May 26, 2026

Copy link
Copy Markdown

This PR replaces LuaJIT's builtin allocator with custom slab allocator on reserved space, and triggers LuaJIT GC when allocation failed.

Fixes crash on some systems when game calls lua_newuserdata, reserving 256M is enough, but defaulting to 512M for better stability.

Tested for hours with omnimix without crashing

GEEKiDoS added 5 commits May 26, 2026 11:27
…locateVirtualMemory hook

Replace the NtAllocateVirtualMemory hook approach with a custom slab-style
allocator that manages memory from a pre-reserved block, using size classes
and free lists for efficient allocation. The allocator is injected directly
into luaL_newstate via code patching. Also add proper Exit() cleanup and
move Init() earlier in the startup sequence.

Co-Authored-By: GPT5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant