Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#5383: Fix macOS arm64 test build/run #7171

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions core/unix/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -7691,8 +7691,6 @@ os_forge_exception(app_pc target_pc, dr_exception_type_t type)
sigframe_rt_t *frame = (sigframe_rt_t *)frame_no_xstate;
int sig;
dr_where_am_i_t cur_whereami = dcontext->whereami;
kernel_ucontext_t *uc = get_ucontext_from_rt_frame(frame);
sigcontext_t *sc = SIGCXT_FROM_UCXT(uc);
switch (type) {
case ILLEGAL_INSTRUCTION_EXCEPTION: sig = SIGILL; break;
case UNREADABLE_MEMORY_EXECUTION_EXCEPTION: sig = SIGSEGV; break;
Expand All @@ -7710,6 +7708,16 @@ os_forge_exception(app_pc target_pc, dr_exception_type_t type)
* to a plain frame on delivery.
*/
memset(frame, 0, sizeof(*frame));

kernel_ucontext_t *uc = get_ucontext_from_rt_frame(frame);
#if defined(MACOS)
/* Since SIGCXT_FROM_UCXT just accesses the uc->uc_mcontext ptr field on
* macOS, sc will be NULL below if we do not initialize uc_mcontext first
*/
uc->IF_X64_ELSE(uc_mcontext64, uc_mcontext) = (void *)&frame->mc;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems weird.
frame is zeroed-out anyway, isn't this just changing sc to be a "different" NULL?
Also, shouldn't sc being NULL break more than MACOS?

#endif
sigcontext_t *sc = SIGCXT_FROM_UCXT(uc);

frame->info.si_signo = sig;
/* Set si_code to match what would happen natively. We also need this to
* avoid the !is_sys_kill() check in record_pending_signal() to avoid an
Expand Down
11 changes: 10 additions & 1 deletion suite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,13 @@ if (CMAKE_CROSSCOMPILING AND DEFINED CMAKE_FIND_ROOT_PATH)
set(dr_test_ops -xarch_root ${CMAKE_FIND_ROOT_PATH} ${dr_test_ops})
endif ()

if (APPLE AND AARCH64)
# On macOS + arm64 tests will randomly fail depending on
# whether mmap returns a region satisfying 32-bit reachability constraints.
# Reducing the vm_size appears to eliminate this issue.
set(dr_test_ops -vm_size 500M ${dr_test_ops})
endif ()

function(runtest_cmd outcmd outops key native standalone_dr dr_ops_aux separate_script)
# assumes tools have been built: enforced at top level
set(dr_ops ${dr_test_ops} ${dr_ops_aux} ${TEST_OPTIONS})
Expand Down Expand Up @@ -6040,7 +6047,9 @@ if (NOT ARM) # FIXME i#1551: fix bugs on ARM
endif ()
endif (NOT ARM)

if (X86 OR AARCH64) # FIXME i#1551: port asm to ARM
# FIXME i#1551: port asm to ARM
# FIXME i#xxx: selfmod tests fail to build on macOS + ARM64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change i#xxx with i#5383 (this falls within that issue).

if (X86 OR AARCH64 AND NOT (APPLE AND AARCH64))
tobuild(security-common.selfmod2 security-common/selfmod2.c)
tochcon(security-common.selfmod2 textrel_shlib_t)

Expand Down
8 changes: 6 additions & 2 deletions suite/tests/client-interface/cbr-retarget.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ main(void)
}
;
#elif defined(AARCH64)
__asm("cbnz xzr, skip");
__asm("cbnz xzr, 1f");
# ifdef MACOS
__asm("bl _foo");
# else
__asm("bl foo");
__asm("skip:");
# endif
__asm("1:");
#else
__asm("movl $0x0, %ecx");
__asm("cmp $0x0, %ecx");
Expand Down
4 changes: 3 additions & 1 deletion suite/tests/client-interface/strace.dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ event_post_syscall(void *drcontext, int sysnum)
static int
get_write_sysnum(void)
{
#ifdef UNIX
#if defined(MACOS)
return SYS_write_nocancel;
#elif defined(UNIX)
return SYS_write;
#else
byte *entry;
Expand Down
9 changes: 6 additions & 3 deletions suite/tests/linux/mangle_pauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ handle_signal(int signal, siginfo_t *siginfo, ucontext_t *ucxt)
* We need to strip the PAC from from the fault address to canonicalize it and
* compare it to the expected branch target address.
*/
const uintptr_t fault_pc = strip_pac(ucxt->uc_mcontext.pc);
LOG(" ucxt->uc_mcontext.pc = " PFX "\n", ucxt->uc_mcontext.pc);
const uintptr_t pc =
IF_MACOS_ELSE(ucxt->uc_mcontext->__ss.__pc, ucxt->uc_mcontext.pc);
const uintptr_t fault_pc = strip_pac(pc);
LOG(" ucxt->uc_mcontext.pc = " PFX "\n", pc);
LOG(" fault_pc = " PFX "\n", fault_pc);
LOG(" branch_target_addr = " PFX "\n", branch_target_addr);
if (fault_pc == branch_target_addr)
Expand All @@ -123,7 +125,8 @@ handle_signal(int signal, siginfo_t *siginfo, ucontext_t *ucxt)
/* CPU has FEAT_FPACCOMBINE so the branch instruction generated an authentication
* failure exception and the fault PC should match the branch instruction address.
*/
const uintptr_t fault_pc = ucxt->uc_mcontext.pc;
const uintptr_t fault_pc =
IF_MACOS_ELSE(ucxt->uc_mcontext->__ss.__pc, ucxt->uc_mcontext.pc);
LOG(" fault_pc = " PFX "\n", fault_pc);
LOG(" branch_instr_addr = " PFX "\n", branch_instr_addr);
if (fault_pc == branch_instr_addr)
Expand Down
6 changes: 5 additions & 1 deletion suite/tests/tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ intercept_signal(int sig, handler_3_t handler, bool sigstack)
void
dump_ucontext(ucontext_t *ucxt, bool is_sve, int vl_bytes)
{
# ifdef MACOS
assert(false); /* NYI */
# else
struct _aarch64_ctx *head = (struct _aarch64_ctx *)(ucxt->uc_mcontext.RESERVED);
assert(head->magic == FPSIMD_MAGIC);
assert(head->size == sizeof(struct fpsimd_context));
Expand All @@ -521,7 +524,7 @@ dump_ucontext(ucontext_t *ucxt, bool is_sve, int vl_bytes)
}
print("\n");

# ifndef DR_HOST_NOT_TARGET
# ifndef DR_HOST_NOT_TARGET
if (is_sve) {
size_t offset = sizeof(struct fpsimd_context);
struct _aarch64_ctx *next_head =
Expand Down Expand Up @@ -601,6 +604,7 @@ dump_ucontext(ucontext_t *ucxt, bool is_sve, int vl_bytes)
next_head = (struct _aarch64_ctx *)(ucxt->uc_mcontext.RESERVED + offset);
}
}
# endif
# endif
}
# endif
Expand Down
Loading