external-pointer-inl.h 1.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
// Copyright 2020 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_COMMON_EXTERNAL_POINTER_INL_H_
#define V8_COMMON_EXTERNAL_POINTER_INL_H_

#include "include/v8-internal.h"
#include "src/common/external-pointer.h"
#include "src/execution/isolate.h"

namespace v8 {
namespace internal {

V8_INLINE ExternalPointer_t EncodeExternalPointer(Isolate* isolate,
                                                  Address external_pointer) {
  STATIC_ASSERT(kExternalPointerSize == kSystemPointerSize);
  if (!V8_HEAP_SANDBOX_BOOL) return external_pointer;
  return external_pointer ^ kExternalPointerSalt;
}

V8_INLINE Address DecodeExternalPointer(const Isolate* isolate,
                                        ExternalPointer_t encoded_pointer) {
  STATIC_ASSERT(kExternalPointerSize == kSystemPointerSize);
  if (!V8_HEAP_SANDBOX_BOOL) return encoded_pointer;
  return encoded_pointer ^ kExternalPointerSalt;
}

}  // namespace internal
}  // namespace v8

#endif  // V8_COMMON_EXTERNAL_POINTER_INL_H_