Align thread entry point stack

_beginthreadex does not align the stack on 16-byte boundary as expected
by gcc.

On x86 targets, the force_align_arg_pointer attribute may be applied to
individual function definitions, generating an alternate prologue and
epilogue that realigns the run-time stack if necessary. This supports
mixing legacy codes that run with a 4-byte aligned stack with modern
codes that keep a 16-byte stack for SSE compatibility.
https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html

Change-Id: Ie4e4ab32948c238fa87054d5664189972ca6708e
Signed-off-by: Aleksey Vasenev <margtu-fivt@ya.ru>
This commit is contained in:
Aleksey Vasenev 2016-07-29 11:28:50 +03:00 committed by James Zern
parent 4916a87bfc
commit 343b6b09a1
2 changed files with 11 additions and 0 deletions

View File

@ -24,7 +24,13 @@ extern "C" {
/* Win32 */
#include <process.h>
#include <windows.h>
#if defined(__GNUC__) && \
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
#define THREAD_FUNCTION \
__attribute__((force_align_arg_pointer)) unsigned int __stdcall
#else
#define THREAD_FUNCTION unsigned int __stdcall
#endif
#define THREAD_FUNCTION_RETURN DWORD
#define THREAD_SPECIFIC_INDEX DWORD
#define pthread_t HANDLE

View File

@ -58,7 +58,12 @@ typedef struct {
// simplistic pthread emulation layer
// _beginthreadex requires __stdcall
#if defined(__GNUC__) && \
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
#define THREADFN __attribute__((force_align_arg_pointer)) unsigned int __stdcall
#else
#define THREADFN unsigned int __stdcall
#endif
#define THREAD_RETURN(val) (unsigned int)((DWORD_PTR)val)
#if _WIN32_WINNT >= 0x0501 // Windows XP or greater