1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef BERBERIS_RUNTIME_PRIMITIVES_RUNTIME_LIBRARY_H_ 18 #define BERBERIS_RUNTIME_PRIMITIVES_RUNTIME_LIBRARY_H_ 19 20 #include "berberis/guest_state/guest_addr.h" 21 #include "berberis/guest_state/guest_state_opaque.h" 22 #include "berberis/runtime_primitives/host_code.h" 23 24 namespace berberis { 25 26 extern "C" { 27 28 void berberis_RunGeneratedCode(ThreadState* state, HostCode code); 29 void berberis_entry_Interpret(); 30 void berberis_entry_ExitGeneratedCode(); 31 void berberis_entry_Stop(); 32 void berberis_entry_NoExec(); 33 void berberis_entry_HandleLightCounterThresholdReached(); 34 35 // TODO(b/232598137): use status variable instead? 36 void berberis_entry_NotTranslated(); 37 void berberis_entry_Translating(); 38 void berberis_entry_Invalidating(); 39 void berberis_entry_Wrapping(); 40 41 static_assert(berberis_entry_NotTranslated != berberis_entry_Translating, 42 "code to distinguish entry status got optimized"); 43 44 __attribute__((__visibility__("hidden"))) void berberis_HandleNoExec(ThreadState* state); 45 46 } // extern "C" 47 48 // Inline const since we cannot use constexpr because of reinterpret_cast. 49 inline const auto kEntryInterpret = AsHostCode(berberis_entry_Interpret); 50 inline const auto kEntryExitGeneratedCode = AsHostCode(berberis_entry_ExitGeneratedCode); 51 inline const auto kEntryStop = AsHostCode(berberis_entry_Stop); 52 inline const auto kEntryNoExec = AsHostCode(berberis_entry_NoExec); 53 inline const auto kEntryNotTranslated = AsHostCode(berberis_entry_NotTranslated); 54 inline const auto kEntryTranslating = AsHostCode(berberis_entry_Translating); 55 inline const auto kEntryInvalidating = AsHostCode(berberis_entry_Invalidating); 56 inline const auto kEntryWrapping = AsHostCode(berberis_entry_Wrapping); 57 58 void InvalidateGuestRange(GuestAddr start, GuestAddr end); 59 60 // Don't pull in the dependency on guest_abi to runtime_primitives, since GuestArgumentBuffer is 61 // used strictly in opaque manner here. 62 struct GuestArgumentBuffer; 63 64 void RunGuestCall(GuestAddr pc, GuestArgumentBuffer* buf); 65 void ExecuteGuestCall(ThreadState* state); 66 67 } // namespace berberis 68 69 #endif // BERBERIS_RUNTIME_PRIMITIVES_RUNTIME_LIBRARY_H_ 70