diff options
| author | Mike Pall <mike> | 2025-07-24 15:29:54 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2025-07-24 15:29:54 +0200 |
| commit | c64020f3c6d124503213147f2fb47c20335a395b (patch) | |
| tree | c35b04e06d8d40ef8933f8eb8405bef7793694cc /src | |
| parent | 048972dbfdb6b441fe8a9bfe4d1f048966579ba8 (diff) | |
| download | luajit-c64020f3c6d124503213147f2fb47c20335a395b.tar.gz luajit-c64020f3c6d124503213147f2fb47c20335a395b.tar.bz2 luajit-c64020f3c6d124503213147f2fb47c20335a395b.zip | |
FFI: Fix dangling CType references (again).
Reported by Sergey Kaplun. Collateral of #1360
Diffstat (limited to 'src')
| -rw-r--r-- | src/lj_crecord.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index f686b35f..80e25ef8 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
| @@ -1125,6 +1125,7 @@ static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) | |||
| 1125 | if (ctype_isfunc(info)) { | 1125 | if (ctype_isfunc(info)) { |
| 1126 | TRef func = emitir(IRT(IR_FLOAD, tp), J->base[0], IRFL_CDATA_PTR); | 1126 | TRef func = emitir(IRT(IR_FLOAD, tp), J->base[0], IRFL_CDATA_PTR); |
| 1127 | CType *ctr = ctype_rawchild(cts, ct); | 1127 | CType *ctr = ctype_rawchild(cts, ct); |
| 1128 | CTInfo ctr_info = ctr->info; /* crec_call_args may invalidate ctr. */ | ||
| 1128 | IRType t = crec_ct2irt(cts, ctr); | 1129 | IRType t = crec_ct2irt(cts, ctr); |
| 1129 | TRef tr; | 1130 | TRef tr; |
| 1130 | TValue tv; | 1131 | TValue tv; |
| @@ -1133,11 +1134,11 @@ static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) | |||
| 1133 | cdata_getptr(cdataptr(cd), (LJ_64 && tp == IRT_P64) ? 8 : 4)); | 1134 | cdata_getptr(cdataptr(cd), (LJ_64 && tp == IRT_P64) ? 8 : 4)); |
| 1134 | if (tvistrue(lj_tab_get(J->L, cts->miscmap, &tv))) | 1135 | if (tvistrue(lj_tab_get(J->L, cts->miscmap, &tv))) |
| 1135 | lj_trace_err(J, LJ_TRERR_BLACKL); | 1136 | lj_trace_err(J, LJ_TRERR_BLACKL); |
| 1136 | if (ctype_isvoid(ctr->info)) { | 1137 | if (ctype_isvoid(ctr_info)) { |
| 1137 | t = IRT_NIL; | 1138 | t = IRT_NIL; |
| 1138 | rd->nres = 0; | 1139 | rd->nres = 0; |
| 1139 | } else if (!(ctype_isnum(ctr->info) || ctype_isptr(ctr->info) || | 1140 | } else if (!(ctype_isnum(ctr_info) || ctype_isptr(ctr_info) || |
| 1140 | ctype_isenum(ctr->info)) || t == IRT_CDATA) { | 1141 | ctype_isenum(ctr_info)) || t == IRT_CDATA) { |
| 1141 | lj_trace_err(J, LJ_TRERR_NYICALL); | 1142 | lj_trace_err(J, LJ_TRERR_NYICALL); |
| 1142 | } | 1143 | } |
| 1143 | if ((info & CTF_VARARG) | 1144 | if ((info & CTF_VARARG) |
| @@ -1148,7 +1149,7 @@ static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) | |||
| 1148 | func = emitir(IRT(IR_CARG, IRT_NIL), func, | 1149 | func = emitir(IRT(IR_CARG, IRT_NIL), func, |
| 1149 | lj_ir_kint(J, ctype_typeid(cts, ct))); | 1150 | lj_ir_kint(J, ctype_typeid(cts, ct))); |
| 1150 | tr = emitir(IRT(IR_CALLXS, t), crec_call_args(J, rd, cts, ct), func); | 1151 | tr = emitir(IRT(IR_CALLXS, t), crec_call_args(J, rd, cts, ct), func); |
| 1151 | if (ctype_isbool(ctr->info)) { | 1152 | if (ctype_isbool(ctr_info)) { |
| 1152 | if (frame_islua(J->L->base-1) && bc_b(frame_pc(J->L->base-1)[-1]) == 1) { | 1153 | if (frame_islua(J->L->base-1) && bc_b(frame_pc(J->L->base-1)[-1]) == 1) { |
| 1153 | /* Don't check result if ignored. */ | 1154 | /* Don't check result if ignored. */ |
| 1154 | tr = TREF_NIL; | 1155 | tr = TREF_NIL; |
| @@ -1164,7 +1165,7 @@ static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd) | |||
| 1164 | tr = TREF_TRUE; | 1165 | tr = TREF_TRUE; |
| 1165 | } | 1166 | } |
| 1166 | } else if (t == IRT_PTR || (LJ_64 && t == IRT_P32) || | 1167 | } else if (t == IRT_PTR || (LJ_64 && t == IRT_P32) || |
| 1167 | t == IRT_I64 || t == IRT_U64 || ctype_isenum(ctr->info)) { | 1168 | t == IRT_I64 || t == IRT_U64 || ctype_isenum(ctr_info)) { |
| 1168 | TRef trid = lj_ir_kint(J, ctype_cid(info)); | 1169 | TRef trid = lj_ir_kint(J, ctype_cid(info)); |
| 1169 | tr = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, tr); | 1170 | tr = emitir(IRTG(IR_CNEWI, IRT_CDATA), trid, tr); |
| 1170 | if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J); | 1171 | if (t == IRT_I64 || t == IRT_U64) lj_needsplit(J); |
