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_HandleLiteCounterThresholdReached();
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 // These constants are initialized by InitHostEntries()
49 extern HostCodeAddr kEntryInterpret;
50 extern HostCodeAddr kEntryExitGeneratedCode;
51 extern HostCodeAddr kEntryStop;
52 extern HostCodeAddr kEntryNoExec;
53 extern HostCodeAddr kEntryNotTranslated;
54 extern HostCodeAddr kEntryTranslating;
55 extern HostCodeAddr kEntryInvalidating;
56 extern HostCodeAddr kEntryWrapping;
57 
58 void InitHostEntries();
59 
60 void InvalidateGuestRange(GuestAddr start, GuestAddr end);
61 
62 // Don't pull in the dependency on guest_abi to runtime_primitives, since GuestArgumentBuffer is
63 // used strictly in opaque manner here.
64 struct GuestArgumentBuffer;
65 
66 void RunGuestCall(GuestAddr pc, GuestArgumentBuffer* buf);
67 void ExecuteGuestCall(ThreadState* state);
68 
69 }  // namespace berberis
70 
71 #endif  // BERBERIS_RUNTIME_PRIMITIVES_RUNTIME_LIBRARY_H_
72