Skip to content

Commit 7de27fb

Browse files
committed
Removed unnecessary ptr_code field in translated_code_t
It can be deduced from ptr_exit instead
1 parent 58f14d8 commit 7de27fb

5 files changed

Lines changed: 7 additions & 9 deletions

File tree

lib86cpu/core/emitter/x64/jit.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,6 @@ lc86_jit::gen_code_block()
643643
// This code block is complete, so protect and flush the instruction cache now
644644
m_mem.flush_instr_cache(block);
645645

646-
tc->ptr_code = reinterpret_cast<entry_t>(main_offset);
647646
tc->ptr_exit = reinterpret_cast<entry_t>(exit_offset);
648647

649648
// we are done with code generation for this block, so we null the tc pointer to prevent accidental usage
@@ -725,7 +724,7 @@ lc86_jit::gen_aux_funcs()
725724
void
726725
lc86_jit::gen_exit_func()
727726
{
728-
// this should be emitted before main(), so that we can calculate the tc ptr from tc->ptr_code by simply subtracting an offset
727+
// this should be emitted before main(), so that we can calculate the tc ptr from tc->ptr_exit by simply dereferencing it
729728

730729
size_t exit_off_start = m_a.offset();
731730
MOV(RAX, m_cpu->tc);

lib86cpu/core/emitter/x64/linux/ipt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,11 @@ ipt_run_guarded_code(cpu_ctx_t *cpu_ctx, translated_code_t *tc)
502502
{
503503
int ret = sigsetjmp(env, 1);
504504
if (ret == SIG_SAVE_CTX) {
505-
return tc->ptr_code(cpu_ctx);
505+
return GET_PTR_CODE(tc->ptr_exit)(cpu_ctx);
506506
}
507507
else if (ret == SIG_GUEST_PF) {
508508
return ipt_raise_exception(cpu_ctx);
509509
}
510510

511511
LIB86CPU_ABORT();
512512
}
513-

lib86cpu/core/emitter/x64/windows/ipt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ translated_code_t *
482482
ipt_run_guarded_code(cpu_ctx_t *cpu_ctx, translated_code_t *tc)
483483
{
484484
__try {
485-
return tc->ptr_code(cpu_ctx);
485+
return GET_PTR_CODE(tc->ptr_exit)(cpu_ctx);
486486
}
487487
__except (ipt_exception_filter(cpu_ctx->cpu, GetExceptionInformation())) {
488488
if (raise_page_fault) {

lib86cpu/core/translate.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,6 @@ translated_code_t::translated_code_t() noexcept
982982
pc = 0,
983983
virt_pc = 0;
984984
guest_flags = 0;
985-
ptr_code = nullptr;
986985
ptr_exit = nullptr;
987986
flags = 0;
988987
size = 0;
@@ -1194,7 +1193,7 @@ tc_link_jmp(cpu_t *cpu, translated_code_t *ptr_tc)
11941193
elem->virt_pc = ptr_tc->virt_pc;
11951194
elem->cs_base = ptr_tc->cs_base;
11961195
elem->guest_flags = ptr_tc->guest_flags;
1197-
elem->ptr_code = ptr_tc->ptr_code;
1196+
elem->ptr_code = GET_PTR_CODE(ptr_tc->ptr_exit);
11981197
cpu->jmp_page_map[ptr_tc->virt_pc >> PAGE_SHIFT].insert(ptr_tc->virt_pc);
11991198
}
12001199

@@ -1595,7 +1594,7 @@ tc_run_code(cpu_ctx_t *cpu_ctx, translated_code_t *tc)
15951594
#ifdef XBOX_CPU
15961595
return ipt_run_guarded_code(cpu_ctx, tc);
15971596
#else
1598-
return tc->ptr_code(cpu_ctx);
1597+
return GET_PTR_CODE(tc->ptr_exit)(cpu_ctx);
15991598
#endif
16001599
}
16011600
catch (host_exp_t type) {

lib86cpu/lib86cpu_priv.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#define P6(n) P4(n), P4(n ^ 1), P4(n ^ 1), P4(n)
5353
#define GEN_TABLE P6(0), P6(1), P6(1), P6(0)
5454

55+
#define GET_PTR_CODE(ptr_exit) ((entry_t)((uint8_t *)(ptr_exit) + 16))
56+
5557
inline bool g_is_avx_supported = false;
5658

5759
// memory region type
@@ -132,7 +134,6 @@ struct translated_code_t {
132134
addr_t pc;
133135
addr_t virt_pc;
134136
uint32_t guest_flags;
135-
entry_t ptr_code;
136137
entry_t ptr_exit;
137138
uint32_t flags;
138139
uint64_t size;

0 commit comments

Comments
 (0)