aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/src
diff options
context:
space:
mode:
authormonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
committermonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
commit06e5c21a835c0e923506c4ff27929f34e00761c2 (patch)
tree75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /contrib/libs/cxxsupp/libcxx/src
parent03f024c4412e3aa613bb543cf1660176320ba8f4 (diff)
downloadydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz
fix ya.make
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/src')
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource.cpp147
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource_init_helper.h2
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/filesystem/int128_builtins.cpp54
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/support/ibm/mbsnrtowcs.cpp95
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/support/ibm/wcsnrtombs.cpp93
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/support/ibm/xlocale_zos.cpp137
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/support/solaris/mbsnrtowcs.inc76
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/support/solaris/wcsnrtombs.inc92
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/support/solaris/xlocale.cpp68
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/support/win32/atomic_win32.cpp31
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/support/win32/locale_win32.cpp141
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/support/win32/new_win32.cpp28
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/support/win32/support.cpp172
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/support/win32/thread_win32.cpp274
14 files changed, 0 insertions, 1410 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource.cpp b/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource.cpp
deleted file mode 100644
index 018d0159281..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource.cpp
+++ /dev/null
@@ -1,147 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "experimental/memory_resource"
-
-#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
-#include "atomic"
-#elif !defined(_LIBCPP_HAS_NO_THREADS)
-#include "mutex"
-#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-#pragma comment(lib, "pthread")
-#endif
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
-
-// memory_resource
-
-//memory_resource::~memory_resource() {}
-
-// new_delete_resource()
-
-class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp
- : public memory_resource
-{
- void *do_allocate(size_t size, size_t align) override {
-#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
- if (__is_overaligned_for_new(align))
- __throw_bad_alloc();
-#endif
- return _VSTD::__libcpp_allocate(size, align);
- }
-
- void do_deallocate(void *p, size_t n, size_t align) override {
- _VSTD::__libcpp_deallocate(p, n, align);
- }
-
- bool do_is_equal(memory_resource const & other) const noexcept override
- { return &other == this; }
-
-public:
- ~__new_delete_memory_resource_imp() override = default;
-};
-
-// null_memory_resource()
-
-class _LIBCPP_TYPE_VIS __null_memory_resource_imp
- : public memory_resource
-{
-public:
- ~__null_memory_resource_imp() = default;
-
-protected:
- virtual void* do_allocate(size_t, size_t) {
- __throw_bad_alloc();
- }
- virtual void do_deallocate(void *, size_t, size_t) {}
- virtual bool do_is_equal(memory_resource const & __other) const noexcept
- { return &__other == this; }
-};
-
-namespace {
-
-union ResourceInitHelper {
- struct {
- __new_delete_memory_resource_imp new_delete_res;
- __null_memory_resource_imp null_res;
- } resources;
- char dummy;
- _LIBCPP_CONSTEXPR_AFTER_CXX11 ResourceInitHelper() : resources() {}
- ~ResourceInitHelper() {}
-};
-
-// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
-// attribute with a value that's reserved for the implementation (we're the implementation).
-#include "memory_resource_init_helper.h"
-
-} // end namespace
-
-
-memory_resource * new_delete_resource() noexcept {
- return &res_init.resources.new_delete_res;
-}
-
-memory_resource * null_memory_resource() noexcept {
- return &res_init.resources.null_res;
-}
-
-// default_memory_resource()
-
-static memory_resource *
-__default_memory_resource(bool set = false, memory_resource * new_res = nullptr) noexcept
-{
-#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
- _LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res{&res_init.resources.new_delete_res};
- if (set) {
- new_res = new_res ? new_res : new_delete_resource();
- // TODO: Can a weaker ordering be used?
- return _VSTD::atomic_exchange_explicit(
- &__res, new_res, memory_order_acq_rel);
- }
- else {
- return _VSTD::atomic_load_explicit(
- &__res, memory_order_acquire);
- }
-#elif !defined(_LIBCPP_HAS_NO_THREADS)
- _LIBCPP_SAFE_STATIC static memory_resource * res = &res_init.resources.new_delete_res;
- static mutex res_lock;
- if (set) {
- new_res = new_res ? new_res : new_delete_resource();
- lock_guard<mutex> guard(res_lock);
- memory_resource * old_res = res;
- res = new_res;
- return old_res;
- } else {
- lock_guard<mutex> guard(res_lock);
- return res;
- }
-#else
- _LIBCPP_SAFE_STATIC static memory_resource* res = &res_init.resources.new_delete_res;
- if (set) {
- new_res = new_res ? new_res : new_delete_resource();
- memory_resource * old_res = res;
- res = new_res;
- return old_res;
- } else {
- return res;
- }
-#endif
-}
-
-memory_resource * get_default_resource() noexcept
-{
- return __default_memory_resource();
-}
-
-memory_resource * set_default_resource(memory_resource * __new_res) noexcept
-{
- return __default_memory_resource(true, __new_res);
-}
-
-_LIBCPP_END_NAMESPACE_LFTS_PMR
diff --git a/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource_init_helper.h b/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource_init_helper.h
deleted file mode 100644
index 2e1cae5ecc6..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/experimental/memory_resource_init_helper.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#pragma GCC system_header
-_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX; \ No newline at end of file
diff --git a/contrib/libs/cxxsupp/libcxx/src/filesystem/int128_builtins.cpp b/contrib/libs/cxxsupp/libcxx/src/filesystem/int128_builtins.cpp
deleted file mode 100644
index ed531ee145a..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/filesystem/int128_builtins.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/*===-- int128_builtins.cpp - Implement __muloti4 --------------------------===
- *
- * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- * See https://llvm.org/LICENSE.txt for license information.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- *
- * ===----------------------------------------------------------------------===
- *
- * This file implements __muloti4, and is stolen from the compiler_rt library.
- *
- * FIXME: we steal and re-compile it into filesystem, which uses __int128_t,
- * and requires this builtin when sanitized. See llvm.org/PR30643
- *
- * ===----------------------------------------------------------------------===
- */
-#include "__config"
-#include "climits"
-
-#if !defined(_LIBCPP_HAS_NO_INT128)
-
-extern "C" __attribute__((no_sanitize("undefined"))) _LIBCPP_FUNC_VIS
-__int128_t __muloti4(__int128_t a, __int128_t b, int* overflow) {
- const int N = (int)(sizeof(__int128_t) * CHAR_BIT);
- const __int128_t MIN = (__int128_t)1 << (N - 1);
- const __int128_t MAX = ~MIN;
- *overflow = 0;
- __int128_t result = a * b;
- if (a == MIN) {
- if (b != 0 && b != 1)
- *overflow = 1;
- return result;
- }
- if (b == MIN) {
- if (a != 0 && a != 1)
- *overflow = 1;
- return result;
- }
- __int128_t sa = a >> (N - 1);
- __int128_t abs_a = (a ^ sa) - sa;
- __int128_t sb = b >> (N - 1);
- __int128_t abs_b = (b ^ sb) - sb;
- if (abs_a < 2 || abs_b < 2)
- return result;
- if (sa == sb) {
- if (abs_a > MAX / abs_b)
- *overflow = 1;
- } else {
- if (abs_a > MIN / -abs_b)
- *overflow = 1;
- }
- return result;
-}
-
-#endif
diff --git a/contrib/libs/cxxsupp/libcxx/src/support/ibm/mbsnrtowcs.cpp b/contrib/libs/cxxsupp/libcxx/src/support/ibm/mbsnrtowcs.cpp
deleted file mode 100644
index d7220fb46d8..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/support/ibm/mbsnrtowcs.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include <cstddef> // size_t
-#include <cwchar> // mbstate_t
-#include <limits.h> // MB_LEN_MAX
-#include <string.h> // wmemcpy
-
-// Returns the number of wide characters found in the multi byte sequence `src`
-// (of `src_size_bytes`), that fit in the buffer `dst` (of `max_dest_chars`
-// elements size). The count returned excludes the null terminator.
-// When `dst` is NULL, no characters are copied to `dst`.
-// Returns (size_t) -1 when an invalid sequence is encountered.
-// Leaves *`src` pointing to the next character to convert or NULL
-// if a null character was converted from *`src`.
-_LIBCPP_FUNC_VIS
-size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
- size_t src_size_bytes, size_t max_dest_chars,
- mbstate_t *__restrict ps) {
- const size_t terminated_sequence = static_cast<size_t>(0);
- const size_t invalid_sequence = static_cast<size_t>(-1);
- const size_t incomplete_sequence = static_cast<size_t>(-2);
-
- size_t source_converted;
- size_t dest_converted;
- size_t result = 0;
-
- // If `dst` is null then `max_dest_chars` should be ignored according to the
- // standard. Setting `max_dest_chars` to a large value has this effect.
- if (dst == nullptr)
- max_dest_chars = static_cast<size_t>(-1);
-
- for (dest_converted = source_converted = 0;
- source_converted < src_size_bytes && (!dst || dest_converted < max_dest_chars);
- ++dest_converted, source_converted += result) {
- // Converts one multi byte character.
- // If result (char_size) is greater than 0, it's the size in bytes of that character.
- // If result (char_size) is zero, it indicates that the null character has been found.
- // Otherwise, it's an error and errno may be set.
- size_t source_remaining = src_size_bytes - source_converted;
- size_t dest_remaining = max_dest_chars - dest_converted;
-
- if (dst == nullptr) {
- result = mbrtowc(NULL, *src + source_converted, source_remaining, ps);
- } else if (dest_remaining >= source_remaining) {
- // dst has enough space to translate in-place.
- result = mbrtowc(dst + dest_converted, *src + source_converted, source_remaining, ps);
- } else {
- /*
- * dst may not have enough space, so use a temporary buffer.
- *
- * We need to save a copy of the conversion state
- * here so we can restore it if the multibyte
- * character is too long for the buffer.
- */
- wchar_t buff[MB_LEN_MAX];
- mbstate_t mbstate_tmp;
-
- if (ps != nullptr)
- mbstate_tmp = *ps;
- result = mbrtowc(buff, *src + source_converted, source_remaining, ps);
-
- if (result > dest_remaining) {
- // Multi-byte sequence for character won't fit.
- if (ps != nullptr)
- *ps = mbstate_tmp;
- break;
- } else {
- // The buffer was used, so we need copy the translation to dst.
- wmemcpy(dst, buff, result);
- }
- }
-
- // Don't do anything to change errno from here on.
- if (result == invalid_sequence || result == terminated_sequence || result == incomplete_sequence) {
- break;
- }
- }
-
- if (dst) {
- if (result == terminated_sequence)
- *src = NULL;
- else
- *src += source_converted;
- }
- if (result == invalid_sequence)
- return invalid_sequence;
-
- return dest_converted;
-}
diff --git a/contrib/libs/cxxsupp/libcxx/src/support/ibm/wcsnrtombs.cpp b/contrib/libs/cxxsupp/libcxx/src/support/ibm/wcsnrtombs.cpp
deleted file mode 100644
index 66395bfdcb2..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/support/ibm/wcsnrtombs.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include <cwchar> // mbstate_t
-#include <limits.h> // MB_LEN_MAX
-#include <stdlib.h> // MB_CUR_MAX, size_t
-#include <string.h> // memcpy
-
-// Converts `max_source_chars` from the wide character buffer pointer to by *`src`,
-// into the multi byte character sequence buffer stored at `dst`, which must be
-// `dst_size_bytes` bytes in size. Returns the number of bytes in the sequence
-// converted from *src, excluding the null terminator.
-// Returns (size_t) -1 if an error occurs and sets errno.
-// If `dst` is NULL, `dst_size_bytes` is ignored and no bytes are copied to `dst`.
-_LIBCPP_FUNC_VIS
-size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
- size_t max_source_chars, size_t dst_size_bytes,
- mbstate_t *__restrict ps) {
-
- const size_t invalid_wchar = static_cast<size_t>(-1);
-
- size_t source_converted;
- size_t dest_converted;
- size_t result = 0;
-
- // If `dst` is null then `dst_size_bytes` should be ignored according to the
- // standard. Setting dst_size_bytes to a large value has this effect.
- if (dst == nullptr)
- dst_size_bytes = static_cast<size_t>(-1);
-
- for (dest_converted = source_converted = 0;
- source_converted < max_source_chars && (!dst || dest_converted < dst_size_bytes);
- ++source_converted, dest_converted += result) {
- wchar_t c = (*src)[source_converted];
- size_t dest_remaining = dst_size_bytes - dest_converted;
-
- if (dst == nullptr) {
- result = wcrtomb(NULL, c, ps);
- } else if (dest_remaining >= static_cast<size_t>(MB_CUR_MAX)) {
- // dst has enough space to translate in-place.
- result = wcrtomb(dst + dest_converted, c, ps);
- } else {
- /*
- * dst may not have enough space, so use a temporary buffer.
- *
- * We need to save a copy of the conversion state
- * here so we can restore it if the multibyte
- * character is too long for the buffer.
- */
- char buff[MB_LEN_MAX];
- mbstate_t mbstate_tmp;
-
- if (ps != nullptr)
- mbstate_tmp = *ps;
- result = wcrtomb(buff, c, ps);
-
- if (result > dest_remaining) {
- // Multi-byte sequence for character won't fit.
- if (ps != nullptr)
- *ps = mbstate_tmp;
- if (result != invalid_wchar)
- break;
- } else {
- // The buffer was used, so we need copy the translation to dst.
- memcpy(dst, buff, result);
- }
- }
-
- // result (char_size) contains the size of the multi-byte-sequence converted.
- // Otherwise, result (char_size) is (size_t) -1 and wcrtomb() sets the errno.
- if (result == invalid_wchar) {
- if (dst)
- *src = *src + source_converted;
- return invalid_wchar;
- }
-
- if (c == L'\0') {
- if (dst)
- *src = NULL;
- return dest_converted;
- }
- }
-
- if (dst)
- *src = *src + source_converted;
-
- return dest_converted;
-}
diff --git a/contrib/libs/cxxsupp/libcxx/src/support/ibm/xlocale_zos.cpp b/contrib/libs/cxxsupp/libcxx/src/support/ibm/xlocale_zos.cpp
deleted file mode 100644
index 90c1ba95a31..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/support/ibm/xlocale_zos.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include <__support/ibm/xlocale.h>
-#include <sstream>
-#include <vector>
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-locale_t newlocale(int category_mask, const char* locale, locale_t base) {
- // Maintain current locale name(s) to restore later.
- std::string current_loc_name(setlocale(LC_ALL, 0));
-
- // Check for errors.
- if (category_mask == LC_ALL_MASK && setlocale(LC_ALL, locale) == NULL) {
- errno = EINVAL;
- return (locale_t)0;
- } else {
- for (int _Cat = 0; _Cat <= _LC_MAX; ++_Cat) {
- if ((_CATMASK(_Cat) & category_mask) != 0 && setlocale(_Cat, locale) == NULL) {
- setlocale(LC_ALL, current_loc_name.c_str());
- errno = EINVAL;
- return (locale_t)0;
- }
- }
- }
-
- // Create new locale.
- locale_t newloc = new locale_struct();
-
- if (base) {
- if (category_mask != LC_ALL_MASK) {
- // Copy base when it will not be overwritten.
- memcpy(newloc, base, sizeof (locale_struct));
- newloc->category_mask = category_mask | base->category_mask;
- }
- delete base;
- } else {
- newloc->category_mask = category_mask;
- }
-
- if (category_mask & LC_COLLATE_MASK)
- newloc->lc_collate = locale;
- if (category_mask & LC_CTYPE_MASK)
- newloc->lc_ctype = locale;
- if (category_mask & LC_MONETARY_MASK)
- newloc->lc_monetary = locale;
- if (category_mask & LC_NUMERIC_MASK)
- newloc->lc_numeric = locale;
- if (category_mask & LC_TIME_MASK)
- newloc->lc_time = locale;
- if (category_mask & LC_MESSAGES_MASK)
- newloc->lc_messages = locale;
-
- // Restore current locale.
- setlocale(LC_ALL, current_loc_name.c_str());
- return (locale_t)newloc;
-}
-
-void freelocale(locale_t locobj) {
- delete locobj;
-}
-
-locale_t uselocale(locale_t newloc) {
- // Maintain current locale name(s).
- std::string current_loc_name(setlocale(LC_ALL, 0));
-
- if (newloc) {
- // Set locales and check for errors.
- bool is_error =
- (newloc->category_mask & LC_COLLATE_MASK &&
- setlocale(LC_COLLATE, newloc->lc_collate.c_str()) == NULL) ||
- (newloc->category_mask & LC_CTYPE_MASK &&
- setlocale(LC_CTYPE, newloc->lc_ctype.c_str()) == NULL) ||
- (newloc->category_mask & LC_MONETARY_MASK &&
- setlocale(LC_MONETARY, newloc->lc_monetary.c_str()) == NULL) ||
- (newloc->category_mask & LC_NUMERIC_MASK &&
- setlocale(LC_NUMERIC, newloc->lc_numeric.c_str()) == NULL) ||
- (newloc->category_mask & LC_TIME_MASK &&
- setlocale(LC_TIME, newloc->lc_time.c_str()) == NULL) ||
- (newloc->category_mask & LC_MESSAGES_MASK &&
- setlocale(LC_MESSAGES, newloc->lc_messages.c_str()) == NULL);
-
- if (is_error) {
- setlocale(LC_ALL, current_loc_name.c_str());
- errno = EINVAL;
- return (locale_t)0;
- }
- }
-
- // Construct and return previous locale.
- locale_t previous_loc = new locale_struct();
-
- // current_loc_name might be a comma-separated locale name list.
- if (current_loc_name.find(',') != std::string::npos) {
- // Tokenize locale name list.
- const char delimiter = ',';
- std::vector<std::string> tokenized;
- std::stringstream ss(current_loc_name);
- std::string s;
-
- while (std::getline(ss, s, delimiter)) {
- tokenized.push_back(s);
- }
-
- _LIBCPP_ASSERT(tokenized.size() >= _NCAT, "locale-name list is too short");
-
- previous_loc->lc_collate = tokenized[LC_COLLATE];
- previous_loc->lc_ctype = tokenized[LC_CTYPE];
- previous_loc->lc_monetary = tokenized[LC_MONETARY];
- previous_loc->lc_numeric = tokenized[LC_NUMERIC];
- previous_loc->lc_time = tokenized[LC_TIME];
- // Skip LC_TOD.
- previous_loc->lc_messages = tokenized[LC_MESSAGES];
- } else {
- previous_loc->lc_collate = current_loc_name;
- previous_loc->lc_ctype = current_loc_name;
- previous_loc->lc_monetary = current_loc_name;
- previous_loc->lc_numeric = current_loc_name;
- previous_loc->lc_time = current_loc_name;
- previous_loc->lc_messages = current_loc_name;
- }
-
- previous_loc->category_mask = LC_ALL_MASK;
- return previous_loc;
-}
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
diff --git a/contrib/libs/cxxsupp/libcxx/src/support/solaris/mbsnrtowcs.inc b/contrib/libs/cxxsupp/libcxx/src/support/solaris/mbsnrtowcs.inc
deleted file mode 100644
index 074045277ca..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/support/solaris/mbsnrtowcs.inc
+++ /dev/null
@@ -1,76 +0,0 @@
-
-
-/*-
- * As noted in the source, some portions of this implementation are copied from
- * FreeBSD libc. These are covered by the following copyright:
- *
- * Copyright (c) 2002-2004 Tim J. Robbins.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-size_t
-mbsnrtowcs_l(wchar_t * __restrict dst, const char ** __restrict src,
- size_t nms, size_t len, mbstate_t * __restrict ps, locale_t loc)
-{
- const char *s;
- size_t nchr;
- wchar_t wc;
- size_t nb;
- FIX_LOCALE(loc);
-
- s = *src;
- nchr = 0;
-
- if (dst == NULL) {
- for (;;) {
- if ((nb = mbrtowc_l(&wc, s, nms, ps, loc)) == (size_t)-1)
- /* Invalid sequence - mbrtowc() sets errno. */
- return ((size_t)-1);
- else if (nb == 0 || nb == (size_t)-2)
- return (nchr);
- s += nb;
- nms -= nb;
- nchr++;
- }
- /*NOTREACHED*/
- }
-
- while (len-- > 0) {
- if ((nb = mbrtowc_l(dst, s, nms, ps, loc)) == (size_t)-1) {
- *src = s;
- return ((size_t)-1);
- } else if (nb == (size_t)-2) {
- *src = s + nms;
- return (nchr);
- } else if (nb == 0) {
- *src = NULL;
- return (nchr);
- }
- s += nb;
- nms -= nb;
- nchr++;
- dst++;
- }
- *src = s;
- return (nchr);
-}
diff --git a/contrib/libs/cxxsupp/libcxx/src/support/solaris/wcsnrtombs.inc b/contrib/libs/cxxsupp/libcxx/src/support/solaris/wcsnrtombs.inc
deleted file mode 100644
index 239079e4719..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/support/solaris/wcsnrtombs.inc
+++ /dev/null
@@ -1,92 +0,0 @@
-/*-
- * Copyright (c) 2002-2004 Tim J. Robbins.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-
-size_t
-wcsnrtombs_l(char * __restrict dst, const wchar_t ** __restrict src,
- size_t nwc, size_t len, mbstate_t * __restrict ps, locale_t loc)
-{
- FIX_LOCALE(loc);
- mbstate_t mbsbak;
- char buf[MB_CUR_MAX_L(loc)];
- const wchar_t *s;
- size_t nbytes;
- size_t nb;
-
- s = *src;
- nbytes = 0;
-
- if (dst == NULL) {
- while (nwc-- > 0) {
- if ((nb = wcrtomb_l(buf, *s, ps, loc)) == (size_t)-1)
- /* Invalid character - wcrtomb() sets errno. */
- return ((size_t)-1);
- else if (*s == L'\0')
- return (nbytes + nb - 1);
- s++;
- nbytes += nb;
- }
- return (nbytes);
- }
-
- while (len > 0 && nwc-- > 0) {
- if (len > (size_t)MB_CUR_MAX_L(loc)) {
- /* Enough space to translate in-place. */
- if ((nb = wcrtomb_l(dst, *s, ps, loc)) == (size_t)-1) {
- *src = s;
- return ((size_t)-1);
- }
- } else {
- /*
- * May not be enough space; use temp. buffer.
- *
- * We need to save a copy of the conversion state
- * here so we can restore it if the multibyte
- * character is too long for the buffer.
- */
- mbsbak = *ps;
- if ((nb = wcrtomb_l(buf, *s, ps, loc)) == (size_t)-1) {
- *src = s;
- return ((size_t)-1);
- }
- if (nb > (int)len) {
- /* MB sequence for character won't fit. */
- *ps = mbsbak;
- break;
- }
- memcpy(dst, buf, nb);
- }
- if (*s == L'\0') {
- *src = NULL;
- return (nbytes + nb - 1);
- }
- s++;
- dst += nb;
- len -= nb;
- nbytes += nb;
- }
- *src = s;
- return (nbytes);
-}
diff --git a/contrib/libs/cxxsupp/libcxx/src/support/solaris/xlocale.cpp b/contrib/libs/cxxsupp/libcxx/src/support/solaris/xlocale.cpp
deleted file mode 100644
index d25adcd21d3..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/support/solaris/xlocale.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifdef __sun__
-
-#include "__support/solaris/xlocale.h"
-#include <stdarg.h>
-#include <stdio.h>
-#include <sys/localedef.h>
-
-extern "C" {
-
-int isxdigit_l(int __c, locale_t __l) {
- return isxdigit(__c);
-}
-
-int iswxdigit_l(wint_t __c, locale_t __l) {
- return isxdigit(__c);
-}
-
-// FIXME: This disregards the locale, which is Very Wrong
-#define vsnprintf_l(__s, __n, __l, __format, __va) \
- vsnprintf(__s, __n, __format, __va)
-
-int snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...)
-{
- va_list __va;
- va_start(__va, __format);
- int __res = vsnprintf_l(__s, __n , __l, __format, __va);
- va_end(__va);
- return __res;
-}
-
-int asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
- va_list __va;
- va_start(__va, __format);
- // FIXME:
- int __res = vasprintf(__s, __format, __va);
- va_end(__va);
- return __res;
-}
-
-int sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
- va_list __va;
- va_start(__va, __format);
- // FIXME:
- int __res = vsscanf(__s, __format, __va);
- va_end(__va);
- return __res;
-}
-
-size_t mbrtowc_l(wchar_t *__pwc, const char *__pmb,
- size_t __max, mbstate_t *__ps, locale_t __loc) {
- return mbrtowc(__pwc, __pmb, __max, __ps);
-}
-
-struct lconv *localeconv_l(locale_t __l) {
- return localeconv();
-}
-
-};
-
-#endif // __sun__
diff --git a/contrib/libs/cxxsupp/libcxx/src/support/win32/atomic_win32.cpp b/contrib/libs/cxxsupp/libcxx/src/support/win32/atomic_win32.cpp
deleted file mode 100644
index 28cb0722ce7..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/support/win32/atomic_win32.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <intrin.h>
-#include <cstdint>
-
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-namespace {
-static const int __msvc_locks_size = 1024;
-volatile long __msvc_locks[__msvc_locks_size];
-
-size_t __msvc_lock_hash(void* __p) {
- uintptr_t __num = reinterpret_cast<uintptr_t>(__p);
- return (__num ^ (__num >> 10)) & (__msvc_locks_size - 1);
-}
-}
-
-void __msvc_lock(void* __p) {
- volatile long& __lock = __msvc_locks[__msvc_lock_hash(__p)];
- while (_InterlockedExchange(&__lock, 1) == 0) {
-#if defined(_M_ARM) || defined(_M_ARM64)
- __yield();
-#endif
- }
-}
-
-void __msvc_unlock(void* __p) {
- volatile long& __lock = __msvc_locks[__msvc_lock_hash(__p)];
- _InterlockedExchange(&__lock, 0);
-}
-
-_LIBCPP_END_NAMESPACE_STD \ No newline at end of file
diff --git a/contrib/libs/cxxsupp/libcxx/src/support/win32/locale_win32.cpp b/contrib/libs/cxxsupp/libcxx/src/support/win32/locale_win32.cpp
deleted file mode 100644
index 67f4d1341ab..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/support/win32/locale_win32.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include <locale>
-#include <cstdarg> // va_start, va_end
-#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
-locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
-{
- return {_create_locale( LC_ALL, locale ), locale};
-}
-
-decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
-{
-#if defined(_LIBCPP_MSVCRT)
- return ___mb_cur_max_l_func(__l);
-#else
- __libcpp_locale_guard __current(__l);
- return MB_CUR_MAX;
-#endif
-}
-
-lconv *localeconv_l( locale_t &loc )
-{
- __libcpp_locale_guard __current(loc);
- lconv *lc = localeconv();
- if (!lc)
- return lc;
- return loc.__store_lconv(lc);
-}
-size_t mbrlen_l( const char *__restrict s, size_t n,
- mbstate_t *__restrict ps, locale_t loc )
-{
- __libcpp_locale_guard __current(loc);
- return mbrlen( s, n, ps );
-}
-size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
- size_t len, mbstate_t *__restrict ps, locale_t loc )
-{
- __libcpp_locale_guard __current(loc);
- return mbsrtowcs( dst, src, len, ps );
-}
-size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps,
- locale_t loc )
-{
- __libcpp_locale_guard __current(loc);
- return wcrtomb( s, wc, ps );
-}
-size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s,
- size_t n, mbstate_t *__restrict ps, locale_t loc )
-{
- __libcpp_locale_guard __current(loc);
- return mbrtowc( pwc, s, n, ps );
-}
-size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
- size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc )
-{
- __libcpp_locale_guard __current(loc);
- return mbsnrtowcs( dst, src, nms, len, ps );
-}
-size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src,
- size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc )
-{
- __libcpp_locale_guard __current(loc);
- return wcsnrtombs( dst, src, nwc, len, ps );
-}
-wint_t btowc_l( int c, locale_t loc )
-{
- __libcpp_locale_guard __current(loc);
- return btowc( c );
-}
-int wctob_l( wint_t c, locale_t loc )
-{
- __libcpp_locale_guard __current(loc);
- return wctob( c );
-}
-
-int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...)
-{
- va_list ap;
- va_start( ap, format );
-#if defined(_LIBCPP_MSVCRT)
- // FIXME: Remove usage of internal CRT function and globals.
- int result = __stdio_common_vsprintf(
- _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR,
- ret, n, format, loc, ap);
-#else
- __libcpp_locale_guard __current(loc);
- _LIBCPP_DIAGNOSTIC_PUSH
- _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
- int result = vsnprintf( ret, n, format, ap );
- _LIBCPP_DIAGNOSTIC_POP
-#endif
- va_end(ap);
- return result;
-}
-
-int asprintf_l( char **ret, locale_t loc, const char *format, ... )
-{
- va_list ap;
- va_start( ap, format );
- int result = vasprintf_l( ret, loc, format, ap );
- va_end(ap);
- return result;
-}
-int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap )
-{
- __libcpp_locale_guard __current(loc);
- return __libcpp_vasprintf( ret, format, ap );
-}
-
-#if !defined(_LIBCPP_MSVCRT)
-float strtof_l(const char* nptr, char** endptr, locale_t loc) {
- __libcpp_locale_guard __current(loc);
- return strtof(nptr, endptr);
-}
-
-long double strtold_l(const char* nptr, char** endptr, locale_t loc) {
- __libcpp_locale_guard __current(loc);
- return strtold(nptr, endptr);
-}
-#endif
-
-#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
-size_t strftime_l(char *ret, size_t n, const char *format, const struct tm *tm,
- locale_t loc) {
- __libcpp_locale_guard __current(loc);
- return strftime(ret, n, format, tm);
-}
-#endif
diff --git a/contrib/libs/cxxsupp/libcxx/src/support/win32/new_win32.cpp b/contrib/libs/cxxsupp/libcxx/src/support/win32/new_win32.cpp
deleted file mode 100644
index 00eff4abf9d..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/support/win32/new_win32.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <atomic>
-#include <new>
-
-namespace std {
-
-void
-__throw_bad_alloc()
-{
-#ifndef _LIBCPP_NO_EXCEPTIONS
- throw bad_alloc();
-#endif
-}
-
-static std::atomic<std::new_handler> __new_handler;
-
-new_handler
-set_new_handler(new_handler handler) _NOEXCEPT
-{
- return __new_handler.exchange(handler);
-}
-
-new_handler
-get_new_handler() _NOEXCEPT
-{
- return __new_handler.load();
-}
-
-} \ No newline at end of file
diff --git a/contrib/libs/cxxsupp/libcxx/src/support/win32/support.cpp b/contrib/libs/cxxsupp/libcxx/src/support/win32/support.cpp
deleted file mode 100644
index dbec4083cba..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/support/win32/support.cpp
+++ /dev/null
@@ -1,172 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include <cstdarg> // va_start, va_end
-#include <cstddef> // size_t
-#include <cstdlib> // malloc
-#include <cstdio> // vsprintf, vsnprintf
-#include <cstring> // strcpy, wcsncpy
-#include <cwchar> // mbstate_t
-
-
-// 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 __libcpp_vasprintf( char **sptr, const char *__restrict format, va_list ap )
-{
- *sptr = NULL;
- // Query the count required.
- va_list ap_copy;
- va_copy(ap_copy, ap);
- _LIBCPP_DIAGNOSTIC_PUSH
- _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
- int count = vsnprintf( NULL, 0, format, ap_copy );
- _LIBCPP_DIAGNOSTIC_POP
- va_end(ap_copy);
- if (count < 0)
- return count;
- size_t buffer_size = static_cast<size_t>(count) + 1;
- char* p = static_cast<char*>(malloc(buffer_size));
- if ( ! p )
- return -1;
- // If we haven't used exactly what was required, something is wrong.
- // Maybe bug in vsnprintf. Report the error and return.
- _LIBCPP_DIAGNOSTIC_PUSH
- _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
- if (vsnprintf(p, buffer_size, format, ap) != count) {
- _LIBCPP_DIAGNOSTIC_POP
- free(p);
- return -1;
- }
- // All good. This is returning memory to the caller not freeing it.
- *sptr = p;
- return count;
-}
-
-// Returns >= 0: the number of wide characters found in the
-// multi byte sequence src (of src_size_bytes), that fit in the buffer dst
-// (of max_dest_chars elements size). The count returned excludes the
-// null terminator. When dst is NULL, no characters are copied
-// and no "out" parameters are updated.
-// Returns (size_t) -1: an incomplete sequence encountered.
-// Leaves *src pointing the next character to convert or NULL
-// if a null character was converted from *src.
-size_t mbsnrtowcs( wchar_t *__restrict dst, const char **__restrict src,
- size_t src_size_bytes, size_t max_dest_chars, mbstate_t *__restrict ps )
-{
- const size_t terminated_sequence = static_cast<size_t>(0);
- //const size_t invalid_sequence = static_cast<size_t>(-1);
- const size_t incomplete_sequence = static_cast< size_t>(-2);
-
- size_t dest_converted = 0;
- size_t source_converted = 0;
- size_t source_remaining = src_size_bytes;
- size_t result = 0;
- bool have_result = false;
-
- // If dst is null then max_dest_chars should be ignored according to the
- // standard. Setting max_dest_chars to a large value has this effect.
- if (!dst)
- max_dest_chars = static_cast<size_t>(-1);
-
- while ( source_remaining ) {
- if ( dst && dest_converted >= max_dest_chars )
- break;
- // Converts one multi byte character.
- // if result > 0, it's the size in bytes of that character.
- // othewise if result is zero it indicates the null character has been found.
- // otherwise it's an error and errno may be set.
- size_t char_size = mbrtowc( dst ? dst + dest_converted : NULL, *src + source_converted, source_remaining, ps );
- // Don't do anything to change errno from here on.
- if ( char_size > 0 ) {
- source_remaining -= char_size;
- source_converted += char_size;
- ++dest_converted;
- continue;
- }
- result = char_size;
- have_result = true;
- break;
- }
- if ( dst ) {
- if ( have_result && result == terminated_sequence )
- *src = NULL;
- else
- *src += source_converted;
- }
- if ( have_result && result != terminated_sequence && result != incomplete_sequence )
- return static_cast<size_t>(-1);
-
- return dest_converted;
-}
-
-// Converts max_source_chars from the wide character buffer pointer to by *src,
-// into the multi byte character sequence buffer stored at dst which must be
-// dst_size_bytes bytes in size.
-// Returns >= 0: the number of bytes in the sequence
-// converted from *src, excluding the null terminator.
-// Returns size_t(-1) if an error occurs, also sets errno.
-// If dst is NULL dst_size_bytes is ignored and no bytes are copied to dst
-// and no "out" parameters are updated.
-size_t wcsnrtombs( char *__restrict dst, const wchar_t **__restrict src,
- size_t max_source_chars, size_t dst_size_bytes, mbstate_t *__restrict ps )
-{
- //const size_t invalid_sequence = static_cast<size_t>(-1);
-
- size_t source_converted = 0;
- size_t dest_converted = 0;
- size_t dest_remaining = dst_size_bytes;
- size_t char_size = 0;
- const errno_t no_error = ( errno_t) 0;
- errno_t result = ( errno_t ) 0;
- bool have_result = false;
- bool terminator_found = false;
-
- // If dst is null then dst_size_bytes should be ignored according to the
- // standard. Setting dest_remaining to a large value has this effect.
- if (!dst)
- dest_remaining = static_cast<size_t>(-1);
-
- while ( source_converted != max_source_chars ) {
- if ( ! dest_remaining )
- break;
- wchar_t c = (*src)[source_converted];
- if ( dst )
- result = wcrtomb_s( &char_size, dst + dest_converted, dest_remaining, c, ps);
- else
- result = wcrtomb_s( &char_size, NULL, 0, c, ps);
- // If result is zero there is no error and char_size contains the
- // size of the multi-byte-sequence converted.
- // Otherwise result indicates an errno type error.
- if ( result == no_error ) {
- if ( c == L'\0' ) {
- terminator_found = true;
- break;
- }
- ++source_converted;
- if ( dst )
- dest_remaining -= char_size;
- dest_converted += char_size;
- continue;
- }
- have_result = true;
- break;
- }
- if ( dst ) {
- if ( terminator_found )
- *src = NULL;
- else
- *src = *src + source_converted;
- }
- if ( have_result && result != no_error ) {
- errno = result;
- return static_cast<size_t>(-1);
- }
-
- return dest_converted;
-}
diff --git a/contrib/libs/cxxsupp/libcxx/src/support/win32/thread_win32.cpp b/contrib/libs/cxxsupp/libcxx/src/support/win32/thread_win32.cpp
deleted file mode 100644
index f2072b14356..00000000000
--- a/contrib/libs/cxxsupp/libcxx/src/support/win32/thread_win32.cpp
+++ /dev/null
@@ -1,274 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include <__threading_support>
-#define NOMINMAX
-#define WIN32_LEAN_AND_MEAN
-#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,
- __libcpp_timespec_t *__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)
-{
- // round-up to the nearest millisecond
- chrono::milliseconds __ms = chrono::ceil<chrono::milliseconds>(__ns);
- // 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