Skip to content

uc_ctl_remove_cache() causes memory leak #2203

Closed as not planned
Closed as not planned
@yakamoz423

Description

@yakamoz423

Original title: Failed to uc_emu_start: Unhandled CPU exception (UC_ERR_EXCEPTION)

To reproduce:

  1. open unicorn as AArch64 target
  2. mem_map 0xC3053000[4096]
  3. write instr opcode 0xd100071b(SUB) to address 0xc3053bfc
  4. uc_emu_start to single step
  5. get PC reg value, it is 0xc3053bfc+4
  6. write the same instr opcode to address 0xc3053bfc+4
  7. uc_emu_start again, but it reports UC_ERR_EXCEPTION

I'm confused if there was anything wrong, and how to obtian the detials of inner engine exception?

My code:

    uc_engine* uc;
    uc_err err;
    uint32_t data1;
    uint64_t data2;

    err = uc_open(UC_ARCH_ARM64, 0, &uc);
    if (err) {
        printf("Failed to open: %s\n", uc_strerror(err));
    }

    err = uc_mem_map(uc, 0xc3053bfc >> 12 << 12, 4 * 1024, UC_PROT_ALL);
    if (err) {
        printf("Failed to mem_map: %s\n", uc_strerror(err));
    }

    data1 = 0xd100071b;  // sub    x27, x24, #1
    err = uc_mem_write(uc, 0xc3053bfc, &data1, sizeof(data1));
    if (err) {
        printf("Failed to mem_write: %s\n", uc_strerror(err));
    }

    err = uc_emu_start(uc, 0xc3053bfc, -1, 0, 1);
    if (err) {
        printf("Failed to emu_start1: %s\n", uc_strerror(err));
    }

    err = uc_reg_read(uc, UC_ARM64_REG_PC, &data2);
    if (err) {
        printf("Failed to reg_read: %s\n", uc_strerror(err));
    }
    printf("%llx\n", data2);

    data1 = 0xd100071b; 
    err = uc_mem_write(uc, 0xc3053c00, &data1, sizeof(data1));
    if (err) {
        printf("Failed to mem_write: %s\n", uc_strerror(err));
    }

    err = uc_emu_start(uc, 0xc3053c00, -1, 0, 1);
    if (err) {
        printf("Failed to emu_start2: %s\n", uc_strerror(err));
    }

    err = uc_reg_read(uc, UC_ARM64_REG_PC, &data2);
    if (err) {
        printf("Failed to reg_read: %s\n", uc_strerror(err));
    }
    printf("%llx\n", data2);

Output:

c3053c00
Failed to emu_start2: Unhandled CPU exception (UC_ERR_EXCEPTION)
c3053c00

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions