mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-13 09:40:29 +00:00
Work around the invalid lightuserdata usage for 48-bit platform
Static variable's virtual address will exceed 47-bit under 48-bit platform, which causes failure when such variable is used as light user data. This patch changes such static variables to heap variables to get around this issue. Change-Id: Iaf046d567a553cff33109af57e28acdf38c8507b
This commit is contained in:
parent
1131fa22a2
commit
aafb49ea89
@ -283,13 +283,29 @@ LJLIB_CF(debug_setuservalue)
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
static const char KEY_HOOK = 'h';
|
static const char *KEY_HOOK = NULL;
|
||||||
|
|
||||||
|
static const char *get_key_hook(lua_State *L, const char **KEY_HOOK) {
|
||||||
|
if (*KEY_HOOK == NULL) {
|
||||||
|
char *p = lj_mem_newt(L, sizeof(char), char);
|
||||||
|
*p = 'h';
|
||||||
|
*KEY_HOOK = p;
|
||||||
|
}
|
||||||
|
return *KEY_HOOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_key_hook(lua_State *L) {
|
||||||
|
if (KEY_HOOK != NULL) {
|
||||||
|
lj_mem_free(G(L), (void *)KEY_HOOK, sizeof(char));
|
||||||
|
KEY_HOOK = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void hookf(lua_State *L, lua_Debug *ar)
|
static void hookf(lua_State *L, lua_Debug *ar)
|
||||||
{
|
{
|
||||||
static const char *const hooknames[] =
|
static const char *const hooknames[] =
|
||||||
{"call", "return", "line", "count", "tail return"};
|
{"call", "return", "line", "count", "tail return"};
|
||||||
lua_pushlightuserdata(L, (void *)&KEY_HOOK);
|
lua_pushlightuserdata(L, (void *)get_key_hook(L, &KEY_HOOK));
|
||||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||||
if (lua_isfunction(L, -1)) {
|
if (lua_isfunction(L, -1)) {
|
||||||
lua_pushstring(L, hooknames[(int)ar->event]);
|
lua_pushstring(L, hooknames[(int)ar->event]);
|
||||||
@ -334,7 +350,7 @@ LJLIB_CF(debug_sethook)
|
|||||||
count = luaL_optint(L, arg+3, 0);
|
count = luaL_optint(L, arg+3, 0);
|
||||||
func = hookf; mask = makemask(smask, count);
|
func = hookf; mask = makemask(smask, count);
|
||||||
}
|
}
|
||||||
lua_pushlightuserdata(L, (void *)&KEY_HOOK);
|
lua_pushlightuserdata(L, (void *)get_key_hook(L, &KEY_HOOK));
|
||||||
lua_pushvalue(L, arg+1);
|
lua_pushvalue(L, arg+1);
|
||||||
lua_rawset(L, LUA_REGISTRYINDEX);
|
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||||
lua_sethook(L, func, mask, count);
|
lua_sethook(L, func, mask, count);
|
||||||
@ -349,7 +365,7 @@ LJLIB_CF(debug_gethook)
|
|||||||
if (hook != NULL && hook != hookf) { /* external hook? */
|
if (hook != NULL && hook != hookf) { /* external hook? */
|
||||||
lua_pushliteral(L, "external hook");
|
lua_pushliteral(L, "external hook");
|
||||||
} else {
|
} else {
|
||||||
lua_pushlightuserdata(L, (void *)&KEY_HOOK);
|
lua_pushlightuserdata(L, (void *)get_key_hook(L, &KEY_HOOK));
|
||||||
lua_rawget(L, LUA_REGISTRYINDEX); /* get hook */
|
lua_rawget(L, LUA_REGISTRYINDEX); /* get hook */
|
||||||
}
|
}
|
||||||
lua_pushstring(L, unmakemask(mask, buff));
|
lua_pushstring(L, unmakemask(mask, buff));
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "lj_obj.h"
|
#include "lj_obj.h"
|
||||||
#include "lj_err.h"
|
#include "lj_err.h"
|
||||||
#include "lj_lib.h"
|
#include "lj_lib.h"
|
||||||
|
#include "lj_gc.h"
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
@ -399,11 +400,23 @@ static int lj_cf_package_loader_preload(lua_State *L)
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
static const int sentinel_ = 0;
|
static const int *sentinel_ = NULL;
|
||||||
#define sentinel ((void *)&sentinel_)
|
#define sentinel ((void *)sentinel_)
|
||||||
|
|
||||||
|
void lj_cf_free_sentinel(lua_State *L) {
|
||||||
|
if (sentinel_ != NULL) {
|
||||||
|
lj_mem_free(G(L), (void *)sentinel_, sizeof(int));
|
||||||
|
sentinel_ = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int lj_cf_package_require(lua_State *L)
|
static int lj_cf_package_require(lua_State *L)
|
||||||
{
|
{
|
||||||
|
if (sentinel_ == NULL) {
|
||||||
|
int *p = lj_mem_newt(L, sizeof(int), int);
|
||||||
|
*p = 0;
|
||||||
|
sentinel_ = p;
|
||||||
|
}
|
||||||
const char *name = luaL_checkstring(L, 1);
|
const char *name = luaL_checkstring(L, 1);
|
||||||
int i;
|
int i;
|
||||||
lua_settop(L, 1); /* _LOADED table will be at index 2 */
|
lua_settop(L, 1); /* _LOADED table will be at index 2 */
|
||||||
|
@ -157,6 +157,9 @@ static TValue *cpluaopen(lua_State *L, lua_CFunction dummy, void *ud)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void lj_cf_free_sentinel(lua_State *L);
|
||||||
|
extern void free_key_hook(lua_State *L);
|
||||||
|
|
||||||
static void close_state(lua_State *L)
|
static void close_state(lua_State *L)
|
||||||
{
|
{
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
@ -171,6 +174,8 @@ static void close_state(lua_State *L)
|
|||||||
lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef);
|
lj_mem_freevec(g, g->strhash, g->strmask+1, GCRef);
|
||||||
lj_buf_free(g, &g->tmpbuf);
|
lj_buf_free(g, &g->tmpbuf);
|
||||||
lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);
|
lj_mem_freevec(g, tvref(L->stack), L->stacksize, TValue);
|
||||||
|
lj_cf_free_sentinel(L);
|
||||||
|
free_key_hook(L);
|
||||||
lua_assert(g->gc.total == sizeof(GG_State));
|
lua_assert(g->gc.total == sizeof(GG_State));
|
||||||
#ifndef LUAJIT_USE_SYSMALLOC
|
#ifndef LUAJIT_USE_SYSMALLOC
|
||||||
if (g->allocf == lj_alloc_f)
|
if (g->allocf == lj_alloc_f)
|
||||||
|
Loading…
Reference in New Issue
Block a user