1 // Copyright 2019 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_EXECUTION_POINTER_AUTHENTICATION_H_
6 #define V8_EXECUTION_POINTER_AUTHENTICATION_H_
7 
8 #include "include/v8-internal.h"
9 #include "src/base/macros.h"
10 #include "src/common/globals.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class PointerAuthentication : public AllStatic {
16  public:
17   // When CFI is enabled, authenticate the address stored in {pc_address} and
18   // return the authenticated address. {offset_from_sp} is the offset between
19   // {pc_address} and the pointer used as a context for signing.
20   // When CFI is not enabled, simply load return address from {pc_address} and
21   // return it.
22   V8_INLINE static Address AuthenticatePC(Address* pc_address,
23                                           unsigned offset_from_sp);
24 
25   // When CFI is enabled, strip Pointer Authentication Code (PAC) from {pc} and
26   // return the raw value.
27   // When CFI is not enabled, return {pc} unmodified.
28   V8_INLINE static Address StripPAC(Address pc);
29 
30   // When CFI is enabled, authenticate the address stored in {pc_address} and
31   // replace it with {new_pc}, after signing it. {offset_from_sp} is the offset
32   // between {pc_address} and the pointer used as a context for signing.
33   // When CFI is not enabled, store {new_pc} to {pc_address} without signing.
34   V8_INLINE static void ReplacePC(Address* pc_address, Address new_pc,
35                                   int offset_from_sp);
36 
37   // When CFI is enabled, sign {pc} using {sp}, check the address and return the
38   // signed value. When CFI is not enabled, return {pc} unmodified. This method
39   // only applies in the deoptimizer.
40   V8_INLINE static Address SignAndCheckPC(Address pc, Address sp);
41 };
42 
43 }  // namespace internal
44 }  // namespace v8
45 
46 #ifdef V8_ENABLE_CONTROL_FLOW_INTEGRITY
47 
48 #ifndef V8_TARGET_ARCH_ARM64
49 #error "V8_ENABLE_CONTROL_FLOW_INTEGRITY should imply V8_TARGET_ARCH_ARM64"
50 #endif
51 #include "src/execution/arm64/pointer-authentication-arm64.h"
52 
53 #else
54 
55 #include "src/execution/pointer-authentication-dummy.h"
56 
57 #endif
58 
59 #endif  // V8_EXECUTION_POINTER_AUTHENTICATION_H_
60