@@ -60,46 +60,49 @@ ABISysV_arm64::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch)
60
60
return ABISP ();
61
61
}
62
62
63
- static bool PushToLinuxGuardedControlStack (addr_t return_addr,
64
- RegisterContext *reg_ctx,
65
- Thread &thread) {
66
- // If the Guarded Control Stack extension is enabled we need to put the return
67
- // address onto that stack.
63
+ static Status PushToLinuxGuardedControlStack (addr_t return_addr,
64
+ RegisterContext *reg_ctx,
65
+ Thread &thread) {
66
+ Status err;
67
+
68
+ // If the Guarded Control Stack extension is present we may need to put the
69
+ // return address onto that stack.
68
70
const RegisterInfo *gcs_features_enabled_info =
69
71
reg_ctx->GetRegisterInfoByName (" gcs_features_enabled" );
70
72
if (!gcs_features_enabled_info)
71
- return false ;
73
+ return err ;
72
74
73
75
uint64_t gcs_features_enabled = reg_ctx->ReadRegisterAsUnsigned (
74
76
gcs_features_enabled_info, LLDB_INVALID_ADDRESS);
75
77
if (gcs_features_enabled == LLDB_INVALID_ADDRESS)
76
- return false ;
78
+ return Status ( " Could not read GCS features enabled register. " ) ;
77
79
78
80
// Only attempt this if GCS is enabled. If it's not enabled then gcspr_el0
79
81
// may point to unmapped memory.
80
82
if ((gcs_features_enabled & 1 ) == 0 )
81
- return false ;
83
+ return err ;
82
84
83
85
const RegisterInfo *gcspr_el0_info =
84
86
reg_ctx->GetRegisterInfoByName (" gcspr_el0" );
85
87
if (!gcspr_el0_info)
86
- return false ;
88
+ return Status ( " Could not get register info for gcspr_el0. " ) ;
87
89
88
90
uint64_t gcspr_el0 =
89
91
reg_ctx->ReadRegisterAsUnsigned (gcspr_el0_info, LLDB_INVALID_ADDRESS);
90
92
if (gcspr_el0 == LLDB_INVALID_ADDRESS)
91
- return false ;
93
+ return Status ( " Could not read gcspr_el0. " ) ;
92
94
93
95
// A link register entry on the GCS is 8 bytes.
94
96
gcspr_el0 -= 8 ;
95
97
if (!reg_ctx->WriteRegisterFromUnsigned (gcspr_el0_info, gcspr_el0))
96
- return false ;
98
+ return Status (
99
+ " Attempted to decrement gcspr_el0, but could not write to it." );
97
100
98
101
Status error;
99
102
size_t wrote = thread.GetProcess ()->WriteMemory (gcspr_el0, &return_addr,
100
103
sizeof (return_addr), error);
101
104
if ((wrote != sizeof (return_addr) || error.Fail ()))
102
- return false ;
105
+ return Status ( " Failed to write new Guarded Control Stack entry. " ) ;
103
106
104
107
Log *log = GetLog (LLDBLog::Expressions);
105
108
LLDB_LOGF (log,
@@ -110,7 +113,7 @@ static bool PushToLinuxGuardedControlStack(addr_t return_addr,
110
113
// gcspr_el0 will be restored to the original value by lldb-server after
111
114
// the call has finished, which serves as the "pop".
112
115
113
- return true ;
116
+ return err ;
114
117
}
115
118
116
119
bool ABISysV_arm64::PrepareTrivialCall (Thread &thread, addr_t sp,
@@ -156,8 +159,15 @@ bool ABISysV_arm64::PrepareTrivialCall(Thread &thread, addr_t sp,
156
159
return_addr))
157
160
return false ;
158
161
159
- if (GetProcessSP ()->GetTarget ().GetArchitecture ().GetTriple ().isOSLinux ())
160
- PushToLinuxGuardedControlStack (return_addr, reg_ctx, thread);
162
+ if (GetProcessSP ()->GetTarget ().GetArchitecture ().GetTriple ().isOSLinux ()) {
163
+ Status err = PushToLinuxGuardedControlStack (return_addr, reg_ctx, thread);
164
+ // If we could not manage the GCS, the expression will certainly fail,
165
+ // and if we just carried on, that failure would be a lot more cryptic.
166
+ if (err.Fail ()) {
167
+ LLDB_LOGF (log, " Failed to setup Guarded Call Stack: %s" , err.AsCString ());
168
+ return false ;
169
+ }
170
+ }
161
171
162
172
// Set "sp" to the requested value
163
173
if (!reg_ctx->WriteRegisterFromUnsigned (
0 commit comments