chromium/v8/src/sandbox/external-buffer-tag.h

// Copyright 2024 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_SANDBOX_EXTERNAL_BUFFER_TAG_H_
#define V8_SANDBOX_EXTERNAL_BUFFER_TAG_H_

#include "src/common/globals.h"

namespace v8 {
namespace internal {

// Defines the list of valid external buffer tags.
//
// When accessing a buffer located outside the V8 sandbox, an ExternalBufferTag
// must be provided which indicates the expected type of the external buffer.
// When the sandbox is enabled, this tag is used to ensure type-safe access to
// the buffer data: if the provided tag doesn't match the tag of the buffer in
// the external buffer table, an inaccessible (external pointer, size) tuple
// will be returned.
//
// We use the AND-based type-checking mechanism in the ExternalBufferTable,
// similar to the one used by the ExternalPointerTable: the entry in the table
// is ORed with the tag and then ANDed with the inverse of the tag upon access.
// This has the benefit that the type check and the removal of the marking bit
// can be folded into a single bitwise operations.

constexpr uint64_t kExternalBufferMarkBit =;
constexpr uint64_t kExternalBufferTagMask =;
constexpr uint64_t kExternalBufferTagMaskWithoutMarkBit =;
constexpr uint64_t kExternalBufferTagShift =;

#define TAG

// clang-format off

// Shared external buffers are owned by the shared Isolate and stored in the
// shared external buffer table associated with that Isolate, where they can
// be accessed from multiple threads at the same time. The objects referenced
// in this way must therefore always be thread-safe.
#define SHARED_EXTERNAL_BUFFER_TAGS(V)

// External buffers using these tags are kept in a per-Isolate external
// buffer table and can only be accessed when this Isolate is active.
#define PER_ISOLATE_EXTERNAL_BUFFER_TAGS(V)

// All external buffer tags.
#define ALL_EXTERNAL_BUFFER_TAGS(V)

#define EXTERNAL_BUFFER_TAG_ENUM
#define MAKE_TAG
enum ExternalBufferTag : uint64_t {};

#undef MAKE_TAG
#undef TAG
#undef EXTERNAL_BUFFER_TAG_ENUM

// clang-format on

// True if the external pointer must be accessed from external buffer table.
V8_INLINE static constexpr bool IsSharedExternalBufferType(
    ExternalBufferTag tag) {}

}  // namespace internal
}  // namespace v8

#endif  // V8_SANDBOX_EXTERNAL_BUFFER_TAG_H_