1
1
/*
2
- * Copyright (c) 2001, 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2001, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* Copyright (c) 2015, 2019, Red Hat Inc.
4
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
5
*
@@ -70,6 +70,9 @@ public class AARCH64Frame extends Frame {
70
70
// Native frames
71
71
private static final int NATIVE_FRAME_INITIAL_PARAM_OFFSET = 2 ;
72
72
73
+ private static CIntegerField ropProtectionField ;
74
+ private static CIntegerField pacMaskField ;
75
+
73
76
private static VMReg fp = new VMReg (29 << 1 );
74
77
75
78
static {
@@ -90,8 +93,11 @@ private static synchronized void initialize(TypeDataBase db) {
90
93
INTERPRETER_FRAME_INITIAL_SP_OFFSET = INTERPRETER_FRAME_BCX_OFFSET - 1 ;
91
94
INTERPRETER_FRAME_MONITOR_BLOCK_TOP_OFFSET = INTERPRETER_FRAME_INITIAL_SP_OFFSET ;
92
95
INTERPRETER_FRAME_MONITOR_BLOCK_BOTTOM_OFFSET = INTERPRETER_FRAME_INITIAL_SP_OFFSET ;
93
- }
94
96
97
+ Type vmVersion = db .lookupType ("VM_Version" );
98
+ ropProtectionField = vmVersion .getCIntegerField ("_rop_protection" );
99
+ pacMaskField = vmVersion .getCIntegerField ("_pac_mask" );
100
+ }
95
101
96
102
// an additional field beyond sp and pc:
97
103
Address raw_fp ; // frame pointer
@@ -391,7 +397,7 @@ private Frame senderForCompiledFrame(AARCH64RegisterMap map, CodeBlob cb) {
391
397
Address senderSP = getUnextendedSP ().addOffsetTo (cb .getFrameSize ());
392
398
393
399
// The return_address is always the word on the stack
394
- Address senderPC = senderSP .getAddressAt (-1 * VM .getVM ().getAddressSize ());
400
+ Address senderPC = stripPAC ( senderSP .getAddressAt (-1 * VM .getVM ().getAddressSize () ));
395
401
396
402
// This is the saved value of FP which may or may not really be an FP.
397
403
// It is only an FP if the sender is an interpreter frame.
@@ -445,7 +451,19 @@ public Address getLink() {
445
451
446
452
// Return address:
447
453
public Address getSenderPCAddr () { return addressOfStackSlot (RETURN_ADDR_OFFSET ); }
448
- public Address getSenderPC () { return getSenderPCAddr ().getAddressAt (0 ); }
454
+ public Address getSenderPC () { return stripPAC (getSenderPCAddr ().getAddressAt (0 )); }
455
+
456
+ // Remove any embedded pointer authentication code from an address.
457
+ private Address stripPAC (Address addr ) {
458
+ // Really we should use the XPACI instruction to do this but we
459
+ // can't access that from Java so rely on the mask of PAC bits
460
+ // calculated by vm_version_aarch64.cpp on startup.
461
+ if (ropProtectionField .getValue () != 0 ) {
462
+ return addr .andWithMask (pacMaskField .getValue ());
463
+ } else {
464
+ return addr ;
465
+ }
466
+ }
449
467
450
468
// return address of param, zero origin index.
451
469
public Address getNativeParamAddr (int idx ) {
0 commit comments