This is a reland of commit ac7c47e253
One wrong DCHECK was fixed.
Original change's description:
> [base,heap] Record thread stack start at thread entry
>
> On Linux, pthread_attr_getstack returns the base and size of the
> thread's entire mmap allocation, where glibc places static TLS and the
> TCB at the top of the region. This causes conservative stack scanning
> on worker threads to scan TLS, leading to false positives and possible
> crashes during heap verification.
>
> This CL:
>
> 1. Introduces and exposes cppgc::StackStartScope (aliased as
> v8::StackStartScope) for embedder threads and uses it in LocalHeap
> for background threads. This will replace cppgc::StackStartMarker in
> follow-up CLs.
> 2. Introduces methods in base::Stack for setting and resetting a custom
> stack start (used at v8::base::Thread entry and by StackStartScope),
> along with Stack::GetEffectiveStackStart which returns the effective
> stack start (overridden or not) for Heap and CppHeap.
> 3. Introduces base::Stack::ValidateStackSegment to check stack segment
> bounds and, when marking verification is enabled, ensure that stack
> segments do not contain TLS data.
>
> Design doc: https://docs.google.com/document/d/10d8E1MlLwSrrII5TuC10HsLCulfWzh02Kouy7W7-6nc
>
> TAG=agy
> CONV=3c50cafd-8b7d-4358-b569-9070d961402f
>
> Bug: 540324230
> Change-Id: I62faeffdcbd0bae0bdd966d8fe35494a33d382df
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8380481
> Commit-Queue: Nikolaos Papaspyrou <nikolaos@chromium.org>
> Reviewed-by: Omer Katz <omerkatz@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#110891}
Bug: 540324230
Bug: 41480448
Change-Id: Ie068fe129eb496a0ea43fcb1f7da78ed9e4b5362
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8605449
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Commit-Queue: Nikolaos Papaspyrou <nikolaos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#110928}
57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef INCLUDE_CPPGC_COMMON_H_
|
|
#define INCLUDE_CPPGC_COMMON_H_
|
|
|
|
#include "cppgc/macros.h"
|
|
#include "v8config.h" // NOLINT(build/include_directory)
|
|
|
|
#if V8_CC_MSVC
|
|
#include <intrin.h> // _AddressOfReturnAddress()
|
|
#endif
|
|
|
|
namespace cppgc {
|
|
|
|
/**
|
|
* Indicator for the stack state of the embedder.
|
|
*/
|
|
enum class EmbedderStackState {
|
|
/**
|
|
* Stack may contain interesting heap pointers.
|
|
*/
|
|
kMayContainHeapPointers,
|
|
/**
|
|
* Stack does not contain any interesting heap pointers.
|
|
*/
|
|
kNoHeapPointers,
|
|
};
|
|
|
|
/**
|
|
* A stack-allocated scope that sets the current thread's stack start address
|
|
* for conservative stack scanning and restores the previous stack start on
|
|
* destruction.
|
|
*/
|
|
class V8_EXPORT V8_NODISCARD StackStartScope final {
|
|
CPPGC_STACK_ALLOCATED();
|
|
|
|
public:
|
|
#if V8_CC_MSVC
|
|
explicit StackStartScope(void* stack_start = _AddressOfReturnAddress());
|
|
#else
|
|
explicit StackStartScope(void* stack_start = __builtin_frame_address(0));
|
|
#endif
|
|
~StackStartScope();
|
|
|
|
StackStartScope(const StackStartScope&) = delete;
|
|
StackStartScope& operator=(const StackStartScope&) = delete;
|
|
|
|
private:
|
|
void* const previous_stack_start_;
|
|
};
|
|
|
|
} // namespace cppgc
|
|
|
|
#endif // INCLUDE_CPPGC_COMMON_H_
|