add new API uc_query() to query internal status of emulator at runtime

This commit is contained in:
Nguyen Anh Quynh
2016-01-23 17:14:44 +08:00
parent 9c2017e115
commit 4dbad9aa9b
4 changed files with 47 additions and 0 deletions

View File

@ -32,6 +32,8 @@ typedef struct ModuleEntry {
typedef QTAILQ_HEAD(, ModuleEntry) ModuleTypeList;
typedef uc_err (*query_t)(struct uc_struct *uc, uc_query_type type, size_t *result);
// return 0 on success, -1 on failure
typedef int (*reg_read_t)(struct uc_struct *uc, unsigned int regid, void *value);
typedef int (*reg_write_t)(struct uc_struct *uc, unsigned int regid, const void *value);
@ -93,6 +95,7 @@ struct uc_struct {
struct CPUTailQ cpus; // qemu/cpu-exec.c
uc_err errnum; // qemu/cpu-exec.c
AddressSpace as;
query_t query;
reg_read_t reg_read;
reg_write_t reg_write;
reg_reset_t reg_reset;

View File

@ -255,6 +255,12 @@ typedef struct uc_mem_region {
uint32_t perms; // memory permissions of the region
} uc_mem_region;
// All type of queries for uc_query() API.
typedef enum uc_query_type {
// Query current hardware mode for ARM. Return 1 for Thumb, 0 for ARM
UC_QUERY_ARM_MODE = 1,
} uc_query_type;
/*
Return combined API version & major and minor version numbers.
@ -315,6 +321,18 @@ uc_err uc_open(uc_arch arch, uc_mode mode, uc_engine **uc);
UNICORN_EXPORT
uc_err uc_close(uc_engine *uc);
/*
Query internal status of engine.
@uc: handle returned by uc_open()
@type: query type
@result: status retrieved
@return: error code of uc_err enum type (UC_ERR_*, see above)
*/
UNICORN_EXPORT
uc_err uc_query(uc_engine *uc, uc_query_type type, size_t *result);
/*
Report the last error number when some API function fail.
Like glibc's errno, uc_errno might not retain its old value once accessed.