uc_struct: remove current_cpu

This commit is contained in:
Nguyen Anh Quynh 2020-06-27 21:59:58 +08:00
parent 0f0bf3ed83
commit b22d4cfbb2
17 changed files with 65 additions and 66 deletions

View File

@ -1797,9 +1797,9 @@ uc_err uc_emu_stop(uc_engine *uc)
uc->stop_request = true;
if (uc->current_cpu) {
if (uc->cpu) {
// 退出当前线程
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
}
return UC_ERR_OK;

View File

@ -169,8 +169,7 @@ struct uc_struct {
uc_readonly_mem_t readonly_mem;
uc_mem_redirect_t mem_redirect;
uc_cpus_init cpus_init;
// TODO: remove current_cpu, as it's a flag for something else ("cpu running"?)
CPUState *cpu, *current_cpu;
CPUState *cpu;
uc_insn_hook_validate insn_hook_validate;

View File

@ -70,7 +70,7 @@ int cpu_exec(struct uc_struct *uc, CPUArchState *env)
cpu->halted = 0;
}
uc->current_cpu = cpu;
uc->cpu = cpu;
/* As long as current_cpu is null, up to the assignment just above,
* requests by other threads to exit the execution loop are expected to
@ -281,7 +281,7 @@ int cpu_exec(struct uc_struct *uc, CPUArchState *env)
} else {
/* Reload env after longjmp - the compiler may have smashed all
* local variables as longjmp is marked 'noreturn'. */
cpu = uc->current_cpu;
cpu = uc->cpu;
env = cpu->env_ptr;
cc = CPU_GET_CLASS(uc, cpu);
#ifdef TARGET_I386
@ -291,7 +291,7 @@ int cpu_exec(struct uc_struct *uc, CPUArchState *env)
} /* for(;;) */
// Unicorn: Clear any TCG exit flag that might have been left set by exit requests
uc->current_cpu->tcg_exit_req = 0;
uc->cpu->tcg_exit_req = 0;
cc->cpu_exec_exit(cpu);
@ -300,8 +300,8 @@ int cpu_exec(struct uc_struct *uc, CPUArchState *env)
// TODO: optimize this for better performance
tb_flush(env);
/* fail safe : never use current_cpu outside cpu_exec() */
// uc->current_cpu = NULL;
/* fail safe : never use cpu outside cpu_exec() */
// uc->cpu = NULL;
return ret;
}

View File

@ -1105,8 +1105,8 @@ static void notdirty_mem_write(struct uc_struct* uc, void *opaque, hwaddr ram_ad
/* we remove the notdirty callback only if the code has been
flushed */
if (!cpu_physical_memory_is_clean(uc, ram_addr)) {
CPUArchState *env = uc->current_cpu->env_ptr;
tlb_set_dirty(env, uc->current_cpu->mem_io_vaddr);
CPUArchState *env = uc->cpu->env_ptr;
tlb_set_dirty(env, uc->cpu->mem_io_vaddr);
}
}

View File

