From 576ffaa3298b4e99b7e46d4eccad4763b18985f8 Mon Sep 17 00:00:00 2001 From: kcbanner Date: Tue, 4 Jul 2023 13:40:50 -0400 Subject: [PATCH] darwin: update mcontext_t definition for aarch64 to add neon state --- lib/std/c/darwin.zig | 6 +----- lib/std/c/darwin/aarch64.zig | 13 +++++++++++++ lib/std/c/darwin/x86_64.zig | 6 ++++++ lib/std/debug.zig | 9 ++++++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 5f281912215bba2cc096087d8b7328ae128aae3a..1901271b83c2463c414c2eb1b20fd2568abcbaa7 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -151,11 +151,7 @@ pub const ucontext_t = extern struct { __mcontext_data: mcontext_t, }; -pub const mcontext_t = extern struct { - es: arch_bits.exception_state, - ss: arch_bits.thread_state, - fs: arch_bits.float_state, -}; +pub const mcontext_t = arch_bits.mcontext_t; extern "c" fn __error() *c_int; pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32; diff --git a/lib/std/c/darwin/aarch64.zig b/lib/std/c/darwin/aarch64.zig index 48b03363a165a790c0c5beb0884d30386eb83a88..d00b92af83838978867fa103f3106e9abf13dd58 100644 --- a/lib/std/c/darwin/aarch64.zig +++ b/lib/std/c/darwin/aarch64.zig @@ -1,5 +1,12 @@ // See C headers in // lib/libc/include/aarch64-macos.12-gnu/mach/arm/_structs.h +// lib/libc/include/aarch64-macos.13-none/arm/_mcontext.h + +pub const mcontext_t = extern struct { + es: exception_state, + ss: thread_state, + ns: neon_state, +}; pub const exception_state = extern struct { far: u64, // Virtual Fault Address @@ -17,6 +24,12 @@ pub const thread_state = extern struct { __pad: u32, }; +pub const neon_state = extern struct { + q: [32]u128, + fpsr: u32, + fpcr: u32, +}; + pub const EXC_TYPES_COUNT = 14; pub const EXC_MASK_MACHINE = 0; diff --git a/lib/std/c/darwin/x86_64.zig b/lib/std/c/darwin/x86_64.zig index db94840d9da2f5a5284792e706a06114d7bd704b..7b66fb2e97987da8f29d7825601ed9ac6fada23f 100644 --- a/lib/std/c/darwin/x86_64.zig +++ b/lib/std/c/darwin/x86_64.zig @@ -1,5 +1,11 @@ const c = @import("../darwin.zig"); +pub const mcontext_t = extern struct { + es: exception_state, + ss: thread_state, + fs: float_state, +}; + pub const exception_state = extern struct { trapno: u16, cpu: u16, diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 249674e0d40d71e7852e97e55f73f6b102f758eb..eef65bd6770eb35f5cd4b415c905602719b50ad0 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -445,7 +445,14 @@ pub inline fn getContext(context: *StackTraceContext) bool { } const result = have_getcontext and os.system.getcontext(context) == 0; - if (native_os == .macos) assert(context.mcsize == @sizeOf(std.c.mcontext_t)); + if (native_os == .macos) { + // TODO: Temp, to discover this size via aarch64 CI + if (context.mcsize != @sizeOf(std.c.mcontext_t)) { + print("context.mcsize does not match! {} vs {}\n", .{ context.mcsize, @sizeOf(std.c.mcontext_t)}); + } + + assert(context.mcsize == @sizeOf(std.c.mcontext_t)); + } return result; } -- 2.54.0