• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #pragma once
18 
19 #define BINDER_LOG_LEVEL_NONE 0
20 #define BINDER_LOG_LEVEL_NORMAL 1
21 #define BINDER_LOG_LEVEL_VERBOSE 2
22 
23 #ifndef BINDER_LOG_LEVEL
24 #define BINDER_LOG_LEVEL BINDER_LOG_LEVEL_NORMAL
25 #endif // BINDER_LOG_LEVEL
26 
27 #ifndef TLOG_TAG
28 #ifdef LOG_TAG
29 #define TLOG_TAG "libbinder-" LOG_TAG
30 #else // LOG_TAG
31 #define TLOG_TAG "libbinder"
32 #endif // LOG_TAG
33 #endif // TLOG_TAG
34 
35 #include <stdlib.h>
36 #include <trusty_log.h>
37 
__ignore_va_args__(...)38 static inline void __ignore_va_args__(...) {}
39 
40 #if BINDER_LOG_LEVEL >= BINDER_LOG_LEVEL_NORMAL
41 #define ALOGD(fmt, ...) TLOGD(fmt "\n", ##__VA_ARGS__)
42 #define ALOGI(fmt, ...) TLOGI(fmt "\n", ##__VA_ARGS__)
43 #define ALOGW(fmt, ...) TLOGW(fmt "\n", ##__VA_ARGS__)
44 #define ALOGE(fmt, ...) TLOGE(fmt "\n", ##__VA_ARGS__)
45 #else // BINDER_LOG_LEVEL >= BINDER_LOG_LEVEL_NORMAL
46 #define ALOGD(fmt, ...)                  \
47     while (0) {                          \
48         __ignore_va_args__(__VA_ARGS__); \
49     }
50 #define ALOGI(fmt, ...)                  \
51     while (0) {                          \
52         __ignore_va_args__(__VA_ARGS__); \
53     }
54 #define ALOGW(fmt, ...)                  \
55     while (0) {                          \
56         __ignore_va_args__(__VA_ARGS__); \
57     }
58 #define ALOGE(fmt, ...)                  \
59     while (0) {                          \
60         __ignore_va_args__(__VA_ARGS__); \
61     }
62 #endif // BINDER_LOG_LEVEL >= BINDER_LOG_LEVEL_NORMAL
63 
64 #if BINDER_LOG_LEVEL >= BINDER_LOG_LEVEL_VERBOSE
65 #define IF_ALOGV() if (TLOG_LVL >= TLOG_LVL_INFO)
66 #define ALOGV(fmt, ...) TLOGI(fmt "\n", ##__VA_ARGS__)
67 #else // BINDER_LOG_LEVEL >= BINDER_LOG_LEVEL_VERBOSE
68 #define IF_ALOGV() if (false)
69 #define ALOGV(fmt, ...)                  \
70     while (0) {                          \
71         __ignore_va_args__(__VA_ARGS__); \
72     }
73 #endif // BINDER_LOG_LEVEL >= BINDER_LOG_LEVEL_VERBOSE
74 
75 #define ALOGI_IF(cond, ...)                \
76     do {                                   \
77         if (cond) {                        \
78             ALOGI(#cond ": " __VA_ARGS__); \
79         }                                  \
80     } while (0)
81 #define ALOGE_IF(cond, ...)                \
82     do {                                   \
83         if (cond) {                        \
84             ALOGE(#cond ": " __VA_ARGS__); \
85         }                                  \
86     } while (0)
87 #define ALOGW_IF(cond, ...)                \
88     do {                                   \
89         if (cond) {                        \
90             ALOGW(#cond ": " __VA_ARGS__); \
91         }                                  \
92     } while (0)
93 
94 #define LOG_ALWAYS_FATAL(fmt, ...)                                \
95     do {                                                          \
96         TLOGE("libbinder fatal error: " fmt "\n", ##__VA_ARGS__); \
97         abort();                                                  \
98     } while (0)
99 #define LOG_ALWAYS_FATAL_IF(cond, ...)                \
100     do {                                              \
101         if (cond) {                                   \
102             LOG_ALWAYS_FATAL(#cond ": " __VA_ARGS__); \
103         }                                             \
104     } while (0)
105 #define LOG_FATAL(fmt, ...)                                       \
106     do {                                                          \
107         TLOGE("libbinder fatal error: " fmt "\n", ##__VA_ARGS__); \
108         abort();                                                  \
109     } while (0)
110 #define LOG_FATAL_IF(cond, ...)                \
111     do {                                       \
112         if (cond) {                            \
113             LOG_FATAL(#cond ": " __VA_ARGS__); \
114         }                                      \
115     } while (0)
116 
117 #define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ##__VA_ARGS__)
118 
119 #define android_errorWriteLog(tag, subTag)                               \
120     do {                                                                 \
121         TLOGE("android_errorWriteLog: tag:%x subTag:%s\n", tag, subTag); \
122     } while (0)
123 
124 // Override the definition of __assert from binder_status.h
125 #ifndef __BIONIC__
126 #undef __assert
127 #define __assert(file, line, str) LOG_ALWAYS_FATAL("%s:%d: %s", file, line, str)
128 #endif // __BIONIC__
129