Skip to content

Commit fcca82b

Browse files
committed
Format code
1 parent d50bbb5 commit fcca82b

File tree

6 files changed

+75
-53
lines changed

6 files changed

+75
-53
lines changed

include/uc_priv.h

+10-9
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ typedef MemoryRegion *(*uc_memory_mapping_t)(struct uc_struct *, hwaddr addr);
108108

109109
typedef void (*uc_memory_filter_t)(MemoryRegion *, int32_t);
110110

111-
typedef bool (*uc_flatview_copy_t)(struct uc_struct *, FlatView *, FlatView *, bool);
111+
typedef bool (*uc_flatview_copy_t)(struct uc_struct *, FlatView *, FlatView *,
112+
bool);
112113

113114
typedef void (*uc_readonly_mem_t)(MemoryRegion *mr, bool readonly);
114115

@@ -426,14 +427,14 @@ struct uc_struct {
426427

427428
// Metadata stub for the variable-size cpu context used with uc_context_*()
428429
struct uc_context {
429-
size_t context_size; // size of the real internal context structure
430-
uc_mode mode; // the mode of this context
431-
uc_arch arch; // the arch of this context
432-
int snapshot_level; // the memory snapshot level to restore
433-
bool ramblock_freed; // wheter there was a some ramblock freed
434-
RAMBlock *last_block;// The last element of the ramblock list
435-
FlatView *fv; // The current flatview of the memory
436-
char data[0]; // context
430+
size_t context_size; // size of the real internal context structure
431+
uc_mode mode; // the mode of this context
432+
uc_arch arch; // the arch of this context
433+
int snapshot_level; // the memory snapshot level to restore
434+
bool ramblock_freed; // wheter there was a some ramblock freed
435+
RAMBlock *last_block; // The last element of the ramblock list
436+
FlatView *fv; // The current flatview of the memory
437+
char data[0]; // context
437438
};
438439

439440
// We have to support 32bit system so we can't hold uint64_t on void*

include/unicorn/unicorn.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ typedef size_t uc_hook;
6565
#define UNICORN_DEPRECATED __declspec(deprecated)
6666
#else
6767
#pragma message( \
68-
"WARNING: You need to implement UNICORN_DEPRECATED for this compiler")
68+
"WARNING: You need to implement UNICORN_DEPRECATED for this compiler")
6969
#define UNICORN_DEPRECATED
7070
#endif
7171

qemu/target/i386/unicorn.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,8 @@ static bool x86_stop_interrupt(struct uc_struct *uc, int intno)
20002000

