1 /*
2  * Copyright (C) 2020 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 <unistd.h>
18 
19 #include "native_bridge_support/vdso/vdso.h"
20 
21 extern void __cxa_finalize(void* dso_handle);
22 
exit(int status)23 void exit(int status) {
24   // We don't need to call __cxa_thread_finalize because host "exit" would do that for us.
25   // __cxa_thread_finalize();
26   // That's slight deviation from standard behavior: there we first call __cxa_thread_finalize()
27   // for all objects and __cxa_finalize() for all objects and here we would first do
28   // __cxa_finalize() for guest objects, then __cxa_thread_finalize() (and after that we would do
29   // __cxa_finalize() for host objects, of course).
30   // TODO(b/65052237): Fix that with bionic refactoring?
31   __cxa_finalize(NULL);
32   ((void (*)(int))(native_bridge_find_proxy_library_symbol("libc.so", "exit")))(status);
33   __builtin_unreachable();
34 }
35