Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/lj-gc-objs.sxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function process(L)
printf("main machine code area size: %d bytes\n", mc_size)
}

cts = $*g->ctype_state->ptr32
cts = $*g->ctype_state->ptr64
$*cts := @cast(cts, "CTState", "$^libluajit_path")
if (cts) {
printf("C callback machine code size: %d bytes\n", @CALLBACK_MCODE_SIZE)
Expand Down Expand Up @@ -158,7 +158,7 @@ function process(L)

} else {
/* for LuaJIT 2.1 */
sizetmpbuf = $*g->tmpbuf->e->ptr32 - $*g->tmpbuf->b->ptr32
sizetmpbuf = $*g->tmpbuf->e->ptr32 - $*g->tmpbuf->b->ptr64
}

if (sizetmpbuf) {
Expand Down
4 changes: 2 additions & 2 deletions samples/lj-vm-states.sxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function process_timer_event()

$*g := @cast(g, "global_State", "$^libluajit_path")

gco = $*g->cur_L->gcptr32
gco = $*g->cur_L->gcptr64
$*gco := @cast(gco, "GCobj", "$^libluajit_path")

L = &$*gco->th
Expand Down Expand Up @@ -62,7 +62,7 @@ function process_timer_event()
states["C"]++

} else if (vmstate == -3) {
if ($*g->jit_base->ptr32) {
if ($*g->jit_base->ptr64) {
states["NG"]++

} else {
Expand Down
2 changes: 1 addition & 1 deletion samples/ngx-pcre-top.sxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ probe process("$^exec_path").function("ngx_http_lua_ffi_exec_regex")

function gcref(gcr)
{
return @cast(gcr, "GCRef", "$^libluajit_path")->gcptr32
return @cast(gcr, "GCRef", "$^libluajit_path")->gcptr64
}

function gcval(o)
Expand Down
78 changes: 47 additions & 31 deletions tapset/luajit.sxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $*pt := @cast(pt, "GCproto", "$^libluajit_path")
@define LJ_TLIGHTUD %( 4294901760 %)
@define LJ_TSTR %( 4294967291 %)
@define LJ_TUDATA %( 4294967283 %)
@define LJ_TTHREAD %( 4294967289 %)
@define LJ_TFUNC %( 4294967287 %)


Expand Down Expand Up @@ -40,6 +41,9 @@ $*pt := @cast(pt, "GCproto", "$^libluajit_path")

@define NO_BCPOS %( ~0 %)

@define LJ_GCVMASK %( 140737488355327 %)
@define LJ_FR2 %( 1 %)

@define sizeof_GCtab %( &@cast(0, "GCtab", "$^libluajit_path")[1] %)
@define sizeof_TValue %( &@cast(0, "TValue", "$^libluajit_path")[1] %)
@define sizeof_lua_State %( &@cast(0, "struct lua_State", "$^libluajit_path")[1] %)
Expand Down Expand Up @@ -67,12 +71,20 @@ $*pt := @cast(pt, "GCproto", "$^libluajit_path")
(@s + @sizeof_GCstr)
%)

@define gcrefu(frame) %(
@cast(@frame, "TValue", "$^libluajit_path")->gcr->gcptr64
%)

@define gcval(frame) %(
(@gcrefu(@frame) & @LJ_GCVMASK)
%)

@define frame_gc(frame) %(
@cast(@frame, "TValue", "$^libluajit_path")->fr->func->gcptr32
@gcval(@frame - @sizeof_TValue)
%)

@define frame_ftsz(tv) %(
@cast(@tv, "TValue", "$^libluajit_path")->fr->tp->ftsz
@cast(@tv, "TValue", "$^libluajit_path")->ftsz
%)

@define frame_type(f) %(
Expand All @@ -92,19 +104,19 @@ $*pt := @cast(pt, "GCproto", "$^libluajit_path")
%)

@define frame_pc(tv) %(
@cast(@tv, "TValue", "$^libluajit_path")->fr->tp->pcr->ptr32
@cast(@tv, "TValue", "$^libluajit_path")->ftsz
%)

@define frame_contpc(f) %(
(@frame_pc(@f) - 1 * @sizeof_BCIns)
(@frame_pc(@f - 2 * @sizeof_TValue))
%)

@define bc_a(i) %(
((@i >> 8) & 0xff)
%)

@define frame_prevl(f) %(
(@f - (1 + @bc_a(user_uint32(@frame_pc(@f) - 4))) * @sizeof_TValue)
(@f - (1 + @LJ_FR2 + @bc_a(user_uint32(@frame_pc(@f) - 4))) * @sizeof_TValue)
%)

@define FRAME_VARG %( 3 %)
Expand All @@ -130,19 +142,19 @@ $*pt := @cast(pt, "GCproto", "$^libluajit_path")
%)

@define funcproto(fn) %(
(@cast(@fn, "GCfunc", "$^libluajit_path")->l->pc->ptr32 - @sizeof_GCproto)
(@cast(@fn, "GCfunc", "$^libluajit_path")->l->pc->ptr64 - @sizeof_GCproto)
%)

@define proto_bc(pt) %(
(@pt + @sizeof_GCproto)
%)

@define proto_bcpos(pt, pc) %(
((@pc - @proto_bc(@pt)) / @sizeof_BCIns)
((@pc - @proto_bc(@pt)) / @sizeof_TValue)
%)

@define proto_lineinfo(pt) %(
@cast(@pt, "GCproto", "$^libluajit_path")->lineinfo->ptr32
@cast(@pt, "GCproto", "$^libluajit_path")->lineinfo->ptr64
%)


Expand All @@ -159,14 +171,14 @@ function luajit_frame_func(f) {
function luajit_G(L)
{
$*L := @cast(L, "lua_State", "$^libluajit_path")
return $*L->glref->ptr32
return $*L->glref->ptr64
}


function luajit_gcref(r)
{
$*r := @cast(r, "GCRef", "$^libluajit_path")
return $*r->gcptr32
return $*r->gcptr64
}


Expand Down Expand Up @@ -278,7 +290,7 @@ function luajit_objlen(o, gct, g)
}

/* cdata is not a vector */
cts = $*g->ctype_state->ptr32
cts = $*g->ctype_state->ptr64
$*cts := @cast(cts, "CTState", "$^libluajit_path")
id = $*cd->ctypeid
ct = &$*cts->tab[id]
Expand Down Expand Up @@ -316,9 +328,9 @@ function luajit_jit_state_size(J)
//
/*
$*k := @cast(k, "K64Array", "$^libluajit_path")
for (k = $*J->k64->ptr32; k; ) {
for (k = $*J->k64->ptr64; k; ) {
ir_k64_size += @sizeof_K64Array
k = $*k->next->ptr32
k = $*k->next->ptr64
}
if (ir_k64_size) {
//printf("64-bit constants: %d\n", ir_k64_size)
Expand Down Expand Up @@ -389,7 +401,7 @@ function luajit_tostring(L, idx)
}

if ($*o->it == @LJ_TSTR) {
gco = $*o->gcr->gcptr32
gco = $*o->gcr->gcptr64
$*gco := @cast(gco, "GCobj", "$^libluajit_path")
s = &$*gco->str
$*s := @cast(s, "GCstr", "$^libluajit_path")
Expand All @@ -409,7 +421,7 @@ function luajit_tostringlen(L, idx)
}

if ($*o->it == @LJ_TSTR) {
gco = $*o->gcr->gcptr32
gco = $*o->gcr->gcptr64
$*gco := @cast(gco, "GCobj", "$^libluajit_path")
s = &$*gco->str
$*s := @cast(s, "GCstr", "$^libluajit_path")
Expand All @@ -431,7 +443,7 @@ function luajit_touserdata(L, idx)
//printf("udata type: %d (%d)\n", $*o->it, ($*o->it >> 15))

if ($*o->it == @LJ_TUDATA) {
gco = $*o->gcr->gcptr32
gco = $*o->gcr->gcptr64
ud = &$*gco->ud
$*ud := @cast(ud, "GCudata", "$^libluajit_path")
return ud + @sizeof_GCudata
Expand All @@ -446,20 +458,20 @@ function luajit_touserdata(L, idx)


function luajit_proto_chunkname(pt) {
gco = $*pt->chunkname->gcptr32
gco = $*pt->chunkname->gcptr64
return &$*gco->str
}


function luajit_debug_framepc(L, T, fn, pt, nextframe) {
//printf("debug framepc: L=%p, fn=%p, nextframe = %p\\n", L, fn, nextframe)
//printf("debug framepc: L=%p, fn=%p, nextframe=%p\n", L, fn, nextframe)
if (nextframe == 0) {
return @NO_BCPOS
}

if (@frame_islua(nextframe)) {
ins = @frame_pc(nextframe);
//printf("frame is lua, ins = %p\\n", ins)
//printf("frame is lua, ins = %p\n", ins)

} else if (@frame_iscont(nextframe)) {
//println("frame is cont")
Expand All @@ -469,16 +481,18 @@ function luajit_debug_framepc(L, T, fn, pt, nextframe) {
/* TODO: add support for cframe */
}

