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