20012001
static bool x86_insn_hook_validate(uint32_t insn_enum)
20022002
{
2003-
// for x86 we can only hook IN, OUT, SYSCALL, SYSENTER, CPUID, RDTSC, and RDTSCP
2003+
// for x86 we can only hook IN, OUT, SYSCALL, SYSENTER, CPUID, RDTSC, and
2004+
// RDTSCP
20042005
if (insn_enum != UC_X86_INS_IN && insn_enum != UC_X86_INS_OUT &&
20052006
insn_enum != UC_X86_INS_SYSCALL && insn_enum != UC_X86_INS_SYSENTER &&
20062007
insn_enum != UC_X86_INS_CPUID && insn_enum != UC_X86_INS_RDTSC &&

tests/unit/test_arm64.c

+34-17
Original file line numberDiff line numberDiff line change
@@ -529,26 +529,36 @@ static void test_arm64_pc_wrap(void)
529529
OK(uc_close(uc));
530530
}
531531

532-
static void
533-
test_arm64_mem_prot_regress_hook_mem(uc_engine *uc, uc_mem_type type,
534-
uint64_t address, int size, int64_t value, void *user_data)
532+
static void test_arm64_mem_prot_regress_hook_mem(uc_engine *uc,
533+
uc_mem_type type,
534+
uint64_t address, int size,
535+
int64_t value, void *user_data)
535536
{
536-
// fprintf(stderr, "%s %p %d\n", (type == UC_MEM_WRITE) ? "UC_MEM_WRITE" : "UC_MEM_READ", (void *)address, size);
537+
// fprintf(stderr, "%s %p %d\n", (type == UC_MEM_WRITE) ? "UC_MEM_WRITE" :
538+
// "UC_MEM_READ", (void *)address, size);
537539
}
538540

539-
static bool
540-
test_arm64_mem_prot_regress_hook_prot(uc_engine *uc, uc_mem_type type,
541-
uint64_t address, int size, int64_t value, void *user_data)
541+
static bool test_arm64_mem_prot_regress_hook_prot(uc_engine *uc,
542+
uc_mem_type type,
543+
uint64_t address, int size,
544+
int64_t value,
545+
void *user_data)
542546
{
543-
// fprintf(stderr, "%s %p %d\n", (type == UC_MEM_WRITE_PROT) ? "UC_MEM_WRITE_PROT" : ((type == UC_MEM_FETCH_PROT) ? "UC_MEM_FETCH_PROT" : "UC_MEM_READ_PROT"), (void *)address, size);
547+
// fprintf(stderr, "%s %p %d\n", (type == UC_MEM_WRITE_PROT) ?
548+
// "UC_MEM_WRITE_PROT" : ((type == UC_MEM_FETCH_PROT) ? "UC_MEM_FETCH_PROT"
549+
// : "UC_MEM_READ_PROT"), (void *)address, size);
544550
return false;
545551
}
546552

547-
static bool
548-
test_arm64_mem_prot_regress_hook_unm(uc_engine *uc, uc_mem_type type,
549-
uint64_t address, int size, int64_t value, void *user_data)
553+
static bool test_arm64_mem_prot_regress_hook_unm(uc_engine *uc,
554+
uc_mem_type type,
555+
uint64_t address, int size,
556+
int64_t value, void *user_data)
550557
{
551-
// fprintf(stderr, "%s %p %d\n", (type == UC_MEM_WRITE_UNMAPPED) ? "UC_MEM_WRITE_UNMAPPED" : ((type == UC_MEM_FETCH_UNMAPPED) ? "UC_MEM_FETCH_UNMAPPED" : "UC_MEM_READ_UNMAPPED"), (void *)address, size);
558+
// fprintf(stderr, "%s %p %d\n", (type == UC_MEM_WRITE_UNMAPPED) ?
559+
// "UC_MEM_WRITE_UNMAPPED" : ((type == UC_MEM_FETCH_UNMAPPED) ?
560+
// "UC_MEM_FETCH_UNMAPPED" : "UC_MEM_READ_UNMAPPED"), (void *)address,
561+
// size);
552562
return false;
553563
}
554564

@@ -562,17 +572,24 @@ static void test_arm64_mem_prot_regress(void)
562572
uc_engine *uc;
563573
OK(uc_open(UC_ARCH_ARM64, UC_MODE_ARM, &uc));
564574

565-
OK(uc_mem_map(uc, 0, 0x4000, UC_PROT_READ|UC_PROT_EXEC));
566-
OK(uc_mem_map(uc, 0x4000, 0xC000, UC_PROT_READ|UC_PROT_WRITE));
575+
OK(uc_mem_map(uc, 0, 0x4000, UC_PROT_READ | UC_PROT_EXEC));
576+
OK(uc_mem_map(uc, 0x4000, 0xC000, UC_PROT_READ | UC_PROT_WRITE));
567577
OK(uc_mem_write(uc, 0, code, sizeof(code)));
568578
uc_hook hh_mem;
569-
OK(uc_hook_add(uc, &hh_mem, UC_HOOK_MEM_READ | UC_HOOK_MEM_WRITE, test_arm64_mem_prot_regress_hook_mem, NULL, 1, 0));
579+
OK(uc_hook_add(uc, &hh_mem, UC_HOOK_MEM_READ | UC_HOOK_MEM_WRITE,
580+
test_arm64_mem_prot_regress_hook_mem, NULL, 1, 0));
570581

571582
uc_hook hh_prot;
572-
OK(uc_hook_add(uc, &hh_prot, UC_HOOK_MEM_READ_PROT | UC_HOOK_MEM_WRITE_PROT | UC_HOOK_MEM_FETCH_PROT, test_arm64_mem_prot_regress_hook_prot, NULL, 1, 0));
583+
OK(uc_hook_add(uc, &hh_prot,
584+
UC_HOOK_MEM_READ_PROT | UC_HOOK_MEM_WRITE_PROT |
585+
UC_HOOK_MEM_FETCH_PROT,
586+
test_arm64_mem_prot_regress_hook_prot, NULL, 1, 0));
573587

574588
uc_hook hh_unm;
575-
OK(uc_hook_add(uc, &hh_unm, UC_HOOK_MEM_READ_UNMAPPED | UC_HOOK_MEM_WRITE_UNMAPPED | UC_HOOK_MEM_FETCH_UNMAPPED, test_arm64_mem_prot_regress_hook_unm, NULL, 1, 0));
589+
OK(uc_hook_add(uc, &hh_unm,
590+
UC_HOOK_MEM_READ_UNMAPPED | UC_HOOK_MEM_WRITE_UNMAPPED |
591+
UC_HOOK_MEM_FETCH_UNMAPPED,
592+
test_arm64_mem_prot_regress_hook_unm, NULL, 1, 0));
576593

577594
const uint64_t value = 0x801b;
578595
OK(uc_reg_write(uc, UC_ARM64_REG_X0, &value));

tests/unit/test_x86.c

+22-22
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,11 @@ static void test_x86_smc_add(void)
632632
/*
633633
* mov qword ptr [rip+0x10], rax
634634
* mov word ptr [rip], 0x0548
635-
* [orig] mov eax, dword ptr [rax + 0x12345678]; [after SMC] 480578563412 add rax, 0x12345678
636-
* hlt
635+
* [orig] mov eax, dword ptr [rax + 0x12345678]; [after SMC] 480578563412
636+
* add rax, 0x12345678 hlt
637637
*/
638-
char code[] = "\x48\x89\x05\x10\x00\x00\x00\x66\xc7\x05\x00\x00\x00\x00\x48\x05\x8b\x80\x78\x56\x34\x12\xf4";
638+
char code[] = "\x48\x89\x05\x10\x00\x00\x00\x66\xc7\x05\x00\x00\x00\x00\x48"
639+
"\x05\x8b\x80\x78\x56\x34\x12\xf4";
639640
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_64, code, sizeof(code) - 1);
640641

