Skip to content

Commit 432ba8b

Browse files
authored
Fix memcpy overlap issue in RECOVER_BR_INFO for i64/v128 copy (#4797)
When copying single i64 or V128 values in RECOVER_BR_INFO, source and destination memory regions may overlap, causing memcpy-param-overlap errors Use temporary variables to separate read and write operations, preventing the overlap issue. This fix references the approach used in the other path (when arity != 1), which calls copy_stack_values, that function explicitly handles memcpy overlap. Signed-off-by: zhenweijin <zhenwei.jin@intel.com>
1 parent 09a2456 commit 432ba8b

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,9 @@ copy_stack_values(WASMModuleInstance *module, uint32 *frame_lp, uint32 arity,
999999
} \
10001000
} \
10011001
else if (cells[0] == 2) { \
1002-
PUT_I64_TO_ADDR( \
1003-
frame_lp + dst_offsets[0], \
1004-
GET_I64_FROM_ADDR(frame_lp + src_offsets[0])); \
1002+
int64 tmp_i64 = \
1003+
GET_I64_FROM_ADDR(frame_lp + src_offsets[0]); \
1004+
PUT_I64_TO_ADDR(frame_lp + dst_offsets[0], tmp_i64); \
10051005
/* Ignore constants because they are not reference */ \
10061006
if (src_offsets[0] >= 0) { \
10071007
CLEAR_FRAME_REF((unsigned)src_offsets[0]); \
@@ -1011,9 +1011,9 @@ copy_stack_values(WASMModuleInstance *module, uint32 *frame_lp, uint32 arity,
10111011
} \
10121012
} \
10131013
else if (cells[0] == 4) { \
1014-
PUT_V128_TO_ADDR( \
1015-
frame_lp + dst_offsets[0], \
1016-
GET_V128_FROM_ADDR(frame_lp + src_offsets[0])); \
1014+
V128 tmp_v128 = \
1015+
GET_V128_FROM_ADDR(frame_lp + src_offsets[0]); \
1016+
PUT_V128_TO_ADDR(frame_lp + dst_offsets[0], tmp_v128); \
10171017
/* Ignore constants because they are not reference */ \
10181018
if (src_offsets[0] >= 0) { \
10191019
CLEAR_FRAME_REF((unsigned)src_offsets[0]); \
@@ -1062,14 +1062,14 @@ copy_stack_values(WASMModuleInstance *module, uint32 *frame_lp, uint32 arity,
10621062
if (cells[0] == 1) \
10631063
frame_lp[dst_offsets[0]] = frame_lp[src_offsets[0]]; \
10641064
else if (cells[0] == 2) { \
1065-
PUT_I64_TO_ADDR( \
1066-
frame_lp + dst_offsets[0], \
1067-
GET_I64_FROM_ADDR(frame_lp + src_offsets[0])); \
1065+
int64 tmp_i64 = \
1066+
GET_I64_FROM_ADDR(frame_lp + src_offsets[0]); \
1067+
PUT_I64_TO_ADDR(frame_lp + dst_offsets[0], tmp_i64); \
10681068
} \
10691069
else if (cells[0] == 4) { \
1070-
PUT_V128_TO_ADDR( \
1071-
frame_lp + dst_offsets[0], \
1072-
GET_V128_FROM_ADDR(frame_lp + src_offsets[0])); \
1070+
V128 tmp_v128 = \
1071+
GET_V128_FROM_ADDR(frame_lp + src_offsets[0]); \
1072+
PUT_V128_TO_ADDR(frame_lp + dst_offsets[0], tmp_v128); \
10731073
} \
10741074
} \
10751075
else { \

0 commit comments

Comments
 (0)