Loading libs/binder/Android.bp +1 −3 Original line number Diff line number Diff line Loading @@ -217,6 +217,7 @@ cc_defaults { host_supported: true, header_libs: [ "liblog_stub", "trusty_mock_headers", ], Loading Loading @@ -262,9 +263,6 @@ cc_library_shared { "trusty/TrustyStatus.cpp", "trusty/socket.cpp", ], shared_libs: [ "liblog", ], } cc_defaults { Loading libs/binder/liblog_stub/Android.bp 0 → 100644 +44 −0 Original line number Diff line number Diff line // Copyright (C) 2023 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package { // See: http://go/android-license-faq // A large-scale-change added 'default_applicable_licenses' to import // all of the 'license_kinds' from "frameworks_native_license" // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 default_applicable_licenses: ["frameworks_native_license"], } cc_library_headers { name: "liblog_stub", export_include_dirs: ["include"], host_supported: true, native_bridge_supported: true, product_available: true, recovery_available: true, vendor_available: true, target: { windows: { enabled: true, }, }, visibility: [ "//frameworks/native/libs/binder:__subpackages__", "//system/core/libutils/binder", ], } libs/binder/liblog_stub/include/android/log.h 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once extern "C" { /** * Android log priority values, in increasing order of priority. */ typedef enum android_LogPriority { /** For internal use only. */ ANDROID_LOG_UNKNOWN = 0, /** The default priority, for internal use only. */ ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */ /** Verbose logging. Should typically be disabled for a release apk. */ ANDROID_LOG_VERBOSE, /** Debug logging. Should typically be disabled for a release apk. */ ANDROID_LOG_DEBUG, /** Informational logging. Should typically be disabled for a release apk. */ ANDROID_LOG_INFO, /** Warning logging. For use with recoverable failures. */ ANDROID_LOG_WARN, /** Error logging. For use with unrecoverable failures. */ ANDROID_LOG_ERROR, /** Fatal logging. For use when aborting. */ ANDROID_LOG_FATAL, /** For internal use only. */ ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */ } android_LogPriority; typedef void (*__android_logger_function)(const struct __android_log_message* log_message); inline void __android_log_set_logger(__android_logger_function) {} inline void __android_log_stderr_logger(const struct __android_log_message*) {} } // extern "C" libs/binder/liblog_stub/include/log/log.h 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <cstdio> #include <cstdlib> #include <android/log.h> extern "C" { #ifndef ANDROID_LOG_STUB_MIN_PRIORITY #define ANDROID_LOG_STUB_MIN_PRIORITY ANDROID_LOG_INFO #endif #ifndef LOG_TAG #define LOG_TAG "" #endif constexpr bool __android_log_stub_is_loggable(android_LogPriority priority) { return ANDROID_LOG_STUB_MIN_PRIORITY <= priority; } int __android_log_print(int prio, const char* tag, const char* fmt, ...) __attribute__((format(printf, 3, 4))) #ifdef ANDROID_LOG_STUB_WEAK_PRINT __attribute__((weak)) #endif ; #define IF_ALOG(priority, tag) \ if (__android_log_stub_is_loggable(ANDROID_##priority) && __android_log_print) #define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG) #define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG) #define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG) #define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG) #define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG) #define ALOG(priority, tag, fmt, ...) \ do { \ if (false)[[/*VERY*/ unlikely]] { /* ignore unused __VA_ARGS__ */ \ std::fprintf(stderr, fmt __VA_OPT__(, ) __VA_ARGS__); \ } \ IF_ALOG(priority, tag) { \ __android_log_print(ANDROID_##priority, tag, \ tag ": " fmt "\n" __VA_OPT__(, ) __VA_ARGS__); \ } \ if constexpr (ANDROID_##priority == ANDROID_LOG_FATAL) std::abort(); \ } while (false) #define ALOGV(...) ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__) #define ALOGD(...) ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__) #define ALOGI(...) ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__) #define ALOGW(...) ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__) #define ALOGE(...) ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__) #define LOG_FATAL(...) ALOG(LOG_FATAL, LOG_TAG, __VA_ARGS__) #define LOG_ALWAYS_FATAL LOG_FATAL #define ALOG_IF(cond, priority, tag, ...) \ if (cond) [[unlikely]] \ ALOG(priority, tag, #cond ": " __VA_ARGS__) #define ALOGV_IF(cond, ...) ALOG_IF(cond, LOG_VERBOSE, LOG_TAG, __VA_ARGS__) #define ALOGD_IF(cond, ...) ALOG_IF(cond, LOG_DEBUG, LOG_TAG, __VA_ARGS__) #define ALOGI_IF(cond, ...) ALOG_IF(cond, LOG_INFO, LOG_TAG, __VA_ARGS__) #define ALOGW_IF(cond, ...) ALOG_IF(cond, LOG_WARN, LOG_TAG, __VA_ARGS__) #define ALOGE_IF(cond, ...) ALOG_IF(cond, LOG_ERROR, LOG_TAG, __VA_ARGS__) #define LOG_FATAL_IF(cond, ...) ALOG_IF(cond, LOG_FATAL, LOG_TAG, __VA_ARGS__) #define LOG_ALWAYS_FATAL_IF LOG_FATAL_IF #define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ##__VA_ARGS__) inline int android_errorWriteLog(int tag, const char* subTag) { ALOGE("android_errorWriteLog(%x, %s)", tag, subTag); return 0; } } // extern "C" libs/binder/trusty/OS.cpp +44 −0 Original line number Diff line number Diff line Loading @@ -22,10 +22,14 @@ #endif #include <binder/RpcTransportTipcTrusty.h> #include <log/log.h> #include <trusty_log.h> #include "../OS.h" #include "TrustyStatus.h" #include <cstdarg> using android::binder::borrowed_fd; using android::binder::unique_fd; Loading Loading @@ -87,3 +91,43 @@ ssize_t receiveMessageFromSocket( } } // namespace android::binder::os int __android_log_print(int prio [[maybe_unused]], const char* tag, const char* fmt, ...) { #ifdef TRUSTY_USERSPACE #define trusty_tlog _tlog #define trusty_vtlog _vtlog #else // mapping taken from kernel trusty_log.h (TLOGx) int kernelLogLevel; if (prio <= ANDROID_LOG_DEBUG) { kernelLogLevel = LK_DEBUGLEVEL_ALWAYS; } else if (prio == ANDROID_LOG_INFO) { kernelLogLevel = LK_DEBUGLEVEL_SPEW; } else if (prio == ANDROID_LOG_WARN) { kernelLogLevel = LK_DEBUGLEVEL_INFO; } else if (prio == ANDROID_LOG_ERROR) { kernelLogLevel = LK_DEBUGLEVEL_CRITICAL; } else { /* prio >= ANDROID_LOG_FATAL */ kernelLogLevel = LK_DEBUGLEVEL_CRITICAL; } #if LK_DEBUGLEVEL_NO_ALIASES auto LK_DEBUGLEVEL_kernelLogLevel = kernelLogLevel; #endif #define trusty_tlog(...) _tlog(kernelLogLevel, __VA_ARGS__) #define trusty_vtlog(...) _vtlog(kernelLogLevel, __VA_ARGS__) #endif va_list args; va_start(args, fmt); trusty_tlog((tag[0] == '\0') ? "libbinder" : "libbinder-"); trusty_vtlog(fmt, args); va_end(args); return 1; } // TODO(b/285204695): remove once trusty mock doesn't depend on libbase extern "C" int __android_log_buf_print(int, int, const char*, const char*, ...) { return -ENOSYS; } Loading
libs/binder/Android.bp +1 −3 Original line number Diff line number Diff line Loading @@ -217,6 +217,7 @@ cc_defaults { host_supported: true, header_libs: [ "liblog_stub", "trusty_mock_headers", ], Loading Loading @@ -262,9 +263,6 @@ cc_library_shared { "trusty/TrustyStatus.cpp", "trusty/socket.cpp", ], shared_libs: [ "liblog", ], } cc_defaults { Loading
libs/binder/liblog_stub/Android.bp 0 → 100644 +44 −0 Original line number Diff line number Diff line // Copyright (C) 2023 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package { // See: http://go/android-license-faq // A large-scale-change added 'default_applicable_licenses' to import // all of the 'license_kinds' from "frameworks_native_license" // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 default_applicable_licenses: ["frameworks_native_license"], } cc_library_headers { name: "liblog_stub", export_include_dirs: ["include"], host_supported: true, native_bridge_supported: true, product_available: true, recovery_available: true, vendor_available: true, target: { windows: { enabled: true, }, }, visibility: [ "//frameworks/native/libs/binder:__subpackages__", "//system/core/libutils/binder", ], }
libs/binder/liblog_stub/include/android/log.h 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once extern "C" { /** * Android log priority values, in increasing order of priority. */ typedef enum android_LogPriority { /** For internal use only. */ ANDROID_LOG_UNKNOWN = 0, /** The default priority, for internal use only. */ ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */ /** Verbose logging. Should typically be disabled for a release apk. */ ANDROID_LOG_VERBOSE, /** Debug logging. Should typically be disabled for a release apk. */ ANDROID_LOG_DEBUG, /** Informational logging. Should typically be disabled for a release apk. */ ANDROID_LOG_INFO, /** Warning logging. For use with recoverable failures. */ ANDROID_LOG_WARN, /** Error logging. For use with unrecoverable failures. */ ANDROID_LOG_ERROR, /** Fatal logging. For use when aborting. */ ANDROID_LOG_FATAL, /** For internal use only. */ ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */ } android_LogPriority; typedef void (*__android_logger_function)(const struct __android_log_message* log_message); inline void __android_log_set_logger(__android_logger_function) {} inline void __android_log_stderr_logger(const struct __android_log_message*) {} } // extern "C"
libs/binder/liblog_stub/include/log/log.h 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <cstdio> #include <cstdlib> #include <android/log.h> extern "C" { #ifndef ANDROID_LOG_STUB_MIN_PRIORITY #define ANDROID_LOG_STUB_MIN_PRIORITY ANDROID_LOG_INFO #endif #ifndef LOG_TAG #define LOG_TAG "" #endif constexpr bool __android_log_stub_is_loggable(android_LogPriority priority) { return ANDROID_LOG_STUB_MIN_PRIORITY <= priority; } int __android_log_print(int prio, const char* tag, const char* fmt, ...) __attribute__((format(printf, 3, 4))) #ifdef ANDROID_LOG_STUB_WEAK_PRINT __attribute__((weak)) #endif ; #define IF_ALOG(priority, tag) \ if (__android_log_stub_is_loggable(ANDROID_##priority) && __android_log_print) #define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG) #define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG) #define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG) #define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG) #define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG) #define ALOG(priority, tag, fmt, ...) \ do { \ if (false)[[/*VERY*/ unlikely]] { /* ignore unused __VA_ARGS__ */ \ std::fprintf(stderr, fmt __VA_OPT__(, ) __VA_ARGS__); \ } \ IF_ALOG(priority, tag) { \ __android_log_print(ANDROID_##priority, tag, \ tag ": " fmt "\n" __VA_OPT__(, ) __VA_ARGS__); \ } \ if constexpr (ANDROID_##priority == ANDROID_LOG_FATAL) std::abort(); \ } while (false) #define ALOGV(...) ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__) #define ALOGD(...) ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__) #define ALOGI(...) ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__) #define ALOGW(...) ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__) #define ALOGE(...) ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__) #define LOG_FATAL(...) ALOG(LOG_FATAL, LOG_TAG, __VA_ARGS__) #define LOG_ALWAYS_FATAL LOG_FATAL #define ALOG_IF(cond, priority, tag, ...) \ if (cond) [[unlikely]] \ ALOG(priority, tag, #cond ": " __VA_ARGS__) #define ALOGV_IF(cond, ...) ALOG_IF(cond, LOG_VERBOSE, LOG_TAG, __VA_ARGS__) #define ALOGD_IF(cond, ...) ALOG_IF(cond, LOG_DEBUG, LOG_TAG, __VA_ARGS__) #define ALOGI_IF(cond, ...) ALOG_IF(cond, LOG_INFO, LOG_TAG, __VA_ARGS__) #define ALOGW_IF(cond, ...) ALOG_IF(cond, LOG_WARN, LOG_TAG, __VA_ARGS__) #define ALOGE_IF(cond, ...) ALOG_IF(cond, LOG_ERROR, LOG_TAG, __VA_ARGS__) #define LOG_FATAL_IF(cond, ...) ALOG_IF(cond, LOG_FATAL, LOG_TAG, __VA_ARGS__) #define LOG_ALWAYS_FATAL_IF LOG_FATAL_IF #define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ##__VA_ARGS__) inline int android_errorWriteLog(int tag, const char* subTag) { ALOGE("android_errorWriteLog(%x, %s)", tag, subTag); return 0; } } // extern "C"
libs/binder/trusty/OS.cpp +44 −0 Original line number Diff line number Diff line Loading @@ -22,10 +22,14 @@ #endif #include <binder/RpcTransportTipcTrusty.h> #include <log/log.h> #include <trusty_log.h> #include "../OS.h" #include "TrustyStatus.h" #include <cstdarg> using android::binder::borrowed_fd; using android::binder::unique_fd; Loading Loading @@ -87,3 +91,43 @@ ssize_t receiveMessageFromSocket( } } // namespace android::binder::os int __android_log_print(int prio [[maybe_unused]], const char* tag, const char* fmt, ...) { #ifdef TRUSTY_USERSPACE #define trusty_tlog _tlog #define trusty_vtlog _vtlog #else // mapping taken from kernel trusty_log.h (TLOGx) int kernelLogLevel; if (prio <= ANDROID_LOG_DEBUG) { kernelLogLevel = LK_DEBUGLEVEL_ALWAYS; } else if (prio == ANDROID_LOG_INFO) { kernelLogLevel = LK_DEBUGLEVEL_SPEW; } else if (prio == ANDROID_LOG_WARN) { kernelLogLevel = LK_DEBUGLEVEL_INFO; } else if (prio == ANDROID_LOG_ERROR) { kernelLogLevel = LK_DEBUGLEVEL_CRITICAL; } else { /* prio >= ANDROID_LOG_FATAL */ kernelLogLevel = LK_DEBUGLEVEL_CRITICAL; } #if LK_DEBUGLEVEL_NO_ALIASES auto LK_DEBUGLEVEL_kernelLogLevel = kernelLogLevel; #endif #define trusty_tlog(...) _tlog(kernelLogLevel, __VA_ARGS__) #define trusty_vtlog(...) _vtlog(kernelLogLevel, __VA_ARGS__) #endif va_list args; va_start(args, fmt); trusty_tlog((tag[0] == '\0') ? "libbinder" : "libbinder-"); trusty_vtlog(fmt, args); va_end(args); return 1; } // TODO(b/285204695): remove once trusty mock doesn't depend on libbase extern "C" int __android_log_buf_print(int, int, const char*, const char*, ...) { return -ENOSYS; }