5#ifndef V8_WASM_WASM_CODE_POINTER_TABLE_INL_H_
6#define V8_WASM_WASM_CODE_POINTER_TABLE_INL_H_
14#if !V8_ENABLE_WEBASSEMBLY
15#error This header should only be included if WebAssembly is enabled.
21 uint64_t signature_hash) {
22 entrypoint_.store(entrypoint, std::memory_order_relaxed);
23#ifdef V8_ENABLE_SANDBOX
24 signature_hash_ = signature_hash;
29 Address entrypoint, uint64_t signature_hash) {
30#ifdef V8_ENABLE_SANDBOX
33 entrypoint_.store(entrypoint, std::memory_order_relaxed);
37 uint64_t signature_hash)
const {
38#ifdef V8_ENABLE_SANDBOX
49 entrypoint_.store(next_entry_index, std::memory_order_relaxed);
50#ifdef V8_ENABLE_SANDBOX
56 return static_cast<uint32_t
>(
entrypoint_.load(std::memory_order_relaxed));
60 uint64_t signature_hash)
const {
61 return at(index.value()).GetEntrypoint(signature_hash);
66 return at(index.value()).GetEntrypointWithoutSignatureCheck();
71 uint64_t signature_hash) {
72 WriteScope write_scope(
"WasmCodePointerTable write");
73 at(index.value()).UpdateCodePointerEntry(value, signature_hash);
78 uint64_t signature_hash) {
79 WriteScope write_scope(
"WasmCodePointerTable write");
80 at(index.value()).MakeCodePointerEntry(value, signature_hash);
86 at(index.value()).MakeCodePointerEntry(value, signature_hash);
90 Address entrypoint, uint64_t signature_hash) {
92 WriteScope write_scope(
"WasmCodePointerTable write");
93 at(index.value()).MakeCodePointerEntry(entrypoint, signature_hash);
99 FreelistHead freelist =
freelist_head_.load(std::memory_order_acquire);
114 uint32_t allocated_entry;
154 if (current_freelist_head.is_empty()) {
161 if (!
freelist_head_.compare_exchange_strong(current_freelist_head,
166 uint32_t next_freelist_entry =
167 at(current_freelist_head.next()).GetNextFreelistEntryIndex();
168 FreelistHead new_freelist_head(next_freelist_entry,
169 current_freelist_head.length() - 1);
173 freelist_head_.store(new_freelist_head, std::memory_order_relaxed);
175 *index = current_freelist_head.next();
182 FreelistHead* freelist_head) {
183 DCHECK(!freelist_head->is_empty());
184 uint32_t index = freelist_head->next();
185 uint32_t next_next =
at(freelist_head->next()).GetNextFreelistEntryIndex();
186 *freelist_head = FreelistHead(next_next, freelist_head->length() - 1);
198 FreelistHead freelist_to_link, uint32_t last_element) {
199 DCHECK(!freelist_to_link.is_empty());
201 FreelistHead current_head, new_head;
204 new_head = FreelistHead(freelist_to_link.next(),
205 freelist_to_link.length() + current_head.length());
207 WriteScope write_scope(
"write free list entry");
208 at(last_element).MakeFreelistEntry(current_head.next());
212 }
while (!
freelist_head_.compare_exchange_strong(current_head, new_head,
213 std::memory_order_release));
#define SBXCHECK_EQ(lhs, rhs)
WasmCodePointerTableEntry & at(uint32_t index)
bool is_initialized() const
std::pair< Segment, FreelistHead > AllocateAndInitializeSegment()
static constexpr FreelistHead kRetryMarker
V8_INLINE FreelistHead LinkFreelist(FreelistHead new_freelist, uint32_t last_element)
static bool IsRetryMarker(FreelistHead freelist)
void UpdateEntrypoint(WasmCodePointer index, Address value, uint64_t signature_hash)
std::atomic< FreelistHead > freelist_head_
Address GetEntrypoint(WasmCodePointer index, uint64_t signature_hash) const
V8_INLINE FreelistHead ReadFreelistHead()
Address GetEntrypointWithoutSignatureCheck(WasmCodePointer index) const
void FreeEntry(WasmCodePointer index)
base::Mutex segment_allocation_mutex_
V8_INLINE bool TryAllocateFromFreelist(uint32_t *index)
void SetEntrypointWithWriteScope(WasmCodePointer index, Address value, uint64_t signature_hash, WriteScope &write_scope)
WasmCodePointer AllocateUninitializedEntry()
void SetEntrypointAndSignature(WasmCodePointer index, Address value, uint64_t signature_hash)
V8_INLINE uint32_t AllocateEntryFromFreelistNonAtomic(FreelistHead *freelist_head)
WasmCodePointer AllocateAndInitializeEntry(Address entrypoint, uint64_t signature_hash)
constexpr uint64_t kInvalidWasmSignatureHash
#define DCHECK(condition)
void UpdateCodePointerEntry(Address entrypoint, uint64_t signature_hash)
void MakeCodePointerEntry(Address entrypoint, uint64_t signature_hash)
std::atomic< Address > entrypoint_
Address GetEntrypoint(uint64_t signature_hash) const
uint32_t GetNextFreelistEntryIndex() const
Address GetEntrypointWithoutSignatureCheck() const
void MakeFreelistEntry(uint32_t next_entry_index)