aboutsummaryrefslogtreecommitdiff
path: root/src/lj_ccallback.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lj_ccallback.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/lj_ccallback.c b/src/lj_ccallback.c
index 5fe63a76..60735ade 100644
--- a/src/lj_ccallback.c
+++ b/src/lj_ccallback.c
@@ -422,7 +422,7 @@ static void callback_conv_args(CTState *cts, lua_State *L)
422 422
423 if (slot < cts->cb.sizeid && (id = cts->cb.cbid[slot]) != 0) { 423 if (slot < cts->cb.sizeid && (id = cts->cb.cbid[slot]) != 0) {
424 ct = ctype_get(cts, id); 424 ct = ctype_get(cts, id);
425 rid = ctype_cid(ct->info); 425 rid = ctype_cid(ct->info); /* Return type. x86: +(spadj<<16). */
426 fn = funcV(lj_tab_getint(cts->miscmap, (int32_t)slot)); 426 fn = funcV(lj_tab_getint(cts->miscmap, (int32_t)slot));
427 fntp = LJ_TFUNC; 427 fntp = LJ_TFUNC;
428 } else { /* Must set up frame first, before throwing the error. */ 428 } else { /* Must set up frame first, before throwing the error. */
@@ -431,9 +431,16 @@ static void callback_conv_args(CTState *cts, lua_State *L)
431 fn = (GCfunc *)L; 431 fn = (GCfunc *)L;
432 fntp = LJ_TTHREAD; 432 fntp = LJ_TTHREAD;
433 } 433 }
434 o->u32.lo = LJ_CONT_FFI_CALLBACK; /* Continuation returns from callback. */ 434 /* Continuation returns from callback. */
435 o->u32.hi = rid; /* Return type. x86: +(spadj<<16). */ 435 if (LJ_FR2) {
436 o++; 436 (o++)->u64 = LJ_CONT_FFI_CALLBACK;
437 (o++)->u64 = rid;
438 o++;
439 } else {
440 o->u32.lo = LJ_CONT_FFI_CALLBACK;
441 o->u32.hi = rid;
442 o++;
443 }
437 setframe_gc(o, obj2gco(fn), fntp); 444 setframe_gc(o, obj2gco(fn), fntp);
438 setframe_ftsz(o, ((char *)(o+1) - (char *)L->base) + FRAME_CONT); 445 setframe_ftsz(o, ((char *)(o+1) - (char *)L->base) + FRAME_CONT);
439 L->top = L->base = ++o; 446 L->top = L->base = ++o;
@@ -486,9 +493,14 @@ static void callback_conv_args(CTState *cts, lua_State *L)
486 L->top = o; 493 L->top = o;
487#if LJ_TARGET_X86 494#if LJ_TARGET_X86
488 /* Store stack adjustment for returns from non-cdecl callbacks. */ 495 /* Store stack adjustment for returns from non-cdecl callbacks. */
489 if (ctype_cconv(ct->info) != CTCC_CDECL) 496 if (ctype_cconv(ct->info) != CTCC_CDECL) {
497#if LJ_FR2
498 (L->base-3)->u64 |= (nsp << (16+2));
499#else
490 (L->base-2)->u32.hi |= (nsp << (16+2)); 500 (L->base-2)->u32.hi |= (nsp << (16+2));
491#endif 501#endif
502 }
503#endif
492 while (gcsteps-- > 0) 504 while (gcsteps-- > 0)
493 lj_gc_check(L); 505 lj_gc_check(L);
494} 506}
@@ -496,7 +508,11 @@ static void callback_conv_args(CTState *cts, lua_State *L)
496/* Convert Lua object to callback result. */ 508/* Convert Lua object to callback result. */
497static void callback_conv_result(CTState *cts, lua_State *L, TValue *o) 509static void callback_conv_result(CTState *cts, lua_State *L, TValue *o)
498{ 510{
511#if LJ_FR2
512 CType *ctr = ctype_raw(cts, (uint16_t)(L->base-3)->u64);
513#else
499 CType *ctr = ctype_raw(cts, (uint16_t)(L->base-2)->u32.hi); 514 CType *ctr = ctype_raw(cts, (uint16_t)(L->base-2)->u32.hi);
515#endif
500#if LJ_TARGET_X86 516#if LJ_TARGET_X86
501 cts->cb.gpr[2] = 0; 517 cts->cb.gpr[2] = 0;
502#endif 518#endif
@@ -565,7 +581,7 @@ void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o)
565 } 581 }
566 callback_conv_result(cts, L, o); 582 callback_conv_result(cts, L, o);
567 /* Finally drop C frame and continuation frame. */ 583 /* Finally drop C frame and continuation frame. */
568 L->top -= 2; 584 L->top -= 2+2*LJ_FR2;
569 L->base = obase; 585 L->base = obase;
570 L->cframe = cframe_prev(L->cframe); 586 L->cframe = cframe_prev(L->cframe);
571 cts->cb.slot = 0; /* Blacklist C function that called the callback. */ 587 cts->cb.slot = 0; /* Blacklist C function that called the callback. */