[Tarantool-patches] [PATCH luajit 1/2] Add support for full-range 64 bit lightuserdata.

Igor Munkin imun at tarantool.org
Sun Aug 1 13:36:15 MSK 2021


Sergey,

Thanks for the fixes and comments! LGTM then, except the three typos
I've missed in the previous review.

On 28.07.21, Sergey Kaplun wrote:
> Igor,
> Thanks for the review!
> 

<snipped>

> 
> The new commit message is the following:
> 
> ===================================================================
> Add support for full-range 64 bit lightuserdata.
> 
> (cherry picked from commit e9af1abec542e6f9851ff2368e7f196b6382a44c)
> 
> LuaJIT uses special NaN-tagging technique to store internal type on
> the Lua stack. In case LJ_GC64 first 13 bits are set in special NaN
> type (0xfff8...). FPU generates the only one type. The next 4 bits are
> used for an internal LuaJIT type of object on stack. The next 47 bits
> are used for storing this object's content. For userdata, it is its
> address. In case arm64 the pointer can have more than 47 significant
> bits [1]. In this case the error BADLU error is raised.
> 
> For the support of full 64-bit range lightuserdata pointers two new
> fields in GCState are added:
> 
> `lightudseg` - vector of segments of lightuserdata. Each element keeps
> 32-bit value. 25 MSB equal to MSB of lightuserdata address, the rest are
> filled with zeros. The lentgh of the vector is power of 2.

Typo: s/lentgh/length/.

> 
> `lightudnum` - the length - 1 of aforementioned vector (up to 255).
> 
> When lightuserdata is pushed on the stack, if its segment is not stored
> in vector new value is appended on top of this vector. The maximum
> amount of segments is 256. BADLU error is raised in case when user tried

Typo: s/tried/tries/.

> to add userdata with the new 257-th segment, so the whole VA-space
> isn't covered by this patch.
> 
> Also, in this patch all internal usage of lightuserdata (for hooks,
> profilers, built-in package, IR and so on) is changed to special values
> on Lua Stack.
> 
> Also, conversion of TValue to FFI C type with store is no longer
> compiled for lightuserdata.
> 
> [1]: https://www.kernel.org/doc/html/latest/arm64/memory.html
> 
> Sergey Kaplun:
> * added the description and the test for the problem
> 
> Resolves tarantool/tarantool#2712
> Needed for tarantool/tarantool#6154

Minor: Why #5629 is not mentioned?

> ===================================================================
> 

<snipped>

> 
> See the iterative patch below.
> 
> ===================================================================

<snipped>

> diff --git a/test/tarantool-tests/lj-49-bad-lightuserdata/testlightuserdata.c b/test/tarantool-tests/lj-49-bad-lightuserdata/testlightuserdata.c
> index 801c7fe1..c958841f 100644
> --- a/test/tarantool-tests/lj-49-bad-lightuserdata/testlightuserdata.c
> +++ b/test/tarantool-tests/lj-49-bad-lightuserdata/testlightuserdata.c

<snipped>

> @@ -26,8 +34,8 @@ static int longptr(lua_State *L)
>  	 * equals -1.

Typo: s/hint equals -1/hint that equals to -1/.

>  	 */
>  	const size_t pagesize = getpagesize();
> -	void *mmaped = mmap(START, pagesize, PROT_NONE,
> -				  MAP_PRIVATE | MAP_ANON, -1, 0);
> +	void *mmaped = mmap(START, pagesize, PROT_NONE, MAP_PRIVATE | MAP_ANON,
> +			    -1, 0);
>  	if (mmaped != MAP_FAILED) {
>  		lua_pushlightuserdata(L, mmaped);
>  		assert(mmaped == lua_topointer(L, -1));

<snipped>

> ===================================================================
> 

<snipped>

> 
> -- 
> Best regards,
> Sergey Kaplun

-- 
Best regards,
IM


More information about the Tarantool-patches mailing list