Home | History | Annotate | Download | only in private
      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 <stdint.h>
     25 #include <sys/types.h>
     26 
     27 #include <log/log.h>
     28 #include <log/log_read.h>
     29 
     30 #define LOGGER_MAGIC 'l'
     31 
     32 /* Header Structure to pstore */
     33 typedef struct __attribute__((__packed__)) {
     34     uint8_t magic;
     35     uint16_t len;
     36     uint16_t uid;
     37     uint16_t pid;
     38 } android_pmsg_log_header_t;
     39 
     40 /* Header Structure to logd, and second header for pstore */
     41 typedef struct __attribute__((__packed__)) {
     42     typeof_log_id_t id;
     43     uint16_t tid;
     44     log_time realtime;
     45 } android_log_header_t;
     46 
     47 /* Event Header Structure to logd */
     48 typedef struct __attribute__((__packed__)) {
     49     int32_t tag;  // Little Endian Order
     50 } android_event_header_t;
     51 
     52 /* Event payload EVENT_TYPE_INT */
     53 typedef struct __attribute__((__packed__)) {
     54     int8_t type;  // EVENT_TYPE_INT
     55     int32_t data; // Little Endian Order
     56 } android_event_int_t;
     57 
     58 /* Event with single EVENT_TYPE_INT */
     59 typedef struct __attribute__((__packed__)) {
     60     android_event_header_t header;
     61     android_event_int_t payload;
     62 } android_log_event_int_t;
     63 
     64 /* Event payload EVENT_TYPE_LONG */
     65 typedef struct __attribute__((__packed__)) {
     66     int8_t type;  // EVENT_TYPE_LONG
     67     int64_t data; // Little Endian Order
     68 } android_event_long_t;
     69 
     70 /* Event with single EVENT_TYPE_LONG */
     71 typedef struct __attribute__((__packed__)) {
     72     android_event_header_t header;
     73     android_event_long_t payload;
     74 } android_log_event_long_t;
     75 
     76 /*
     77  * Event payload EVENT_TYPE_STRING
     78  *
     79  * Danger: do not embed this structure into another structure.
     80  * This structure uses a flexible array member, and when
     81  * compiled using g++, __builtin_object_size(data, 1) returns
     82  * a bad value. This is possibly a g++ bug, or a bug due to
     83  * the fact that flexible array members are not supported
     84  * in C++.
     85  * http://stackoverflow.com/questions/4412749/are-flexible-array-members-valid-in-c
     86  */
     87 typedef struct __attribute__((__packed__)) {
     88     int8_t type;    // EVENT_TYPE_STRING;
     89     int32_t length; // Little Endian Order
     90     char data[];
     91 } android_event_string_t;
     92 
     93 /* Event with single EVENT_TYPE_STRING */
     94 typedef struct __attribute__((__packed__)) {
     95     android_event_header_t header;
     96     int8_t type;    // EVENT_TYPE_STRING;
     97     int32_t length; // Little Endian Order
     98     char data[];
     99 } android_log_event_string_t;
    100 
    101 #if defined(__cplusplus)
    102 extern "C" {
    103 #endif
    104 
    105 #define ANDROID_LOG_PMSG_FILE_MAX_SEQUENCE 256 /* 1MB file */
    106 #define ANDROID_LOG_PMSG_FILE_SEQUENCE     1000
    107 
    108 ssize_t __android_log_pmsg_file_write(
    109         log_id_t logId,
    110         char prio,
    111         const char *filename,
    112         const char *buf, size_t len);
    113 
    114 #define LOG_ID_ANY      ((log_id_t)-1)
    115 #define ANDROID_LOG_ANY ANDROID_LOG_UNKNOWN
    116 
    117 /* first 5 arguments match __android_log_msg_file_write, a cast is safe */
    118 typedef ssize_t (*__android_log_pmsg_file_read_fn)(
    119         log_id_t logId,
    120         char prio,
    121         const char *filename,
    122         const char *buf, size_t len, void *arg);
    123 
    124 ssize_t __android_log_pmsg_file_read(
    125         log_id_t logId, char prio, const char *prefix,
    126         __android_log_pmsg_file_read_fn fn, void *arg);
    127 
    128 #if defined(__cplusplus)
    129 }
    130 #endif
    131 
    132 #endif /* _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_ */
    133