1 // Copyright 2020 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_EXTERNAL_POINTER_H_
6 #define V8_SANDBOX_EXTERNAL_POINTER_H_
7 
8 #include "src/common/globals.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 // Convert external pointer from on-V8-heap representation to an actual external
14 // pointer value.
15 V8_INLINE Address DecodeExternalPointer(const Isolate* isolate,
16                                         ExternalPointer_t encoded_pointer,
17                                         ExternalPointerTag tag);
18 
19 constexpr ExternalPointer_t kNullExternalPointer = 0;
20 
21 // Creates zero-initialized entry in external pointer table and writes the entry
22 // id to the field. When sandbox is not enabled, it's a no-op.
23 V8_INLINE void InitExternalPointerField(Address field_address, Isolate* isolate,
24                                         ExternalPointerTag tag);
25 
26 // Creates and initializes entry in external pointer table and writes the entry
27 // id to the field.
28 // Basically, it's InitExternalPointerField() followed by
29 // WriteExternalPointerField().
30 V8_INLINE void InitExternalPointerField(Address field_address, Isolate* isolate,
31                                         Address value, ExternalPointerTag tag);
32 
33 // Reads and returns a raw external pointer value.
34 V8_INLINE ExternalPointer_t ReadRawExternalPointerField(Address field_address);
35 
36 // Reads external pointer for the field, and decodes it if the sandbox is
37 // enabled.
38 V8_INLINE Address ReadExternalPointerField(Address field_address,
39                                            const Isolate* isolate,
40                                            ExternalPointerTag tag);
41 
42 // Encodes value if the sandbox is enabled and writes it into the field.
43 V8_INLINE void WriteExternalPointerField(Address field_address,
44                                          Isolate* isolate, Address value,
45                                          ExternalPointerTag tag);
46 
47 }  // namespace internal
48 }  // namespace v8
49 
50 #endif  // V8_SANDBOX_EXTERNAL_POINTER_H_
51