mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -101,6 +101,7 @@ internal struct _ThreadLocalStorage {
|
||||
|
||||
// Destructor to register with pthreads. Responsible for deallocating any memory
|
||||
// owned.
|
||||
@_silgen_name("_swift_stdlib_destroyTLS")
|
||||
internal func _destroyTLS(_ ptr: UnsafeMutableRawPointer?) {
|
||||
_sanityCheck(ptr != nil,
|
||||
"_destroyTLS was called, but with nil...")
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "swift/Basic/Lazy.h"
|
||||
#include "swift/Runtime/Config.h"
|
||||
#include "../SwiftShims/LibcShims.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,
|
||||
"__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
|
||||
int
|
||||
swift::_swift_stdlib_thread_key_create(__swift_thread_key_t * _Nonnull key,
|
||||
void (* _Nullable destructor)(void *)) {
|
||||
// TODO(compnerd) account for x86 CC violation (__stdcall)
|
||||
*key = FlsAlloc(reinterpret_cast<PFLS_CALLBACK_FUNCTION>(destructor));
|
||||
*key = FlsAlloc(_swift_stdlib_destroyTLS_CCAdjustmentThunk);
|
||||
return *key != FLS_OUT_OF_INDEXES;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user