diff --git a/include/uc_priv.h b/include/uc_priv.h index 968ab22f..d1a3dab2 100644 --- a/include/uc_priv.h +++ b/include/uc_priv.h @@ -90,7 +90,7 @@ typedef void (*uc_args_void_t)(void *); typedef void (*uc_args_uc_t)(struct uc_struct *); typedef void (*uc_args_int_uc_t)(struct uc_struct *); -typedef void (*uc_args_uc_long_t)(struct uc_struct *, unsigned long); +typedef void (*uc_args_uc_long_t)(struct uc_struct *, uint32_t); typedef void (*uc_args_uc_u64_t)(struct uc_struct *, uint64_t addr); @@ -400,6 +400,7 @@ struct uc_struct { FlatView *empty_view; // Static function variable moved from flatviews_init + uint32_t tcg_buffer_size; // The buffer size we are going to use #ifdef WIN32 PVOID seh_handle; void* seh_closure; diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index feae9eea..8c7dc3e6 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -571,8 +571,12 @@ typedef enum uc_control_type { // Change the tlb implementation // see uc_tlb_type for current implemented types // Write: @args = (int) - UC_CTL_TLB_TYPE - + UC_CTL_TLB_TYPE, + // Change the tcg translation buffer size, note that + // unicorn may adjust this value. + // Write: @args = (uint32_t) + // Read: @args = (uint32_t*) + UC_CTL_TCG_BUFFER_SIZE, } uc_control_type; /* diff --git a/qemu/accel/tcg/translate-all.c b/qemu/accel/tcg/translate-all.c index 835c054f..8d6cb251 100644 --- a/qemu/accel/tcg/translate-all.c +++ b/qemu/accel/tcg/translate-all.c @@ -1209,7 +1209,7 @@ static uc_err uc_gen_tb(struct uc_struct *uc, uint64_t addr, uc_tb *out_tb) /* Must be called before using the QEMU cpus. 'tb_size' is the size (in bytes) allocated to the translation buffer. Zero means default size. */ -void tcg_exec_init(struct uc_struct *uc, unsigned long tb_size) +void tcg_exec_init(struct uc_struct *uc, uint32_t tb_size) { /* remove tcg object. init here. */ /* tcg class init: tcg-all.c:tcg_accel_class_init(), skip all. */ diff --git a/qemu/include/sysemu/tcg.h b/qemu/include/sysemu/tcg.h index ea267831..77ab926a 100644 --- a/qemu/include/sysemu/tcg.h +++ b/qemu/include/sysemu/tcg.h @@ -14,6 +14,6 @@ struct uc_struct; -void tcg_exec_init(struct uc_struct *uc, unsigned long tb_size); +void tcg_exec_init(struct uc_struct *uc, uint32_t tb_size); #endif diff --git a/qemu/unicorn_common.h b/qemu/unicorn_common.h index d7802b3b..98b8cf37 100644 --- a/qemu/unicorn_common.h +++ b/qemu/unicorn_common.h @@ -10,7 +10,7 @@ // codes for unicorns purposes. void vm_start(struct uc_struct*); -void tcg_exec_init(struct uc_struct *uc, unsigned long tb_size); +void tcg_exec_init(struct uc_struct *uc, uint32_t tb_size); bool unicorn_fill_tlb(CPUState *cs, vaddr address, int size, MMUAccessType rw, int mmu_idx, bool probe, uintptr_t retaddr); diff --git a/uc.c b/uc.c index 0b464a4d..a07ff789 100644 --- a/uc.c +++ b/uc.c @@ -2374,6 +2374,20 @@ uc_err uc_ctl(uc_engine *uc, uc_control_type control, ...) break; } + case UC_CTL_TCG_BUFFER_SIZE: { + if (rw == UC_CTL_IO_WRITE) { + uint32_t size = va_arg(args, uint32_t); + uc->tcg_buffer_size = size; + } else { + + UC_INIT(uc); + + uint32_t *size = va_arg(args, uint32_t *); + *size = uc->tcg_buffer_size; + } + break; + } + default: err = UC_ERR_ARG; break;