diff options
author | 2019-02-04 16:55:44 +0000 | |
---|---|---|
committer | 2019-02-04 16:55:44 +0000 | |
commit | 76c648e7a477ffb2a882ad5ffe523269bd9a3f6a (patch) | |
tree | 29d319d598650bab04e4f58e5e8769567e33091e /lib/libcxx/src/support | |
parent | Import libc++abi 7.0.1. (diff) | |
download | wireguard-openbsd-76c648e7a477ffb2a882ad5ffe523269bd9a3f6a.tar.xz wireguard-openbsd-76c648e7a477ffb2a882ad5ffe523269bd9a3f6a.zip |
Import libc++ 7.0.1.
Diffstat (limited to 'lib/libcxx/src/support')
-rw-r--r-- | lib/libcxx/src/support/runtime/exception_libcxxabi.ipp | 2 | ||||
-rw-r--r-- | lib/libcxx/src/support/runtime/exception_msvc.ipp | 28 | ||||
-rw-r--r-- | lib/libcxx/src/support/runtime/exception_pointer_msvc.ipp | 34 | ||||
-rw-r--r-- | lib/libcxx/src/support/win32/locale_win32.cpp | 4 | ||||
-rw-r--r-- | lib/libcxx/src/support/win32/support.cpp | 2 | ||||
-rw-r--r-- | lib/libcxx/src/support/win32/thread_win32.cpp | 276 |
6 files changed, 299 insertions, 47 deletions
diff --git a/lib/libcxx/src/support/runtime/exception_libcxxabi.ipp b/lib/libcxx/src/support/runtime/exception_libcxxabi.ipp index c3dcf1ec591..feefc515289 100644 --- a/lib/libcxx/src/support/runtime/exception_libcxxabi.ipp +++ b/lib/libcxx/src/support/runtime/exception_libcxxabi.ipp @@ -18,7 +18,7 @@ bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; } int uncaught_exceptions() _NOEXCEPT { -# if _LIBCPPABI_VERSION > 1101 +# if _LIBCPPABI_VERSION > 1001 return __cxa_uncaught_exceptions(); # else return __cxa_uncaught_exception() ? 1 : 0; diff --git a/lib/libcxx/src/support/runtime/exception_msvc.ipp b/lib/libcxx/src/support/runtime/exception_msvc.ipp index d5bf5b726ea..87d5a66fc8f 100644 --- a/lib/libcxx/src/support/runtime/exception_msvc.ipp +++ b/lib/libcxx/src/support/runtime/exception_msvc.ipp @@ -15,30 +15,18 @@ #include <stdio.h> #include <stdlib.h> -#if !defined(_ACRTIMP) -#define _ACRTIMP __declspec(dllimport) -#endif - -#if !defined(_VCRTIMP) -#define _VCRTIMP __declspec(dllimport) -#endif - -#if !defined(__CRTDECL) -#define __CRTDECL __cdecl -#endif - extern "C" { -typedef void (__CRTDECL* terminate_handler)(); -_ACRTIMP terminate_handler __cdecl set_terminate( +typedef void (__cdecl* terminate_handler)(); +_LIBCPP_CRT_FUNC terminate_handler __cdecl set_terminate( terminate_handler _NewTerminateHandler) throw(); -_ACRTIMP terminate_handler __cdecl _get_terminate(); +_LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate(); -typedef void (__CRTDECL* unexpected_handler)(); -_VCRTIMP unexpected_handler __cdecl set_unexpected( +typedef void (__cdecl* unexpected_handler)(); +unexpected_handler __cdecl set_unexpected( unexpected_handler _NewUnexpectedHandler) throw(); -_VCRTIMP unexpected_handler __cdecl _get_unexpected(); +unexpected_handler __cdecl _get_unexpected(); -_VCRTIMP int __cdecl __uncaught_exceptions(); +int __cdecl __uncaught_exceptions(); } namespace std { @@ -109,6 +97,7 @@ bad_array_length::what() const _NOEXCEPT return "bad_array_length"; } +#if defined(_LIBCPP_NO_VCRUNTIME) bad_cast::bad_cast() _NOEXCEPT { } @@ -137,7 +126,6 @@ bad_typeid::what() const _NOEXCEPT return "std::bad_typeid"; } -#if defined(_LIBCPP_NO_VCRUNTIME) exception::~exception() _NOEXCEPT { } diff --git a/lib/libcxx/src/support/runtime/exception_pointer_msvc.ipp b/lib/libcxx/src/support/runtime/exception_pointer_msvc.ipp index 5ca7519a600..9b0d2361e40 100644 --- a/lib/libcxx/src/support/runtime/exception_pointer_msvc.ipp +++ b/lib/libcxx/src/support/runtime/exception_pointer_msvc.ipp @@ -11,30 +11,16 @@ #include <stdio.h> #include <stdlib.h> -#if !defined(_CRTIMP2_PURE) -#define _CRTIMP2_PURE __declspec(dllimport) -#endif - -#if !defined(__CLRCALL_PURE_OR_CDECL) -#define __CLRCALL_PURE_OR_CDECL __cdecl -#endif - -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(void*); -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(void*); -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopy(void*, - const void*); -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL -__ExceptionPtrAssign(void*, const void*); -_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL -__ExceptionPtrCompare(const void*, const void*); -_CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL -__ExceptionPtrToBool(const void*); -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrSwap(void*, void*); -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL -__ExceptionPtrCurrentException(void*); -[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL -__ExceptionPtrRethrow(const void*); -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL +_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCreate(void*); +_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrDestroy(void*); +_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopy(void*, const void*); +_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrAssign(void*, const void*); +_LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrCompare(const void*, const void*); +_LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrToBool(const void*); +_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrSwap(void*, void*); +_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCurrentException(void*); +[[noreturn]] _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrRethrow(const void*); +_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopyException(void*, const void*, const void*); namespace std { diff --git a/lib/libcxx/src/support/win32/locale_win32.cpp b/lib/libcxx/src/support/win32/locale_win32.cpp index fdca7efff06..cad9d4e8146 100644 --- a/lib/libcxx/src/support/win32/locale_win32.cpp +++ b/lib/libcxx/src/support/win32/locale_win32.cpp @@ -13,6 +13,8 @@ #include <memory> #include <type_traits> +int __libcpp_vasprintf(char **sptr, const char *__restrict fmt, va_list ap); + using std::__libcpp_locale_guard; // FIXME: base currently unused. Needs manual work to construct the new locale @@ -105,7 +107,7 @@ int asprintf_l( char **ret, locale_t loc, const char *format, ... ) int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap ) { __libcpp_locale_guard __current(loc); - return vasprintf( ret, format, ap ); + return __libcpp_vasprintf( ret, format, ap ); } #if !defined(_LIBCPP_MSVCRT) diff --git a/lib/libcxx/src/support/win32/support.cpp b/lib/libcxx/src/support/win32/support.cpp index dbd1c4c418a..aa636fba50b 100644 --- a/lib/libcxx/src/support/win32/support.cpp +++ b/lib/libcxx/src/support/win32/support.cpp @@ -19,7 +19,7 @@ // Like sprintf, but when return value >= 0 it returns // a pointer to a malloc'd string in *sptr. // If return >= 0, use free to delete *sptr. -int vasprintf( char **sptr, const char *__restrict format, va_list ap ) +int __libcpp_vasprintf( char **sptr, const char *__restrict format, va_list ap ) { *sptr = NULL; // Query the count required. diff --git a/lib/libcxx/src/support/win32/thread_win32.cpp b/lib/libcxx/src/support/win32/thread_win32.cpp new file mode 100644 index 00000000000..1567042d8e2 --- /dev/null +++ b/lib/libcxx/src/support/win32/thread_win32.cpp @@ -0,0 +1,276 @@ +// -*- C++ -*- +//===-------------------- support/win32/thread_win32.cpp ------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <__threading_support> +#include <windows.h> +#include <process.h> +#include <fibersapi.h> + +_LIBCPP_BEGIN_NAMESPACE_STD + +static_assert(sizeof(__libcpp_mutex_t) == sizeof(SRWLOCK), ""); +static_assert(alignof(__libcpp_mutex_t) == alignof(SRWLOCK), ""); + +static_assert(sizeof(__libcpp_recursive_mutex_t) == sizeof(CRITICAL_SECTION), + ""); +static_assert(alignof(__libcpp_recursive_mutex_t) == alignof(CRITICAL_SECTION), + ""); + +static_assert(sizeof(__libcpp_condvar_t) == sizeof(CONDITION_VARIABLE), ""); +static_assert(alignof(__libcpp_condvar_t) == alignof(CONDITION_VARIABLE), ""); + +static_assert(sizeof(__libcpp_exec_once_flag) == sizeof(INIT_ONCE), ""); +static_assert(alignof(__libcpp_exec_once_flag) == alignof(INIT_ONCE), ""); + +static_assert(sizeof(__libcpp_thread_id) == sizeof(DWORD), ""); +static_assert(alignof(__libcpp_thread_id) == alignof(DWORD), ""); + +static_assert(sizeof(__libcpp_thread_t) == sizeof(HANDLE), ""); +static_assert(alignof(__libcpp_thread_t) == alignof(HANDLE), ""); + +static_assert(sizeof(__libcpp_tls_key) == sizeof(DWORD), ""); +static_assert(alignof(__libcpp_tls_key) == alignof(DWORD), ""); + +// Mutex +int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m) +{ + InitializeCriticalSection((LPCRITICAL_SECTION)__m); + return 0; +} + +int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m) +{ + EnterCriticalSection((LPCRITICAL_SECTION)__m); + return 0; +} + +bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m) +{ + return TryEnterCriticalSection((LPCRITICAL_SECTION)__m) != 0; +} + +int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m) +{ + LeaveCriticalSection((LPCRITICAL_SECTION)__m); + return 0; +} + +int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m) +{ + DeleteCriticalSection((LPCRITICAL_SECTION)__m); + return 0; +} + +int __libcpp_mutex_lock(__libcpp_mutex_t *__m) +{ + AcquireSRWLockExclusive((PSRWLOCK)__m); + return 0; +} + +bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m) +{ + return TryAcquireSRWLockExclusive((PSRWLOCK)__m) != 0; +} + +int __libcpp_mutex_unlock(__libcpp_mutex_t *__m) +{ + ReleaseSRWLockExclusive((PSRWLOCK)__m); + return 0; +} + +int __libcpp_mutex_destroy(__libcpp_mutex_t *__m) +{ + static_cast<void>(__m); + return 0; +} + +// Condition Variable +int __libcpp_condvar_signal(__libcpp_condvar_t *__cv) +{ + WakeConditionVariable((PCONDITION_VARIABLE)__cv); + return 0; +} + +int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv) +{ + WakeAllConditionVariable((PCONDITION_VARIABLE)__cv); + return 0; +} + +int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m) +{ + SleepConditionVariableSRW((PCONDITION_VARIABLE)__cv, (PSRWLOCK)__m, INFINITE, 0); + return 0; +} + +int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, + timespec *__ts) +{ + using namespace _VSTD::chrono; + + auto duration = seconds(__ts->tv_sec) + nanoseconds(__ts->tv_nsec); + auto abstime = + system_clock::time_point(duration_cast<system_clock::duration>(duration)); + auto timeout_ms = duration_cast<milliseconds>(abstime - system_clock::now()); + + if (!SleepConditionVariableSRW((PCONDITION_VARIABLE)__cv, (PSRWLOCK)__m, + timeout_ms.count() > 0 ? timeout_ms.count() + : 0, + 0)) + { + auto __ec = GetLastError(); + return __ec == ERROR_TIMEOUT ? ETIMEDOUT : __ec; + } + return 0; +} + +int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv) +{ + static_cast<void>(__cv); + return 0; +} + +// Execute Once +static inline _LIBCPP_INLINE_VISIBILITY BOOL CALLBACK +__libcpp_init_once_execute_once_thunk(PINIT_ONCE __init_once, PVOID __parameter, + PVOID *__context) +{ + static_cast<void>(__init_once); + static_cast<void>(__context); + + void (*init_routine)(void) = reinterpret_cast<void (*)(void)>(__parameter); + init_routine(); + return TRUE; +} + +int __libcpp_execute_once(__libcpp_exec_once_flag *__flag, + void (*__init_routine)(void)) +{ + if (!InitOnceExecuteOnce((PINIT_ONCE)__flag, __libcpp_init_once_execute_once_thunk, + reinterpret_cast<void *>(__init_routine), NULL)) + return GetLastError(); + return 0; +} + +// Thread ID +bool __libcpp_thread_id_equal(__libcpp_thread_id __lhs, + __libcpp_thread_id __rhs) +{ + return __lhs == __rhs; +} + +bool __libcpp_thread_id_less(__libcpp_thread_id __lhs, __libcpp_thread_id __rhs) +{ + return __lhs < __rhs; +} + +// Thread +struct __libcpp_beginthreadex_thunk_data +{ + void *(*__func)(void *); + void *__arg; +}; + +static inline _LIBCPP_INLINE_VISIBILITY unsigned WINAPI +__libcpp_beginthreadex_thunk(void *__raw_data) +{ + auto *__data = + static_cast<__libcpp_beginthreadex_thunk_data *>(__raw_data); + auto *__func = __data->__func; + void *__arg = __data->__arg; + delete __data; + return static_cast<unsigned>(reinterpret_cast<uintptr_t>(__func(__arg))); +} + +bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) { + return *__t == 0; +} + +int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *), + void *__arg) +{ + auto *__data = new __libcpp_beginthreadex_thunk_data; + __data->__func = __func; + __data->__arg = __arg; + + *__t = reinterpret_cast<HANDLE>(_beginthreadex(nullptr, 0, + __libcpp_beginthreadex_thunk, + __data, 0, nullptr)); + + if (*__t) + return 0; + return GetLastError(); +} + +__libcpp_thread_id __libcpp_thread_get_current_id() +{ + return GetCurrentThreadId(); +} + +__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t) +{ + return GetThreadId(*__t); +} + +int __libcpp_thread_join(__libcpp_thread_t *__t) +{ + if (WaitForSingleObjectEx(*__t, INFINITE, FALSE) == WAIT_FAILED) + return GetLastError(); + if (!CloseHandle(*__t)) + return GetLastError(); + return 0; +} + +int __libcpp_thread_detach(__libcpp_thread_t *__t) +{ + if (!CloseHandle(*__t)) + return GetLastError(); + return 0; +} + +void __libcpp_thread_yield() +{ + SwitchToThread(); +} + +void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) +{ + using namespace chrono; + // round-up to the nearest milisecond + milliseconds __ms = + duration_cast<milliseconds>(__ns + chrono::nanoseconds(999999)); + // FIXME(compnerd) this should be an alertable sleep (WFSO or SleepEx) + Sleep(__ms.count()); +} + +// Thread Local Storage +int __libcpp_tls_create(__libcpp_tls_key* __key, + void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*)) +{ + DWORD index = FlsAlloc(__at_exit); + if (index == FLS_OUT_OF_INDEXES) + return GetLastError(); + *__key = index; + return 0; +} + +void *__libcpp_tls_get(__libcpp_tls_key __key) +{ + return FlsGetValue(__key); +} + +int __libcpp_tls_set(__libcpp_tls_key __key, void *__p) +{ + if (!FlsSetValue(__key, __p)) + return GetLastError(); + return 0; +} + +_LIBCPP_END_NAMESPACE_STD |