1 /*
2 * Copyright (C) 2021 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 ART_LIBARTBASE_BASE_FAST_EXIT_H_
18 #define ART_LIBARTBASE_BASE_FAST_EXIT_H_
19
20 // Header-only definition of `art::FastExit`.
21 //
22 // Ideally, this routine should be declared in `base/os.h` and defined in
23 // `base/os_linux.cc`, but as `libartbase` is not linked (directly) with
24 // `dalvikvm`, we would not be able to easily use `art::FastExit` in
25 // `dex2oat`. Use a header-only approach and define `art::FastExit` in its own
26 // file for clarity.
27
28 #include <base/macros.h>
29
30 namespace art {
31
32 #ifdef __ANDROID_CLANG_COVERAGE__
33 static constexpr bool kAndroidClangCoverage = true;
34 #else
35 static constexpr bool kAndroidClangCoverage = false;
36 #endif
37
38 // Terminate program without completely cleaning the resources (e.g. without
39 // calling destructors), unless ART is built with Clang (native) code coverage
40 // instrumentation; in that case, exit normally to allow LLVM's code coverage
41 // profile dumping routine (`__llvm_profile_write_file`), registered via
42 // `atexit` in Android when Clang instrumentation is enabled, to be called
43 // before terminating the program.
FastExit(int exit_code)44 NO_RETURN inline void FastExit(int exit_code) {
45 if (kAndroidClangCoverage) {
46 exit(exit_code);
47 } else {
48 _exit(exit_code);
49 }
50 }
51
52 } // namespace art
53
54 #endif // ART_LIBARTBASE_BASE_FAST_EXIT_H_
55