• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <stdlib.h>
6 
7 #include <atomic>
8 #include <cassert>
9 #include <cstdarg>
10 #include <cstdint>
11 #include <cstdio>
12 #include <thread>
13 
14 #include <lib/syslog/global.h>
15 
16 #include "cutils/log.h"
17 #include "cutils/properties.h"
18 #include "cutils/threads.h"
19 
20 extern "C" {
21 
property_get(const char * key,char * value,const char * default_value)22 int property_get(const char* key, char* value, const char* default_value) {
23   return 0;
24 }
25 
__android_log_print(int priority,const char * tag,const char * format,...)26 int __android_log_print(int priority, const char* tag, const char* format,
27                         ...) {
28   if (priority == ANDROID_LOG_VERBOSE || priority == ANDROID_LOG_DEBUG) {
29     return 1;
30   }
31   const char* local_tag = tag;
32   if (!local_tag) {
33     local_tag = "<NO_TAG>";
34   }
35   va_list ap;
36   va_start(ap, format);
37   switch (priority) {
38     case ANDROID_LOG_WARN:
39       FX_LOGVF(WARNING, local_tag, format, ap);
40       break;
41     case ANDROID_LOG_ERROR:
42     case ANDROID_LOG_FATAL:
43       FX_LOGVF(ERROR, local_tag, format, ap);
44       break;
45     case ANDROID_LOG_INFO:
46     default:
47       FX_LOGVF(INFO, local_tag, format, ap);
48       break;
49   }
50   return 1;
51 }
52 
__android_log_assert(const char * condition,const char * tag,const char * format,...)53 void __android_log_assert(const char* condition, const char* tag,
54                           const char* format, ...) {
55   const char* local_tag = tag;
56   if (!local_tag) {
57     local_tag = "<NO_TAG>";
58   }
59   va_list ap;
60   va_start(ap, format);
61   FX_LOGVF(ERROR, local_tag, format, ap);
62   va_end(ap);
63 
64   abort();
65 }
66 
sync_wait(int fd,int timeout)67 int sync_wait(int fd, int timeout) {
68   return -1;
69 }
70 
thread_store_get(thread_store_t * store)71 void* thread_store_get(thread_store_t* store) {
72   return store->has_tls ? pthread_getspecific(store->tls) : nullptr;
73 }
74 
thread_store_set(thread_store_t * store,void * value,thread_store_destruct_t destroy)75 void thread_store_set(thread_store_t* store,
76                       void* value,
77                       thread_store_destruct_t destroy) {
78     pthread_mutex_lock(&store->lock);
79     if (!store->has_tls) {
80         if (pthread_key_create(&store->tls, destroy) != 0) {
81             pthread_mutex_unlock(&store->lock);
82             return;
83         }
84         store->has_tls = 1;
85     }
86     pthread_mutex_unlock(&store->lock);
87     pthread_setspecific(store->tls, value);
88 }
89 
gettid()90 pid_t gettid() {
91   static thread_local pid_t id = 0;
92   if (!id) {
93     static std::atomic<pid_t> next_thread_id{1};
94     id = next_thread_id++;
95   }
96   return id;
97 }
98 
99 }
100