Skip to content

Commit

Permalink
tcg/tci: Make tci_tb_ptr thread-local
Browse files Browse the repository at this point in the history
Each thread must have its own pc, even under TCI.

Remove the GETPC ifdef, because GETPC is always available for
helpers, and thus is always required.  Move the assignment
under INDEX_op_call, because the value is only visible when
we make a call to a helper function.

Reviewed-by: Alex Bennée <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
rth7680 committed Feb 5, 2021
1 parent c6fbea4 commit 13e71f0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion include/exec/exec-all.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr);

/* GETPC is the true target of the return instruction that we'll execute. */
#if defined(CONFIG_TCG_INTERPRETER)
extern uintptr_t tci_tb_ptr;
extern __thread uintptr_t tci_tb_ptr;
# define GETPC() tci_tb_ptr
#else
# define GETPC() \
Expand Down
4 changes: 0 additions & 4 deletions tcg/tcg-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
#include "qemu/osdep.h"
#include "tcg/tcg.h"

#if defined(CONFIG_TCG_INTERPRETER)
uintptr_t tci_tb_ptr;
#endif

TCGOpDef tcg_op_defs[] = {
#define DEF(s, oargs, iargs, cargs, flags) \
{ #s, oargs, iargs, cargs, iargs + oargs + cargs, flags },
Expand Down
7 changes: 3 additions & 4 deletions tcg/tci.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ typedef uint64_t (*helper_function)(tcg_target_ulong, tcg_target_ulong,
tcg_target_ulong, tcg_target_ulong);
#endif

__thread uintptr_t tci_tb_ptr;

static tcg_target_ulong tci_read_reg(const tcg_target_ulong *regs, TCGReg index)
{
tci_assert(index < TCG_TARGET_NB_REGS);
Expand Down Expand Up @@ -526,16 +528,13 @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env,
#endif
TCGMemOpIdx oi;

#if defined(GETPC)
tci_tb_ptr = (uintptr_t)tb_ptr;
#endif

/* Skip opcode and size entry. */
tb_ptr += 2;

switch (opc) {
case INDEX_op_call:
t0 = tci_read_ri(regs, &tb_ptr);
tci_tb_ptr = (uintptr_t)tb_ptr;
#if TCG_TARGET_REG_BITS == 32
tmp64 = ((helper_function)t0)(tci_read_reg(regs, TCG_REG_R0),
tci_read_reg(regs, TCG_REG_R1),
Expand Down

0 comments on commit 13e71f0

Please sign in to comment.