Skip to content

Commit

Permalink
i#2799: Make sure dstack_offs is 8-byte aligned on ARM. (#2803)
Browse files Browse the repository at this point in the history
2e9f20e made get_clean_call_switch_stack_size() 8-byte aligned for ARM,
which is required by the "Procedure Call Standard for the ARM Architecture
[AAPCS]" [1]. priv_mcontext_t on ARM only contains 31 8-byte slots,
which is why an extra adjustment is needed in insert_push_all_registers.

Fixes #2799

[1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka4127.html
  • Loading branch information
fhahn authored Mar 22, 2018
1 parent 8471d5c commit dd1589c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions core/arch/aarchxx/mangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ insert_push_all_registers(dcontext_t *dcontext, clean_call_info_t *cci,
DR_REG_LIST_LENGTH_ARM, DR_REG_LIST_ARM));
}
dstack_offs += 15 * XSP_SZ;

/* Make dstack_offs 8-byte algined, as we only accounted for 17 4-byte slots. */
dstack_offs += XSP_SZ;
ASSERT(cci->skip_save_flags ||
cci->num_simd_skip != 0 ||
cci->num_regs_skip != 0 ||
Expand Down
4 changes: 2 additions & 2 deletions core/arch/emit_utils_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -5011,10 +5011,10 @@ emit_new_thread_dynamo_start(dcontext_t *dcontext, byte *pc)
SCRATCH_REG0 _IF_AARCH64(false));
# ifndef AARCH64
/* put pre-push xsp into priv_mcontext_t.xsp slot */
ASSERT(offset == sizeof(priv_mcontext_t));
ASSERT(offset == get_clean_call_switch_stack_size());
APP(&ilist, XINST_CREATE_add_2src
(dcontext, opnd_create_reg(SCRATCH_REG0),
opnd_create_reg(REG_XSP), OPND_CREATE_INT32(sizeof(priv_mcontext_t))));
opnd_create_reg(REG_XSP), OPND_CREATE_INT32(offset)));
APP(&ilist, XINST_CREATE_store
(dcontext, OPND_CREATE_MEMPTR(REG_XSP, offsetof(priv_mcontext_t, xsp)),
opnd_create_reg(SCRATCH_REG0)));
Expand Down
3 changes: 2 additions & 1 deletion core/arch/mangle_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ prepare_for_clean_call(dcontext_t *dcontext, clean_call_info_t *cci,
ASSERT(cci->skip_save_flags ||
cci->num_simd_skip != 0 ||
cci->num_regs_skip != 0 ||
dstack_offs == sizeof(priv_mcontext_t) + clean_call_beyond_mcontext());
(int) dstack_offs == (get_clean_call_switch_stack_size() +
clean_call_beyond_mcontext()));
return dstack_offs;
}

Expand Down

0 comments on commit dd1589c

Please sign in to comment.