@ -58,8 +58,8 @@ MemoryRegion *memory_map(struct uc_struct *uc, hwaddr begin, size_t size, uint32
memory_region_add_subregion(get_system_memory(uc), begin, ram);
if (uc->current_cpu)
tlb_flush(uc->current_cpu, 1);
if (uc->cpu)
tlb_flush(uc->cpu, 1);
return ram;
}
@ -76,8 +76,8 @@ MemoryRegion *memory_map_ptr(struct uc_struct *uc, hwaddr begin, size_t size, ui
memory_region_add_subregion(get_system_memory(uc), begin, ram);
if (uc->current_cpu)
tlb_flush(uc->current_cpu, 1);
if (uc->cpu)
tlb_flush(uc->cpu, 1);
return ram;
}
@ -91,9 +91,9 @@ void memory_unmap(struct uc_struct *uc, MemoryRegion *mr)
// Make sure all pages associated with the MemoryRegion are flushed
// Only need to do this if we are in a running state
if (uc->current_cpu) {
if (uc->cpu) {
for (addr = mr->addr; addr < mr->end; addr += uc->target_page_size) {
tlb_flush_page(uc->current_cpu, addr);
tlb_flush_page(uc->cpu, addr);
}
}
memory_region_del_subregion(get_system_memory(uc), mr);
@ -713,8 +713,8 @@ static uint64_t unassigned_mem_read(struct uc_struct* uc, hwaddr addr, unsigned
#ifdef DEBUG_UNASSIGNED
printf("Unassigned mem read " TARGET_FMT_plx "\n", addr);
#endif
if (uc->current_cpu != NULL) {
cpu_unassigned_access(uc->current_cpu, addr, false, false, 0, size);
if (uc->cpu != NULL) {
cpu_unassigned_access(uc->cpu, addr, false, false, 0, size);
}
return 0;
}
@ -725,8 +725,8 @@ static void unassigned_mem_write(struct uc_struct* uc, hwaddr addr,
#ifdef DEBUG_UNASSIGNED
printf("Unassigned mem write " TARGET_FMT_plx " = 0x%"PRIx64"\n", addr, val);
#endif
if (uc->current_cpu != NULL) {
cpu_unassigned_access(uc->current_cpu, addr, true, false, 0, size);
if (uc->cpu != NULL) {
cpu_unassigned_access(uc->cpu, addr, true, false, 0, size);
}
}

View File

@ -227,7 +227,7 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
env->invalid_addr = addr;
env->invalid_error = error_code;
// printf("***** Invalid fetch (unmapped memory) at " TARGET_FMT_lx "\n", addr);
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
}
}
@ -251,7 +251,7 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_FETCH_PROT;
// printf("***** Invalid fetch (non-executable) at " TARGET_FMT_lx "\n", addr);
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
}
}
@ -292,7 +292,7 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_READ_PROT;
// printf("***** Invalid memory read (non-readable) at " TARGET_FMT_lx "\n", addr);
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
}
}
@ -316,7 +316,7 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
#else
env->invalid_error = UC_ERR_READ_UNALIGNED;
#endif
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
}
#endif
@ -338,7 +338,7 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_READ_UNMAPPED;
// printf("Invalid memory read at " TARGET_FMT_lx "\n", addr);
cpu_exit(env->uc->current_cpu);
cpu_exit(env->uc->cpu);
return 0;
} else {
env->invalid_error = UC_ERR_OK;
@ -368,7 +368,7 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
#else
env->invalid_error = UC_ERR_READ_UNALIGNED;
#endif
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
#endif
addr1 = addr & ~(DATA_SIZE - 1);
@ -398,7 +398,7 @@ WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
#else
env->invalid_error = UC_ERR_READ_UNALIGNED;
#endif
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
}
#endif
@ -477,7 +477,7 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
env->invalid_addr = addr;
env->invalid_error = error_code;
// printf("***** Invalid fetch (unmapped memory) at " TARGET_FMT_lx "\n", addr);
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
}
}
@ -501,7 +501,7 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_FETCH_PROT;
// printf("***** Invalid fetch (non-executable) at " TARGET_FMT_lx "\n", addr);
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
}
}
@ -542,7 +542,7 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_READ_PROT;
// printf("***** Invalid memory read (non-readable) at " TARGET_FMT_lx "\n", addr);
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
}
}
@ -566,7 +566,7 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
#else
env->invalid_error = UC_ERR_READ_UNALIGNED;
#endif
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
}
#endif
@ -589,7 +589,7 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_READ_UNMAPPED;
// printf("Invalid memory read at " TARGET_FMT_lx "\n", addr);
cpu_exit(env->uc->current_cpu);
cpu_exit(env->uc->cpu);
return 0;
}
@ -617,7 +617,7 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
#else
env->invalid_error = UC_ERR_READ_UNALIGNED;
#endif
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
#endif
addr1 = addr & ~(DATA_SIZE - 1);
@ -647,7 +647,7 @@ WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
#else
env->invalid_error = UC_ERR_READ_UNALIGNED;
#endif
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return 0;
}
#endif
@ -761,7 +761,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_UNMAPPED;
// printf("***** Invalid memory write at " TARGET_FMT_lx "\n", addr);
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return;
} else {
env->invalid_error = UC_ERR_OK;
@ -787,7 +787,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_PROT;
// printf("***** Invalid memory write (ro) at " TARGET_FMT_lx "\n", addr);
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return;
}
}
@ -804,7 +804,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
// mmu_idx, retaddr);
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_UNALIGNED;
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return;
}
#endif
@ -825,7 +825,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_UNMAPPED;
// printf("***** Invalid memory write at " TARGET_FMT_lx "\n", addr);
cpu_exit(env->uc->current_cpu);
cpu_exit(env->uc->cpu);
return;
}
@ -847,7 +847,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
mmu_idx, retaddr);
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_UNALIGNED;
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return;
#endif
/* XXX: not efficient, but simple */
@ -876,7 +876,7 @@ void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
mmu_idx, retaddr);
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_UNALIGNED;
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return;
}
#endif
@ -931,7 +931,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_UNMAPPED;
// printf("***** Invalid memory write at " TARGET_FMT_lx "\n", addr);
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return;
} else {
env->invalid_error = UC_ERR_OK;
@ -957,7 +957,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_PROT;
// printf("***** Invalid memory write (ro) at " TARGET_FMT_lx "\n", addr);
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return;
}
}
@ -974,7 +974,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
mmu_idx, retaddr);
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_UNALIGNED;
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return;
}
#endif
@ -995,7 +995,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_UNMAPPED;
// printf("***** Invalid memory write at " TARGET_FMT_lx "\n", addr);
cpu_exit(env->uc->current_cpu);
cpu_exit(env->uc->cpu);
return;
}
@ -1017,7 +1017,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
mmu_idx, retaddr);
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_UNALIGNED;
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return;
#endif
/* XXX: not efficient, but simple */
@ -1046,7 +1046,7 @@ void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
mmu_idx, retaddr);
env->invalid_addr = addr;
env->invalid_error = UC_ERR_WRITE_UNALIGNED;
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
return;
}
#endif

