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

Commit

Permalink
ensure allocated stack is 16-byte aligned for x86_64
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed Jun 2, 2011
1 parent 10eb812 commit 5c15308
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/core/thread.d
Original file line number Diff line number Diff line change
Expand Up @@ -2794,11 +2794,17 @@ private
version = AsmX86_Win32;
else version( Posix )
version = AsmX86_Posix;

version( OSX )
version = AlignFiberStackTo16Byte;
}
else version( D_InlineAsm_X86_64 )
{
version( Posix )
{
version = AsmX86_64_Posix;
version = AlignFiberStackTo16Byte;
}
}
else version( PPC )
{
Expand Down Expand Up @@ -3613,9 +3619,10 @@ private:
}
}

// NOTE: On OS X the stack must be 16-byte aligned according to the
// IA-32 call spec.
version( OSX )
// NOTE: On OS X the stack must be 16-byte aligned according
// to the IA-32 call spec. For x86_64 the stack also needs to
// be aligned to 16-byte according to SysV AMD64 ABI.
version( AlignFiberStackTo16Byte )
{
version( StackGrowsDown )
{
Expand Down Expand Up @@ -3649,7 +3656,7 @@ private:
}
else version( AsmX86_Posix )
{
push( 0x00000000 ); // Pad stack for OSX
push( 0x00000000 ); // Return address of fiber_entryPoint call
push( cast(size_t) &fiber_entryPoint ); // EIP
push( 0x00000000 ); // EBP
push( 0x00000000 ); // EAX
Expand All @@ -3659,7 +3666,7 @@ private:
}
else version( AsmX86_64_Posix )
{
push(0); // Pad stack for OSX
push(0); // Return address of fiber_entryPoint call
push( cast(size_t) &fiber_entryPoint ); // RIP
push(0); // RBX
push(0); // RBP
Expand Down Expand Up @@ -3929,6 +3936,25 @@ unittest
}
}

version( AsmX86_64_Posix )
{
unittest
{
void testStackAlignment()
{
void* pRSP;
asm
{
mov pRSP, RSP;
}
assert((cast(size_t)pRSP & 0xF) == 0);
}

auto fib = new Fiber(&testStackAlignment);
fib.call();
}
}

version( OSX )
{
// NOTE: The Mach-O object file format does not allow for thread local
Expand Down

0 comments on commit 5c15308

Please sign in to comment.