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 #include "system_properties_trampolines.h"
18
19 #include <sys/system_properties.h>
20
21 #include "berberis/guest_abi/function_wrappers.h"
22 #include "berberis/guest_abi/guest_params_arch.h"
23 #include "berberis/guest_state/guest_addr.h"
24
25 namespace berberis {
26
27 // int __system_property_foreach(void (*propfn)(const prop_info* pi, void*
28 // cookie), void* cookie);
DoCustomTrampoline___system_property_foreach(HostCode,ProcessState * state)29 void DoCustomTrampoline___system_property_foreach(HostCode /* callee */,
30 ProcessState* state) {
31 auto [guest_prop_func, cookie] =
32 GuestParamsValues<decltype(__system_property_foreach)>(state);
33 auto prop_func =
34 WrapGuestFunction(guest_prop_func, "__system_property_foreach-callback");
35 auto&& [ret] =
36 GuestReturnReference<decltype(__system_property_foreach)>(state);
37 ret = __system_property_foreach(prop_func, cookie);
38 }
39
40 // void __system_property_read_callback(
41 // const prop_info* pi,
42 // void (*callback)(void* cookie, const char* name, const char* value,
43 // uint32_t serial), void* cookie);
DoCustomTrampoline___system_property_read_callback(HostCode,ProcessState * state)44 void DoCustomTrampoline___system_property_read_callback(HostCode /* callee */,
45 ProcessState* state) {
46 auto [property_info, guest_prop_func, cookie] =
47 GuestParamsValues<decltype(__system_property_read_callback)>(state);
48 auto prop_func = WrapGuestFunction(
49 guest_prop_func, "__system_property_read_callback-callback");
50 __system_property_read_callback(property_info, prop_func, cookie);
51 }
52
53 } // namespace berberis
54