11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_SANDBOX_EXTERNAL_POINTER_H_
61cb0ef41Sopenharmony_ci#define V8_SANDBOX_EXTERNAL_POINTER_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/common/globals.h"
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cinamespace v8 {
111cb0ef41Sopenharmony_cinamespace internal {
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci// Convert external pointer from on-V8-heap representation to an actual external
141cb0ef41Sopenharmony_ci// pointer value.
151cb0ef41Sopenharmony_ciV8_INLINE Address DecodeExternalPointer(const Isolate* isolate,
161cb0ef41Sopenharmony_ci                                        ExternalPointer_t encoded_pointer,
171cb0ef41Sopenharmony_ci                                        ExternalPointerTag tag);
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciconstexpr ExternalPointer_t kNullExternalPointer = 0;
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci// Creates zero-initialized entry in external pointer table and writes the entry
221cb0ef41Sopenharmony_ci// id to the field. When sandbox is not enabled, it's a no-op.
231cb0ef41Sopenharmony_ciV8_INLINE void InitExternalPointerField(Address field_address, Isolate* isolate,
241cb0ef41Sopenharmony_ci                                        ExternalPointerTag tag);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci// Creates and initializes entry in external pointer table and writes the entry
271cb0ef41Sopenharmony_ci// id to the field.
281cb0ef41Sopenharmony_ci// Basically, it's InitExternalPointerField() followed by
291cb0ef41Sopenharmony_ci// WriteExternalPointerField().
301cb0ef41Sopenharmony_ciV8_INLINE void InitExternalPointerField(Address field_address, Isolate* isolate,
311cb0ef41Sopenharmony_ci                                        Address value, ExternalPointerTag tag);
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci// Reads and returns a raw external pointer value.
341cb0ef41Sopenharmony_ciV8_INLINE ExternalPointer_t ReadRawExternalPointerField(Address field_address);
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci// Reads external pointer for the field, and decodes it if the sandbox is
371cb0ef41Sopenharmony_ci// enabled.
381cb0ef41Sopenharmony_ciV8_INLINE Address ReadExternalPointerField(Address field_address,
391cb0ef41Sopenharmony_ci                                           const Isolate* isolate,
401cb0ef41Sopenharmony_ci                                           ExternalPointerTag tag);
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci// Encodes value if the sandbox is enabled and writes it into the field.
431cb0ef41Sopenharmony_ciV8_INLINE void WriteExternalPointerField(Address field_address,
441cb0ef41Sopenharmony_ci                                         Isolate* isolate, Address value,
451cb0ef41Sopenharmony_ci                                         ExternalPointerTag tag);
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci}  // namespace internal
481cb0ef41Sopenharmony_ci}  // namespace v8
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci#endif  // V8_SANDBOX_EXTERNAL_POINTER_H_
51