blob: abc24cec1c13bc72bfb934175395edd949c03515 [file] [log] [blame]
Mark Salyzyn018a96d2016-03-01 13:45:42 -08001/*
2 * Copyright (C) 2007-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
17#include <errno.h>
Tom Cherry349b0c42020-01-08 14:47:42 -080018#include <inttypes.h>
Mark Salyzyn018a96d2016-03-01 13:45:42 -080019#include <stdlib.h>
20#include <string.h>
21#include <sys/time.h>
22
23#ifdef __BIONIC__
24#include <android/set_abort_message.h>
25#endif
26
Tom Cherry349b0c42020-01-08 14:47:42 -080027#include <shared_mutex>
28
Tom Cherry121292d2020-01-14 09:52:10 -080029#include <android-base/macros.h>
Mark Salyzyn018a96d2016-03-01 13:45:42 -080030#include <private/android_filesystem_config.h>
31#include <private/android_logger.h>
32
Tom Cherry349b0c42020-01-08 14:47:42 -080033#include "android/log.h"
Mark Salyzyn018a96d2016-03-01 13:45:42 -080034#include "logger.h"
Tom Cherry349b0c42020-01-08 14:47:42 -080035#include "rwlock.h"
Tom Cherry6f6ef392019-01-16 14:17:08 -080036#include "uio.h"
Mark Salyzyn018a96d2016-03-01 13:45:42 -080037
Tom Cherry97ec4ee2019-10-02 10:52:55 -070038#if (FAKE_LOG_DEVICE == 0)
Tom Cherry21bb36c2020-01-08 15:18:26 -080039#include "logd_writer.h"
40#include "pmsg_writer.h"
Tom Cherry97ec4ee2019-10-02 10:52:55 -070041#else
Tom Cherry21bb36c2020-01-08 15:18:26 -080042#include "fake_log_device.h"
Tom Cherry97ec4ee2019-10-02 10:52:55 -070043#endif
Tom Cherry2beabe52019-10-01 13:05:58 -070044
Tom Cherry349b0c42020-01-08 14:47:42 -080045#if defined(__APPLE__)
46#include <pthread.h>
47#elif defined(__linux__) && !defined(__ANDROID__)
48#include <syscall.h>
49#elif defined(_WIN32)
50#include <windows.h>
51#endif
52
Tom Cherry21bb36c2020-01-08 15:18:26 -080053#define LOG_BUF_SIZE 1024
54
Dan Willemsen0910d2d2016-11-29 13:39:55 -080055#if defined(__ANDROID__)
Tom Cherry06e0fce2019-12-11 14:26:37 -080056static int check_log_uid_permissions() {
Tom Cherryb47aa2a2020-01-08 15:34:14 -080057 uid_t uid = getuid();
Mark Salyzync33103c2016-03-28 16:20:29 -070058
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080059 /* Matches clientHasLogCredentials() in logd */
60 if ((uid != AID_SYSTEM) && (uid != AID_ROOT) && (uid != AID_LOG)) {
61 uid = geteuid();
Mark Salyzync33103c2016-03-28 16:20:29 -070062 if ((uid != AID_SYSTEM) && (uid != AID_ROOT) && (uid != AID_LOG)) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080063 gid_t gid = getgid();
64 if ((gid != AID_SYSTEM) && (gid != AID_ROOT) && (gid != AID_LOG)) {
65 gid = getegid();
66 if ((gid != AID_SYSTEM) && (gid != AID_ROOT) && (gid != AID_LOG)) {
67 int num_groups;
68 gid_t* groups;
Mark Salyzync33103c2016-03-28 16:20:29 -070069
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080070 num_groups = getgroups(0, NULL);
71 if (num_groups <= 0) {
72 return -EPERM;
73 }
Tom Cherry71ba1642019-01-10 10:37:36 -080074 groups = static_cast<gid_t*>(calloc(num_groups, sizeof(gid_t)));
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080075 if (!groups) {
76 return -ENOMEM;
77 }
78 num_groups = getgroups(num_groups, groups);
79 while (num_groups > 0) {
80 if (groups[num_groups - 1] == AID_LOG) {
81 break;
Mark Salyzync33103c2016-03-28 16:20:29 -070082 }
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080083 --num_groups;
84 }
85 free(groups);
86 if (num_groups <= 0) {
87 return -EPERM;
88 }
Mark Salyzync33103c2016-03-28 16:20:29 -070089 }
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080090 }
Mark Salyzync33103c2016-03-28 16:20:29 -070091 }
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080092 }
Mark Salyzyn2ed51d72017-03-09 08:09:43 -080093 return 0;
Mark Salyzync33103c2016-03-28 16:20:29 -070094}
Tom Cherry06e0fce2019-12-11 14:26:37 -080095#endif
Mark Salyzync33103c2016-03-28 16:20:29 -070096
Mark Salyzyndf7a4c62016-08-23 10:23:36 -070097/*
98 * Release any logger resources. A new log write will immediately re-acquire.
99 */
Tom Cherry2d9779e2019-02-08 11:46:19 -0800100void __android_log_close() {
Tom Cherry21bb36c2020-01-08 15:18:26 -0800101#if (FAKE_LOG_DEVICE == 0)
102 LogdClose();
103 PmsgClose();
104#else
105 FakeClose();
106#endif
Mark Salyzyndf7a4c62016-08-23 10:23:36 -0700107}
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800108
Tom Cherry349b0c42020-01-08 14:47:42 -0800109#ifdef __ANDROID__
110static __android_logger_function logger_function = __android_log_logd_logger;
111#else
112static __android_logger_function logger_function = __android_log_stderr_logger;
113#endif
114static RwLock logger_function_lock;
115
116void __android_log_set_logger(__android_logger_function logger) {
117 auto lock = std::unique_lock{logger_function_lock};
118 logger_function = logger;
119}
120
121void __android_log_default_aborter(const char* abort_message) {
122#ifdef __ANDROID__
123 android_set_abort_message(abort_message);
124#else
125 UNUSED(abort_message);
126#endif
127 abort();
128}
129
130static __android_aborter_function aborter_function = __android_log_default_aborter;
131static RwLock aborter_function_lock;
132
133void __android_log_set_aborter(__android_aborter_function aborter) {
134 auto lock = std::unique_lock{aborter_function_lock};
135 aborter_function = aborter;
136}
137
138void __android_log_call_aborter(const char* abort_message) {
139 auto lock = std::shared_lock{aborter_function_lock};
140 aborter_function(abort_message);
141}
142
143#ifdef __ANDROID__
Tom Cherry06e0fce2019-12-11 14:26:37 -0800144static int write_to_log(log_id_t log_id, struct iovec* vec, size_t nr) {
Mark Salyzyn72d37242018-03-07 10:42:06 -0800145 int ret, save_errno;
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800146 struct timespec ts;
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800147
Mark Salyzyn72d37242018-03-07 10:42:06 -0800148 save_errno = errno;
Tom Cherry06e0fce2019-12-11 14:26:37 -0800149
150 if (log_id == LOG_ID_KERNEL) {
151 return -EINVAL;
152 }
153
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800154 clock_gettime(android_log_clockid(), &ts);
Mark Salyzyn142b43d2016-12-28 10:30:57 -0800155
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800156 if (log_id == LOG_ID_SECURITY) {
157 if (vec[0].iov_len < 4) {
Mark Salyzyn72d37242018-03-07 10:42:06 -0800158 errno = save_errno;
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800159 return -EINVAL;
160 }
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800161
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800162 ret = check_log_uid_permissions();
163 if (ret < 0) {
Mark Salyzyn72d37242018-03-07 10:42:06 -0800164 errno = save_errno;
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800165 return ret;
166 }
167 if (!__android_log_security()) {
168 /* If only we could reset downstream logd counter */
Mark Salyzyn72d37242018-03-07 10:42:06 -0800169 errno = save_errno;
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800170 return -EPERM;
171 }
Yao Chen025f05a2017-12-01 15:48:19 -0800172 } else if (log_id == LOG_ID_EVENTS || log_id == LOG_ID_STATS) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800173 if (vec[0].iov_len < 4) {
Mark Salyzyn72d37242018-03-07 10:42:06 -0800174 errno = save_errno;
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800175 return -EINVAL;
176 }
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800177 } else {
Tom Cherry2187a412019-10-01 17:13:43 -0700178 int prio = *static_cast<int*>(vec[0].iov_base);
179 const char* tag = static_cast<const char*>(vec[1].iov_base);
180 size_t len = vec[1].iov_len;
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800181
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800182 if (!__android_log_is_loggable_len(prio, tag, len - 1, ANDROID_LOG_VERBOSE)) {
Mark Salyzyn72d37242018-03-07 10:42:06 -0800183 errno = save_errno;
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800184 return -EPERM;
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800185 }
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800186 }
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800187
Tom Cherry21bb36c2020-01-08 15:18:26 -0800188 ret = LogdWrite(log_id, &ts, vec, nr);
189 PmsgWrite(log_id, &ts, vec, nr);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800190
Mark Salyzyn72d37242018-03-07 10:42:06 -0800191 errno = save_errno;
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800192 return ret;
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800193}
Tom Cherry349b0c42020-01-08 14:47:42 -0800194#else
195static int write_to_log(log_id_t, struct iovec*, size_t) {
196 // Non-Android text logs should go to __android_log_stderr_logger, not here.
197 // Non-Android binary logs are always dropped.
198 return 1;
199}
200#endif
201
202// Copied from base/threads.cpp
203static uint64_t GetThreadId() {
204#if defined(__BIONIC__)
205 return gettid();
206#elif defined(__APPLE__)
207 uint64_t tid;
208 pthread_threadid_np(NULL, &tid);
209 return tid;
210#elif defined(__linux__)
211 return syscall(__NR_gettid);
212#elif defined(_WIN32)
213 return GetCurrentThreadId();
214#endif
215}
216
217void __android_log_stderr_logger(const struct __android_logger_data* logger_data,
218 const char* message) {
219 struct tm now;
220 time_t t = time(nullptr);
221
222#if defined(_WIN32)
223 localtime_s(&now, &t);
224#else
225 localtime_r(&t, &now);
226#endif
227
228 char timestamp[32];
229 strftime(timestamp, sizeof(timestamp), "%m-%d %H:%M:%S", &now);
230
231 static const char log_characters[] = "XXVDIWEF";
232 static_assert(arraysize(log_characters) - 1 == ANDROID_LOG_SILENT,
233 "Mismatch in size of log_characters and values in android_LogPriority");
234 int priority =
235 logger_data->priority > ANDROID_LOG_SILENT ? ANDROID_LOG_FATAL : logger_data->priority;
236 char priority_char = log_characters[priority];
237 uint64_t tid = GetThreadId();
238
239 if (logger_data->file != nullptr) {
240 fprintf(stderr, "%s %c %s %5d %5" PRIu64 " %s:%u] %s\n",
241 logger_data->tag ? logger_data->tag : "nullptr", priority_char, timestamp, getpid(),
242 tid, logger_data->file, logger_data->line, message);
243 } else {
244 fprintf(stderr, "%s %c %s %5d %5" PRIu64 " %s\n",
245 logger_data->tag ? logger_data->tag : "nullptr", priority_char, timestamp, getpid(),
246 tid, message);
247 }
248}
249
250void __android_log_logd_logger(const struct __android_logger_data* logger_data,
251 const char* message) {
252 int buffer_id = logger_data->buffer_id == LOG_ID_DEFAULT ? LOG_ID_MAIN : logger_data->buffer_id;
253
254 struct iovec vec[3];
255 vec[0].iov_base =
256 const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(&logger_data->priority));
257 vec[0].iov_len = 1;
258 vec[1].iov_base = const_cast<void*>(static_cast<const void*>(logger_data->tag));
259 vec[1].iov_len = strlen(logger_data->tag) + 1;
260 vec[2].iov_base = const_cast<void*>(static_cast<const void*>(message));
261 vec[2].iov_len = strlen(message) + 1;
262
263 write_to_log(static_cast<log_id_t>(buffer_id), vec, 3);
264}
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800265
Tom Cherry2d9779e2019-02-08 11:46:19 -0800266int __android_log_write(int prio, const char* tag, const char* msg) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800267 return __android_log_buf_write(LOG_ID_MAIN, prio, tag, msg);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800268}
269
Tom Cherry349b0c42020-01-08 14:47:42 -0800270void __android_log_write_logger_data(__android_logger_data* logger_data, const char* msg) {
271 if (logger_data->tag == nullptr) logger_data->tag = "";
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800272
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800273#if __BIONIC__
Tom Cherry349b0c42020-01-08 14:47:42 -0800274 if (logger_data->priority == ANDROID_LOG_FATAL) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800275 android_set_abort_message(msg);
276 }
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800277#endif
278
Tom Cherry349b0c42020-01-08 14:47:42 -0800279 auto lock = std::shared_lock{logger_function_lock};
280 logger_function(logger_data, msg);
281}
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800282
Tom Cherry349b0c42020-01-08 14:47:42 -0800283int __android_log_buf_write(int bufID, int prio, const char* tag, const char* msg) {
284 __android_logger_data logger_data = {sizeof(__android_logger_data), bufID, prio, tag, nullptr, 0};
285 __android_log_write_logger_data(&logger_data, msg);
286 return 1;
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800287}
288
Tom Cherry2d9779e2019-02-08 11:46:19 -0800289int __android_log_vprint(int prio, const char* tag, const char* fmt, va_list ap) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800290 char buf[LOG_BUF_SIZE];
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800291
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800292 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800293
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800294 return __android_log_write(prio, tag, buf);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800295}
296
Tom Cherry2d9779e2019-02-08 11:46:19 -0800297int __android_log_print(int prio, const char* tag, const char* fmt, ...) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800298 va_list ap;
299 char buf[LOG_BUF_SIZE];
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800300
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800301 va_start(ap, fmt);
302 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
303 va_end(ap);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800304
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800305 return __android_log_write(prio, tag, buf);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800306}
307
Tom Cherry2d9779e2019-02-08 11:46:19 -0800308int __android_log_buf_print(int bufID, int prio, const char* tag, const char* fmt, ...) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800309 va_list ap;
310 char buf[LOG_BUF_SIZE];
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800311
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800312 va_start(ap, fmt);
313 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
314 va_end(ap);
315
316 return __android_log_buf_write(bufID, prio, tag, buf);
317}
318
Tom Cherry2d9779e2019-02-08 11:46:19 -0800319void __android_log_assert(const char* cond, const char* tag, const char* fmt, ...) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800320 char buf[LOG_BUF_SIZE];
321
322 if (fmt) {
323 va_list ap;
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800324 va_start(ap, fmt);
325 vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
326 va_end(ap);
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800327 } else {
328 /* Msg not provided, log condition. N.B. Do not use cond directly as
329 * format string as it could contain spurious '%' syntax (e.g.
330 * "%d" in "blocks%devs == 0").
331 */
332 if (cond)
333 snprintf(buf, LOG_BUF_SIZE, "Assertion failed: %s", cond);
334 else
335 strcpy(buf, "Unspecified assertion failed");
336 }
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800337
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800338 // Log assertion failures to stderr for the benefit of "adb shell" users
339 // and gtests (http://b/23675822).
Tom Cherry6f6ef392019-01-16 14:17:08 -0800340 TEMP_FAILURE_RETRY(write(2, buf, strlen(buf)));
341 TEMP_FAILURE_RETRY(write(2, "\n", 1));
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800342
343 __android_log_write(ANDROID_LOG_FATAL, tag, buf);
Tom Cherry349b0c42020-01-08 14:47:42 -0800344 __android_log_call_aborter(buf);
345 abort();
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800346}
347
Tom Cherry2d9779e2019-02-08 11:46:19 -0800348int __android_log_bwrite(int32_t tag, const void* payload, size_t len) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800349 struct iovec vec[2];
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800350
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800351 vec[0].iov_base = &tag;
352 vec[0].iov_len = sizeof(tag);
353 vec[1].iov_base = (void*)payload;
354 vec[1].iov_len = len;
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800355
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800356 return write_to_log(LOG_ID_EVENTS, vec, 2);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800357}
358
Tom Cherry2d9779e2019-02-08 11:46:19 -0800359int __android_log_stats_bwrite(int32_t tag, const void* payload, size_t len) {
Stefan Lafon701a0652017-08-24 20:14:06 -0700360 struct iovec vec[2];
361
362 vec[0].iov_base = &tag;
363 vec[0].iov_len = sizeof(tag);
364 vec[1].iov_base = (void*)payload;
365 vec[1].iov_len = len;
366
367 return write_to_log(LOG_ID_STATS, vec, 2);
368}
369
Tom Cherry2d9779e2019-02-08 11:46:19 -0800370int __android_log_security_bwrite(int32_t tag, const void* payload, size_t len) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800371 struct iovec vec[2];
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800372
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800373 vec[0].iov_base = &tag;
374 vec[0].iov_len = sizeof(tag);
375 vec[1].iov_base = (void*)payload;
376 vec[1].iov_len = len;
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800377
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800378 return write_to_log(LOG_ID_SECURITY, vec, 2);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800379}
380
381/*
382 * Like __android_log_bwrite, but takes the type as well. Doesn't work
383 * for the general case where we're generating lists of stuff, but very
384 * handy if we just want to dump an integer into the log.
385 */
Tom Cherry2d9779e2019-02-08 11:46:19 -0800386int __android_log_btwrite(int32_t tag, char type, const void* payload, size_t len) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800387 struct iovec vec[3];
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800388
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800389 vec[0].iov_base = &tag;
390 vec[0].iov_len = sizeof(tag);
391 vec[1].iov_base = &type;
392 vec[1].iov_len = sizeof(type);
393 vec[2].iov_base = (void*)payload;
394 vec[2].iov_len = len;
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800395
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800396 return write_to_log(LOG_ID_EVENTS, vec, 3);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800397}
398
399/*
400 * Like __android_log_bwrite, but used for writing strings to the
401 * event log.
402 */
Tom Cherry2d9779e2019-02-08 11:46:19 -0800403int __android_log_bswrite(int32_t tag, const char* payload) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800404 struct iovec vec[4];
405 char type = EVENT_TYPE_STRING;
406 uint32_t len = strlen(payload);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800407
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800408 vec[0].iov_base = &tag;
409 vec[0].iov_len = sizeof(tag);
410 vec[1].iov_base = &type;
411 vec[1].iov_len = sizeof(type);
412 vec[2].iov_base = &len;
413 vec[2].iov_len = sizeof(len);
414 vec[3].iov_base = (void*)payload;
415 vec[3].iov_len = len;
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800416
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800417 return write_to_log(LOG_ID_EVENTS, vec, 4);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800418}
419
420/*
421 * Like __android_log_security_bwrite, but used for writing strings to the
422 * security log.
423 */
Tom Cherry2d9779e2019-02-08 11:46:19 -0800424int __android_log_security_bswrite(int32_t tag, const char* payload) {
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800425 struct iovec vec[4];
426 char type = EVENT_TYPE_STRING;
427 uint32_t len = strlen(payload);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800428
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800429 vec[0].iov_base = &tag;
430 vec[0].iov_len = sizeof(tag);
431 vec[1].iov_base = &type;
432 vec[1].iov_len = sizeof(type);
433 vec[2].iov_base = &len;
434 vec[2].iov_len = sizeof(len);
435 vec[3].iov_base = (void*)payload;
436 vec[3].iov_len = len;
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800437
Mark Salyzyn2ed51d72017-03-09 08:09:43 -0800438 return write_to_log(LOG_ID_SECURITY, vec, 4);
Mark Salyzyn018a96d2016-03-01 13:45:42 -0800439}