Fix data races in atomic wait/notify and interp goto table (#1971)

Add shared memory lock when accessing the address to atomic wait/notify
inside linear memory to resolve its data race issue.

And statically initialize the goto table of interpreter labels to resolve the
data race issue of accessing the table.
This commit is contained in:
Enrico Loparco
2023-02-22 04:43:49 +01:00
committed by GitHub
parent 0fa0813a5a
commit bc60064de5
2 changed files with 37 additions and 19 deletions

View File

@ -675,12 +675,14 @@ typedef enum WASMAtomicEXTOpcode {
} WASMAtomicEXTOpcode;
#if WASM_ENABLE_DEBUG_INTERP != 0
#define DEF_DEBUG_BREAK_HANDLE(_name) \
_name[DEBUG_OP_BREAK] = HANDLE_OPCODE(DEBUG_OP_BREAK); /* 0xd7 */
#define DEF_DEBUG_BREAK_HANDLE() \
[DEBUG_OP_BREAK] = HANDLE_OPCODE(DEBUG_OP_BREAK), /* 0xd7 */
#else
#define DEF_DEBUG_BREAK_HANDLE(_name)
#define DEF_DEBUG_BREAK_HANDLE()
#endif
#define SET_GOTO_TABLE_ELEM(opcode) [opcode] = HANDLE_OPCODE(opcode)
/*
* Macro used to generate computed goto tables for the C interpreter.
*/
@ -903,14 +905,10 @@ typedef enum WASMAtomicEXTOpcode {
HANDLE_OPCODE(EXT_OP_LOOP), /* 0xd4 */ \
HANDLE_OPCODE(EXT_OP_IF), /* 0xd5 */ \
HANDLE_OPCODE(EXT_OP_BR_TABLE_CACHE), /* 0xd6 */ \
}; \
do { \
_name[WASM_OP_MISC_PREFIX] = \
HANDLE_OPCODE(WASM_OP_MISC_PREFIX); /* 0xfc */ \
_name[WASM_OP_ATOMIC_PREFIX] = \
HANDLE_OPCODE(WASM_OP_ATOMIC_PREFIX); /* 0xfe */ \
DEF_DEBUG_BREAK_HANDLE(_name) \
} while (0)
SET_GOTO_TABLE_ELEM(WASM_OP_MISC_PREFIX), /* 0xfc */ \
SET_GOTO_TABLE_ELEM(WASM_OP_ATOMIC_PREFIX), /* 0xfe */ \
DEF_DEBUG_BREAK_HANDLE() \
};
#ifdef __cplusplus
}