// Copyright 2018 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 V8_OBJECTS_SLOTS_H_ #define V8_OBJECTS_SLOTS_H_ #include "src/base/memory.h" #include "src/common/assert-scope.h" #include "src/common/globals.h" #include "src/sandbox/external-pointer-table.h" #include "src/sandbox/external-pointer.h" #include "src/sandbox/indirect-pointer-tag.h" #include "src/sandbox/isolate.h" namespace v8 { namespace internal { class Object; class ExposedTrustedObject; TaggedBase; template <typename Subclass, typename Data, size_t SlotDataAlignment = sizeof(Data)> class SlotBase { … }; // An FullObjectSlot instance describes a kSystemPointerSize-sized field // ("slot") holding a tagged pointer (smi or strong heap object). // Its address() is the address of the slot. // The slot's contents can be read and written using operator* and store(). class FullObjectSlot : public SlotBase<FullObjectSlot, Address> { … }; // A FullMaybeObjectSlot instance describes a kSystemPointerSize-sized field // ("slot") holding a possibly-weak tagged pointer (think: Tagged<MaybeObject>). // Its address() is the address of the slot. // The slot's contents can be read and written using operator* and store(). class FullMaybeObjectSlot : public SlotBase<FullMaybeObjectSlot, Address, kSystemPointerSize> { … }; // A FullHeapObjectSlot instance describes a kSystemPointerSize-sized field // ("slot") holding a weak or strong pointer to a heap object (think: // Tagged<HeapObjectReference>). // Its address() is the address of the slot. // The slot's contents can be read and written using operator* and store(). // In case it is known that that slot contains a strong heap object pointer, // ToHeapObject() can be used to retrieve that heap object. class FullHeapObjectSlot : public SlotBase<FullHeapObjectSlot, Address> { … }; // TODO(ishell, v8:8875): When pointer compression is enabled the [u]intptr_t // and double fields are only kTaggedSize aligned so in order to avoid undefined // behavior in C++ code we use this iterator adaptor when using STL algorithms // with unaligned pointers. // It will be removed once all v8:8875 is fixed and all the full pointer and // double values in compressed V8 heap are properly aligned. template <typename T> class UnalignedSlot : public SlotBase<UnalignedSlot<T>, T, 1> { … }; // An off-heap uncompressed object slot can be the same as an on-heap one, with // a few methods deleted. class OffHeapFullObjectSlot : public FullObjectSlot { … }; // An ExternalPointerSlot instance describes a kExternalPointerSlotSize-sized // field ("slot") holding a pointer to objects located outside the V8 heap and // V8 sandbox (think: ExternalPointer_t). // It's basically an ExternalPointer_t* but abstracting away the fact that the // pointer might not be kExternalPointerSlotSize-aligned in certain // configurations. Its address() is the address of the slot. class ExternalPointerSlot : public SlotBase<ExternalPointerSlot, ExternalPointer_t, kTaggedSize /* slot alignment */> { … }; // Similar to ExternalPointerSlot with the difference that it refers to an // `CppHeapPointer_t` which has different sizing and alignment than // `ExternalPointer_t`. class CppHeapPointerSlot : public SlotBase<CppHeapPointerSlot, CppHeapPointer_t, /*SlotDataAlignment=*/sizeof(CppHeapPointer_t)> { … }; // An IndirectPointerSlot instance describes a 32-bit field ("slot") containing // an IndirectPointerHandle, i.e. an index to an entry in a pointer table which // contains the "real" pointer to the referenced HeapObject. These slots are // used when the sandbox is enabled to securely reference HeapObjects outside // of the sandbox. class IndirectPointerSlot : public SlotBase<IndirectPointerSlot, IndirectPointerHandle, kTaggedSize /* slot alignment */> { … }; class WritableJitAllocation; template <typename SlotT> class WriteProtectedSlot : public SlotT { … }; } // namespace internal } // namespace v8 #endif // V8_OBJECTS_SLOTS_H_