1 /* 2 * Copyright (C) 2015 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 /* This file is used to define the internal protocol for the Android Logger */ 18 19 #pragma once 20 21 /* Android private interfaces */ 22 23 #include <stdbool.h> 24 #include <stdint.h> 25 #include <sys/types.h> 26 27 #ifdef __cplusplus 28 #include <string> 29 #endif 30 31 #include <log/log.h> 32 #include <log/log_event_list.h> 33 34 #define LOGGER_MAGIC 'l' 35 36 #if defined(__cplusplus) 37 extern "C" { 38 #endif 39 40 /* Header Structure to pstore */ 41 typedef struct __attribute__((__packed__)) { 42 uint8_t magic; 43 uint16_t len; 44 uint16_t uid; 45 uint16_t pid; 46 } android_pmsg_log_header_t; 47 48 /* Header Structure to logd, and second header for pstore */ 49 typedef struct __attribute__((__packed__)) { 50 uint8_t id; 51 uint16_t tid; 52 log_time realtime; 53 } android_log_header_t; 54 55 /* Event Header Structure to logd */ 56 typedef struct __attribute__((__packed__)) { 57 int32_t tag; // Little Endian Order 58 } android_event_header_t; 59 60 // Event payload EVENT_TYPE_LIST 61 typedef struct __attribute__((__packed__)) { 62 int8_t type; // EVENT_TYPE_LIST 63 int8_t element_count; 64 } android_event_list_t; 65 66 // Event payload EVENT_TYPE_FLOAT 67 typedef struct __attribute__((__packed__)) { 68 int8_t type; // EVENT_TYPE_FLOAT 69 float data; 70 } android_event_float_t; 71 72 /* Event payload EVENT_TYPE_INT */ 73 typedef struct __attribute__((__packed__)) { 74 int8_t type; // EVENT_TYPE_INT 75 int32_t data; // Little Endian Order 76 } android_event_int_t; 77 78 /* Event with single EVENT_TYPE_INT */ 79 typedef struct __attribute__((__packed__)) { 80 android_event_header_t header; 81 android_event_int_t payload; 82 } android_log_event_int_t; 83 84 /* Event payload EVENT_TYPE_LONG */ 85 typedef struct __attribute__((__packed__)) { 86 int8_t type; // EVENT_TYPE_LONG 87 int64_t data; // Little Endian Order 88 } android_event_long_t; 89 90 /* Event with single EVENT_TYPE_LONG */ 91 typedef struct __attribute__((__packed__)) { 92 android_event_header_t header; 93 android_event_long_t payload; 94 } android_log_event_long_t; 95 96 /* 97 * Event payload EVENT_TYPE_STRING 98 * 99 * Danger: do not embed this structure into another structure. 100 * This structure uses a flexible array member, and when 101 * compiled using g++, __builtin_object_size(data, 1) returns 102 * a bad value. This is possibly a g++ bug, or a bug due to 103 * the fact that flexible array members are not supported 104 * in C++. 105 * http://stackoverflow.com/questions/4412749/are-flexible-array-members-valid-in-c 106 */ 107 108 typedef struct __attribute__((__packed__)) { 109 int8_t type; // EVENT_TYPE_STRING; 110 int32_t length; // Little Endian Order 111 char data[]; 112 } android_event_string_t; 113 114 /* Event with single EVENT_TYPE_STRING */ 115 typedef struct __attribute__((__packed__)) { 116 android_event_header_t header; 117 int8_t type; // EVENT_TYPE_STRING; 118 int32_t length; // Little Endian Order 119 char data[]; 120 } android_log_event_string_t; 121 122 #define ANDROID_LOG_PMSG_FILE_MAX_SEQUENCE 256 /* 1MB file */ 123 #define ANDROID_LOG_PMSG_FILE_SEQUENCE 1000 124 125 ssize_t __android_log_pmsg_file_write(log_id_t logId, char prio, 126 const char* filename, const char* buf, 127 size_t len); 128 129 #define LOG_ID_ANY ((log_id_t)-1) 130 #define ANDROID_LOG_ANY ANDROID_LOG_UNKNOWN 131 132 /* first 5 arguments match __android_log_msg_file_write, a cast is safe */ 133 typedef ssize_t (*__android_log_pmsg_file_read_fn)(log_id_t logId, char prio, 134 const char* filename, 135 const char* buf, size_t len, 136 void* arg); 137 138 ssize_t __android_log_pmsg_file_read(log_id_t logId, char prio, 139 const char* prefix, 140 __android_log_pmsg_file_read_fn fn, 141 void* arg); 142 143 int __android_log_security_bwrite(int32_t tag, const void* payload, size_t len); 144 int __android_log_security_bswrite(int32_t tag, const char* payload); 145 int __android_log_security(); /* Device Owner is present */ 146 147 /* Retrieve the composed event buffer */ 148 int android_log_write_list_buffer(android_log_context ctx, const char** msg); 149 150 #if defined(__cplusplus) 151 } 152 #endif 153