2727
2828// clang-format off
2929#include < sys/types.h>
30+ #include < sys/ptrace.h>
3031#include < sys/sysctl.h>
3132#include < sys/time.h>
3233#include < machine/cpu.h>
@@ -37,77 +38,6 @@ using namespace lldb_private::process_openbsd;
3738
3839#define REG_CONTEXT_SIZE (GetGPRSize() + GetFPRSize())
3940
40- // ARM64 general purpose registers.
41- static const uint32_t g_gpr_regnums_arm64[] = {
42- gpr_x0_arm64, gpr_x1_arm64, gpr_x2_arm64, gpr_x3_arm64,
43- gpr_x4_arm64, gpr_x5_arm64, gpr_x6_arm64, gpr_x7_arm64,
44- gpr_x8_arm64, gpr_x9_arm64, gpr_x10_arm64, gpr_x11_arm64,
45- gpr_x12_arm64, gpr_x13_arm64, gpr_x14_arm64, gpr_x15_arm64,
46- gpr_x16_arm64, gpr_x17_arm64, gpr_x18_arm64, gpr_x19_arm64,
47- gpr_x20_arm64, gpr_x21_arm64, gpr_x22_arm64, gpr_x23_arm64,
48- gpr_x24_arm64, gpr_x25_arm64, gpr_x26_arm64, gpr_x27_arm64,
49- gpr_x28_arm64, gpr_fp_arm64, gpr_lr_arm64, gpr_sp_arm64,
50- gpr_pc_arm64, gpr_cpsr_arm64, gpr_w0_arm64, gpr_w1_arm64,
51- gpr_w2_arm64, gpr_w3_arm64, gpr_w4_arm64, gpr_w5_arm64,
52- gpr_w6_arm64, gpr_w7_arm64, gpr_w8_arm64, gpr_w9_arm64,
53- gpr_w10_arm64, gpr_w11_arm64, gpr_w12_arm64, gpr_w13_arm64,
54- gpr_w14_arm64, gpr_w15_arm64, gpr_w16_arm64, gpr_w17_arm64,
55- gpr_w18_arm64, gpr_w19_arm64, gpr_w20_arm64, gpr_w21_arm64,
56- gpr_w22_arm64, gpr_w23_arm64, gpr_w24_arm64, gpr_w25_arm64,
57- gpr_w26_arm64, gpr_w27_arm64, gpr_w28_arm64,
58- LLDB_INVALID_REGNUM // register sets need to end with this flag
59- };
60- static_assert (((sizeof g_gpr_regnums_arm64 / sizeof g_gpr_regnums_arm64[0 ]) -
61- 1 ) == k_num_gpr_registers_arm64,
62- " g_gpr_regnums_arm64 has wrong number of register infos" );
63-
64- // ARM64 floating point registers.
65- static const uint32_t g_fpu_regnums_arm64[] = {
66- fpu_v0_arm64, fpu_v1_arm64, fpu_v2_arm64, fpu_v3_arm64,
67- fpu_v4_arm64, fpu_v5_arm64, fpu_v6_arm64, fpu_v7_arm64,
68- fpu_v8_arm64, fpu_v9_arm64, fpu_v10_arm64, fpu_v11_arm64,
69- fpu_v12_arm64, fpu_v13_arm64, fpu_v14_arm64, fpu_v15_arm64,
70- fpu_v16_arm64, fpu_v17_arm64, fpu_v18_arm64, fpu_v19_arm64,
71- fpu_v20_arm64, fpu_v21_arm64, fpu_v22_arm64, fpu_v23_arm64,
72- fpu_v24_arm64, fpu_v25_arm64, fpu_v26_arm64, fpu_v27_arm64,
73- fpu_v28_arm64, fpu_v29_arm64, fpu_v30_arm64, fpu_v31_arm64,
74-
75- fpu_s0_arm64, fpu_s1_arm64, fpu_s2_arm64, fpu_s3_arm64,
76- fpu_s4_arm64, fpu_s5_arm64, fpu_s6_arm64, fpu_s7_arm64,
77- fpu_s8_arm64, fpu_s9_arm64, fpu_s10_arm64, fpu_s11_arm64,
78- fpu_s12_arm64, fpu_s13_arm64, fpu_s14_arm64, fpu_s15_arm64,
79- fpu_s16_arm64, fpu_s17_arm64, fpu_s18_arm64, fpu_s19_arm64,
80- fpu_s20_arm64, fpu_s21_arm64, fpu_s22_arm64, fpu_s23_arm64,
81- fpu_s24_arm64, fpu_s25_arm64, fpu_s26_arm64, fpu_s27_arm64,
82- fpu_s28_arm64, fpu_s29_arm64, fpu_s30_arm64, fpu_s31_arm64,
83-
84- fpu_d0_arm64, fpu_d1_arm64, fpu_d2_arm64, fpu_d3_arm64,
85- fpu_d4_arm64, fpu_d5_arm64, fpu_d6_arm64, fpu_d7_arm64,
86- fpu_d8_arm64, fpu_d9_arm64, fpu_d10_arm64, fpu_d11_arm64,
87- fpu_d12_arm64, fpu_d13_arm64, fpu_d14_arm64, fpu_d15_arm64,
88- fpu_d16_arm64, fpu_d17_arm64, fpu_d18_arm64, fpu_d19_arm64,
89- fpu_d20_arm64, fpu_d21_arm64, fpu_d22_arm64, fpu_d23_arm64,
90- fpu_d24_arm64, fpu_d25_arm64, fpu_d26_arm64, fpu_d27_arm64,
91- fpu_d28_arm64, fpu_d29_arm64, fpu_d30_arm64, fpu_d31_arm64,
92- fpu_fpsr_arm64, fpu_fpcr_arm64,
93- LLDB_INVALID_REGNUM // register sets need to end with this flag
94- };
95- static_assert (((sizeof g_fpu_regnums_arm64 / sizeof g_fpu_regnums_arm64[0 ]) -
96- 1 ) == k_num_fpr_registers_arm64,
97- " g_fpu_regnums_arm64 has wrong number of register infos" );
98-
99- namespace {
100- // Number of register sets provided by this context.
101- enum { k_num_register_sets = 2 };
102- }
103-
104- // Register sets for ARM64.
105- static const RegisterSet g_reg_sets_arm64[k_num_register_sets] = {
106- {" General Purpose Registers" , " gpr" , k_num_gpr_registers_arm64,
107- g_gpr_regnums_arm64},
108- {" Floating Point Registers" , " fpu" , k_num_fpr_registers_arm64,
109- g_fpu_regnums_arm64}};
110-
11141std::unique_ptr<NativeRegisterContextOpenBSD>
11242NativeRegisterContextOpenBSD::CreateHostNativeRegisterContextOpenBSD (
11343 const ArchSpec &target_arch, NativeThreadProtocol &native_thread) {
@@ -122,7 +52,9 @@ static RegisterInfoInterface *
12252CreateRegisterInfoInterface (const ArchSpec &target_arch) {
12353 assert ((HostInfo::GetArchitecture ().GetAddressByteSize () == 8 ) &&
12454 " Register setting path assumes this is a 64-bit host" );
125- return new RegisterInfoPOSIX_arm64 (target_arch, 0 );
55+
56+ Flags opt_regsets = RegisterInfoPOSIX_arm64::eRegsetMaskPAuth;
57+ return new RegisterInfoPOSIX_arm64 (target_arch, opt_regsets);
12658}
12759
12860static llvm::APInt uint128ToAPInt (__uint128_t in) {
@@ -145,23 +77,25 @@ NativeRegisterContextOpenBSD_arm64::NativeRegisterContextOpenBSD_arm64(
14577 CreateRegisterInfoInterface (target_arch)),
14678 m_gpr(), m_fpr() {}
14779
148- uint32_t NativeRegisterContextOpenBSD_arm64::GetUserRegisterCount () const {
149- uint32_t count = 0 ;
150- for (uint32_t set_index = 0 ; set_index < k_num_register_sets; ++set_index)
151- count += g_reg_sets_arm64[set_index].num_registers ;
152- return count;
80+ RegisterInfoPOSIX_arm64 &
81+ NativeRegisterContextOpenBSD_arm64::GetRegisterInfo () const {
82+ return static_cast <RegisterInfoPOSIX_arm64 &>(*m_register_info_interface_up);
15383}
15484
15585uint32_t NativeRegisterContextOpenBSD_arm64::GetRegisterSetCount () const {
156- return k_num_register_sets ;
86+ return GetRegisterInfo (). GetRegisterSetCount () ;
15787}
15888
15989const RegisterSet *
16090NativeRegisterContextOpenBSD_arm64::GetRegisterSet (uint32_t set_index) const {
161- if (set_index < k_num_register_sets)
162- return &g_reg_sets_arm64[set_index];
91+ return GetRegisterInfo (). GetRegisterSet (set_index);
92+ }
16393
164- return nullptr ;
94+ uint32_t NativeRegisterContextOpenBSD_arm64::GetUserRegisterCount () const {
95+ uint32_t count = 0 ;
96+ for (uint32_t set_index = 0 ; set_index < GetRegisterSetCount (); ++set_index)
97+ count += GetRegisterSet (set_index)->num_registers ;
98+ return count;
16599}
166100
167101Status
@@ -202,6 +136,18 @@ NativeRegisterContextOpenBSD_arm64::ReadRegister(const RegisterInfo *reg_info,
202136 return error;
203137 }
204138
139+ if (GetRegisterInfo ().IsPAuthReg (reg)) {
140+ uint32_t offset;
141+
142+ offset = reg_info->byte_offset - GetRegisterInfo ().GetPAuthOffset ();
143+ reg_value = (uint64_t )m_pacmask[offset > 0 ];
144+ if (reg_value.GetByteSize () > reg_info->byte_size ) {
145+ reg_value.SetType (reg_info);
146+ }
147+
148+ return error;
149+ }
150+
205151 switch (reg) {
206152 case gpr_x0_arm64:
207153 case gpr_x1_arm64:
@@ -527,6 +473,8 @@ int NativeRegisterContextOpenBSD_arm64::GetSetForNativeRegNum(
527473 return GPRegSet;
528474 else if (reg_num >= k_first_fpr_arm64 && reg_num <= k_last_fpr_arm64)
529475 return FPRegSet;
476+ else if (GetRegisterInfo ().IsPAuthReg (reg_num))
477+ return PACMaskRegSet;
530478 else
531479 return -1 ;
532480}
@@ -539,6 +487,9 @@ int NativeRegisterContextOpenBSD_arm64::ReadRegisterSet(uint32_t set) {
539487 case FPRegSet:
540488 ReadFPR ();
541489 return 0 ;
490+ case PACMaskRegSet:
491+ ReadPACMask ();
492+ return 0 ;
542493 default :
543494 break ;
544495 }
@@ -558,4 +509,16 @@ int NativeRegisterContextOpenBSD_arm64::WriteRegisterSet(uint32_t set) {
558509 }
559510 return -1 ;
560511}
512+
513+ Status NativeRegisterContextOpenBSD_arm64::ReadPACMask () {
514+ #ifdef PT_PACMASK
515+ return NativeProcessOpenBSD::PtraceWrapper (PT_PACMASK, GetProcessPid (),
516+ &m_pacmask, sizeof (m_pacmask));
517+ #else
518+ Status error;
519+ ::memset (&m_pacmask, 0 , sizeof (m_pacmask));
520+ return error;
521+ #endif
522+ }
523+
561524#endif
0 commit comments