//printf("debug framepc: ins = %p\\n", ins)
//printf("debug framepc: ins = %p\n", ins)
pos = @proto_bcpos(pt, ins) - 1;
//printf("debug framepc: pos = %d\n", pos)
sizebc = $*pt->sizebc
//printf("debug framepc: ins = %p, pos=%d, sizebc=%d\n", ins, pos, sizebc)
if (pos > sizebc) {
//printf("Undo the effects of lj_trace_exit for JLOOP.\n")
if (!T) {
T = ins - 1 * @sizeof_BCIns - &@cast(0, "GCtrace", "$^libluajit_path")->startins;
}
//printf("startpc: %d\n", $*T->startpc->ptr32)
pos = @proto_bcpos(pt, $*T->startpc->ptr32);
//printf("startpc: %d\n", $*T->startpc->ptr64)
pos = @proto_bcpos(pt, $*T->startpc->ptr64);
//printf("Found adjusted position: %d\n", pos)
}
return pos;
Expand Down Expand Up @@ -531,18 +545,19 @@ function luajit_debug_frameline(L, T, fn, pt, nextframe)
}



function luajit_debug_dumpstack(L, T, depth, base, simple)
{
level = 0
dir = 1
if (depth < 0) {
if (depth < 0) { // reverse frames
level = ~depth
depth = dir = -1
}
bt = ""
while (level != depth) {
/* lj_debug_frame(L, level, &size) {{{ */
bot = $*L->stack->ptr32
bot = $*L->stack->ptr64 + @sizeof_TValue //@LJ_FR2
found_frame = 0
tmp_level = level
/* Traverse frames backwards. */
Expand All @@ -557,6 +572,7 @@ function luajit_debug_dumpstack(L, T, depth, base, simple)
break
}
nextframe = frame

if (@frame_islua(frame)) {
frame = @frame_prevl(frame)

Expand All @@ -576,7 +592,7 @@ function luajit_debug_dumpstack(L, T, depth, base, simple)
/* }}} */

if (frame) {
//nextframe = size ? frame + size * @sizeof_TValue : 0
nextframe = size ? frame + size * @sizeof_TValue : 0
fn = luajit_frame_func(frame)
if (fn == 0) {
return ""
Expand Down Expand Up @@ -636,7 +652,7 @@ function luajit_debug_dumpstack(L, T, depth, base, simple)
function luajit_cur_thread(g)
{
$*g := @cast(g, "global_State", "$^libluajit_path")
gco = $*g->cur_L->gcptr32
gco = $*g->cur_L->gcptr64
if (gco == 0) {
return 0
}
Expand All @@ -655,14 +671,14 @@ function luajit_get_trace(g, traceno)
return 0
}

return $*J->trace[traceno]->gcptr32
return $*J->trace[traceno]->gcptr64
}


function luajit_trace_starting_func(g, trace)
{
$*trace := @cast(trace, "GCtrace", "$^libluajit_path")
gco = $*trace->startpt->gcptr32
gco = $*trace->startpt->gcptr64
if (gco == 0) {
return ""
}
Expand Down Expand Up @@ -710,7 +726,7 @@ function luajit_backtrace(L, g, simple)
bt = ""

vmstate = $*g->vmstate
if (vmstate >= 0 || (vmstate == -3 && $*g->jit_base->ptr32)) {
if (vmstate >= 0 || (vmstate == -3 && $*g->jit_base->ptr64)) {
/* compiled Lua code */

T = luajit_get_trace(g, vmstate)
Expand All @@ -722,13 +738,13 @@ function luajit_backtrace(L, g, simple)
}

} else {
//printf("start pc: %d\n", $*T->startpc->ptr32)
//printf("start pc: %d\n", $*T->startpc->ptr64)
}

#warn(sprintf("bt: %s", bt))
}

base = $*g->jit_base->ptr32
base = $*g->jit_base->ptr64
if (!base) {
return bt
}
Expand Down
Loading