Skip to content

Commit

Permalink
darwin-mapper: Fix TLV init runtime code for arm64
Browse files Browse the repository at this point in the history
- We now store the allocated TLV area into the correct slot in the
  region pointed to by TPIDRRO_EL0, instead of vice versa.
- tlv_get_addr_addr may be signed by Dyld; strip the signature before
  calling it from the runtime.
- We want to skip pre-allocated pthread keys, but emitted the wrong
  condition. We now correctly check against the key.
  • Loading branch information
jiska2342 authored and oleavr committed Aug 19, 2024
1 parent b833cb9 commit c827a73
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions gum/backend-darwin/gumdarwinmapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1957,22 +1957,22 @@ gum_emit_arm64_tlv_init_code (GumEmitArm64Context * ctx)
gum_arm64_writer_put_add_reg_reg_reg (aw, ARM64_REG_X19, ARM64_REG_X19,
ARM64_REG_X20);
gum_arm64_writer_put_ldr_reg_address (aw, ARM64_REG_X20, self->tlv_area);
gum_arm64_writer_put_str_reg_reg (aw, ARM64_REG_X19, ARM64_REG_X20);
gum_arm64_writer_put_str_reg_reg (aw, ARM64_REG_X20, ARM64_REG_X19);

gum_arm64_writer_put_ldr_reg_u64 (aw, ARM64_REG_X20, tlv_section);
gum_arm64_writer_put_ldr_reg_address (aw, ARM64_REG_X21,
tlv->num_descriptors);

gum_arm64_writer_put_label (aw, next_label);

gum_arm64_writer_put_ldr_reg_u64 (aw, ARM64_REG_X19, self->tlv_get_addr_addr);
gum_arm64_writer_put_ldr_reg_u64 (aw, ARM64_REG_X19,
gum_strip_code_address (self->tlv_get_addr_addr));
gum_arm64_writer_put_str_reg_reg (aw, ARM64_REG_X19, ARM64_REG_X20);
gum_arm64_writer_put_add_reg_reg_imm (aw, ARM64_REG_X20, ARM64_REG_X20,
pointer_size);

gum_arm64_writer_put_ldr_reg_reg (aw, ARM64_REG_X19, ARM64_REG_X20);
gum_arm64_writer_put_cmp_reg_reg (aw, ARM64_REG_X19, ARM64_REG_X19);
gum_arm64_writer_put_cbnz_reg_label (aw, ARM64_REG_X21, has_key_label);
gum_arm64_writer_put_cbnz_reg_label (aw, ARM64_REG_X19, has_key_label);

gum_arm64_writer_put_ldr_reg_address (aw, ARM64_REG_X19, self->pthread_key);
gum_arm64_writer_put_ldr_reg_reg (aw, ARM64_REG_X19, ARM64_REG_X19);
Expand Down

0 comments on commit c827a73

Please sign in to comment.