• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
20 #define _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
21 
22 /* Android private interfaces */
23 
24 #include <stdbool.h>
25 #include <stdint.h>
26 #include <sys/types.h>
27 
28 #if (defined(__cplusplus) && defined(_USING_LIBCXX))
29 extern "C++" {
30 #include <string>
31 }
32 #endif
33 
34 #include <log/log.h>
35 #include <log/log_event_list.h>
36 
37 #define LOGGER_MAGIC 'l'
38 
39 #if defined(__cplusplus)
40 extern "C" {
41 #endif
42 
43 /* Header Structure to pstore */
44 typedef struct __attribute__((__packed__)) {
45   uint8_t magic;
46   uint16_t len;
47   uint16_t uid;
48   uint16_t pid;
49 } android_pmsg_log_header_t;
50 
51 /* Header Structure to logd, and second header for pstore */
52 typedef struct __attribute__((__packed__)) {
53   typeof_log_id_t id;
54   uint16_t tid;
55   log_time realtime;
56 } android_log_header_t;
57 
58 /* Event Header Structure to logd */
59 typedef struct __attribute__((__packed__)) {
60   int32_t tag;  // Little Endian Order
61 } android_event_header_t;
62 
63 /* Event payload EVENT_TYPE_INT */
64 typedef struct __attribute__((__packed__)) {
65   int8_t type;   // EVENT_TYPE_INT
66   int32_t data;  // Little Endian Order
67 } android_event_int_t;
68 
69 /* Event with single EVENT_TYPE_INT */
70 typedef struct __attribute__((__packed__)) {
71   android_event_header_t header;
72   android_event_int_t payload;
73 } android_log_event_int_t;
74 
75 /* Event payload EVENT_TYPE_LONG */
76 typedef struct __attribute__((__packed__)) {
77   int8_t type;   // EVENT_TYPE_LONG
78   int64_t data;  // Little Endian Order
79 } android_event_long_t;
80 
81 /* Event with single EVENT_TYPE_LONG */
82 typedef struct __attribute__((__packed__)) {
83   android_event_header_t header;
84   android_event_long_t payload;
85 } android_log_event_long_t;
86 
87 /*
88  * Event payload EVENT_TYPE_STRING
89  *
90  * Danger: do not embed this structure into another structure.
91  * This structure uses a flexible array member, and when
92  * compiled using g++, __builtin_object_size(data, 1) returns
93  * a bad value. This is possibly a g++ bug, or a bug due to
94  * the fact that flexible array members are not supported
95  * in C++.
96  * http://stackoverflow.com/questions/4412749/are-flexible-array-members-valid-in-c
97  */
98 
99 typedef struct __attribute__((__packed__)) {
100   int8_t type;     // EVENT_TYPE_STRING;
101   int32_t length;  // Little Endian Order
102   char data[];
103 } android_event_string_t;
104 
105 /* Event with single EVENT_TYPE_STRING */
106 typedef struct __attribute__((__packed__)) {
107   android_event_header_t header;
108   int8_t type;     // EVENT_TYPE_STRING;
109   int32_t length;  // Little Endian Order
110   char data[];
111 } android_log_event_string_t;
112 
113 #define ANDROID_LOG_PMSG_FILE_MAX_SEQUENCE 256 /* 1MB file */
114 #define ANDROID_LOG_PMSG_FILE_SEQUENCE 1000
115 
116 ssize_t __android_log_pmsg_file_write(log_id_t logId, char prio,
117                                       const char* filename, const char* buf,
118                                       size_t len);
119 
120 #define LOG_ID_ANY ((log_id_t)-1)
121 #define ANDROID_LOG_ANY ANDROID_LOG_UNKNOWN
122 
123 /* first 5 arguments match __android_log_msg_file_write, a cast is safe */
124 typedef ssize_t (*__android_log_pmsg_file_read_fn)(log_id_t logId, char prio,
125                                                    const char* filename,
126                                                    const char* buf, size_t len,
127                                                    void* arg);
128 
129 ssize_t __android_log_pmsg_file_read(log_id_t logId, char prio,
130                                      const char* prefix,
131                                      __android_log_pmsg_file_read_fn fn,
132                                      void* arg);
133 
134 int __android_log_security_bwrite(int32_t tag, const void* payload, size_t len);
135 int __android_log_security_bswrite(int32_t tag, const char* payload);
136 int __android_log_security(); /* Device Owner is present */
137 
138 #define BOOL_DEFAULT_FLAG_TRUE_FALSE 0x1
139 #define BOOL_DEFAULT_FALSE 0x0        /* false if property not present   */
140 #define BOOL_DEFAULT_TRUE 0x1         /* true if property not present    */
141 #define BOOL_DEFAULT_FLAG_PERSIST 0x2 /* <key>, persist.<key>, ro.<key>  */
142 #define BOOL_DEFAULT_FLAG_ENG 0x4     /* off for user                    */
143 #define BOOL_DEFAULT_FLAG_SVELTE 0x8  /* off for low_ram                 */
144 bool __android_logger_property_get_bool(const char* key, int flag);
145 
146 #define LOG_BUFFER_SIZE (256 * 1024) /* Tuned with ro.logd.size per-platform \
147                                       */
148 #define LOG_BUFFER_MIN_SIZE (64 * 1024UL)
149 #define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL)
150 unsigned long __android_logger_get_buffer_size(log_id_t logId);
151 bool __android_logger_valid_buffer_size(unsigned long value);
152 
153 /* Retrieve the composed event buffer */
154 int android_log_write_list_buffer(android_log_context ctx, const char** msg);
155 
156 #ifdef __cplusplus
157 #ifdef __class_android_log_event_list_defined
158 #ifndef __class_android_log_event_list_private_defined
159 #define __class_android_log_event_list_private_defined
160 /* android_log_context C++ helpers */
161 extern "C++" {
162 class __android_log_event_list : public android_log_event_list {
163   __android_log_event_list(const android_log_event_list&) = delete;
164   void operator=(const __android_log_event_list&) = delete;
165 
166  public:
__android_log_event_list(int tag)167   explicit __android_log_event_list(int tag) : android_log_event_list(tag) {
168   }
__android_log_event_list(log_msg & log_msg)169   explicit __android_log_event_list(log_msg& log_msg)
170       : android_log_event_list(log_msg) {
171   }
172 
173 #if defined(_USING_LIBCXX)
string()174   operator std::string() {
175     if (ret) return std::string("");
176     const char* cp = NULL;
177     ssize_t len = android_log_write_list_buffer(ctx, &cp);
178     if (len < 0) ret = len;
179     if (!cp || (len <= 0)) return std::string("");
180     return std::string(cp, len);
181   }
182 #endif
183 };
184 }
185 #endif
186 #endif
187 #endif
188 
189 #if defined(__cplusplus)
190 }
191 #endif
192 
193 #endif /* _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_ */
194