stubs: fix Windows x86 TLS callback CC violation

Windows x86 requires that the TLS destructor callback uses the "stdcall"
calling convention.  Provide a shim which will adjust the calling
convention and call back into the swift portion of the code code with
the expected calling convention.
This commit is contained in:
Saleem Abdulrasool
2017-09-19 11:27:05 -07:00
parent 8bf538cab1
commit 42c98e63d0
2 changed files with 14 additions and 2 deletions

View File

@@ -101,6 +101,7 @@ internal struct _ThreadLocalStorage {
// Destructor to register with pthreads. Responsible for deallocating any memory // Destructor to register with pthreads. Responsible for deallocating any memory
// owned. // owned.
@_silgen_name("_swift_stdlib_destroyTLS")
internal func _destroyTLS(_ ptr: UnsafeMutableRawPointer?) { internal func _destroyTLS(_ ptr: UnsafeMutableRawPointer?) {
_sanityCheck(ptr != nil, _sanityCheck(ptr != nil,
"_destroyTLS was called, but with nil...") "_destroyTLS was called, but with nil...")

View File

@@ -26,6 +26,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "swift/Basic/Lazy.h" #include "swift/Basic/Lazy.h"
#include "swift/Runtime/Config.h"
#include "../SwiftShims/LibcShims.h" #include "../SwiftShims/LibcShims.h"
#include "llvm/Support/DataTypes.h" #include "llvm/Support/DataTypes.h"
@@ -104,12 +105,22 @@ int swift::_swift_stdlib_close(int fd) {
static_assert(std::is_same<__swift_thread_key_t, DWORD>::value, static_assert(std::is_same<__swift_thread_key_t, DWORD>::value,
"__swift_thread_key_t is not a DWORD"); "__swift_thread_key_t is not a DWORD");
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERFACE
void _swift_stdlib_destroyTLS(void *);
static void
#if defined(_M_X86)
__stdcall
#endif
_swift_stdlib_destroyTLS_CCAdjustmentThunk(void *ptr) {
_swift_stdlib_destroyTLS(ptr);
}
SWIFT_RUNTIME_STDLIB_INTERFACE SWIFT_RUNTIME_STDLIB_INTERFACE
int int
swift::_swift_stdlib_thread_key_create(__swift_thread_key_t * _Nonnull key, swift::_swift_stdlib_thread_key_create(__swift_thread_key_t * _Nonnull key,
void (* _Nullable destructor)(void *)) { void (* _Nullable destructor)(void *)) {
// TODO(compnerd) account for x86 CC violation (__stdcall) *key = FlsAlloc(_swift_stdlib_destroyTLS_CCAdjustmentThunk);
*key = FlsAlloc(reinterpret_cast<PFLS_CALLBACK_FUNCTION>(destructor));
return *key != FLS_OUT_OF_INDEXES; return *key != FLS_OUT_OF_INDEXES;
} }