From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1698) id A90F038438A4; Sun, 13 Dec 2020 17:43:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A90F038438A4 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Iain D Sandoe To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/iains/heads/d-for-darwin)] libphobos: Fix broken ucontext implementation, and other small test fixes X-Act-Checkin: gcc X-Git-Author: Iain Buclaw X-Git-Refname: refs/users/iains/heads/d-for-darwin X-Git-Oldrev: 3931c797ef3e392fd6fafe04e2e21977d7ae9768 X-Git-Newrev: 874c22a8289142029f75854d3dd089f08268ae3d Message-Id: <20201213174343.A90F038438A4@sourceware.org> Date: Sun, 13 Dec 2020 17:43:43 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Dec 2020 17:43:43 -0000 https://gcc.gnu.org/g:874c22a8289142029f75854d3dd089f08268ae3d commit 874c22a8289142029f75854d3dd089f08268ae3d Author: Iain Buclaw Date: Wed Dec 9 10:49:34 2020 +0100 libphobos: Fix broken ucontext implementation, and other small test fixes Diff: --- libphobos/libdruntime/core/sys/posix/ucontext.d | 85 ++++++++++++++++++++-- libphobos/libdruntime/core/thread.d | 28 +++++-- libphobos/src/std/experimental/allocator/package.d | 3 +- .../testsuite/libphobos.thread/fiber_guard_page.d | 6 +- 4 files changed, 106 insertions(+), 16 deletions(-) diff --git a/libphobos/libdruntime/core/sys/posix/ucontext.d b/libphobos/libdruntime/core/sys/posix/ucontext.d index 9400edd11f2..4e4365efda2 100644 --- a/libphobos/libdruntime/core/sys/posix/ucontext.d +++ b/libphobos/libdruntime/core/sys/posix/ucontext.d @@ -32,6 +32,8 @@ else version (TVOS) else version (WatchOS) version = Darwin; +version (ARM) version = ARM_Any; +version (AArch64) version = ARM_Any; version (MIPS32) version = MIPS_Any; version (MIPS64) version = MIPS_Any; version (PPC) version = PPC_Any; @@ -657,7 +659,7 @@ version (CRuntime_Glibc) mcontext_t uc_mcontext; } } - else version (SPARC64) + else version (SPARC_Any) { enum MC_NGREG = 19; alias mc_greg_t = c_ulong; @@ -958,7 +960,17 @@ else version (Darwin) int[2] __fpu_reserved; ushort __fpu_fcw; ushort __fpu_fsw; - uint[7] __fpu_regs; + ubyte __fpu_ftw; + ubyte __fpu_rsrv1; + ushort __fpu_fop; + uint __fpu_ip; + ushort __fpu_cs; + ushort __fpu_rsrv2; + uint __fpu_dp; + ushort __fpu_ds; + ushort __fpu_rsrv3; + uint __fpu_mxcsr; + uint __fpu_mxcsrmask; __darwin_mmst_reg[8] __fpu_stmm; version (X86_64) { @@ -980,6 +992,69 @@ else version (Darwin) __darwin_float_state __fs; } } + else version (ARM_Any) + { + struct __darwin_exception_state + { + version (AArch64) + { + ulong __far; + uint __esr; + uint __exception; + } + else + { + uint __exception; + uint __fsr; + uint __far; + } + } + + struct __darwin_thread_state + { + version (AArch64) + { + ulong[29] x; + ulong fp; + ulong lr; + ulong sp; + ulong pc; + uint cpsr; + uint __pad; + } + else + { + uint[13] r; + uint sp; + uint lr; + uint pc; + uint cpsr; + } + } + + struct __darwin_vfp_state + { + uint[64] r; + uint fpscr; + } + + struct __darwin_neon_state + { + align(16) ulong[64] __v; + uint __fpsr; + uint __fpcr; + } + + struct __darwin_mcontext + { + __darwin_exception_state __es; + __darwin_thread_state __ss; + version (AArch64) + __darwin_neon_state __ns; + else + __darwin_vfp_state __fs; + } + } else version (PPC_Any) { struct __darwin_exception_state @@ -1408,7 +1483,7 @@ else version (OpenBSD) int sc_trapno; int sc_err; void* sc_fpstate; // union savefpu* - }; + } } else version (PPC) { @@ -1495,7 +1570,7 @@ else version (DragonFlyBSD) uint mc_reserved; uint[8] mc_unused; int[256] mc_fpregs; - }; // __attribute__((aligned(64))); + } // __attribute__((aligned(64))); } else { @@ -1609,7 +1684,7 @@ else version (Solaris) { uint[32] fpu_regs; double[16] fpu_dregs; - }; + } fq *fpu_q; uint fpu_fsr; ubyte fpu_qcnt; diff --git a/libphobos/libdruntime/core/thread.d b/libphobos/libdruntime/core/thread.d index 7506a8b3ee3..5381cda103b 100644 --- a/libphobos/libdruntime/core/thread.d +++ b/libphobos/libdruntime/core/thread.d @@ -1343,6 +1343,7 @@ class Thread // NOTE: This function may not be called until thread_init has // completed. See thread_suspendAll for more information // on why this might occur. + version (GNU) pragma(inline, false); return sm_this; } @@ -2039,6 +2040,16 @@ extern (C) void thread_init() version (Darwin) { + // thread id different in forked child process + static extern(C) void initChildAfterFork() + { + auto thisThread = Thread.getThis(); + thisThread.m_addr = pthread_self(); + assert( thisThread.m_addr != thisThread.m_addr.init ); + thisThread.m_tmach = pthread_mach_thread_np( thisThread.m_addr ); + assert( thisThread.m_tmach != thisThread.m_tmach.init ); + } + pthread_atfork(null, null, &initChildAfterFork); } else version (Posix) { @@ -4463,6 +4474,7 @@ class Fiber */ static Fiber getThis() @safe nothrow @nogc { + version(GNU) pragma(inline, false); return sm_this; } @@ -4618,14 +4630,14 @@ private: } else { - version (Posix) import core.sys.posix.sys.mman; // mmap - version (FreeBSD) import core.sys.freebsd.sys.mman : MAP_ANON; - version (NetBSD) import core.sys.netbsd.sys.mman : MAP_ANON; - version (OpenBSD) import core.sys.openbsd.sys.mman : MAP_ANON; - version (DragonFlyBSD) import core.sys.dragonflybsd.sys.mman : MAP_ANON; - version (CRuntime_Glibc) import core.sys.linux.sys.mman : MAP_ANON; - version (Darwin) import core.sys.darwin.sys.mman : MAP_ANON; - version (CRuntime_UClibc) import core.sys.linux.sys.mman : MAP_ANON; + version (Posix) import core.sys.posix.sys.mman; // mmap, MAP_ANON + + static if ( __traits( compiles, ucontext_t ) ) + { + // Stack size must be at least the minimum allowable by the OS. + if (sz < MINSIGSTKSZ) + sz = MINSIGSTKSZ; + } static if ( __traits( compiles, mmap ) ) { diff --git a/libphobos/src/std/experimental/allocator/package.d b/libphobos/src/std/experimental/allocator/package.d index 11c85474365..7c404070ffa 100644 --- a/libphobos/src/std/experimental/allocator/package.d +++ b/libphobos/src/std/experimental/allocator/package.d @@ -622,7 +622,8 @@ allocator can be cast to $(D shared). testAllocatorObject(processAllocator); testAllocatorObject(theAllocator); - assertThrown!AssertError(processAllocator = null); + // XBUG: Asserts are not thrown in release code, so is a pointless check. + //assertThrown!AssertError(processAllocator = null); // Restore initial processAllocator state processAllocator = oldProcessAllocator; diff --git a/libphobos/testsuite/libphobos.thread/fiber_guard_page.d b/libphobos/testsuite/libphobos.thread/fiber_guard_page.d index 61a616acd8e..ca3ff2afca0 100644 --- a/libphobos/testsuite/libphobos.thread/fiber_guard_page.d +++ b/libphobos/testsuite/libphobos.thread/fiber_guard_page.d @@ -1,13 +1,15 @@ // { dg-options "-O0" } // { dg-shouldfail "segv or bus error" } import core.thread; +import core.sys.posix.signal; import core.sys.posix.sys.mman; // this should be true for most architectures // (taken from core.thread) -version = StackGrowsDown; +version (GNU_StackGrowsDown) + version = StackGrowsDown; -enum stackSize = 4096; +enum stackSize = MINSIGSTKSZ; // Simple method that causes a stack overflow void stackMethod()