/src/hermes/lib/Support/OSCompatCommon.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | #include "hermes/Support/OSCompat.h" |
9 | | |
10 | | namespace hermes { |
11 | | namespace oscompat { |
12 | | |
13 | 53 | std::pair<const void *, size_t> thread_stack_bounds(unsigned gap) { |
14 | | // Avoid calling into the platform-specific code if we can cache the result |
15 | | // on a per-thread basis. |
16 | | |
17 | | // The cached result of thread_stack_bounds(). |
18 | 53 | static thread_local std::pair<const void *, size_t> cachedBounds{nullptr, 0}; |
19 | | |
20 | 53 | std::pair<const void *, size_t> bounds = cachedBounds; |
21 | | |
22 | 53 | if (LLVM_UNLIKELY(!bounds.first)) { |
23 | 1 | cachedBounds = bounds = detail::thread_stack_bounds_impl(); |
24 | 1 | } |
25 | | |
26 | | // Adjust for the gap here to allow caching with multiple gaps. |
27 | 53 | auto [high, size] = bounds; |
28 | 53 | return {high, gap < size ? size - gap : 0}; |
29 | 53 | } |
30 | | |
31 | | } // namespace oscompat |
32 | | } // namespace hermes |