641642
OK(uc_mem_map(uc, stack_base, 0x2000, UC_PROT_ALL));
@@ -648,10 +649,11 @@ static void test_x86_smc_mem_hook_callback(uc_engine *uc, uc_mem_type t,
648649
uint64_t addr, int size,
649650
uint64_t value, void *user_data)
650651
{
651-
uint64_t write_addresses[] = { 0x1030, 0x1010, 0x1010, 0x1018, 0x1018, 0x1029, 0x1029 };
652+
uint64_t write_addresses[] = {0x1030, 0x1010, 0x1010, 0x1018,
653+
0x1018, 0x1029, 0x1029};
652654
unsigned int *i = user_data;
653655

654-
TEST_CHECK(*i < (sizeof(write_addresses)/sizeof(write_addresses[0])));
656+
TEST_CHECK(*i < (sizeof(write_addresses) / sizeof(write_addresses[0])));
655657
TEST_CHECK(write_addresses[*i] == addr);
656658
(*i)++;
657659
}
@@ -666,19 +668,19 @@ static void test_x86_smc_mem_hook(void)
666668
/*
667669
* mov qword ptr [rip+0x29], rax
668670
* mov word ptr [rip], 0x0548
669-
* [orig] mov eax, dword ptr [rax + 0x12345678]; [after SMC] 480578563412 add rax, 0x12345678
670-
* nop
671-
* nop
672-
* nop
673-
* mov qword ptr [rip-0x08], rax
674-
* mov word ptr [rip], 0x0548
675-
* [orig] mov eax, dword ptr [rax + 0x12345678]; [after SMC] 480578563412 add rax, 0x12345678
676-
* hlt
671+
* [orig] mov eax, dword ptr [rax + 0x12345678]; [after SMC] 480578563412
672+
* add rax, 0x12345678 nop nop nop mov qword ptr [rip-0x08], rax mov word
673+
* ptr [rip], 0x0548 [orig] mov eax, dword ptr [rax + 0x12345678]; [after
674+
* SMC] 480578563412 add rax, 0x12345678 hlt
677675
*/
678-
char code[] = "\x48\x89\x05\x29\x00\x00\x00\x66\xC7\x05\x00\x00\x00\x00\x48\x05\x8B\x80\x78\x56\x34\x12\x90\x90\x90\x48\x89\x05\xF8\xFF\xFF\xFF\x66\xC7\x05\x00\x00\x00\x00\x48\x05\x8B\x80\x78\x56\x34\x12\xF4";
676+
char code[] =
677+
"\x48\x89\x05\x29\x00\x00\x00\x66\xC7\x05\x00\x00\x00\x00\x48\x05\x8B"
678+
"\x80\x78\x56\x34\x12\x90\x90\x90\x48\x89\x05\xF8\xFF\xFF\xFF\x66\xC7"
679+
"\x05\x00\x00\x00\x00\x48\x05\x8B\x80\x78\x56\x34\x12\xF4";
679680
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_64, code, sizeof(code) - 1);
680681

