1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _LIBC_LOGGING_H 30 #define _LIBC_LOGGING_H 31 32 #include <sys/cdefs.h> 33 #include <stdarg.h> 34 #include <stddef.h> 35 #include <stdint.h> 36 37 __BEGIN_DECLS 38 39 enum { 40 ANDROID_LOG_UNKNOWN = 0, 41 ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */ 42 43 ANDROID_LOG_VERBOSE, 44 ANDROID_LOG_DEBUG, 45 ANDROID_LOG_INFO, 46 ANDROID_LOG_WARN, 47 ANDROID_LOG_ERROR, 48 ANDROID_LOG_FATAL, 49 50 ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */ 51 }; 52 53 enum { 54 LOG_ID_MIN = 0, 55 56 LOG_ID_MAIN = 0, 57 LOG_ID_RADIO = 1, 58 LOG_ID_EVENTS = 2, 59 LOG_ID_SYSTEM = 3, 60 LOG_ID_CRASH = 4, 61 62 LOG_ID_MAX 63 }; 64 65 // Formats a message to the log (priority 'fatal'), then aborts. 66 __noreturn void __libc_fatal(const char* _Nonnull, ...) __printflike(1, 2); 67 68 // Formats a message to the log (priority 'fatal'), prefixed by "FORTIFY: ", then aborts. 69 __noreturn void __fortify_fatal(const char* _Nonnull, ...) __printflike(1, 2); 70 71 // 72 // Formatting routines for the C library's internal debugging. 73 // Unlike the usual alternatives, these don't allocate, and they don't drag in all of stdio. 74 // 75 76 int __libc_format_buffer(char* _Nonnull buf, size_t size, const char* _Nonnull fmt, ...) __printflike(3, 4); 77 78 #if defined(__arm__) || defined(__aarch64__) || defined(__x86_64__) 79 int __libc_format_buffer_va_list(char* _Nonnull buffer, size_t buffer_size, 80 const char* _Nonnull format, va_list args); 81 #else // defined(__mips__) || defined(__i386__) 82 int __libc_format_buffer_va_list(char* _Nonnull buffer, size_t buffer_size, 83 const char* _Nonnull format, va_list _Nonnull args); 84 #endif 85 86 int __libc_format_fd(int fd, const char* _Nonnull format , ...) __printflike(2, 3); 87 int __libc_format_log(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, ...) __printflike(3, 4); 88 #if defined(__arm__) || defined(__aarch64__) || defined(__x86_64__) 89 int __libc_format_log_va_list(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, va_list ap); 90 #else // defined(__mips__) || defined(__i386__) 91 int __libc_format_log_va_list(int pri, const char* _Nonnull tag, const char* _Nonnull fmt, va_list _Nonnull ap); 92 #endif 93 int __libc_write_log(int pri, const char* _Nonnull tag, const char* _Nonnull msg); 94 95 #define CHECK(predicate) \ 96 do { \ 97 if (!(predicate)) { \ 98 __libc_fatal("%s:%d: %s CHECK '" #predicate "' failed", \ 99 __FILE__, __LINE__, __FUNCTION__); \ 100 } \ 101 } while(0) 102 103 __END_DECLS 104 105 #endif 106