diff options
author | sfan5 <sfan5@live.de> | 2020-04-08 20:14:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-08 20:14:08 +0200 |
commit | 659245acc7dcc28e345b8dfa50571102f4f07728 (patch) | |
tree | a0bcb88e12627c01e1858c9dc52ecff0326d7675 /src/script | |
parent | de73f989eb1397b1103236031fd91309b294583c (diff) | |
download | minetest-659245acc7dcc28e345b8dfa50571102f4f07728.tar.gz minetest-659245acc7dcc28e345b8dfa50571102f4f07728.tar.bz2 minetest-659245acc7dcc28e345b8dfa50571102f4f07728.zip |
Work around LuaJIT issues on aarch64 (#9614)
- Move the text segment below the 47-bit limit, needed for script_exception_wrapper which must be lightuserdata
- Replace CUSTOM_RIDX_SCRIPTAPI with full userdata
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/common/c_internal.h | 9 | ||||
-rw-r--r-- | src/script/cpp_api/s_base.cpp | 4 | ||||
-rw-r--r-- | src/script/cpp_api/s_security.cpp | 7 | ||||
-rw-r--r-- | src/script/lua_api/l_base.cpp | 7 |
4 files changed, 25 insertions, 2 deletions
diff --git a/src/script/common/c_internal.h b/src/script/common/c_internal.h index d8cf3fe76..747400769 100644 --- a/src/script/common/c_internal.h +++ b/src/script/common/c_internal.h @@ -54,6 +54,15 @@ extern "C" { #define CUSTOM_RIDX_CURRENT_MOD_NAME (CUSTOM_RIDX_BASE + 2) #define CUSTOM_RIDX_BACKTRACE (CUSTOM_RIDX_BASE + 3) +// Determine if CUSTOM_RIDX_SCRIPTAPI will hold a light or full userdata +#if defined(__aarch64__) && USE_LUAJIT +/* LuaJIT has a 47-bit limit for lightuserdata on this platform and we cannot + * assume that the ScriptApi class was allocated at a fitting address. */ +#define INDIRECT_SCRIPTAPI_RIDX 1 +#else +#define INDIRECT_SCRIPTAPI_RIDX 0 +#endif + // Pushes the error handler onto the stack and returns its index #define PUSH_ERROR_HANDLER(L) \ (lua_rawgeti((L), LUA_REGISTRYINDEX, CUSTOM_RIDX_BACKTRACE), lua_gettop((L))) diff --git a/src/script/cpp_api/s_base.cpp b/src/script/cpp_api/s_base.cpp index ecb1ba39b..f234a15d4 100644 --- a/src/script/cpp_api/s_base.cpp +++ b/src/script/cpp_api/s_base.cpp @@ -90,7 +90,11 @@ ScriptApiBase::ScriptApiBase(ScriptingType type): luaL_openlibs(m_luastack); // Make the ScriptApiBase* accessible to ModApiBase +#if INDIRECT_SCRIPTAPI_RIDX + *(void **)(lua_newuserdata(m_luastack, sizeof(void *))) = this; +#else lua_pushlightuserdata(m_luastack, this); +#endif lua_rawseti(m_luastack, LUA_REGISTRYINDEX, CUSTOM_RIDX_SCRIPTAPI); // Add and save an error handler diff --git a/src/script/cpp_api/s_security.cpp b/src/script/cpp_api/s_security.cpp index b5abcfb5d..2afa3a191 100644 --- a/src/script/cpp_api/s_security.cpp +++ b/src/script/cpp_api/s_security.cpp @@ -499,7 +499,12 @@ bool ScriptApiSecurity::checkPath(lua_State *L, const char *path, // Get server from registry lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_SCRIPTAPI); - ScriptApiBase *script = (ScriptApiBase *) lua_touserdata(L, -1); + ScriptApiBase *script; +#if INDIRECT_SCRIPTAPI_RIDX + script = (ScriptApiBase *) *(void**)(lua_touserdata(L, -1)); +#else + script = (ScriptApiBase *) lua_touserdata(L, -1); +#endif lua_pop(L, 1); const IGameDef *gamedef = script->getGameDef(); if (!gamedef) diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp index 8486fc7bc..c980bba39 100644 --- a/src/script/lua_api/l_base.cpp +++ b/src/script/lua_api/l_base.cpp @@ -30,7 +30,12 @@ ScriptApiBase *ModApiBase::getScriptApiBase(lua_State *L) { // Get server from registry lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_SCRIPTAPI); - ScriptApiBase *sapi_ptr = (ScriptApiBase*) lua_touserdata(L, -1); + ScriptApiBase *sapi_ptr; +#if INDIRECT_SCRIPTAPI_RIDX + sapi_ptr = (ScriptApiBase*) *(void**)(lua_touserdata(L, -1)); +#else + sapi_ptr = (ScriptApiBase*) lua_touserdata(L, -1); +#endif lua_pop(L, 1); return sapi_ptr; } |