681-
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_WRITE, test_x86_smc_mem_hook_callback, &i, 1, 0));
682+
OK(uc_hook_add(uc, &hook, UC_HOOK_MEM_WRITE, test_x86_smc_mem_hook_callback,
683+
&i, 1, 0));
682684
OK(uc_mem_map(uc, stack_base, 0x2000, UC_PROT_ALL));
683685
r_rsp = stack_base + 0x1800;
684686
OK(uc_reg_write(uc, UC_X86_REG_RSP, &r_rsp));
@@ -1343,14 +1345,13 @@ static void test_x86_unaligned_access(void)
13431345
OK(uc_close(uc));
13441346
}
13451347

1346-
static void test_x86_64_unaligned_access(void){
1348+
static void test_x86_64_unaligned_access(void)
1349+
{
13471350
uc_engine *uc;
13481351
uc_hook hook;
1349-
char code[] = {
1350-
"\x48\x89\x01" // mov qword ptr [rcx],rax
1351-
"\x48\x8b\x00" // mov rax,qword ptr [rax]
1352-
"\xcc"
1353-
};
1352+
char code[] = {"\x48\x89\x01" // mov qword ptr [rcx],rax
1353+
"\x48\x8b\x00" // mov rax,qword ptr [rax]
1354+
"\xcc"};
13541355
uint64_t r_rax = LEINT64(0x2fffff);
13551356
uint64_t r_rcx = LEINT64(0x2fffff);
13561357
struct writelog_t write_log[10];
@@ -1382,7 +1383,6 @@ static void test_x86_64_unaligned_access(void){
13821383
TEST_CHECK(b == 0x2fffff);
13831384

13841385
OK(uc_close(uc));
1385-
13861386
}
13871387
#endif
13881388

uc.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ static void clear_deleted_hooks(uc_engine *uc);
3535
static uc_err uc_snapshot(uc_engine *uc);
3636
static uc_err uc_restore_latest_snapshot(uc_engine *uc);
3737

38-
#if defined(__APPLE__) && defined(HAVE_PTHREAD_JIT_PROTECT) && (defined(__arm__) || defined(__aarch64__))
38+
#if defined(__APPLE__) && defined(HAVE_PTHREAD_JIT_PROTECT) && \
39+
(defined(__arm__) || defined(__aarch64__))
3940
static void save_jit_state(uc_engine *uc)
4041
{
4142
if (!uc->nested) {
@@ -2148,7 +2149,8 @@ uc_err uc_context_save(uc_engine *uc, uc_context *context)
21482149
if (!context->fv) {
21492150
return UC_ERR_NOMEM;
21502151
}
2151-
if (!uc->flatview_copy(uc, context->fv, uc->address_space_memory.current_map, false)) {
2152+
if (!uc->flatview_copy(uc, context->fv,
2153+
uc->address_space_memory.current_map, false)) {
21522154
restore_jit_state(uc);
21532155
return UC_ERR_NOMEM;
21542156
}
@@ -2434,7 +2436,8 @@ uc_err uc_context_restore(uc_engine *uc, uc_context *context)
24342436
uc_snapshot(uc);
24352437
uc->ram_list.freed = context->ramblock_freed;
24362438
uc->ram_list.last_block = context->last_block;
2437-
if (!uc->flatview_copy(uc, uc->address_space_memory.current_map, context->fv, true)) {
2439+
if (!uc->flatview_copy(uc, uc->address_space_memory.current_map,
2440+
context->fv, true)) {
24382441
return UC_ERR_NOMEM;
24392442
}
24402443
uc->tcg_flush_tlb(uc);

0 commit comments

Comments
 (0)