View File

@ -15,7 +15,7 @@ const int ARM64_REGS_STORAGE_SIZE = offsetof(CPUARMState, tlb_table);
static void arm64_set_pc(struct uc_struct *uc, uint64_t address)
{
((CPUARMState *)uc->current_cpu->env_ptr)->pc = address;
((CPUARMState *)uc->cpu->env_ptr)->pc = address;
}
static void arm64_release(void* ctx)

View File

@ -14,8 +14,8 @@ const int ARM_REGS_STORAGE_SIZE = offsetof(CPUARMState, tlb_table);
static void arm_set_pc(struct uc_struct *uc, uint64_t address)
{
((CPUARMState *)uc->current_cpu->env_ptr)->pc = address;
((CPUARMState *)uc->current_cpu->env_ptr)->regs[15] = address;
((CPUARMState *)uc->cpu->env_ptr)->pc = address;
((CPUARMState *)uc->cpu->env_ptr)->regs[15] = address;
}
static void arm_release(void* ctx)

View File

@ -26,7 +26,7 @@ const int X86_REGS_STORAGE_SIZE = offsetof(CPUX86State, tlb_table);
static void x86_set_pc(struct uc_struct *uc, uint64_t address)
{
((CPUX86State *)uc->current_cpu->env_ptr)->eip = address;
((CPUX86State *)uc->cpu->env_ptr)->eip = address;
}
static void x86_release(void *ctx)

View File

