Skip to content

Commit 1930510

Browse files
committed
Merge pull request atomvm#509 from pguyot/w16/fix-refc-binary-info
Fix potential GC crash related to `OP_RECV_MARKER_RESERVE` This bug could potentially yield a crash with current GC/memory implementation, however it was not observed. The crash can be observed with heap fragments, though. The compiler puts allocate to allocate three y registers, registers 1 and 2 are filled with move opcode, register 0 is supposed to be filled by the recv_marker_reserve, and then GC is called and can find garbage (here 2B) and then crash. <img width="735" alt="image" src="https://user-images.githubusercontent.com/168407/233457776-0402d466-4231-4418-b9af-22f39efc742b.png"> These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 2cf5b8c + 5205c88 commit 1930510

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/libAtomVM/opcodesswitch.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6195,6 +6195,10 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
61956195
dreg_type_t reg_a_type;
61966196
DECODE_DEST_REGISTER(reg_a, reg_a_type, code, i, next_off);
61976197
TRACE("recv_marker_reserve/1: reg1=%c%i\n", T_DEST_REG(reg_a_type, reg_a));
6198+
#ifdef IMPL_EXECUTE_LOOP
6199+
// Clear register to avoid any issue with GC
6200+
WRITE_REGISTER(reg_a_type, reg_a, term_nil());
6201+
#endif
61986202
NEXT_INSTRUCTION(next_off);
61996203
break;
62006204
}

0 commit comments

Comments
 (0)