You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by je...@apache.org on 2017/02/28 21:56:28 UTC
[trafficserver] branch master updated: Don't push stack variables
in lightuserdata
This is an automated email from the ASF dual-hosted git repository.
jesus pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 466fffc Don't push stack variables in lightuserdata
466fffc is described below
commit 466fffc68e72a54ced79db448b3a58add437f27a
Author: Theo Schlossnagle <je...@lethargy.org>
AuthorDate: Tue Feb 28 14:21:49 2017 +0000
Don't push stack variables in lightuserdata
---
lib/bindings/bindings.cc | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/lib/bindings/bindings.cc b/lib/bindings/bindings.cc
index 1bc2547..02d273b 100644
--- a/lib/bindings/bindings.cc
+++ b/lib/bindings/bindings.cc
@@ -227,7 +227,19 @@ BindingInstance::construct()
luaL_openlibs(this->lua);
// Push a pointer to ourself into the well-known registry key.
- lua_pushlightuserdata(this->lua, this);
+
+ // We do not use lightuserdata here because BindingInstance variables
+ // are often declared on stack which would make "this" a stack variable.
+ // While this might seem fine and actually work on many platforms, those
+ // 64bit platforms with split VA space where heap and stack may live in
+ // a separate 47bit VA will violate internal assumptions that luajit
+ // places on lightuserdata. Plain userdata will provide luajit-happy
+ // address in which we have the full 64bits to store our pointer to this.
+ // see: https://www.circonus.com/2016/07/luajit-illumos-vm/
+
+ BindingInstance **lua_surrogate;
+ lua_surrogate = (BindingInstance **)lua_newuserdata(this->lua, sizeof(BindingInstance *));
+ *lua_surrogate = this;
lua_setfield(this->lua, LUA_REGISTRYINDEX, selfkey);
ink_release_assert(BindingInstance::self(this->lua) == this);
@@ -268,16 +280,17 @@ BindingInstance::eval(const char *chunk)
BindingInstance *
BindingInstance::self(lua_State *lua)
{
- BindingInstance *binding;
+ BindingInstance **binding;
lua_getfield(lua, LUA_REGISTRYINDEX, selfkey);
- binding = (BindingInstance *)lua_touserdata(lua, -1);
+ binding = (BindingInstance **)lua_touserdata(lua, -1);
ink_release_assert(binding != nullptr);
- ink_release_assert(binding->lua == lua);
+ ink_release_assert(*binding != nullptr);
+ ink_release_assert((*binding)->lua == lua);
lua_pop(lua, 1);
- return binding;
+ return *binding;
}
void
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].