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 "cxa_trampolines.h"
18
19 #include "berberis/guest_abi/function_wrappers.h"
20 #include "berberis/guest_abi/guest_params.h"
21
22 namespace berberis {
23
24 // That function is normally only called by a compiler, but here we need to call
25 // it somehow.
26 extern "C" void* __dso_handle;
27 extern "C" int __cxa_thread_atexit_impl(void (*func)(void*), void* arg,
28 void* dso_handle);
29
DoCustomTrampoline_native_bridge___cxa_thread_atexit_impl(HostCode,ProcessState * state)30 void DoCustomTrampoline_native_bridge___cxa_thread_atexit_impl(
31 HostCode /* callee */, ProcessState* state) {
32 auto [guest_func, arg, dso_handle] =
33 GuestParamsValues<decltype(__cxa_thread_atexit_impl)>(state);
34 auto func =
35 WrapGuestFunction(guest_func, "__cxa_thread_atexit_impl-callback");
36 auto&& [ret] =
37 GuestReturnReference<decltype(__cxa_thread_atexit_impl)>(state);
38 ret = __cxa_thread_atexit_impl(func, arg, &__dso_handle);
39 }
40
41 } // namespace berberis
42