Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Tom Cherry | bab5220 | 2019-01-15 17:47:48 -0800 | [diff] [blame] | 17 | #pragma once |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 18 | |
Mark Salyzyn | db8a266 | 2016-10-10 07:27:42 -0700 | [diff] [blame] | 19 | #include <stdatomic.h> |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 20 | |
| 21 | #include <cutils/list.h> |
Mark Salyzyn | aeaaf81 | 2016-09-30 13:30:33 -0700 | [diff] [blame] | 22 | #include <log/log.h> |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 23 | |
| 24 | #include "log_portability.h" |
Tom Cherry | 6f6ef39 | 2019-01-16 14:17:08 -0800 | [diff] [blame] | 25 | #include "uio.h" |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 26 | |
| 27 | __BEGIN_DECLS |
| 28 | |
| 29 | /* Union, sock or fd of zero is not allowed unless static initialized */ |
Tom Cherry | 71ba164 | 2019-01-10 10:37:36 -0800 | [diff] [blame] | 30 | union android_log_context_union { |
Mark Salyzyn | 04bbc8e | 2017-03-08 15:03:20 -0800 | [diff] [blame] | 31 | void* priv; |
Mark Salyzyn | db8a266 | 2016-10-10 07:27:42 -0700 | [diff] [blame] | 32 | atomic_int sock; |
| 33 | atomic_int fd; |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | struct android_log_transport_write { |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 37 | const char* name; /* human name to describe the transport */ |
| 38 | unsigned logMask; /* mask cache of available() success */ |
Tom Cherry | 71ba164 | 2019-01-10 10:37:36 -0800 | [diff] [blame] | 39 | union android_log_context_union context; /* Initialized by static allocation */ |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 40 | |
Mark Salyzyn | 7048f0b | 2017-02-06 10:21:56 -0800 | [diff] [blame] | 41 | int (*available)(log_id_t logId); /* Does not cause resources to be taken */ |
| 42 | int (*open)(); /* can be called multiple times, reusing current resources */ |
| 43 | void (*close)(); /* free up resources */ |
| 44 | /* write log to transport, returns number of bytes propagated, or -errno */ |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 45 | int (*write)(log_id_t logId, struct timespec* ts, struct iovec* vec, |
| 46 | size_t nr); |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 47 | }; |
| 48 | |
Tom Cherry | 828db1a | 2019-11-14 10:39:40 -0800 | [diff] [blame] | 49 | struct logger_list { |
Tom Cherry | 026ddde | 2019-11-18 15:13:47 -0800 | [diff] [blame^] | 50 | atomic_int fd; |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 51 | int mode; |
| 52 | unsigned int tail; |
| 53 | log_time start; |
| 54 | pid_t pid; |
Tom Cherry | 9156c53 | 2019-11-14 08:56:39 -0800 | [diff] [blame] | 55 | uint32_t log_mask; |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 56 | }; |
| 57 | |
Tom Cherry | 9156c53 | 2019-11-14 08:56:39 -0800 | [diff] [blame] | 58 | // Format for a 'logger' entry: uintptr_t where only the bottom 32 bits are used. |
| 59 | // bit 31: Set if this 'logger' is for logd. |
| 60 | // bit 30: Set if this 'logger' is for pmsg |
| 61 | // bits 0-2: the decimal value of the log buffer. |
| 62 | // Other bits are unused. |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 63 | |
Tom Cherry | 9156c53 | 2019-11-14 08:56:39 -0800 | [diff] [blame] | 64 | #define LOGGER_LOGD (1 << 31) |
| 65 | #define LOGGER_PMSG (1 << 30) |
| 66 | #define LOGGER_LOG_ID_MASK ((1 << 3) - 1) |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 67 | |
Tom Cherry | 9156c53 | 2019-11-14 08:56:39 -0800 | [diff] [blame] | 68 | inline bool android_logger_is_logd(struct logger* logger) { |
| 69 | return reinterpret_cast<uintptr_t>(logger) & LOGGER_LOGD; |
| 70 | } |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 71 | |
| 72 | /* OS specific dribs and drabs */ |
| 73 | |
| 74 | #if defined(_WIN32) |
Mark Salyzyn | ec4f5c7 | 2016-07-13 07:38:39 -0700 | [diff] [blame] | 75 | #include <private/android_filesystem_config.h> |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 76 | typedef uint32_t uid_t; |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 77 | static inline uid_t __android_log_uid() { |
| 78 | return AID_SYSTEM; |
| 79 | } |
Mark Salyzyn | ec4f5c7 | 2016-07-13 07:38:39 -0700 | [diff] [blame] | 80 | #else |
Mark Salyzyn | 2ed51d7 | 2017-03-09 08:09:43 -0800 | [diff] [blame] | 81 | static inline uid_t __android_log_uid() { |
| 82 | return getuid(); |
| 83 | } |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 84 | #endif |
| 85 | |
Tom Cherry | 2d9779e | 2019-02-08 11:46:19 -0800 | [diff] [blame] | 86 | void __android_log_lock(); |
| 87 | int __android_log_trylock(); |
| 88 | void __android_log_unlock(); |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 89 | |
Mark Salyzyn | 018a96d | 2016-03-01 13:45:42 -0800 | [diff] [blame] | 90 | __END_DECLS |