aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLev Rumyantsev <levarum@google.com>2024-04-26 15:08:23 +0000
committerAndroid Build Cherrypicker Worker <android-build-cherrypicker-worker@google.com>2024-05-01 01:32:33 +0000
commit09fc54a7b8ae1f3aa3019fcc87756f6f99395cc0 (patch)
tree13c18d7ed6b5385d93e602a6de33fcfc9e6065f8
parent906d91fe1083b1c906c6d37fbed1ae7061670247 (diff)
downloadbinary_translation-09fc54a7b8ae1f3aa3019fcc87756f6f99395cc0.tar.gz
rt_prim: rename HostCallFrame into VirtualGuestCallFrame
It implements guest call frame semantics, so calling it host is confusing even though it does represent (hide) host execution between two nested guest executions. The latter should still be clear from the comment. Also rename guest_pc field to return_address for clarity. Test: tree-hugger Bug: 232598137 Merged-In: Ie178e32103b8eee438ff95a97ddb70be31aff355 Change-Id: Ie178e32103b8eee438ff95a97ddb70be31aff355
-rw-r--r--guest_loader/guest_loader.cc6
-rw-r--r--runtime/run_guest_call_riscv64.cc6
-rw-r--r--runtime/translator_riscv64.cc4
-rw-r--r--runtime_primitives/Android.bp6
-rw-r--r--runtime_primitives/include/berberis/runtime_primitives/virtual_guest_call_frame.h (renamed from runtime_primitives/include/berberis/runtime_primitives/host_call_frame.h)18
-rw-r--r--runtime_primitives/virtual_guest_call_frame.cc (renamed from runtime_primitives/host_call_frame.cc)6
-rw-r--r--runtime_primitives/virtual_guest_call_frame_riscv64.cc (renamed from runtime_primitives/host_call_frame_riscv64.cc)12
-rw-r--r--runtime_primitives/virtual_guest_call_frame_riscv64_test.cc (renamed from runtime_primitives/host_call_frame_riscv64_test.cc)23
8 files changed, 41 insertions, 40 deletions
diff --git a/guest_loader/guest_loader.cc b/guest_loader/guest_loader.cc
index 23f4f26e..4aa90769 100644
--- a/guest_loader/guest_loader.cc
+++ b/guest_loader/guest_loader.cc
@@ -37,9 +37,9 @@
#include "berberis/guest_state/guest_state.h"
#include "berberis/kernel_api/sys_mman_emulation.h"
#include "berberis/proxy_loader/proxy_loader.h"
-#include "berberis/runtime_primitives/host_call_frame.h"
#include "berberis/runtime_primitives/host_function_wrapper_impl.h" // MakeTrampolineCallable
#include "berberis/runtime_primitives/runtime_library.h" // ExecuteGuestCall
+#include "berberis/runtime_primitives/virtual_guest_call_frame.h"
#include "berberis/tiny_loader/tiny_loader.h"
#include "native_bridge_support/linker/static_tls_config.h"
@@ -111,7 +111,7 @@ void FillRandomBuf(uint8_t* buf, size_t size) {
ScopedPendingSignalsEnabler scoped_pending_signals_enabler(main_thread);
CPUState& cpu = state->cpu;
- ScopedHostCallFrame host_call_frame(&cpu, entry_point);
+ ScopedVirtualGuestCallFrame virtual_guest_call_frame(&cpu, entry_point);
GuestAddr updated_stack = InitKernelArgs(GetStackRegister(cpu),
argc,
@@ -221,7 +221,7 @@ bool InitializeVdso(const LoadedElfFile& vdso_elf_file, std::string* error_msg)
*error_msg = "couldn't find \"native_bridge_call_guest\" symbol in vdso";
return false;
}
- InitHostCallFrameGuestPC(ToGuestAddr(call_guest_addr));
+ InitVirtualGuestCallFrameReturnAddress(ToGuestAddr(call_guest_addr));
return true;
}
diff --git a/runtime/run_guest_call_riscv64.cc b/runtime/run_guest_call_riscv64.cc
index 2a82550b..5ddbf883 100644
--- a/runtime/run_guest_call_riscv64.cc
+++ b/runtime/run_guest_call_riscv64.cc
@@ -26,7 +26,7 @@
#include "berberis/guest_state/guest_addr.h"
#include "berberis/guest_state/guest_state_arch.h"
#include "berberis/instrument/guest_call.h"
-#include "berberis/runtime_primitives/host_call_frame.h"
+#include "berberis/runtime_primitives/virtual_guest_call_frame.h"
namespace berberis {
@@ -34,7 +34,7 @@ namespace berberis {
// value is stored in the first argument of the buffer after the call returns.
//
// Within the guest call stack, the host has its own call frame. This stack
-// frame is allocated by the ScopedHostCallFrame instance. The host call frame
+// frame is allocated by the ScopedVirtualGuestCallFrame instance. Virtual guest call frame
// simulates the minimum necessary prologue and epilogue for saving and
// restoring the frame pointer and return address on the stack. Within that call
// frame, we can make further adjustments to the stack pointer, such as
@@ -69,7 +69,7 @@ void RunGuestCall(GuestAddr pc, GuestArgumentBuffer* buf) {
ScopedPendingSignalsEnabler scoped_pending_signals_enabler(thread);
- ScopedHostCallFrame host_call_frame(&state->cpu, pc);
+ ScopedVirtualGuestCallFrame virtual_guest_call_frame(&state->cpu, pc);
// Copy argc int and fp_argc float registers for the arguments into the argument buffer.
memcpy(&(state->cpu.x[A0]), buf->argv, buf->argc * sizeof(buf->argv[0]));
diff --git a/runtime/translator_riscv64.cc b/runtime/translator_riscv64.cc
index 468f8fa9..6410eb7c 100644
--- a/runtime/translator_riscv64.cc
+++ b/runtime/translator_riscv64.cc
@@ -32,11 +32,11 @@
#include "berberis/interpreter/riscv64/interpreter.h"
#include "berberis/lite_translator/lite_translate_region.h"
#include "berberis/runtime_primitives/code_pool.h"
-#include "berberis/runtime_primitives/host_call_frame.h"
#include "berberis/runtime_primitives/host_code.h"
#include "berberis/runtime_primitives/profiler_interface.h"
#include "berberis/runtime_primitives/runtime_library.h"
#include "berberis/runtime_primitives/translation_cache.h"
+#include "berberis/runtime_primitives/virtual_guest_call_frame.h"
namespace berberis {
@@ -122,7 +122,7 @@ HostCodePiece InstallTranslated(MachineCode* machine_code,
void InitTranslator() {
UpdateTranslationMode();
- InitHostCallFrameGuestPC(ToGuestAddr(g_native_bridge_call_guest + 1));
+ InitVirtualGuestCallFrameReturnAddress(ToGuestAddr(g_native_bridge_call_guest + 1));
InitInterpreter();
}
diff --git a/runtime_primitives/Android.bp b/runtime_primitives/Android.bp
index bce02e50..5820a61f 100644
--- a/runtime_primitives/Android.bp
+++ b/runtime_primitives/Android.bp
@@ -42,7 +42,6 @@ cc_library_static {
"code_pool.cc",
"crash_reporter.cc",
"guest_function_wrapper_impl.cc",
- "host_call_frame.cc",
"host_function_wrapper_impl.cc",
"known_guest_function_wrapper.cc",
"platform.cc",
@@ -50,6 +49,7 @@ cc_library_static {
"recovery_code.cc",
"signal_queue.cc",
"translation_cache.cc",
+ "virtual_guest_call_frame.cc",
],
header_libs: [
"libberberis_code_gen_lib_headers",
@@ -101,8 +101,8 @@ cc_library_static {
host_supported: true,
srcs: [
"checks_riscv64.cc",
- "host_call_frame_riscv64.cc",
"interpret_helpers_riscv64.cc",
+ "virtual_guest_call_frame_riscv64.cc",
],
whole_static_libs: [
"libberberis_runtime_primitives",
@@ -142,11 +142,11 @@ cc_test_library {
defaults: ["berberis_test_library_defaults_64"],
host_supported: true,
srcs: [
- "host_call_frame_riscv64_test.cc",
"memory_region_reservation_test.cc",
// Translation cache test relies on implementation of runtime_library
// function pointers to link.
"translation_cache_test.cc",
+ "virtual_guest_call_frame_riscv64_test.cc",
],
header_libs: [
"berberis_test_utils_headers",
diff --git a/runtime_primitives/include/berberis/runtime_primitives/host_call_frame.h b/runtime_primitives/include/berberis/runtime_primitives/virtual_guest_call_frame.h
index b2e3ad2d..c20b4db8 100644
--- a/runtime_primitives/include/berberis/runtime_primitives/host_call_frame.h
+++ b/runtime_primitives/include/berberis/runtime_primitives/virtual_guest_call_frame.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef BERBERIS_RUNTIME_PRIMITIVES_HOST_CALL_FRAME_H_
-#define BERBERIS_RUNTIME_PRIMITIVES_HOST_CALL_FRAME_H_
+#ifndef BERBERIS_RUNTIME_PRIMITIVES_VIRTUAL_GUEST_CALL_FRAME_H_
+#define BERBERIS_RUNTIME_PRIMITIVES_VIRTUAL_GUEST_CALL_FRAME_H_
#include "berberis/guest_state/guest_addr.h"
#include "berberis/guest_state/guest_state_opaque.h"
@@ -43,15 +43,15 @@ namespace berberis {
// register.
//
// Finally, we need to save the registers that are not preserved by guest function.
-class ScopedHostCallFrame {
+class ScopedVirtualGuestCallFrame {
public:
- ScopedHostCallFrame(CPUState* cpu, GuestAddr pc);
- ~ScopedHostCallFrame();
+ ScopedVirtualGuestCallFrame(CPUState* cpu, GuestAddr pc);
+ ~ScopedVirtualGuestCallFrame();
- static void SetGuestPC(GuestAddr pc) { g_host_call_frame_guest_pc_ = pc; }
+ static void SetReturnAddress(GuestAddr ra) { g_return_address_ = ra; }
private:
- static GuestAddr g_host_call_frame_guest_pc_;
+ static GuestAddr g_return_address_;
CPUState* cpu_;
@@ -62,8 +62,8 @@ class ScopedHostCallFrame {
};
// Set return address for guest calls. On this address, guest execution will stop.
-void InitHostCallFrameGuestPC(GuestAddr pc);
+void InitVirtualGuestCallFrameReturnAddress(GuestAddr ra);
} // namespace berberis
-#endif // BERBERIS_RUNTIME_PRIMITIVES_HOST_CALL_FRAME_H_
+#endif // BERBERIS_RUNTIME_PRIMITIVES_VIRTUAL_GUEST_CALL_FRAME_H_
diff --git a/runtime_primitives/host_call_frame.cc b/runtime_primitives/virtual_guest_call_frame.cc
index 68cd734d..de9b10a0 100644
--- a/runtime_primitives/host_call_frame.cc
+++ b/runtime_primitives/virtual_guest_call_frame.cc
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "berberis/runtime_primitives/host_call_frame.h"
+#include "berberis/runtime_primitives/virtual_guest_call_frame.h"
#include "berberis/base/checks.h"
#include "berberis/guest_state/guest_addr.h"
@@ -22,8 +22,8 @@
namespace berberis {
-void InitHostCallFrameGuestPC(GuestAddr pc) {
- ScopedHostCallFrame::SetGuestPC(pc);
+void InitVirtualGuestCallFrameReturnAddress(GuestAddr pc) {
+ ScopedVirtualGuestCallFrame::SetReturnAddress(pc);
CHECK(TranslationCache::GetInstance()->SetStop(pc));
}
diff --git a/runtime_primitives/host_call_frame_riscv64.cc b/runtime_primitives/virtual_guest_call_frame_riscv64.cc
index 22d2d49b..d4f1603c 100644
--- a/runtime_primitives/host_call_frame_riscv64.cc
+++ b/runtime_primitives/virtual_guest_call_frame_riscv64.cc
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "berberis/runtime_primitives/host_call_frame.h"
+#include "berberis/runtime_primitives/virtual_guest_call_frame.h"
#include <cstdint>
@@ -24,7 +24,7 @@
namespace berberis {
-GuestAddr ScopedHostCallFrame::g_host_call_frame_guest_pc_ = {};
+GuestAddr ScopedVirtualGuestCallFrame::g_return_address_ = {};
// For RISC-V, guest function preserves at least sp and returns by jumping
// to address provided in ra. So here ctor emulates the following code:
@@ -48,7 +48,7 @@ GuestAddr ScopedHostCallFrame::g_host_call_frame_guest_pc_ = {};
// ld ra, 8(sp)
// addi sp, sp, 16
//
-ScopedHostCallFrame::ScopedHostCallFrame(CPUState* cpu, GuestAddr pc) : cpu_(cpu) {
+ScopedVirtualGuestCallFrame::ScopedVirtualGuestCallFrame(CPUState* cpu, GuestAddr pc) : cpu_(cpu) {
// addi sp, sp, -16
SetXReg<SP>(*cpu_, GetXReg<SP>(*cpu_) - 16);
// sd fp, 0(sp)
@@ -66,13 +66,13 @@ ScopedHostCallFrame::ScopedHostCallFrame(CPUState* cpu, GuestAddr pc) : cpu_(cpu
program_counter_ = cpu_->insn_addr;
// Set pc and ra as for 'jalr ra, <guest>'.
- SetXReg<RA>(*cpu_, g_host_call_frame_guest_pc_);
+ SetXReg<RA>(*cpu_, g_return_address_);
cpu_->insn_addr = pc;
}
-ScopedHostCallFrame::~ScopedHostCallFrame() {
+ScopedVirtualGuestCallFrame::~ScopedVirtualGuestCallFrame() {
// Safety check - returned to correct pc?
- CHECK_EQ(g_host_call_frame_guest_pc_, cpu_->insn_addr);
+ CHECK_EQ(g_return_address_, cpu_->insn_addr);
// Safety check - guest call didn't preserve fp?
CHECK_EQ(stack_pointer_, GetXReg<FP>(*cpu_));
diff --git a/runtime_primitives/host_call_frame_riscv64_test.cc b/runtime_primitives/virtual_guest_call_frame_riscv64_test.cc
index 869fad62..667c31bd 100644
--- a/runtime_primitives/host_call_frame_riscv64_test.cc
+++ b/runtime_primitives/virtual_guest_call_frame_riscv64_test.cc
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
#include "gtest/gtest.h"
#include <array>
@@ -20,36 +21,36 @@
#include "berberis/guest_state/guest_addr.h"
#include "berberis/guest_state/guest_state.h"
-#include "berberis/runtime_primitives/host_call_frame.h"
+#include "berberis/runtime_primitives/virtual_guest_call_frame.h"
namespace berberis {
namespace {
-TEST(HostCallFrame, InitPC) {
- constexpr GuestAddr kHostCallFrameGuestPC = 0xbeefface;
- ScopedHostCallFrame::SetGuestPC(kHostCallFrameGuestPC);
+TEST(VirtualGuestFrame, InitReturnAddress) {
+ constexpr GuestAddr kVirtualGuestFrameReturnAddress = 0xbeefface;
+ ScopedVirtualGuestCallFrame::SetReturnAddress(kVirtualGuestFrameReturnAddress);
CPUState cpu{};
alignas(uint64_t) std::array<char, 128> stack;
SetXReg<SP>(cpu, ToGuestAddr(stack.data() + stack.size()));
- ScopedHostCallFrame host_call_frame(&cpu, 0xdeadbeef);
+ ScopedVirtualGuestCallFrame virtual_guest_call_frame(&cpu, 0xdeadbeef);
- EXPECT_EQ(kHostCallFrameGuestPC, GetXReg<RA>(cpu));
+ EXPECT_EQ(kVirtualGuestFrameReturnAddress, GetXReg<RA>(cpu));
// Pretend guest code executed up to return address.
cpu.insn_addr = GetXReg<RA>(cpu);
}
-void RunHostCall(CPUState* cpu) {
- ScopedHostCallFrame host_call_frame(cpu, 0xbaaaaaad);
+void RunGuestCall(CPUState* cpu) {
+ ScopedVirtualGuestCallFrame virtual_guest_call_frame(cpu, 0xbaaaaaad);
// Pretend guest code executed up to return address.
cpu->insn_addr = GetXReg<RA>(*cpu);
- // ScopedHostCallFrame creates a stack frame to represent the host function
+ // ScopedVirtualGuestCallFrame creates a stack frame to represent the host function
// that is calling guest code. That pseudo-function can make arbitrary
// adjustments to sp and ra because those are callee-saved registers that are
// restored when the function returns.
@@ -57,7 +58,7 @@ void RunHostCall(CPUState* cpu) {
SetXReg<RA>(*cpu, 0xbaadf00d);
}
-TEST(HostCallFrame, Restore) {
+TEST(VirtualGuestFrame, Restore) {
CPUState cpu{};
alignas(uint64_t) std::array<char, 128> stack;
@@ -69,7 +70,7 @@ TEST(HostCallFrame, Restore) {
SetXReg<SP>(cpu, sp);
SetXReg<FP>(cpu, fp);
- RunHostCall(&cpu);
+ RunGuestCall(&cpu);
EXPECT_EQ(ra, GetXReg<RA>(cpu));
EXPECT_EQ(sp, GetXReg<SP>(cpu));