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_CODE_GEN_LIB_GEN_WRAPPER_H_ 18 #define BERBERIS_CODE_GEN_LIB_GEN_WRAPPER_H_ 19 20 #include "berberis/assembler/machine_code.h" 21 #include "berberis/guest_state/guest_addr.h" 22 #include "berberis/runtime_primitives/host_code.h" 23 24 namespace berberis { 25 26 // Generate machine code fragment which converts arguments 27 // from host ABI to guest ABI, calls 'guest_runner' which executes 28 // guest code at 'pc', and converts results back to the host ABI. 29 // 'guest_runner' usually invokes binary translation engine, to actually 30 // execute the guest code at 'pc'. 31 // It allows calling guest functions, as if they were host 32 // functions, making them suitable arguments for host functions, 33 // taking callbacks. 34 void GenWrapGuestFunction(MachineCode* mc, 35 GuestAddr pc, 36 const char* signature, 37 HostCode guest_runner, 38 const char* name); 39 40 } // namespace berberis 41 42 #endif // BERBERIS_CODE_GEN_LIB_GEN_WRAPPER_H_ 43