2022-06-08 15:07:01 +00:00
|
|
|
// Copyright 2022 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_INTERNAL_CAGED_HEAP_H_
|
|
|
|
#define INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_H_
|
|
|
|
|
2022-06-09 09:26:07 +00:00
|
|
|
#include <climits>
|
2022-06-08 15:07:01 +00:00
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
#include "cppgc/internal/api-constants.h"
|
|
|
|
#include "cppgc/internal/base-page-handle.h"
|
|
|
|
#include "v8config.h" // NOLINT(build/include_directory)
|
|
|
|
|
2022-06-08 16:52:00 +00:00
|
|
|
#if defined(CPPGC_CAGED_HEAP)
|
|
|
|
|
2022-06-08 15:07:01 +00:00
|
|
|
namespace cppgc {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class V8_EXPORT CagedHeapBase {
|
|
|
|
public:
|
2022-06-09 09:26:07 +00:00
|
|
|
V8_INLINE static uintptr_t OffsetFromAddress(const void* address) {
|
|
|
|
return reinterpret_cast<uintptr_t>(address) &
|
|
|
|
(api_constants::kCagedHeapReservationAlignment - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
V8_INLINE static bool IsWithinCage(const void* address) {
|
|
|
|
CPPGC_DCHECK(g_heap_base_);
|
|
|
|
return (reinterpret_cast<uintptr_t>(address) &
|
|
|
|
~(api_constants::kCagedHeapReservationAlignment - 1)) ==
|
|
|
|
g_heap_base_;
|
|
|
|
}
|
|
|
|
|
|
|
|
V8_INLINE static bool AreWithinCage(const void* addr1, const void* addr2) {
|
2022-08-30 14:52:38 +00:00
|
|
|
#if defined(CPPGC_2GB_CAGE)
|
2022-08-08 12:14:05 +00:00
|
|
|
static constexpr size_t kHalfWordShift = sizeof(uint32_t) * CHAR_BIT - 1;
|
2022-08-30 14:52:38 +00:00
|
|
|
#else //! defined(CPPGC_2GB_CAGE)
|
|
|
|
static constexpr size_t kHalfWordShift = sizeof(uint32_t) * CHAR_BIT;
|
|
|
|
#endif //! defined(CPPGC_2GB_CAGE)
|
2022-06-09 09:26:07 +00:00
|
|
|
static_assert((static_cast<size_t>(1) << kHalfWordShift) ==
|
|
|
|
api_constants::kCagedHeapReservationSize);
|
|
|
|
CPPGC_DCHECK(g_heap_base_);
|
|
|
|
return !(((reinterpret_cast<uintptr_t>(addr1) ^ g_heap_base_) |
|
|
|
|
(reinterpret_cast<uintptr_t>(addr2) ^ g_heap_base_)) >>
|
|
|
|
kHalfWordShift);
|
|
|
|
}
|
|
|
|
|
|
|
|
V8_INLINE static uintptr_t GetBase() { return g_heap_base_; }
|
|
|
|
|
2022-06-08 15:07:01 +00:00
|
|
|
private:
|
2022-06-09 09:26:07 +00:00
|
|
|
friend class CagedHeap;
|
|
|
|
|
|
|
|
static uintptr_t g_heap_base_;
|
2022-06-08 15:07:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace cppgc
|
|
|
|
|
2022-06-08 16:52:00 +00:00
|
|
|
#endif // defined(CPPGC_CAGED_HEAP)
|
|
|
|
|
2022-06-08 15:07:01 +00:00
|
|
|
#endif // INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_H_
|