• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_SANDBOX_SANDBOXED_POINTER_INL_H_
6 #define V8_SANDBOX_SANDBOXED_POINTER_INL_H_
7 
8 #include "include/v8-internal.h"
9 #include "src/common/ptr-compr.h"
10 #include "src/execution/isolate.h"
11 #include "src/sandbox/sandboxed-pointer.h"
12 
13 namespace v8 {
14 namespace internal {
15 
ReadSandboxedPointerField(Address field_address,PtrComprCageBase cage_base)16 V8_INLINE Address ReadSandboxedPointerField(Address field_address,
17                                             PtrComprCageBase cage_base) {
18 #ifdef V8_SANDBOXED_POINTERS
19   SandboxedPointer_t sandboxed_pointer =
20       base::ReadUnalignedValue<SandboxedPointer_t>(field_address);
21 
22   Address offset = sandboxed_pointer >> kSandboxedPointerShift;
23   Address pointer = cage_base.address() + offset;
24   return pointer;
25 #else
26   return ReadMaybeUnalignedValue<Address>(field_address);
27 #endif
28 }
29 
WriteSandboxedPointerField(Address field_address,PtrComprCageBase cage_base,Address pointer)30 V8_INLINE void WriteSandboxedPointerField(Address field_address,
31                                           PtrComprCageBase cage_base,
32                                           Address pointer) {
33 #ifdef V8_SANDBOXED_POINTERS
34   // The pointer must point into the sandbox.
35   CHECK(GetProcessWideSandbox()->Contains(pointer));
36 
37   Address offset = pointer - cage_base.address();
38   SandboxedPointer_t sandboxed_pointer = offset << kSandboxedPointerShift;
39   base::WriteUnalignedValue<SandboxedPointer_t>(field_address,
40                                                 sandboxed_pointer);
41 #else
42   WriteMaybeUnalignedValue<Address>(field_address, pointer);
43 #endif
44 }
45 
46 }  // namespace internal
47 }  // namespace v8
48 
49 #endif  // V8_SANDBOX_SANDBOXED_POINTER_INL_H_
50