Skip to content

Commit 3fe267f

Browse files
committed
return status from gcs setup
1 parent c89a16a commit 3fe267f

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,46 +60,49 @@ ABISysV_arm64::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch)
6060
return ABISP();
6161
}
6262

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.
6870
const RegisterInfo *gcs_features_enabled_info =
6971
reg_ctx->GetRegisterInfoByName("gcs_features_enabled");
7072
if (!gcs_features_enabled_info)
71-
return false;
73+
return err;
7274

7375
uint64_t gcs_features_enabled = reg_ctx->ReadRegisterAsUnsigned(
7476
gcs_features_enabled_info, LLDB_INVALID_ADDRESS);
7577
if (gcs_features_enabled == LLDB_INVALID_ADDRESS)
76-
return false;
78+
return Status("Could not read GCS features enabled register.");
7779

7880
// Only attempt this if GCS is enabled. If it's not enabled then gcspr_el0
7981
// may point to unmapped memory.
8082
if ((gcs_features_enabled & 1) == 0)
81-
return false;
83+
return err;
8284

8385
const RegisterInfo *gcspr_el0_info =
8486
reg_ctx->GetRegisterInfoByName("gcspr_el0");
8587
if (!gcspr_el0_info)
86-
return false;
88+
return Status("Could not get register info for gcspr_el0.");
8789

8890
uint64_t gcspr_el0 =
8991
reg_ctx->ReadRegisterAsUnsigned(gcspr_el0_info, LLDB_INVALID_ADDRESS);
9092
if (gcspr_el0 == LLDB_INVALID_ADDRESS)
91-
return false;
93+
return Status("Could not read gcspr_el0.");
9294

9395
// A link register entry on the GCS is 8 bytes.
9496
gcspr_el0 -= 8;
9597
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.");
97100

98101
Status error;
99102
size_t wrote = thread.GetProcess()->WriteMemory(gcspr_el0, &return_addr,
100103
sizeof(return_addr), error);
101104
if ((wrote != sizeof(return_addr) || error.Fail()))
102-
return false;
105+
return Status("Failed to write new Guarded Control Stack entry.");
103106

104107
Log *log = GetLog(LLDBLog::Expressions);
105108
LLDB_LOGF(log,
@@ -110,7 +113,7 @@ static bool PushToLinuxGuardedControlStack(addr_t return_addr,
110113
// gcspr_el0 will be restored to the original value by lldb-server after
111114
// the call has finished, which serves as the "pop".
112115

113-
return true;
116+
return err;
114117
}
115118

116119
bool ABISysV_arm64::PrepareTrivialCall(Thread &thread, addr_t sp,
@@ -156,8 +159,15 @@ bool ABISysV_arm64::PrepareTrivialCall(Thread &thread, addr_t sp,
156159
return_addr))
157160
return false;
158161

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+
}
161171

162172
// Set "sp" to the requested value
163173
if (!reg_ctx->WriteRegisterFromUnsigned(

0 commit comments

Comments
 (0)