mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Enable stack traces on AArch64
Note that `//sandboxed_api/sandbox2:stack_trace_test` may still fail for unrelated reasons, as we are linking libc statically, which is brittle. A follow-up change will fix this. PiperOrigin-RevId: 427175045 Change-Id: Ifb5ec2ac3d60f4bcc9708f26c834c83b75e769d7
This commit is contained in:
parent
d76a0e959e
commit
dc03c38df1
|
@ -286,9 +286,6 @@ absl::StatusOr<UnwindResult> StackTracePeer::LaunchLibunwindSandbox(
|
|||
|
||||
absl::StatusOr<std::vector<std::string>> GetStackTrace(const Regs* regs,
|
||||
const Mounts& mounts) {
|
||||
if constexpr (sapi::host_cpu::IsArm64()) {
|
||||
return absl::UnavailableError("Stack traces unavailable on Aarch64");
|
||||
}
|
||||
if (absl::GetFlag(FLAGS_sandbox_disable_all_stack_traces)) {
|
||||
return absl::UnavailableError("Stacktraces disabled");
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ cc_library(
|
|||
"//sandboxed_api/util:raw_logging",
|
||||
"//sandboxed_api/util:status",
|
||||
"//sandboxed_api/util:strerror",
|
||||
"@com_google_absl//absl/cleanup",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@org_gnu_libunwind//:unwind-ptrace-wrapped",
|
||||
|
|
|
@ -30,6 +30,7 @@ add_library(sandbox2_unwind STATIC
|
|||
)
|
||||
add_library(sandbox2::unwind ALIAS sandbox2_unwind)
|
||||
target_link_libraries(sandbox2_unwind PRIVATE
|
||||
absl::cleanup
|
||||
absl::statusor
|
||||
absl::strings
|
||||
sandbox2::comms
|
||||
|
|
|
@ -19,11 +19,13 @@
|
|||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/cleanup/cleanup.h"
|
||||
#include "absl/status/statusor.h"
|
||||
#include "absl/strings/match.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
|
@ -55,21 +57,20 @@ std::string DemangleSymbol(const std::string& maybe_mangled) {
|
|||
}
|
||||
|
||||
absl::StatusOr<std::vector<uintptr_t>> RunLibUnwind(pid_t pid, int max_frames) {
|
||||
unw_cursor_t cursor;
|
||||
static unw_addr_space_t as =
|
||||
unw_create_addr_space(&_UPT_accessors, 0 /* byte order */);
|
||||
if (as == nullptr) {
|
||||
return absl::InternalError("unw_create_addr_space() failed");
|
||||
}
|
||||
|
||||
std::unique_ptr<struct UPT_info, void (*)(void*)> ui(
|
||||
reinterpret_cast<struct UPT_info*>(_UPT_create(pid)), _UPT_destroy);
|
||||
if (ui == nullptr) {
|
||||
void* context = _UPT_create(pid);
|
||||
if (context == nullptr) {
|
||||
return absl::InternalError("_UPT_create() failed");
|
||||
}
|
||||
absl::Cleanup context_cleanup = [&context] { _UPT_destroy(context); };
|
||||
|
||||
int rc = unw_init_remote(&cursor, as, ui.get());
|
||||
if (rc < 0) {
|
||||
unw_cursor_t cursor;
|
||||
if (int rc = unw_init_remote(&cursor, as, context); rc < 0) {
|
||||
// Could be UNW_EINVAL (8), UNW_EUNSPEC (1) or UNW_EBADREG (3).
|
||||
return absl::InternalError(
|
||||
absl::StrCat("unw_init_remote() failed with error ", rc));
|
||||
|
@ -78,7 +79,7 @@ absl::StatusOr<std::vector<uintptr_t>> RunLibUnwind(pid_t pid, int max_frames) {
|
|||
std::vector<uintptr_t> ips;
|
||||
for (int i = 0; i < max_frames; ++i) {
|
||||
unw_word_t ip;
|
||||
rc = unw_get_reg(&cursor, UNW_REG_IP, &ip);
|
||||
int rc = unw_get_reg(&cursor, UNW_REG_IP, &ip);
|
||||
if (rc < 0) {
|
||||
// Could be UNW_EUNSPEC or UNW_EBADREG.
|
||||
SAPI_RAW_LOG(WARNING, "unw_get_reg() failed with error %d", rc);
|
||||
|
|
Loading…
Reference in New Issue
Block a user