mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Make stack trace test more resilient against optimizer
This fixes tests for PPC, where the tail-call optimization would consistently remove 'violate()' from the stack trace. PiperOrigin-RevId: 371103794 Change-Id: Ifb1a7d588a455041a6b0f3c763276ed44de47e60
This commit is contained in:
parent
00a7cc5a33
commit
0750216bc1
|
@ -32,6 +32,7 @@ cc_library(
|
||||||
deps = [
|
deps = [
|
||||||
":stringop_params_cc_proto",
|
":stringop_params_cc_proto",
|
||||||
"//sandboxed_api:lenval_core",
|
"//sandboxed_api:lenval_core",
|
||||||
|
"@com_google_absl//absl/base:core_headers",
|
||||||
],
|
],
|
||||||
alwayslink = 1, # All functions are linked into dependent binaries
|
alwayslink = 1, # All functions are linked into dependent binaries
|
||||||
)
|
)
|
||||||
|
|
|
@ -39,6 +39,7 @@ add_dependencies(sapi_stringop
|
||||||
target_link_libraries(sapi_stringop
|
target_link_libraries(sapi_stringop
|
||||||
PRIVATE $<TARGET_OBJECTS:sapi_stringop_params_proto>
|
PRIVATE $<TARGET_OBJECTS:sapi_stringop_params_proto>
|
||||||
sapi::base
|
sapi::base
|
||||||
|
absl::core_headers
|
||||||
sapi::lenval_core
|
sapi::lenval_core
|
||||||
PUBLIC protobuf::libprotobuf
|
PUBLIC protobuf::libprotobuf
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "absl/base/attributes.h"
|
||||||
|
#include "absl/base/optimization.h"
|
||||||
#include "sandboxed_api/examples/stringop/lib/stringop_params.pb.h"
|
#include "sandboxed_api/examples/stringop/lib/stringop_params.pb.h"
|
||||||
#include "sandboxed_api/lenval_core.h"
|
#include "sandboxed_api/lenval_core.h"
|
||||||
|
|
||||||
|
@ -77,9 +79,17 @@ extern "C" const void* get_raw_c_string() { return "Ten chars."; }
|
||||||
|
|
||||||
extern "C" void nop() {}
|
extern "C" void nop() {}
|
||||||
|
|
||||||
extern "C" void violate() {
|
// The "no tail-call" annotation and the additional indirection ensure that this
|
||||||
ptrace((__ptrace_request)990, 991, 992, 993);
|
// function shows up in the violation stack trace. Otherwise, depending on
|
||||||
// Once more to avoid tail-call optimization, so that violate is in the
|
// optimization level and optimizer aggressiveness, functions may be inlined,
|
||||||
// stacktrace.
|
// hoisted or omitted (in case of tail calls).
|
||||||
|
static ABSL_ATTRIBUTE_NOINLINE ABSL_ATTRIBUTE_NO_TAIL_CALL void
|
||||||
|
ViolateIndirect() {
|
||||||
ptrace((__ptrace_request)990, 991, 992, 993);
|
ptrace((__ptrace_request)990, 991, 992, 993);
|
||||||
|
ABSL_BLOCK_TAIL_CALL_OPTIMIZATION();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void violate() {
|
||||||
|
ViolateIndirect();
|
||||||
|
ABSL_BLOCK_TAIL_CALL_OPTIMIZATION();
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ TEST(SapiTest, HasStackTraces) {
|
||||||
StringopApi api(sandbox.get());
|
StringopApi api(sandbox.get());
|
||||||
EXPECT_THAT(api.violate(), StatusIs(absl::StatusCode::kUnavailable));
|
EXPECT_THAT(api.violate(), StatusIs(absl::StatusCode::kUnavailable));
|
||||||
const auto& result = sandbox->AwaitResult();
|
const auto& result = sandbox->AwaitResult();
|
||||||
EXPECT_THAT(result.GetStackTrace(), HasSubstr("violate"));
|
EXPECT_THAT(result.GetStackTrace(), HasSubstr("ViolateIndirect"));
|
||||||
EXPECT_THAT(result.final_status(), Eq(sandbox2::Result::VIOLATION));
|
EXPECT_THAT(result.final_status(), Eq(sandbox2::Result::VIOLATION));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user