Skip to content

Commit d7a806c

Browse files
committed
Reformat code with format.sh
1 parent fa1f261 commit d7a806c

17 files changed

+216
-166
lines changed

include/uc_priv.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ struct uc_struct {
403403
uint32_t tcg_buffer_size; // The buffer size we are going to use
404404
#ifdef WIN32
405405
PVOID seh_handle;
406-
void* seh_closure;
406+
void *seh_closure;
407407
#endif
408408
};
409409

include/unicorn/unicorn.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,15 @@ typedef enum uc_mem_type {
264264
265265
@vaddr: virtuall address for lookup
266266
@rw: the access mode
267-
@result: result entry, contains physical address (paddr) and permitted access type (perms) for the entry
267+
@result: result entry, contains physical address (paddr) and permitted access
268+
type (perms) for the entry
268269
269270
@return: return true if the entry was found. If a callback is present but
270271
no one returns true a pagefault is generated.
271272
*/
272-
typedef bool (*uc_cb_tlbevent_t)(uc_engine *uc, uint64_t vaddr, uc_mem_type type,
273-
uc_tlb_entry *result, void *user_data);
273+
typedef bool (*uc_cb_tlbevent_t)(uc_engine *uc, uint64_t vaddr,
274+
uc_mem_type type, uc_tlb_entry *result,
275+
void *user_data);
274276

275277
// Represent a TranslationBlock.
276278
typedef struct uc_tb {
@@ -510,11 +512,12 @@ typedef enum uc_query_type {
510512

511513
// unicorn tlb type selection
512514
typedef enum uc_tlb_type {
513-
// The default unicorn virtuall TLB implementation.
515+
// The default unicorn virtuall TLB implementation.
514516
// The tlb implementation of the CPU, best to use for full system emulation.
515517
UC_TLB_CPU = 0,
516518
// This tlb defaults to virtuall address == physical address
517-
// Also a hook is availible to override the tlb entries (see uc_cb_tlbevent_t).
519+
// Also a hook is availible to override the tlb entries (see
520+
// uc_cb_tlbevent_t).
518521
UC_TLB_VIRTUAL
519522
} uc_tlb_type;
520523

@@ -652,7 +655,8 @@ See sample_ctl.c for a detailed example.
652655
uc_ctl(uc, UC_CTL_READ_WRITE(UC_CTL_TB_REQUEST_CACHE, 2), (address), (tb))
653656
#define uc_ctl_flush_tb(uc) uc_ctl(uc, UC_CTL_WRITE(UC_CTL_TB_FLUSH, 0))
654657
#define uc_ctl_flush_tlb(uc) uc_ctl(uc, UC_CTL_WRITE(UC_CTL_TLB_FLUSH, 0))
655-
#define uc_ctl_tlb_mode(uc, mode) uc_ctl(uc, UC_CTL_WRITE(UC_CTL_TLB_TYPE, 1), (mode))
658+
#define uc_ctl_tlb_mode(uc, mode) \
659+
uc_ctl(uc, UC_CTL_WRITE(UC_CTL_TLB_TYPE, 1), (mode))
656660
#define uc_ctl_get_tcg_buffer_size(uc, size) \
657661
uc_ctl(uc, UC_CTL_READ(UC_CTL_TCG_BUFFER_SIZE, 1), (size))
658662
#define uc_ctl_set_tcg_buffer_size(uc, size) \

msvc/config-host.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
// #define CONFIG_INT128 1
77
#define CONFIG_CMPXCHG128 1
88
// #define CONFIG_ATOMIC64 1
9-
#define CONFIG_PLUGIN 1
9+
#define CONFIG_PLUGIN 1

qemu/target/i386/unicorn.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ static int reg_write(CPUX86State *env, unsigned int regid, const void *value,
986986
goto write_cr;
987987
case UC_X86_REG_CR4:
988988
cpu_x86_update_cr4(env, *(uint32_t *)value);
989-
write_cr:
989+
write_cr:
990990
env->cr[regid - UC_X86_REG_CR0] = *(uint32_t *)value;
991991
break;
992992
case UC_X86_REG_DR0:
@@ -1169,16 +1169,16 @@ static int reg_write(CPUX86State *env, unsigned int regid, const void *value,
11691169
default:
11701170
break;
11711171
case UC_X86_REG_CR0:
1172-
cpu_x86_update_cr0(env, *(uint32_t *) value);
1172+
cpu_x86_update_cr0(env, *(uint32_t *)value);
11731173
goto write_cr64;
11741174
case UC_X86_REG_CR1:
11751175
case UC_X86_REG_CR2:
11761176
case UC_X86_REG_CR3:
1177-
cpu_x86_update_cr3(env, *(uint32_t *) value);
1177+
cpu_x86_update_cr3(env, *(uint32_t *)value);
11781178
goto write_cr64;
11791179
case UC_X86_REG_CR4:
1180-
cpu_x86_update_cr4(env, *(uint32_t *) value);
1181-
write_cr64:
1180+
cpu_x86_update_cr4(env, *(uint32_t *)value);
1181+
write_cr64:
11821182
env->cr[regid - UC_X86_REG_CR0] = *(uint64_t *)value;
11831183
break;
11841184
case UC_X86_REG_DR0:

samples/sample_arm64.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#define ARM64_CODE \
1111
"\xab\x05\x00\xb8\xaf\x05\x40\x38" // str w11, [x13], #0; ldrb w15, [x13],
1212
// #0
13-
//#define ARM64_CODE_EB "\xb8\x00\x05\xab\x38\x40\x05\xaf" // str w11, [x13];
14-
// ldrb w15, [x13]
13+
// #define ARM64_CODE_EB "\xb8\x00\x05\xab\x38\x40\x05\xaf" // str w11, [x13];
14+
// ldrb w15, [x13]
1515
#define ARM64_CODE_EB ARM64_CODE
1616

1717
// mrs x2, tpidrro_el0

samples/sample_mmu.c

+44-31
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,30 @@
1818
* mov rax, 60
1919
* syscall
2020
*/
21-
char code[] = "\xB8\x39\x00\x00\x00\x0F\x05\x48\x85\xC0\x74\x0F\xB8\x3C\x00\x00\x00\x48\x89\x04\x25\x00\x40\x00\x00\x0F\x05\xB9\x2A\x00\x00\x00\x48\x89\x0C\x25\x00\x40\x00\x00\xB8\x3C\x00\x00\x00\x0F\x05";
21+
char code[] = "\xB8\x39\x00\x00\x00\x0F\x05\x48\x85\xC0\x74\x0F\xB8\x3C\x00\x00"
22+
"\x00\x48\x89\x04\x25\x00\x40\x00\x00\x0F\x05\xB9\x2A\x00\x00\x00"
23+
"\x48\x89\x0C\x25\x00\x40\x00\x00\xB8\x3C\x00\x00\x00\x0F\x05";
2224

23-
static void mmu_write_callback(uc_engine *uc, uc_mem_type type, uint64_t address, int size, int64_t value, void *user_data)
25+
static void mmu_write_callback(uc_engine *uc, uc_mem_type type,
26+
uint64_t address, int size, int64_t value,
27+
void *user_data)
2428
{
2529
printf("write at 0x%lx: 0x%lx\n", address, value);
2630
}
2731

28-
static void x86_mmu_prepare_tlb(uc_engine *uc, uint64_t vaddr, uint64_t tlb_base)
32+
static void x86_mmu_prepare_tlb(uc_engine *uc, uint64_t vaddr,
33+
uint64_t tlb_base)
2934
{
3035
uc_err err;
3136
uint64_t cr0;
3237
uint64_t cr4;
3338
uc_x86_msr msr = {.rid = 0xC0000080, .value = 0};
34-
uint64_t pml4o = ((vaddr & 0x00ff8000000000) >> 39)*8;
35-
uint64_t pdpo = ((vaddr & 0x00007fc0000000) >> 30)*8;
36-
uint64_t pdo = ((vaddr & 0x0000003fe00000) >> 21)*8;
39+
uint64_t pml4o = ((vaddr & 0x00ff8000000000) >> 39) * 8;
40+
uint64_t pdpo = ((vaddr & 0x00007fc0000000) >> 30) * 8;
41+
uint64_t pdo = ((vaddr & 0x0000003fe00000) >> 21) * 8;
3742
uint64_t pml4e = (tlb_base + 0x1000) | 1 | (1 << 2);
38-
uint64_t pdpe = (tlb_base + 0x2000) | 1 | (1 << 2);
39-
uint64_t pde = (tlb_base + 0x3000) | 1 | (1 << 2);
43+
uint64_t pdpe = (tlb_base + 0x2000) | 1 | (1 << 2);
44+
uint64_t pde = (tlb_base + 0x3000) | 1 | (1 << 2);
4045
err = uc_mem_write(uc, tlb_base + pml4o, &pml4e, sizeof(pml4o));
4146
if (err) {
4247
printf("failed to write pml4e\n");
@@ -73,10 +78,10 @@ static void x86_mmu_prepare_tlb(uc_engine *uc, uint64_t vaddr, uint64_t tlb_base
7378
exit(1);
7479
}
7580

76-
cr0 |= 1; //enable protected mode
77-
cr0 |= 1l << 31; //enable paging
78-
cr4 |= 1l << 5; //enable physical address extension
79-
msr.value |= 1l << 8; //enable long mode
81+
cr0 |= 1; // enable protected mode
82+
cr0 |= 1l << 31; // enable paging
83+
cr4 |= 1l << 5; // enable physical address extension
84+
msr.value |= 1l << 8; // enable long mode
8085

8186
err = uc_reg_write(uc, UC_X86_REG_CR0, &cr0);
8287
if (err) {
@@ -95,10 +100,11 @@ static void x86_mmu_prepare_tlb(uc_engine *uc, uint64_t vaddr, uint64_t tlb_base
95100
}
96101
}
97102

98-
static void x86_mmu_pt_set(uc_engine *uc, uint64_t vaddr, uint64_t paddr, uint64_t tlb_base)
103+
static void x86_mmu_pt_set(uc_engine *uc, uint64_t vaddr, uint64_t paddr,
104+
uint64_t tlb_base)
99105
{
100-
uint64_t pto = ((vaddr & 0x000000001ff000) >> 12)*8;
101-
uint32_t pte = (paddr) | 1 | (1 << 2);
106+
uint64_t pto = ((vaddr & 0x000000001ff000) >> 12) * 8;
107+
uint32_t pte = (paddr) | 1 | (1 << 2);
102108
uc_mem_write(uc, tlb_base + 0x3000 + pto, &pte, sizeof(pte));
103109
}
104110

@@ -162,20 +168,23 @@ void cpu_tlb(void)
162168
exit(1);
163169
}
164170

165-
err = uc_hook_add(uc, &h1, UC_HOOK_INSN, &x86_mmu_syscall_callback, &parrent_done, 1, 0, UC_X86_INS_SYSCALL);
171+
err = uc_hook_add(uc, &h1, UC_HOOK_INSN, &x86_mmu_syscall_callback,
172+
&parrent_done, 1, 0, UC_X86_INS_SYSCALL);
166173
if (err) {
167174
printf("Failed on uc_hook_add() with error returned: %u\n", err);
168175
exit(1);
169176
}
170177

171-
// Memory hooks are called after the mmu translation, so hook the physicall addresses
172-
err = uc_hook_add(uc, &h2, UC_HOOK_MEM_WRITE, &mmu_write_callback, NULL, 0x1000, 0x3000);
178+
// Memory hooks are called after the mmu translation, so hook the physicall
179+
// addresses
180+
err = uc_hook_add(uc, &h2, UC_HOOK_MEM_WRITE, &mmu_write_callback, NULL,
181+
0x1000, 0x3000);
173182
if (err) {
174183
printf("Faled on uc_hook_add() with error returned: %u\n", err);
175184
}
176185

177186
printf("map code\n");
178-
err = uc_mem_map(uc, 0x0, 0x1000, UC_PROT_ALL); //Code
187+
err = uc_mem_map(uc, 0x0, 0x1000, UC_PROT_ALL); // Code
179188
if (err) {
180189
printf("Failed on uc_mem_map() with error return: %u\n", err);
181190
exit(1);
@@ -186,25 +195,24 @@ void cpu_tlb(void)
186195
exit(1);
187196
}
188197
printf("map parrent memory\n");
189-
err = uc_mem_map(uc, 0x1000, 0x1000, UC_PROT_ALL); //Parrent
198+
err = uc_mem_map(uc, 0x1000, 0x1000, UC_PROT_ALL); // Parrent
190199
if (err) {
191200
printf("Failed on uc_mem_map() with error return: %u\n", err);
192201
exit(1);
193202
}
194203
printf("map child memory\n");
195-
err = uc_mem_map(uc, 0x2000, 0x1000, UC_PROT_ALL); //Child
204+
err = uc_mem_map(uc, 0x2000, 0x1000, UC_PROT_ALL); // Child
196205
if (err) {
197206
printf("failed to map child memory\n");
198207
exit(1);
199208
}
200209
printf("map tlb memory\n");
201-
err = uc_mem_map(uc, tlb_base, 0x4000, UC_PROT_ALL); //TLB
210+
err = uc_mem_map(uc, tlb_base, 0x4000, UC_PROT_ALL); // TLB
202211
if (err) {
203212
printf("failed to map memory for tlb\n");
204213
exit(1);
205214
}
206215

207-
208216
printf("set up the tlb\n");
209217
x86_mmu_prepare_tlb(uc, 0x0, tlb_base);
210218
x86_mmu_pt_set(uc, 0x2000, 0x0, tlb_base);
@@ -277,7 +285,8 @@ void cpu_tlb(void)
277285
uc_close(uc);
278286
}
279287

280-
static bool virtual_tlb_callback(uc_engine *uc, uint64_t addr, uc_mem_type type, uc_tlb_entry *result, void *user_data)
288+
static bool virtual_tlb_callback(uc_engine *uc, uint64_t addr, uc_mem_type type,
289+
uc_tlb_entry *result, void *user_data)
281290
{
282291
bool *parrent_done = user_data;
283292
printf("tlb lookup for address: 0x%lX\n", addr);
@@ -324,20 +333,23 @@ void virtual_tlb(void)
324333
exit(1);
325334
}
326335

327-
err = uc_hook_add(uc, &h1, UC_HOOK_INSN, &x86_mmu_syscall_callback, &parrent_done, 1, 0, UC_X86_INS_SYSCALL);
336+
err = uc_hook_add(uc, &h1, UC_HOOK_INSN, &x86_mmu_syscall_callback,
337+
&parrent_done, 1, 0, UC_X86_INS_SYSCALL);
328338
if (err) {
329339
printf("Failed on uc_hook_add() with error returned: %u\n", err);
330340
exit(1);
331341
}
332342

333-
// Memory hooks are called after the mmu translation, so hook the physicall addresses
334-
err = uc_hook_add(uc, &h2, UC_HOOK_MEM_WRITE, &mmu_write_callback, NULL, 0x1000, 0x3000);
343+
// Memory hooks are called after the mmu translation, so hook the physicall
344+
// addresses
345+
err = uc_hook_add(uc, &h2, UC_HOOK_MEM_WRITE, &mmu_write_callback, NULL,
346+
0x1000, 0x3000);
335347
if (err) {
336348
printf("Faled on uc_hook_add() with error returned: %u\n", err);
337349
}
338350

339351
printf("map code\n");
340-
err = uc_mem_map(uc, 0x0, 0x1000, UC_PROT_ALL); //Code
352+
err = uc_mem_map(uc, 0x0, 0x1000, UC_PROT_ALL); // Code
341353
if (err) {
342354
printf("Failed on uc_mem_map() with error return: %u\n", err);
343355
exit(1);
@@ -348,19 +360,20 @@ void virtual_tlb(void)
348360
exit(1);
349361
}
350362
printf("map parrent memory\n");
351-
err = uc_mem_map(uc, 0x1000, 0x1000, UC_PROT_ALL); //Parrent
363+
err = uc_mem_map(uc, 0x1000, 0x1000, UC_PROT_ALL); // Parrent
352364
if (err) {
353365
printf("Failed on uc_mem_map() with error return: %u\n", err);
354366
exit(1);
355367
}
356368
printf("map child memory\n");
357-
err = uc_mem_map(uc, 0x2000, 0x1000, UC_PROT_ALL); //Child
369+
err = uc_mem_map(uc, 0x2000, 0x1000, UC_PROT_ALL); // Child
358370
if (err) {
359371
printf("failed to map child memory\n");
360372
exit(1);
361373
}
362374

363-
err = uc_hook_add(uc, &h3, UC_HOOK_TLB_FILL, virtual_tlb_callback, &parrent_done, 1, 0);
375+
err = uc_hook_add(uc, &h3, UC_HOOK_TLB_FILL, virtual_tlb_callback,
376+
&parrent_done, 1, 0);
364377

365378
printf("run the parrent\n");
366379
err = uc_emu_start(uc, 0x2000, 0x0, 0, 0);

samples/sample_riscv.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
0 13 05 10 00 addi a0, zero, 1
1212
4 93 85 05 02 addi a1, a1, 0x20
1313
#endif
14-
//#define RISCV_CODE "\x13\x05\x10\x00\x93\x85\x05\x02\x93\x85\x05\x02"
14+
// #define RISCV_CODE "\x13\x05\x10\x00\x93\x85\x05\x02\x93\x85\x05\x02"
1515
#define RISCV_CODE "\x13\x05\x10\x00\x93\x85\x05\x02"
1616

1717
// memory address where emulation starts

samples/sample_sparc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// code to be emulated
1010
#define SPARC_CODE "\x86\x00\x40\x02" // add %g1, %g2, %g3;
11-
//#define SPARC_CODE "\xbb\x70\x00\x00" // illegal code
11+
// #define SPARC_CODE "\xbb\x70\x00\x00" // illegal code
1212

1313
// memory address where emulation starts
1414
#define ADDRESS 0x10000

samples/sample_x86.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"\xeb\x02\x90\x90\x90\x90\x90\x90" // jmp 4; nop; nop; nop; nop; nop; nop
1414
// #define X86_CODE32_SELF
1515
// "\xeb\x1c\x5a\x89\xd6\x8b\x02\x66\x3d\xca\x7d\x75\x06\x66\x05\x03\x03\x89\x02\xfe\xc2\x3d\x41\x41\x41\x41\x75\xe9\xff\xe6\xe8\xdf\xff\xff\xff\x31\xd2\x6a\x0b\x58\x99\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53\x89\xe1\xca\x7d\x41\x41\x41\x41"
16-
//#define X86_CODE32 "\x51\x51\x51\x51" // PUSH ecx;
16+
// #define X86_CODE32 "\x51\x51\x51\x51" // PUSH ecx;
1717
#define X86_CODE32_LOOP "\x41\x4a\xeb\xfe" // INC ecx; DEC edx; JMP self-loop
1818
#define X86_CODE32_MEM_WRITE \
1919
"\x89\x0D\xAA\xAA\xAA\xAA\x41\x4a" // mov [0xaaaaaaaa], ecx; INC ecx; DEC
@@ -30,7 +30,7 @@
3030
// AL; INC ebx
3131
#define X86_CODE32_INC "\x40" // INC eax
3232

33-
//#define X86_CODE64 "\x41\xBC\x3B\xB0\x28\x2A \x49\x0F\xC9 \x90
33+
// #define X86_CODE64 "\x41\xBC\x3B\xB0\x28\x2A \x49\x0F\xC9 \x90
3434
//\x4D\x0F\xAD\xCF\x49\x87\xFD\x90\x48\x81\xD2\x8A\xCE\x77\x35\x48\xF7\xD9" //
3535
//<== still crash #define X86_CODE64
3636
//"\x41\xBC\x3B\xB0\x28\x2A\x49\x0F\xC9\x90\x4D\x0F\xAD\xCF\x49\x87\xFD\x90\x48\x81\xD2\x8A\xCE\x77\x35\x48\xF7\xD9"

tests/unit/acutest.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@
270270
#include <string.h>
271271
#include <setjmp.h>
272272

273-
#if defined(unix) || defined(__unix__) || defined(__unix) || defined(__APPLE__) || defined(__HAIKU__)
273+
#if defined(unix) || defined(__unix__) || defined(__unix) || \
274+
defined(__APPLE__) || defined(__HAIKU__)
274275
#define ACUTEST_UNIX_ 1
275276
#include <errno.h>
276277
#include <libgen.h>

0 commit comments

Comments
 (0)