@ -13,7 +13,7 @@ const int M68K_REGS_STORAGE_SIZE = offsetof(CPUM68KState, tlb_table);
static void m68k_set_pc(struct uc_struct *uc, uint64_t address)
{
((CPUM68KState *)uc->current_cpu->env_ptr)->pc = address;
((CPUM68KState *)uc->cpu->env_ptr)->pc = address;
}
static void m68k_release(void* ctx)

View File

@ -37,7 +37,7 @@ static uint64_t mips_mem_redirect(uint64_t address)
static void mips_set_pc(struct uc_struct *uc, uint64_t address)
{
((CPUMIPSState *)uc->current_cpu->env_ptr)->active_tc.PC = address;
((CPUMIPSState *)uc->cpu->env_ptr)->active_tc.PC = address;
}

View File

@ -38,7 +38,7 @@ static uint64_t ppc_mem_redirect(uint64_t address)
static void ppc_set_pc(struct uc_struct *uc, uint64_t address)
{
((CPUPPCState *)uc->current_cpu->env_ptr)->nip = address;
((CPUPPCState *)uc->cpu->env_ptr)->nip = address;
}

View File

@ -23,8 +23,8 @@ static bool sparc_stop_interrupt(int intno)
static void sparc_set_pc(struct uc_struct *uc, uint64_t address)
{
((CPUSPARCState *)uc->current_cpu->env_ptr)->pc = address;
((CPUSPARCState *)uc->current_cpu->env_ptr)->npc = address + 4;
((CPUSPARCState *)uc->cpu->env_ptr)->pc = address;
((CPUSPARCState *)uc->cpu->env_ptr)->npc = address + 4;
}
static void sparc_release(void *ctx)

View File

@ -23,8 +23,8 @@ static bool sparc_stop_interrupt(int intno)
static void sparc_set_pc(struct uc_struct *uc, uint64_t address)
{
((CPUSPARCState *)uc->current_cpu->env_ptr)->pc = address;
((CPUSPARCState *)uc->current_cpu->env_ptr)->npc = address + 4;
((CPUSPARCState *)uc->cpu->env_ptr)->pc = address;
((CPUSPARCState *)uc->cpu->env_ptr)->npc = address + 4;
}
static void sparc_release(void *ctx)

View File

@ -1197,7 +1197,7 @@ void tb_invalidate_phys_page_range(struct uc_struct *uc, tb_page_addr_t start, t
int is_cpu_write_access)
{
TranslationBlock *tb, *tb_next, *saved_tb;
CPUState *cpu = uc->current_cpu;
CPUState *cpu = uc->cpu;
#if defined(TARGET_HAS_PRECISE_SMC)
CPUArchState *env = NULL;
#endif
@ -1320,7 +1320,7 @@ static void tb_invalidate_phys_page(struct uc_struct *uc, tb_page_addr_t addr,
int n;
#ifdef TARGET_HAS_PRECISE_SMC
TranslationBlock *current_tb = NULL;
CPUState *cpu = uc->current_cpu;
CPUState *cpu = uc->cpu;
CPUArchState *env = NULL;
int current_tb_modified = 0;
target_ulong current_pc = 0;

View File

@ -46,10 +46,10 @@ void cpu_resume(CPUState *cpu)
void cpu_stop_current(struct uc_struct *uc)
{
if (uc->current_cpu) {
uc->current_cpu->stop = false;
uc->current_cpu->stopped = true;
cpu_exit(uc->current_cpu);
if (uc->cpu) {
uc->cpu->stop = false;
uc->cpu->stopped = true;
cpu_exit(uc->cpu);
}
}

4
uc.c
View File

@ -677,9 +677,9 @@ uc_err uc_emu_stop(uc_engine *uc)
uc->stop_request = true;
// TODO: make this atomic somehow?
if (uc->current_cpu) {
if (uc->cpu) {
// exit the current TB
cpu_exit(uc->current_cpu);
cpu_exit(uc->cpu);
}
return UC_ERR_OK;