}
/* Add frame links at the end of the snapshot. */
-static BCReg snapshot_framelinks(jit_State *J, SnapEntry *map)
+static MSize snapshot_framelinks(jit_State *J, SnapEntry *map, uint8_t *topslot)
{
cTValue *frame = J->L->base - 1;
- cTValue *lim = J->L->base - J->baseslot;
- cTValue *ftop = frame + funcproto(frame_func(frame))->framesize;
+ cTValue *lim = J->L->base - J->baseslot + LJ_FR2;
+ GCfunc *fn = frame_func(frame);
+ cTValue *ftop = isluafunc(fn) ? (frame+funcproto(fn)->framesize) : J->L->top;
+#if LJ_FR2
+ uint64_t pcbase = (u64ptr(J->pc) << 8) | (J->baseslot - 2);
+ lj_assertJ(2 <= J->baseslot && J->baseslot <= 257, "bad baseslot");
+ memcpy(map, &pcbase, sizeof(uint64_t));
+#else
MSize f = 0;
map[f++] = SNAP_MKPC(J->pc); /* The current PC is always the first entry. */
- lua_assert(!J->pt ||
+#endif
++ lj_assertJ(!J->pt ||
+ (J->pc >= proto_bc(J->pt) &&
- J->pc < proto_bc(J->pt) + J->pt->sizebc));
++ J->pc < proto_bc(J->pt) + J->pt->sizebc), "bad snapshot PC");
while (frame > lim) { /* Backwards traversal of all frames above base. */
if (frame_islua(frame)) {
+#if !LJ_FR2
map[f++] = SNAP_MKPC(frame_pc(frame));
+#endif
frame = frame_prevl(frame);
} else if (frame_iscont(frame)) {
+#if !LJ_FR2
map[f++] = SNAP_MKFTSZ(frame_ftsz(frame));
map[f++] = SNAP_MKPC(frame_contpc(frame));
+#endif
frame = frame_prevd(frame);
} else {
- lua_assert(!frame_isc(frame));
+ lj_assertJ(!frame_isc(frame), "broken frame chain");
+#if !LJ_FR2
map[f++] = SNAP_MKFTSZ(frame_ftsz(frame));
+#endif
frame = frame_prevd(frame);
continue;
}