[Lldb-commits] [lldb] [lldb][AArch64] Fix expression evaluation with Guarded Control Stacks (PR #123918)
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Fri Jan 24 05:50:37 PST 2025
================
@@ -60,6 +60,69 @@ ABISysV_arm64::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch)
return ABISP();
}
+static Status PushToLinuxGuardedControlStack(addr_t return_addr,
+ RegisterContext *reg_ctx,
+ Thread &thread) {
+ Status err;
+
+ // If the Guarded Control Stack extension is present we may need to put the
+ // return address onto that stack.
+ const RegisterInfo *gcs_features_enabled_info =
+ reg_ctx->GetRegisterInfoByName("gcs_features_enabled");
+ if (!gcs_features_enabled_info)
+ return err;
+
+ uint64_t gcs_features_enabled = reg_ctx->ReadRegisterAsUnsigned(
+ gcs_features_enabled_info, LLDB_INVALID_ADDRESS);
+ if (gcs_features_enabled == LLDB_INVALID_ADDRESS)
+ return Status("Could not read GCS features enabled register.");
+
+ // Only attempt this if GCS is enabled. If it's not enabled then gcspr_el0
+ // may point to unmapped memory.
+ if ((gcs_features_enabled & 1) == 0)
+ return err;
+
+ const RegisterInfo *gcspr_el0_info =
+ reg_ctx->GetRegisterInfoByName("gcspr_el0");
+ if (!gcspr_el0_info)
+ return Status("Could not get register info for gcspr_el0.");
+
+ uint64_t gcspr_el0 =
+ reg_ctx->ReadRegisterAsUnsigned(gcspr_el0_info, LLDB_INVALID_ADDRESS);
+ if (gcspr_el0 == LLDB_INVALID_ADDRESS)
+ return Status("Could not read gcspr_el0.");
+
+ // A link register entry on the GCS is 8 bytes.
+ gcspr_el0 -= 8;
+ if (!reg_ctx->WriteRegisterFromUnsigned(gcspr_el0_info, gcspr_el0))
+ return Status(
+ "Attempted to decrement gcspr_el0, but could not write to it.");
+
+ Status error;
+ size_t wrote = thread.GetProcess()->WriteMemory(gcspr_el0, &return_addr,
+ sizeof(return_addr), error);
+ if ((wrote != sizeof(return_addr) || error.Fail())) {
+ // When PrepareTrivialCall fails, the register context is not restored,
+ // unlike when an expression fails to execute. This is arguably a bug,
+ // see https://github.com/llvm/llvm-project/issues/124269.
+ // For now we are handling this here specifically. We can assume this
+ // write will work as the one to decrement the register did.
----------------
DavidSpickett wrote:
See this comment.
https://github.com/llvm/llvm-project/pull/123918
More information about the lldb-commits
mailing list