Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 4ca9c36

Browse files
authored
Merge pull request #3307 from ibuclaw/ucontext2
Darwin: more fixes for ucontext_t implementation of core.thread.Fiber merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
2 parents a79bb0e + e2349d8 commit 4ca9c36

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

src/core/sys/posix/ucontext.d

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ else version (TVOS)
3333
else version (WatchOS)
3434
version = Darwin;
3535

36+
version (ARM) version = ARM_Any;
37+
version (AArch64) version = ARM_Any;
3638
version (MIPS32) version = MIPS_Any;
3739
version (MIPS64) version = MIPS_Any;
3840
version (PPC) version = PPC_Any;
@@ -921,16 +923,66 @@ else version (CRuntime_Musl)
921923
}
922924
else version (Darwin)
923925
{
924-
alias mcontext_t = void;
926+
private
927+
{
928+
version (X86_64)
929+
{
930+
struct __darwin_mcontext
931+
{
932+
ulong[89] __opaque;
933+
}
934+
static assert(__darwin_mcontext.sizeof == 712);
935+
}
936+
else version (X86)
937+
{
938+
struct __darwin_mcontext
939+
{
940+
uint[150] __opaque;
941+
}
942+
static assert(__darwin_mcontext.sizeof == 600);
943+
}
944+
else version (AArch64)
945+
{
946+
struct __darwin_mcontext
947+
{
948+
align(16) ulong[102] __opaque;
949+
}
950+
static assert(__darwin_mcontext.sizeof == 816);
951+
}
952+
else version (ARM)
953+
{
954+
struct __darwin_mcontext
955+
{
956+
uint[85] __opaque;
957+
}
958+
static assert(__darwin_mcontext.sizeof == 340);
959+
}
960+
else version (PPC_Any)
961+
{
962+
struct __darwin_mcontext
963+
{
964+
version (PPC64)
965+
ulong[129] __opaque;
966+
else
967+
uint[258] __opaque;
968+
}
969+
static assert(__darwin_mcontext.sizeof == 1032);
970+
}
971+
else
972+
static assert(false, "mcontext_t unimplemented for this platform.");
973+
}
974+
975+
alias mcontext_t = __darwin_mcontext*;
925976

926977
struct ucontext
927978
{
928-
int uc_onstack;
929-
sigset_t uc_sigmask;
930-
stack_t uc_stack;
931-
ucontext* uc_link;
932-
size_t uc_mcsize;
933-
mcontext_t* uc_mcontext;
979+
int uc_onstack;
980+
sigset_t uc_sigmask;
981+
stack_t uc_stack;
982+
ucontext* uc_link;
983+
size_t uc_mcsize;
984+
__darwin_mcontext* uc_mcontext;
985+
__darwin_mcontext __mcontext_data;
934986
}
935987

936988
alias ucontext_t = ucontext;

src/core/thread/fiber.d

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,13 @@ private:
958958
{
959959
version (Posix) import core.sys.posix.sys.mman; // mmap, MAP_ANON
960960

961+
static if ( __traits( compiles, ucontext_t ) )
962+
{
963+
// Stack size must be at least the minimum allowable by the OS.
964+
if (sz < MINSIGSTKSZ)
965+
sz = MINSIGSTKSZ;
966+
}
967+
961968
static if ( __traits( compiles, mmap ) )
962969
{
963970
// Allocate more for the memory guard

0 commit comments

Comments
 (0)