public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/ibuclaw/heads/darwin)] libphobos: Fix broken ucontext implementation, and other small test fixes
Date: Tue, 22 Dec 2020 13:41:28 +0000 (GMT)	[thread overview]
Message-ID: <20201222134128.7FBD7388187D@sourceware.org> (raw)

https://gcc.gnu.org/g:379fe34b3ee6cf2f2876f162a2c3b0a93e278bd8

commit 379fe34b3ee6cf2f2876f162a2c3b0a93e278bd8
Author: Iain Buclaw <ibuclaw@gdcproject.org>
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()


             reply	other threads:[~2020-12-22 13:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-22 13:41 Iain Buclaw [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-09-17 14:34 Iain Buclaw
2021-04-19 18:06 Iain Buclaw
2021-04-10 17:01 Iain Buclaw
2021-04-10 15:04 Iain Buclaw
2021-03-14 22:00 Iain Buclaw
2021-03-07 17:02 Iain Buclaw
2021-01-30 19:09 Iain Buclaw
2021-01-28 17:32 Iain Buclaw
2021-01-11 11:40 Iain Buclaw
2020-12-09  9:51 Iain Buclaw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201222134128.7FBD7388187D@sourceware.org \
    --to=ibuclaw@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).