summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Venkatraman2017-01-05 12:22:52 -0600
committerVijay Venkatraman2017-01-22 21:45:38 -0600
commit3c6763ca21c1150d66daf8fde9b440b1c3219fe6 (patch)
tree7a8df02f4d5f95e86faa96886f77e21e61eba4e1 /include
parent41ee55a8754f12389394c0266c05d09123707f77 (diff)
downloadplatform-system-core-3c6763ca21c1150d66daf8fde9b440b1c3219fe6.tar.gz
platform-system-core-3c6763ca21c1150d66daf8fde9b440b1c3219fe6.tar.xz
platform-system-core-3c6763ca21c1150d66daf8fde9b440b1c3219fe6.zip
Exporting C headers from system/core
Moved headers from include/libcutils and include/liblog to libcutils/include and liblog/include respectively, so they can be exported via these libs. They needed to be moved since Soong does not allow export from external folder. Added symlink from old locations. They are needed since Soong includes system/core/include by default. Once all modules are cleaned up to explicitly add the required libs, the symlinks will be removed. Also added liblog_vndk_headers that exports a special log/log.h for VNDK. Moved headers of libcutils to libcutils_headers. They should be used by modules for header-only inlines. Added libcutils_headers as dependency of libcutils. Added libcutils_vndk_headers that exports a special cutils/log.h deprecating usage of the file. A later CL will deprecate the one in libcutils_headers Test: Add above libs to shared lib of local module Change-Id: I6e1f9c5f23d8b6eae13dc3b7e5dfe7fae93b8510
Diffstat (limited to 'include')
l---------include/cutils1
-rw-r--r--include/cutils/android_get_control_file.h37
-rw-r--r--include/cutils/android_reboot.h39
-rw-r--r--include/cutils/ashmem.h34
-rw-r--r--include/cutils/atomic.h246
-rw-r--r--include/cutils/bitops.h120
-rw-r--r--include/cutils/compiler.h44
-rw-r--r--include/cutils/config_utils.h64
-rw-r--r--include/cutils/fs.h85
-rw-r--r--include/cutils/hashmap.h150
-rw-r--r--include/cutils/iosched_policy.h38
-rw-r--r--include/cutils/jstring.h46
-rw-r--r--include/cutils/klog.h47
-rw-r--r--include/cutils/list.h88
-rw-r--r--include/cutils/log.h1
-rw-r--r--include/cutils/memory.h42
-rw-r--r--include/cutils/misc.h41
-rw-r--r--include/cutils/multiuser.h45
-rw-r--r--include/cutils/native_handle.h100
-rw-r--r--include/cutils/open_memstream.h36
-rw-r--r--include/cutils/partition_utils.h26
-rw-r--r--include/cutils/properties.h133
-rw-r--r--include/cutils/qtaguid.h66
-rw-r--r--include/cutils/record_stream.h43
-rw-r--r--include/cutils/sched_policy.h64
-rw-r--r--include/cutils/sockets.h161
-rw-r--r--include/cutils/str_parms.h60
-rw-r--r--include/cutils/threads.h148
-rw-r--r--include/cutils/trace.h257
-rw-r--r--include/cutils/uevent.h36
l---------include/log1
-rw-r--r--include/log/event_tag_map.h65
-rw-r--r--include/log/log.h871
-rw-r--r--include/log/log_event_list.h297
-rw-r--r--include/log/logd.h1
-rw-r--r--include/log/logger.h1
-rw-r--r--include/log/logprint.h163
-rw-r--r--include/log/uio.h51
l---------[-rw-r--r--]include/private/android_logger.h195
39 files changed, 3 insertions, 3940 deletions
diff --git a/include/cutils b/include/cutils
new file mode 120000
index 000000000..ac2ed4004
--- /dev/null
+++ b/include/cutils
@@ -0,0 +1 @@
../libcutils/include/cutils/ \ No newline at end of file
diff --git a/include/cutils/android_get_control_file.h b/include/cutils/android_get_control_file.h
deleted file mode 100644
index ed8fbf830..000000000
--- a/include/cutils/android_get_control_file.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 * Copyright (C) 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#ifndef __CUTILS_ANDROID_GET_CONTROL_FILE_H
18#define __CUTILS_ANDROID_GET_CONTROL_FILE_H
19
20#define ANDROID_FILE_ENV_PREFIX "ANDROID_FILE_"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/*
27 * android_get_control_file - simple helper function to get the file
28 * descriptor of our init-managed file. `path' is the filename path as
29 * given in init.rc. Returns -1 on error.
30 */
31int android_get_control_file(const char* path);
32
33#ifdef __cplusplus
34}
35#endif
36
37#endif /* __CUTILS_ANDROID_GET_CONTROL_FILE_H */
diff --git a/include/cutils/android_reboot.h b/include/cutils/android_reboot.h
deleted file mode 100644
index a3861a02d..000000000
--- a/include/cutils/android_reboot.h
+++ /dev/null
@@ -1,39 +0,0 @@
1/*
2 * Copyright 2011, 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#ifndef __CUTILS_ANDROID_REBOOT_H__
18#define __CUTILS_ANDROID_REBOOT_H__
19
20#include <mntent.h>
21
22__BEGIN_DECLS
23
24/* Commands */
25#define ANDROID_RB_RESTART 0xDEAD0001
26#define ANDROID_RB_POWEROFF 0xDEAD0002
27#define ANDROID_RB_RESTART2 0xDEAD0003
28
29/* Properties */
30#define ANDROID_RB_PROPERTY "sys.powerctl"
31
32int android_reboot(int cmd, int flags, const char *arg);
33int android_reboot_with_callback(
34 int cmd, int flags, const char *arg,
35 void (*cb_on_remount)(const struct mntent*));
36
37__END_DECLS
38
39#endif /* __CUTILS_ANDROID_REBOOT_H__ */
diff --git a/include/cutils/ashmem.h b/include/cutils/ashmem.h
deleted file mode 100644
index d80caa698..000000000
--- a/include/cutils/ashmem.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/* cutils/ashmem.h
2 **
3 ** Copyright 2008 The Android Open Source Project
4 **
5 ** This file is dual licensed. It may be redistributed and/or modified
6 ** under the terms of the Apache 2.0 License OR version 2 of the GNU
7 ** General Public License.
8 */
9
10#ifndef _CUTILS_ASHMEM_H
11#define _CUTILS_ASHMEM_H
12
13#include <stddef.h>
14
15#if defined(__BIONIC__)
16#include <linux/ashmem.h>
17#endif
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23int ashmem_valid(int fd);
24int ashmem_create_region(const char *name, size_t size);
25int ashmem_set_prot_region(int fd, int prot);
26int ashmem_pin_region(int fd, size_t offset, size_t len);
27int ashmem_unpin_region(int fd, size_t offset, size_t len);
28int ashmem_get_size_region(int fd);
29
30#ifdef __cplusplus
31}
32#endif
33
34#endif /* _CUTILS_ASHMEM_H */
diff --git a/include/cutils/atomic.h b/include/cutils/atomic.h
deleted file mode 100644
index 0c88bfedd..000000000
--- a/include/cutils/atomic.h
+++ /dev/null
@@ -1,246 +0,0 @@
1/*
2 * Copyright (C) 2007 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#ifndef ANDROID_CUTILS_ATOMIC_H
18#define ANDROID_CUTILS_ATOMIC_H
19
20#include <stdint.h>
21#include <sys/types.h>
22#include <stdatomic.h>
23
24#ifndef ANDROID_ATOMIC_INLINE
25#define ANDROID_ATOMIC_INLINE static inline
26#endif
27
28/*
29 * A handful of basic atomic operations.
30 * THESE ARE HERE FOR LEGACY REASONS ONLY. AVOID.
31 *
32 * PREFERRED ALTERNATIVES:
33 * - Use C++/C/pthread locks/mutexes whenever there is not a
34 * convincing reason to do otherwise. Note that very clever and
35 * complicated, but correct, lock-free code is often slower than
36 * using locks, especially where nontrivial data structures
37 * are involved.
38 * - C11 stdatomic.h.
39 * - Where supported, C++11 std::atomic<T> .
40 *
41 * PLEASE STOP READING HERE UNLESS YOU ARE TRYING TO UNDERSTAND
42 * OR UPDATE OLD CODE.
43 *
44 * The "acquire" and "release" terms can be defined intuitively in terms
45 * of the placement of memory barriers in a simple lock implementation:
46 * - wait until compare-and-swap(lock-is-free --> lock-is-held) succeeds
47 * - barrier
48 * - [do work]
49 * - barrier
50 * - store(lock-is-free)
51 * In very crude terms, the initial (acquire) barrier prevents any of the
52 * "work" from happening before the lock is held, and the later (release)
53 * barrier ensures that all of the work happens before the lock is released.
54 * (Think of cached writes, cache read-ahead, and instruction reordering
55 * around the CAS and store instructions.)
56 *
57 * The barriers must apply to both the compiler and the CPU. Note it is
58 * legal for instructions that occur before an "acquire" barrier to be
59 * moved down below it, and for instructions that occur after a "release"
60 * barrier to be moved up above it.
61 *
62 * The ARM-driven implementation we use here is short on subtlety,
63 * and actually requests a full barrier from the compiler and the CPU.
64 * The only difference between acquire and release is in whether they
65 * are issued before or after the atomic operation with which they
66 * are associated. To ease the transition to C/C++ atomic intrinsics,
67 * you should not rely on this, and instead assume that only the minimal
68 * acquire/release protection is provided.
69 *
70 * NOTE: all int32_t* values are expected to be aligned on 32-bit boundaries.
71 * If they are not, atomicity is not guaranteed.
72 */
73
74ANDROID_ATOMIC_INLINE
75volatile atomic_int_least32_t* to_atomic_int_least32_t(volatile const int32_t* addr) {
76#ifdef __cplusplus
77 return reinterpret_cast<volatile atomic_int_least32_t*>(const_cast<volatile int32_t*>(addr));
78#else
79 return (volatile atomic_int_least32_t*)addr;
80#endif
81}
82
83/*
84 * Basic arithmetic and bitwise operations. These all provide a
85 * barrier with "release" ordering, and return the previous value.
86 *
87 * These have the same characteristics (e.g. what happens on overflow)
88 * as the equivalent non-atomic C operations.
89 */
90ANDROID_ATOMIC_INLINE
91int32_t android_atomic_inc(volatile int32_t* addr)
92{
93 volatile atomic_int_least32_t* a = to_atomic_int_least32_t(addr);
94 /* Int32_t, if it exists, is the same as int_least32_t. */
95 return atomic_fetch_add_explicit(a, 1, memory_order_release);
96}
97
98ANDROID_ATOMIC_INLINE
99int32_t android_atomic_dec(volatile int32_t* addr)
100{
101 volatile atomic_int_least32_t* a = to_atomic_int_least32_t(addr);
102 return atomic_fetch_sub_explicit(a, 1, memory_order_release);
103}
104
105ANDROID_ATOMIC_INLINE
106int32_t android_atomic_add(int32_t value, volatile int32_t* addr)
107{
108 volatile atomic_int_least32_t* a = to_atomic_int_least32_t(addr);
109 return atomic_fetch_add_explicit(a, value, memory_order_release);
110}
111
112ANDROID_ATOMIC_INLINE
113int32_t android_atomic_and(int32_t value, volatile int32_t* addr)
114{
115 volatile atomic_int_least32_t* a = to_atomic_int_least32_t(addr);
116 return atomic_fetch_and_explicit(a, value, memory_order_release);
117}
118
119ANDROID_ATOMIC_INLINE
120int32_t android_atomic_or(int32_t value, volatile int32_t* addr)
121{
122 volatile atomic_int_least32_t* a = to_atomic_int_least32_t(addr);
123 return atomic_fetch_or_explicit(a, value, memory_order_release);
124}
125
126/*
127 * Perform an atomic load with "acquire" or "release" ordering.
128 *
129 * Note that the notion of a "release" ordering for a load does not
130 * really fit into the C11 or C++11 memory model. The extra ordering
131 * is normally observable only by code using memory_order_relaxed
132 * atomics, or data races. In the rare cases in which such ordering
133 * is called for, use memory_order_relaxed atomics and a leading
134 * atomic_thread_fence (typically with memory_order_acquire,
135 * not memory_order_release!) instead. If you do not understand
136 * this comment, you are in the vast majority, and should not be
137 * using release loads or replacing them with anything other than
138 * locks or default sequentially consistent atomics.
139 */
140ANDROID_ATOMIC_INLINE
141int32_t android_atomic_acquire_load(volatile const int32_t* addr)
142{
143 volatile atomic_int_least32_t* a = to_atomic_int_least32_t(addr);
144 return atomic_load_explicit(a, memory_order_acquire);
145}
146
147ANDROID_ATOMIC_INLINE
148int32_t android_atomic_release_load(volatile const int32_t* addr)
149{
150 volatile atomic_int_least32_t* a = to_atomic_int_least32_t(addr);
151 atomic_thread_fence(memory_order_seq_cst);
152 /* Any reasonable clients of this interface would probably prefer */
153 /* something weaker. But some remaining clients seem to be */
154 /* abusing this API in strange ways, e.g. by using it as a fence. */
155 /* Thus we are conservative until we can get rid of remaining */
156 /* clients (and this function). */
157 return atomic_load_explicit(a, memory_order_relaxed);
158}
159
160/*
161 * Perform an atomic store with "acquire" or "release" ordering.
162 *
163 * Note that the notion of an "acquire" ordering for a store does not
164 * really fit into the C11 or C++11 memory model. The extra ordering
165 * is normally observable only by code using memory_order_relaxed
166 * atomics, or data races. In the rare cases in which such ordering
167 * is called for, use memory_order_relaxed atomics and a trailing
168 * atomic_thread_fence (typically with memory_order_release,
169 * not memory_order_acquire!) instead.
170 */
171ANDROID_ATOMIC_INLINE
172void android_atomic_acquire_store(int32_t value, volatile int32_t* addr)
173{
174 volatile atomic_int_least32_t* a = to_atomic_int_least32_t(addr);
175 atomic_store_explicit(a, value, memory_order_relaxed);
176 atomic_thread_fence(memory_order_seq_cst);
177 /* Again overly conservative to accomodate weird clients. */
178}
179
180ANDROID_ATOMIC_INLINE
181void android_atomic_release_store(int32_t value, volatile int32_t* addr)
182{
183 volatile atomic_int_least32_t* a = to_atomic_int_least32_t(addr);
184 atomic_store_explicit(a, value, memory_order_release);
185}
186
187/*
188 * Compare-and-set operation with "acquire" or "release" ordering.
189 *
190 * This returns zero if the new value was successfully stored, which will
191 * only happen when *addr == oldvalue.
192 *
193 * (The return value is inverted from implementations on other platforms,
194 * but matches the ARM ldrex/strex result.)
195 *
196 * Implementations that use the release CAS in a loop may be less efficient
197 * than possible, because we re-issue the memory barrier on each iteration.
198 */
199ANDROID_ATOMIC_INLINE
200int android_atomic_acquire_cas(int32_t oldvalue, int32_t newvalue,
201 volatile int32_t* addr)
202{
203 volatile atomic_int_least32_t* a = to_atomic_int_least32_t(addr);
204 return !atomic_compare_exchange_strong_explicit(
205 a, &oldvalue, newvalue,
206 memory_order_acquire,
207 memory_order_acquire);
208}
209
210ANDROID_ATOMIC_INLINE
211int android_atomic_release_cas(int32_t oldvalue, int32_t newvalue,
212 volatile int32_t* addr)
213{
214 volatile atomic_int_least32_t* a = to_atomic_int_least32_t(addr);
215 return !atomic_compare_exchange_strong_explicit(
216 a, &oldvalue, newvalue,
217 memory_order_release,
218 memory_order_relaxed);
219}
220
221/*
222 * Fence primitives.
223 */
224ANDROID_ATOMIC_INLINE
225void android_compiler_barrier(void)
226{
227 __asm__ __volatile__ ("" : : : "memory");
228 /* Could probably also be: */
229 /* atomic_signal_fence(memory_order_seq_cst); */
230}
231
232ANDROID_ATOMIC_INLINE
233void android_memory_barrier(void)
234{
235 atomic_thread_fence(memory_order_seq_cst);
236}
237
238/*
239 * Aliases for code using an older version of this header. These are now
240 * deprecated and should not be used. The definitions will be removed
241 * in a future release.
242 */
243#define android_atomic_write android_atomic_release_store
244#define android_atomic_cmpxchg android_atomic_release_cas
245
246#endif // ANDROID_CUTILS_ATOMIC_H
diff --git a/include/cutils/bitops.h b/include/cutils/bitops.h
deleted file mode 100644
index 045830d90..000000000
--- a/include/cutils/bitops.h
+++ /dev/null
@@ -1,120 +0,0 @@
1/*
2 * Copyright (C) 2011 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#ifndef __CUTILS_BITOPS_H
18#define __CUTILS_BITOPS_H
19
20#include <stdbool.h>
21#include <string.h>
22#include <strings.h>
23#include <sys/cdefs.h>
24
25__BEGIN_DECLS
26
27/*
28 * Bitmask Operations
29 *
30 * Note this doesn't provide any locking/exclusion, and isn't atomic.
31 * Additionally no bounds checking is done on the bitmask array.
32 *
33 * Example:
34 *
35 * int num_resources;
36 * unsigned int resource_bits[BITS_TO_WORDS(num_resources)];
37 * bitmask_init(resource_bits, num_resources);
38 * ...
39 * int bit = bitmask_ffz(resource_bits, num_resources);
40 * bitmask_set(resource_bits, bit);
41 * ...
42 * if (bitmask_test(resource_bits, bit)) { ... }
43 * ...
44 * bitmask_clear(resource_bits, bit);
45 *
46 */
47
48#define BITS_PER_WORD (sizeof(unsigned int) * 8)
49#define BITS_TO_WORDS(x) (((x) + BITS_PER_WORD - 1) / BITS_PER_WORD)
50#define BIT_IN_WORD(x) ((x) % BITS_PER_WORD)
51#define BIT_WORD(x) ((x) / BITS_PER_WORD)
52#define BIT_MASK(x) (1 << BIT_IN_WORD(x))
53
54static inline void bitmask_init(unsigned int *bitmask, int num_bits)
55{
56 memset(bitmask, 0, BITS_TO_WORDS(num_bits)*sizeof(unsigned int));
57}
58
59static inline int bitmask_ffz(unsigned int *bitmask, int num_bits)
60{
61 int bit, result;
62 size_t i;
63
64 for (i = 0; i < BITS_TO_WORDS(num_bits); i++) {
65 bit = ffs(~bitmask[i]);
66 if (bit) {
67 // ffs is 1-indexed, return 0-indexed result
68 bit--;
69 result = BITS_PER_WORD * i + bit;
70 if (result >= num_bits)
71 return -1;
72 return result;
73 }
74 }
75 return -1;
76}
77
78static inline int bitmask_weight(unsigned int *bitmask, int num_bits)
79{
80 size_t i;
81 int weight = 0;
82
83 for (i = 0; i < BITS_TO_WORDS(num_bits); i++)
84 weight += __builtin_popcount(bitmask[i]);
85 return weight;
86}
87
88static inline void bitmask_set(unsigned int *bitmask, int bit)
89{
90 bitmask[BIT_WORD(bit)] |= BIT_MASK(bit);
91}
92
93static inline void bitmask_clear(unsigned int *bitmask, int bit)
94{
95 bitmask[BIT_WORD(bit)] &= ~BIT_MASK(bit);
96}
97
98static inline bool bitmask_test(unsigned int *bitmask, int bit)
99{
100 return bitmask[BIT_WORD(bit)] & BIT_MASK(bit);
101}
102
103static inline int popcount(unsigned int x)
104{
105 return __builtin_popcount(x);
106}
107
108static inline int popcountl(unsigned long x)
109{
110 return __builtin_popcountl(x);
111}
112
113static inline int popcountll(unsigned long long x)
114{
115 return __builtin_popcountll(x);
116}
117
118__END_DECLS
119
120#endif /* __CUTILS_BITOPS_H */
diff --git a/include/cutils/compiler.h b/include/cutils/compiler.h
deleted file mode 100644
index 70f884a1e..000000000
--- a/include/cutils/compiler.h
+++ /dev/null
@@ -1,44 +0,0 @@
1/*
2 * Copyright (C) 2009 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#ifndef ANDROID_CUTILS_COMPILER_H
18#define ANDROID_CUTILS_COMPILER_H
19
20/*
21 * helps the compiler's optimizer predicting branches
22 */
23
24#ifdef __cplusplus
25# define CC_LIKELY( exp ) (__builtin_expect( !!(exp), true ))
26# define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), false ))
27#else
28# define CC_LIKELY( exp ) (__builtin_expect( !!(exp), 1 ))
29# define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), 0 ))
30#endif
31
32/**
33 * exports marked symbols
34 *
35 * if used on a C++ class declaration, this macro must be inserted
36 * after the "class" keyword. For instance:
37 *
38 * template <typename TYPE>
39 * class ANDROID_API Singleton { }
40 */
41
42#define ANDROID_API __attribute__((visibility("default")))
43
44#endif // ANDROID_CUTILS_COMPILER_H
diff --git a/include/cutils/config_utils.h b/include/cutils/config_utils.h
deleted file mode 100644
index 2dea6f19f..000000000
--- a/include/cutils/config_utils.h
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * Copyright (C) 2006 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#ifndef __CUTILS_CONFIG_UTILS_H
18#define __CUTILS_CONFIG_UTILS_H
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24typedef struct cnode cnode;
25
26
27struct cnode
28{
29 cnode *next;
30 cnode *first_child;
31 cnode *last_child;
32 const char *name;
33 const char *value;
34};
35
36/* parse a text string into a config node tree */
37void config_load(cnode *root, char *data);
38
39/* parse a file into a config node tree */
40void config_load_file(cnode *root, const char *fn);
41
42/* create a single config node */
43cnode* config_node(const char *name, const char *value);
44
45/* locate a named child of a config node */
46cnode* config_find(cnode *root, const char *name);
47
48/* look up a child by name and return the boolean value */
49int config_bool(cnode *root, const char *name, int _default);
50
51/* look up a child by name and return the string value */
52const char* config_str(cnode *root, const char *name, const char *_default);
53
54/* add a named child to a config node (or modify it if it already exists) */
55void config_set(cnode *root, const char *name, const char *value);
56
57/* free a config node tree */
58void config_free(cnode *root);
59
60#ifdef __cplusplus
61}
62#endif
63
64#endif
diff --git a/include/cutils/fs.h b/include/cutils/fs.h
deleted file mode 100644
index a34ce8602..000000000
--- a/include/cutils/fs.h
+++ /dev/null
@@ -1,85 +0,0 @@
1/*
2 * Copyright (C) 2012 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#ifndef __CUTILS_FS_H
18#define __CUTILS_FS_H
19
20#include <sys/types.h>
21#include <unistd.h>
22
23/*
24 * TEMP_FAILURE_RETRY is defined by some, but not all, versions of
25 * <unistd.h>. (Alas, it is not as standard as we'd hoped!) So, if it's
26 * not already defined, then define it here.
27 */
28#ifndef TEMP_FAILURE_RETRY
29/* Used to retry syscalls that can return EINTR. */
30#define TEMP_FAILURE_RETRY(exp) ({ \
31 typeof (exp) _rc; \
32 do { \
33 _rc = (exp); \
34 } while (_rc == -1 && errno == EINTR); \
35 _rc; })
36#endif
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/*
43 * Ensure that directory exists with given mode and owners. If it exists
44 * with a different mode or owners, they are fixed to match the given values.
45 */
46extern int fs_prepare_dir(const char* path, mode_t mode, uid_t uid, gid_t gid);
47
48/*
49 * Ensure that directory exists with given mode and owners. If it exists
50 * with different owners, they are not fixed and -1 is returned.
51 */
52extern int fs_prepare_dir_strict(const char* path, mode_t mode, uid_t uid, gid_t gid);
53
54/*
55 * Ensure that file exists with given mode and owners. If it exists
56 * with different owners, they are not fixed and -1 is returned.
57 */
58extern int fs_prepare_file_strict(const char* path, mode_t mode, uid_t uid, gid_t gid);
59
60
61/*
62 * Read single plaintext integer from given file, correctly handling files
63 * partially written with fs_write_atomic_int().
64 */
65extern int fs_read_atomic_int(const char* path, int* value);
66
67/*
68 * Write single plaintext integer to given file, creating backup while
69 * in progress.
70 */
71extern int fs_write_atomic_int(const char* path, int value);
72
73/*
74 * Ensure that all directories along given path exist, creating parent
75 * directories as needed. Validates that given path is absolute and that
76 * it contains no relative "." or ".." paths or symlinks. Last path segment
77 * is treated as filename and ignored, unless the path ends with "/".
78 */
79extern int fs_mkdirs(const char* path, mode_t mode);
80
81#ifdef __cplusplus
82}
83#endif
84
85#endif /* __CUTILS_FS_H */
diff --git a/include/cutils/hashmap.h b/include/cutils/hashmap.h
deleted file mode 100644
index 5cb344c15..000000000
--- a/include/cutils/hashmap.h
+++ /dev/null
@@ -1,150 +0,0 @@
1/*
2 * Copyright (C) 2007 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/**
18 * Hash map.
19 */
20
21#ifndef __HASHMAP_H
22#define __HASHMAP_H
23
24#include <stdbool.h>
25#include <stdlib.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/** A hash map. */
32typedef struct Hashmap Hashmap;
33
34/**
35 * Creates a new hash map. Returns NULL if memory allocation fails.
36 *
37 * @param initialCapacity number of expected entries
38 * @param hash function which hashes keys
39 * @param equals function which compares keys for equality
40 */
41Hashmap* hashmapCreate(size_t initialCapacity,
42 int (*hash)(void* key), bool (*equals)(void* keyA, void* keyB));
43
44/**
45 * Frees the hash map. Does not free the keys or values themselves.
46 */
47void hashmapFree(Hashmap* map);
48
49/**
50 * Hashes the memory pointed to by key with the given size. Useful for
51 * implementing hash functions.
52 */
53int hashmapHash(void* key, size_t keySize);
54
55/**
56 * Puts value for the given key in the map. Returns pre-existing value if
57 * any.
58 *
59 * If memory allocation fails, this function returns NULL, the map's size
60 * does not increase, and errno is set to ENOMEM.
61 */
62void* hashmapPut(Hashmap* map, void* key, void* value);
63
64/**
65 * Gets a value from the map. Returns NULL if no entry for the given key is
66 * found or if the value itself is NULL.
67 */
68void* hashmapGet(Hashmap* map, void* key);
69
70/**
71 * Returns true if the map contains an entry for the given key.
72 */
73bool hashmapContainsKey(Hashmap* map, void* key);
74
75/**
76 * Gets the value for a key. If a value is not found, this function gets a
77 * value and creates an entry using the given callback.
78 *
79 * If memory allocation fails, the callback is not called, this function
80 * returns NULL, and errno is set to ENOMEM.
81 */
82void* hashmapMemoize(Hashmap* map, void* key,
83 void* (*initialValue)(void* key, void* context), void* context);
84
85/**
86 * Removes an entry from the map. Returns the removed value or NULL if no
87 * entry was present.
88 */
89void* hashmapRemove(Hashmap* map, void* key);
90
91/**
92 * Gets the number of entries in this map.
93 */
94size_t hashmapSize(Hashmap* map);
95
96/**
97 * Invokes the given callback on each entry in the map. Stops iterating if
98 * the callback returns false.
99 */
100void hashmapForEach(Hashmap* map,
101 bool (*callback)(void* key, void* value, void* context),
102 void* context);
103
104/**
105 * Concurrency support.
106 */
107
108/**
109 * Locks the hash map so only the current thread can access it.
110 */
111void hashmapLock(Hashmap* map);
112
113/**
114 * Unlocks the hash map so other threads can access it.
115 */
116void hashmapUnlock(Hashmap* map);
117
118/**
119 * Key utilities.
120 */
121
122/**
123 * Hashes int keys. 'key' is a pointer to int.
124 */
125int hashmapIntHash(void* key);
126
127/**
128 * Compares two int keys for equality.
129 */
130bool hashmapIntEquals(void* keyA, void* keyB);
131
132/**
133 * For debugging.
134 */
135
136/**
137 * Gets current capacity.
138 */
139size_t hashmapCurrentCapacity(Hashmap* map);
140
141/**
142 * Counts the number of entry collisions.
143 */
144size_t hashmapCountCollisions(Hashmap* map);
145
146#ifdef __cplusplus
147}
148#endif
149
150#endif /* __HASHMAP_H */
diff --git a/include/cutils/iosched_policy.h b/include/cutils/iosched_policy.h
deleted file mode 100644
index 07c5d1fca..000000000
--- a/include/cutils/iosched_policy.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/*
2 * Copyright (C) 2007 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#ifndef __CUTILS_IOSCHED_POLICY_H
18#define __CUTILS_IOSCHED_POLICY_H
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24typedef enum {
25 IoSchedClass_NONE,
26 IoSchedClass_RT,
27 IoSchedClass_BE,
28 IoSchedClass_IDLE,
29} IoSchedClass;
30
31extern int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio);
32extern int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio);
33
34#ifdef __cplusplus
35}
36#endif
37
38#endif /* __CUTILS_IOSCHED_POLICY_H */
diff --git a/include/cutils/jstring.h b/include/cutils/jstring.h
deleted file mode 100644
index a3426081a..000000000
--- a/include/cutils/jstring.h
+++ /dev/null
@@ -1,46 +0,0 @@
1/*
2 * Copyright (C) 2006 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#ifndef __CUTILS_STRING16_H
18#define __CUTILS_STRING16_H
19
20#include <stdint.h>
21#include <stddef.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#if __STDC_VERSION__ < 201112L && __cplusplus < 201103L
28 typedef uint16_t char16_t;
29#endif
30 // otherwise char16_t is a keyword with the right semantics
31
32extern char * strndup16to8 (const char16_t* s, size_t n);
33extern size_t strnlen16to8 (const char16_t* s, size_t n);
34extern char * strncpy16to8 (char *dest, const char16_t*s, size_t n);
35
36extern char16_t * strdup8to16 (const char* s, size_t *out_len);
37extern size_t strlen8to16 (const char* utf8Str);
38extern char16_t * strcpy8to16 (char16_t *dest, const char*s, size_t *out_len);
39extern char16_t * strcpylen8to16 (char16_t *dest, const char*s, int length,
40 size_t *out_len);
41
42#ifdef __cplusplus
43}
44#endif
45
46#endif /* __CUTILS_STRING16_H */
diff --git a/include/cutils/klog.h b/include/cutils/klog.h
deleted file mode 100644
index e7cd30046..000000000
--- a/include/cutils/klog.h
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 * Copyright (C) 2010 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#ifndef _CUTILS_KLOG_H_
18#define _CUTILS_KLOG_H_
19
20#include <sys/cdefs.h>
21#include <sys/uio.h>
22#include <stdarg.h>
23
24__BEGIN_DECLS
25
26int klog_get_level(void);
27void klog_set_level(int level);
28
29void klog_write(int level, const char *fmt, ...)
30 __attribute__ ((format(printf, 2, 3)));
31void klog_writev(int level, const struct iovec* iov, int iov_count);
32
33__END_DECLS
34
35#define KLOG_ERROR_LEVEL 3
36#define KLOG_WARNING_LEVEL 4
37#define KLOG_NOTICE_LEVEL 5
38#define KLOG_INFO_LEVEL 6
39#define KLOG_DEBUG_LEVEL 7
40
41#define KLOG_ERROR(tag,x...) klog_write(KLOG_ERROR_LEVEL, "<3>" tag ": " x)
42#define KLOG_WARNING(tag,x...) klog_write(KLOG_WARNING_LEVEL, "<4>" tag ": " x)
43#define KLOG_NOTICE(tag,x...) klog_write(KLOG_NOTICE_LEVEL, "<5>" tag ": " x)
44#define KLOG_INFO(tag,x...) klog_write(KLOG_INFO_LEVEL, "<6>" tag ": " x)
45#define KLOG_DEBUG(tag,x...) klog_write(KLOG_DEBUG_LEVEL, "<7>" tag ": " x)
46
47#endif
diff --git a/include/cutils/list.h b/include/cutils/list.h
deleted file mode 100644
index 4ba2cfd49..000000000
--- a/include/cutils/list.h
+++ /dev/null
@@ -1,88 +0,0 @@
1/*
2 * Copyright (C) 2008-2013 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#ifndef _CUTILS_LIST_H_
18#define _CUTILS_LIST_H_
19
20#include <stddef.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
26struct listnode
27{
28 struct listnode *next;
29 struct listnode *prev;
30};
31
32#define node_to_item(node, container, member) \
33 (container *) (((char*) (node)) - offsetof(container, member))
34
35#define list_declare(name) \
36 struct listnode name = { \
37 .next = &name, \
38 .prev = &name, \
39 }
40
41#define list_for_each(node, list) \
42 for (node = (list)->next; node != (list); node = node->next)
43
44#define list_for_each_reverse(node, list) \
45 for (node = (list)->prev; node != (list); node = node->prev)
46
47#define list_for_each_safe(node, n, list) \
48 for (node = (list)->next, n = node->next; \
49 node != (list); \
50 node = n, n = node->next)
51
52static inline void list_init(struct listnode *node)
53{
54 node->next = node;
55 node->prev = node;
56}
57
58static inline void list_add_tail(struct listnode *head, struct listnode *item)
59{
60 item->next = head;
61 item->prev = head->prev;
62 head->prev->next = item;
63 head->prev = item;
64}
65
66static inline void list_add_head(struct listnode *head, struct listnode *item)
67{
68 item->next = head->next;
69 item->prev = head;
70 head->next->prev = item;
71 head->next = item;
72}
73
74static inline void list_remove(struct listnode *item)
75{
76 item->next->prev = item->prev;
77 item->prev->next = item->next;
78}
79
80#define list_empty(list) ((list) == (list)->next)
81#define list_head(list) ((list)->next)
82#define list_tail(list) ((list)->prev)
83
84#ifdef __cplusplus
85};
86#endif /* __cplusplus */
87
88#endif
diff --git a/include/cutils/log.h b/include/cutils/log.h
deleted file mode 100644
index 0e0248e50..000000000
--- a/include/cutils/log.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <log/log.h>
diff --git a/include/cutils/memory.h b/include/cutils/memory.h
deleted file mode 100644
index 4d2688255..000000000
--- a/include/cutils/memory.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * Copyright (C) 2006 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#ifndef ANDROID_CUTILS_MEMORY_H
18#define ANDROID_CUTILS_MEMORY_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/* size is given in bytes and must be multiple of 2 */
28void android_memset16(uint16_t* dst, uint16_t value, size_t size);
29
30/* size is given in bytes and must be multiple of 4 */
31void android_memset32(uint32_t* dst, uint32_t value, size_t size);
32
33#if defined(__GLIBC__) || defined(_WIN32)
34/* Declaration of strlcpy() for platforms that don't already have it. */
35size_t strlcpy(char *dst, const char *src, size_t size);
36#endif
37
38#ifdef __cplusplus
39} // extern "C"
40#endif
41
42#endif // ANDROID_CUTILS_MEMORY_H
diff --git a/include/cutils/misc.h b/include/cutils/misc.h
deleted file mode 100644
index 0de505f27..000000000
--- a/include/cutils/misc.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * Copyright (C) 2006 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#ifndef __CUTILS_MISC_H
18#define __CUTILS_MISC_H
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24 /* Load an entire file into a malloc'd chunk of memory
25 * that is length_of_file + 1 (null terminator). If
26 * sz is non-zero, return the size of the file via sz.
27 * Returns 0 on failure.
28 */
29extern void *load_file(const char *fn, unsigned *sz);
30
31 /* This is the range of UIDs (and GIDs) that are reserved
32 * for assigning to applications.
33 */
34#define FIRST_APPLICATION_UID 10000
35#define LAST_APPLICATION_UID 99999
36
37#ifdef __cplusplus
38}
39#endif
40
41#endif /* __CUTILS_MISC_H */
diff --git a/include/cutils/multiuser.h b/include/cutils/multiuser.h
deleted file mode 100644
index 5bd9c7b82..000000000
--- a/include/cutils/multiuser.h
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2 * Copyright (C) 2012 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#ifndef __CUTILS_MULTIUSER_H
18#define __CUTILS_MULTIUSER_H
19
20#include <sys/types.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26typedef uid_t userid_t;
27typedef uid_t appid_t;
28
29extern userid_t multiuser_get_user_id(uid_t uid);
30extern appid_t multiuser_get_app_id(uid_t uid);
31
32extern uid_t multiuser_get_uid(userid_t user_id, appid_t app_id);
33
34extern gid_t multiuser_get_cache_gid(userid_t user_id, appid_t app_id);
35extern gid_t multiuser_get_ext_gid(userid_t user_id, appid_t app_id);
36extern gid_t multiuser_get_shared_gid(userid_t user_id, appid_t app_id);
37
38/* TODO: switch callers over to multiuser_get_shared_gid() */
39extern gid_t multiuser_get_shared_app_gid(uid_t uid);
40
41#ifdef __cplusplus
42}
43#endif
44
45#endif /* __CUTILS_MULTIUSER_H */
diff --git a/include/cutils/native_handle.h b/include/cutils/native_handle.h
deleted file mode 100644
index 7d6a98802..000000000
--- a/include/cutils/native_handle.h
+++ /dev/null
@@ -1,100 +0,0 @@
1/*
2 * Copyright (C) 2009 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#ifndef NATIVE_HANDLE_H_
18#define NATIVE_HANDLE_H_
19
20#include <stdalign.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/* Declare a char array for use with native_handle_init */
27#define NATIVE_HANDLE_DECLARE_STORAGE(name, maxFds, maxInts) \
28 alignas(native_handle_t) char name[ \
29 sizeof(native_handle_t) + sizeof(int) * (maxFds + maxInts)]
30
31typedef struct native_handle
32{
33 int version; /* sizeof(native_handle_t) */
34 int numFds; /* number of file-descriptors at &data[0] */
35 int numInts; /* number of ints at &data[numFds] */
36#if defined(__clang__)
37#pragma clang diagnostic push
38#pragma clang diagnostic ignored "-Wzero-length-array"
39#endif
40 int data[0]; /* numFds + numInts ints */
41#if defined(__clang__)
42#pragma clang diagnostic pop
43#endif
44} native_handle_t;
45
46/*
47 * native_handle_close
48 *
49 * closes the file descriptors contained in this native_handle_t
50 *
51 * return 0 on success, or a negative error code on failure
52 *
53 */
54int native_handle_close(const native_handle_t* h);
55
56/*
57 * native_handle_init
58 *
59 * Initializes a native_handle_t from storage. storage must be declared with
60 * NATIVE_HANDLE_DECLARE_STORAGE. numFds and numInts must not respectively
61 * exceed maxFds and maxInts used to declare the storage.
62 */
63native_handle_t* native_handle_init(char* storage, int numFds, int numInts);
64
65/*
66 * native_handle_create
67 *
68 * creates a native_handle_t and initializes it. must be destroyed with
69 * native_handle_delete().
70 *
71 */
72native_handle_t* native_handle_create(int numFds, int numInts);
73
74/*
75 * native_handle_clone
76 *
77 * creates a native_handle_t and initializes it from another native_handle_t.
78 * Must be destroyed with native_handle_delete().
79 *
80 */
81native_handle_t* native_handle_clone(const native_handle_t* handle);
82
83/*
84 * native_handle_delete
85 *
86 * frees a native_handle_t allocated with native_handle_create().
87 * This ONLY frees the memory allocated for the native_handle_t, but doesn't
88 * close the file descriptors; which can be achieved with native_handle_close().
89 *
90 * return 0 on success, or a negative error code on failure
91 *
92 */
93int native_handle_delete(native_handle_t* h);
94
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif /* NATIVE_HANDLE_H_ */
diff --git a/include/cutils/open_memstream.h b/include/cutils/open_memstream.h
deleted file mode 100644
index c1a81ebbc..000000000
--- a/include/cutils/open_memstream.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * Copyright (C) 2010 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#ifndef __CUTILS_OPEN_MEMSTREAM_H__
18#define __CUTILS_OPEN_MEMSTREAM_H__
19
20#include <stdio.h>
21
22#if defined(__APPLE__)
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28FILE* open_memstream(char** bufp, size_t* sizep);
29
30#ifdef __cplusplus
31}
32#endif
33
34#endif /* __APPLE__ */
35
36#endif /*__CUTILS_OPEN_MEMSTREAM_H__*/
diff --git a/include/cutils/partition_utils.h b/include/cutils/partition_utils.h
deleted file mode 100644
index 72ca80d35..000000000
--- a/include/cutils/partition_utils.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/*
2 * Copyright 2011, 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#ifndef __CUTILS_PARTITION_WIPED_H__
18#define __CUTILS_PARTITION_WIPED_H__
19
20__BEGIN_DECLS
21
22int partition_wiped(char *source);
23
24__END_DECLS
25
26#endif /* __CUTILS_PARTITION_WIPED_H__ */
diff --git a/include/cutils/properties.h b/include/cutils/properties.h
deleted file mode 100644
index adf670bf1..000000000
--- a/include/cutils/properties.h
+++ /dev/null
@@ -1,133 +0,0 @@
1/*
2 * Copyright (C) 2006 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#ifndef __CUTILS_PROPERTIES_H
18#define __CUTILS_PROPERTIES_H
19
20#include <sys/cdefs.h>
21#include <stddef.h>
22#include <sys/system_properties.h>
23#include <stdint.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/* System properties are *small* name value pairs managed by the
30** property service. If your data doesn't fit in the provided
31** space it is not appropriate for a system property.
32**
33** WARNING: system/bionic/include/sys/system_properties.h also defines
34** these, but with different names. (TODO: fix that)
35*/
36#define PROPERTY_KEY_MAX PROP_NAME_MAX
37#define PROPERTY_VALUE_MAX PROP_VALUE_MAX
38
39/* property_get: returns the length of the value which will never be
40** greater than PROPERTY_VALUE_MAX - 1 and will always be zero terminated.
41** (the length does not include the terminating zero).
42**
43** If the property read fails or returns an empty value, the default
44** value is used (if nonnull).
45*/
46int property_get(const char *key, char *value, const char *default_value);
47
48/* property_get_bool: returns the value of key coerced into a
49** boolean. If the property is not set, then the default value is returned.
50**
51* The following is considered to be true (1):
52** "1", "true", "y", "yes", "on"
53**
54** The following is considered to be false (0):
55** "0", "false", "n", "no", "off"
56**
57** The conversion is whitespace-sensitive (e.g. " off" will not be false).
58**
59** If no property with this key is set (or the key is NULL) or the boolean
60** conversion fails, the default value is returned.
61**/
62int8_t property_get_bool(const char *key, int8_t default_value);
63
64/* property_get_int64: returns the value of key truncated and coerced into a
65** int64_t. If the property is not set, then the default value is used.
66**
67** The numeric conversion is identical to strtoimax with the base inferred:
68** - All digits up to the first non-digit characters are read
69** - The longest consecutive prefix of digits is converted to a long
70**
71** Valid strings of digits are:
72** - An optional sign character + or -
73** - An optional prefix indicating the base (otherwise base 10 is assumed)
74** -- 0 prefix is octal
75** -- 0x / 0X prefix is hex
76**
77** Leading/trailing whitespace is ignored. Overflow/underflow will cause
78** numeric conversion to fail.
79**
80** If no property with this key is set (or the key is NULL) or the numeric
81** conversion fails, the default value is returned.
82**/
83int64_t property_get_int64(const char *key, int64_t default_value);
84
85/* property_get_int32: returns the value of key truncated and coerced into an
86** int32_t. If the property is not set, then the default value is used.
87**
88** The numeric conversion is identical to strtoimax with the base inferred:
89** - All digits up to the first non-digit characters are read
90** - The longest consecutive prefix of digits is converted to a long
91**
92** Valid strings of digits are:
93** - An optional sign character + or -
94** - An optional prefix indicating the base (otherwise base 10 is assumed)
95** -- 0 prefix is octal
96** -- 0x / 0X prefix is hex
97**
98** Leading/trailing whitespace is ignored. Overflow/underflow will cause
99** numeric conversion to fail.
100**
101** If no property with this key is set (or the key is NULL) or the numeric
102** conversion fails, the default value is returned.
103**/
104int32_t property_get_int32(const char *key, int32_t default_value);
105
106/* property_set: returns 0 on success, < 0 on failure
107*/
108int property_set(const char *key, const char *value);
109
110int property_list(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie);
111
112#if defined(__BIONIC_FORTIFY) && !defined(__clang__)
113
114extern int __property_get_real(const char *, char *, const char *)
115 __asm__(__USER_LABEL_PREFIX__ "property_get");
116__errordecl(__property_get_too_small_error, "property_get() called with too small of a buffer");
117
118__BIONIC_FORTIFY_INLINE
119int property_get(const char *key, char *value, const char *default_value) {
120 size_t bos = __bos(value);
121 if (bos < PROPERTY_VALUE_MAX) {
122 __property_get_too_small_error();
123 }
124 return __property_get_real(key, value, default_value);
125}
126
127#endif
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif
diff --git a/include/cutils/qtaguid.h b/include/cutils/qtaguid.h
deleted file mode 100644
index f8550fda8..000000000
--- a/include/cutils/qtaguid.h
+++ /dev/null
@@ -1,66 +0,0 @@
1/*
2 * Copyright (C) 2011 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#ifndef __CUTILS_QTAGUID_H
18#define __CUTILS_QTAGUID_H
19
20#include <stdint.h>
21#include <sys/types.h>
22#include <unistd.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/*
29 * Set tags (and owning UIDs) for network sockets.
30*/
31extern int qtaguid_tagSocket(int sockfd, int tag, uid_t uid);
32
33/*
34 * Untag a network socket before closing.
35*/
36extern int qtaguid_untagSocket(int sockfd);
37
38/*
39 * For the given uid, switch counter sets.
40 * The kernel only keeps a limited number of sets.
41 * 2 for now.
42 */
43extern int qtaguid_setCounterSet(int counterSetNum, uid_t uid);
44
45/*
46 * Delete all tag info that relates to the given tag an uid.
47 * If the tag is 0, then ALL info about the uid is freeded.
48 * The delete data also affects active tagged socketd, which are
49 * then untagged.
50 * The calling process can only operate on its own tags.
51 * Unless it is part of the happy AID_NET_BW_ACCT group.
52 * In which case it can clobber everything.
53 */
54extern int qtaguid_deleteTagData(int tag, uid_t uid);
55
56/*
57 * Enable/disable qtaguid functionnality at a lower level.
58 * When pacified, the kernel will accept commands but do nothing.
59 */
60extern int qtaguid_setPacifier(int on);
61
62#ifdef __cplusplus
63}
64#endif
65
66#endif /* __CUTILS_QTAG_UID_H */
diff --git a/include/cutils/record_stream.h b/include/cutils/record_stream.h
deleted file mode 100644
index bfac87a53..000000000
--- a/include/cutils/record_stream.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 * Copyright (C) 2006 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/*
18 * A simple utility for reading fixed records out of a stream fd
19 */
20
21#ifndef _CUTILS_RECORD_STREAM_H
22#define _CUTILS_RECORD_STREAM_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28
29typedef struct RecordStream RecordStream;
30
31extern RecordStream *record_stream_new(int fd, size_t maxRecordLen);
32extern void record_stream_free(RecordStream *p_rs);
33
34extern int record_stream_get_next (RecordStream *p_rs, void ** p_outRecord,
35 size_t *p_outRecordLen);
36
37#ifdef __cplusplus
38}
39#endif
40
41
42#endif /*_CUTILS_RECORD_STREAM_H*/
43
diff --git a/include/cutils/sched_policy.h b/include/cutils/sched_policy.h
deleted file mode 100644
index 591bd4478..000000000
--- a/include/cutils/sched_policy.h
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * Copyright (C) 2007 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#ifndef __CUTILS_SCHED_POLICY_H
18#define __CUTILS_SCHED_POLICY_H
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24/* Keep in sync with THREAD_GROUP_* in frameworks/base/core/java/android/os/Process.java */
25typedef enum {
26 SP_DEFAULT = -1,
27 SP_BACKGROUND = 0,
28 SP_FOREGROUND = 1,
29 SP_SYSTEM = 2, // can't be used with set_sched_policy()
30 SP_AUDIO_APP = 3,
31 SP_AUDIO_SYS = 4,
32 SP_TOP_APP = 5,
33 SP_CNT,
34 SP_MAX = SP_CNT - 1,
35 SP_SYSTEM_DEFAULT = SP_FOREGROUND,
36} SchedPolicy;
37
38extern int set_cpuset_policy(int tid, SchedPolicy policy);
39
40/* Assign thread tid to the cgroup associated with the specified policy.
41 * If the thread is a thread group leader, that is it's gettid() == getpid(),
42 * then the other threads in the same thread group are _not_ affected.
43 * On platforms which support gettid(), zero tid means current thread.
44 * Return value: 0 for success, or -errno for error.
45 */
46extern int set_sched_policy(int tid, SchedPolicy policy);
47
48/* Return the policy associated with the cgroup of thread tid via policy pointer.
49 * On platforms which support gettid(), zero tid means current thread.
50 * Return value: 0 for success, or -1 for error and set errno.
51 */
52extern int get_sched_policy(int tid, SchedPolicy *policy);
53
54/* Return a displayable string corresponding to policy.
55 * Return value: non-NULL NUL-terminated name of unspecified length;
56 * the caller is responsible for displaying the useful part of the string.
57 */
58extern const char *get_sched_policy_name(SchedPolicy policy);
59
60#ifdef __cplusplus
61}
62#endif
63
64#endif /* __CUTILS_SCHED_POLICY_H */
diff --git a/include/cutils/sockets.h b/include/cutils/sockets.h
deleted file mode 100644
index d724dd6a5..000000000
--- a/include/cutils/sockets.h
+++ /dev/null
@@ -1,161 +0,0 @@
1/*
2 * Copyright (C) 2006 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#ifndef __CUTILS_SOCKETS_H
18#define __CUTILS_SOCKETS_H
19
20#include <errno.h>
21#include <limits.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <stdbool.h>
26
27#if defined(_WIN32)
28
29#include <winsock2.h>
30#include <ws2tcpip.h>
31
32typedef int socklen_t;
33typedef SOCKET cutils_socket_t;
34
35#else
36
37#include <sys/socket.h>
38#include <netinet/in.h>
39
40typedef int cutils_socket_t;
41#define INVALID_SOCKET (-1)
42
43#endif
44
45#define ANDROID_SOCKET_ENV_PREFIX "ANDROID_SOCKET_"
46#define ANDROID_SOCKET_DIR "/dev/socket"
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/*
53 * android_get_control_socket - simple helper function to get the file
54 * descriptor of our init-managed Unix domain socket. `name' is the name of the
55 * socket, as given in init.rc. Returns -1 on error.
56 */
57int android_get_control_socket(const char* name);
58
59/*
60 * See also android.os.LocalSocketAddress.Namespace
61 */
62// Linux "abstract" (non-filesystem) namespace
63#define ANDROID_SOCKET_NAMESPACE_ABSTRACT 0
64// Android "reserved" (/dev/socket) namespace
65#define ANDROID_SOCKET_NAMESPACE_RESERVED 1
66// Normal filesystem namespace
67#define ANDROID_SOCKET_NAMESPACE_FILESYSTEM 2
68
69/*
70 * Functions to create sockets for some common usages.
71 *
72 * All these functions are implemented for Unix, but only a few are implemented
73 * for Windows. Those which are can be identified by the cutils_socket_t
74 * return type. The idea is to be able to use this return value with the
75 * standard Unix socket functions on any platform.
76 *
77 * On Unix the returned cutils_socket_t is a standard int file descriptor and
78 * can always be used as normal with all file descriptor functions.
79 *
80 * On Windows utils_socket_t is an unsigned int pointer, and is only valid
81 * with functions that specifically take a socket, e.g. send(), sendto(),
82 * recv(), and recvfrom(). General file descriptor functions such as read(),
83 * write(), and close() will not work with utils_socket_t and will require
84 * special handling.
85 *
86 * These functions return INVALID_SOCKET (-1) on failure for all platforms.
87 */
88cutils_socket_t socket_network_client(const char* host, int port, int type);
89int socket_network_client_timeout(const char* host, int port, int type,
90 int timeout, int* getaddrinfo_error);
91int socket_loopback_server(int port, int type);
92int socket_loopback_server6(int port, int type);
93int socket_local_server(const char* name, int namespaceId, int type);
94int socket_local_server_bind(int s, const char* name, int namespaceId);
95int socket_local_client_connect(int fd, const char *name, int namespaceId,
96 int type);
97int socket_local_client(const char* name, int namespaceId, int type);
98cutils_socket_t socket_inaddr_any_server(int port, int type);
99
100/*
101 * Closes a cutils_socket_t. Windows doesn't allow calling close() on a socket
102 * so this is a cross-platform way to close a cutils_socket_t.
103 *
104 * Returns 0 on success.
105 */
106int socket_close(cutils_socket_t sock);
107
108/*
109 * Sets socket receive timeout using SO_RCVTIMEO. Setting |timeout_ms| to 0
110 * disables receive timeouts.
111 *
112 * Return 0 on success.
113 */
114int socket_set_receive_timeout(cutils_socket_t sock, int timeout_ms);
115
116/*
117 * Returns the local port the socket is bound to or -1 on error.
118 */
119int socket_get_local_port(cutils_socket_t sock);
120
121/*
122 * Sends to a socket from multiple buffers; wraps writev() on Unix or WSASend()
123 * on Windows. This can give significant speedup compared to calling send()
124 * multiple times.
125 *
126 * Example usage:
127 * cutils_socket_buffer_t buffers[2] = { {data0, len0}, {data1, len1} };
128 * socket_send_buffers(sock, buffers, 2);
129 *
130 * If you try to pass more than SOCKET_SEND_BUFFERS_MAX_BUFFERS buffers into
131 * this function it will return -1 without sending anything.
132 *
133 * Returns the number of bytes written or -1 on error.
134 */
135typedef struct {
136 const void* data;
137 size_t length;
138} cutils_socket_buffer_t;
139
140#define SOCKET_SEND_BUFFERS_MAX_BUFFERS 16
141
142ssize_t socket_send_buffers(cutils_socket_t sock,
143 const cutils_socket_buffer_t* buffers,
144 size_t num_buffers);
145
146/*
147 * socket_peer_is_trusted - Takes a socket which is presumed to be a
148 * connected local socket (e.g. AF_LOCAL) and returns whether the peer
149 * (the userid that owns the process on the other end of that socket)
150 * is one of the two trusted userids, root or shell.
151 *
152 * Note: This only works as advertised on the Android OS and always
153 * just returns true when called on other operating systems.
154 */
155extern bool socket_peer_is_trusted(int fd);
156
157#ifdef __cplusplus
158}
159#endif
160
161#endif /* __CUTILS_SOCKETS_H */
diff --git a/include/cutils/str_parms.h b/include/cutils/str_parms.h
deleted file mode 100644
index aa1435a08..000000000
--- a/include/cutils/str_parms.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * Copyright (C) 2011 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#ifndef __CUTILS_STR_PARMS_H
18#define __CUTILS_STR_PARMS_H
19
20#include <stdint.h>
21#include <sys/cdefs.h>
22
23__BEGIN_DECLS
24
25struct str_parms;
26
27struct str_parms *str_parms_create(void);
28struct str_parms *str_parms_create_str(const char *_string);
29void str_parms_destroy(struct str_parms *str_parms);
30
31void str_parms_del(struct str_parms *str_parms, const char *key);
32
33int str_parms_add_str(struct str_parms *str_parms, const char *key,
34 const char *value);
35int str_parms_add_int(struct str_parms *str_parms, const char *key, int value);
36
37int str_parms_add_float(struct str_parms *str_parms, const char *key,
38 float value);
39
40// Returns non-zero if the str_parms contains the specified key.
41int str_parms_has_key(struct str_parms *str_parms, const char *key);
42
43// Gets value associated with the specified key (if present), placing it in the buffer
44// pointed to by the out_val parameter. Returns the length of the returned string value.
45// If 'key' isn't in the parms, then return -ENOENT (-2) and leave 'out_val' untouched.
46int str_parms_get_str(struct str_parms *str_parms, const char *key,
47 char *out_val, int len);
48int str_parms_get_int(struct str_parms *str_parms, const char *key,
49 int *out_val);
50int str_parms_get_float(struct str_parms *str_parms, const char *key,
51 float *out_val);
52
53char *str_parms_to_str(struct str_parms *str_parms);
54
55/* debug */
56void str_parms_dump(struct str_parms *str_parms);
57
58__END_DECLS
59
60#endif /* __CUTILS_STR_PARMS_H */
diff --git a/include/cutils/threads.h b/include/cutils/threads.h
deleted file mode 100644
index 572749407..000000000
--- a/include/cutils/threads.h
+++ /dev/null
@@ -1,148 +0,0 @@
1/*
2 * Copyright (C) 2007 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#ifndef _LIBS_CUTILS_THREADS_H
18#define _LIBS_CUTILS_THREADS_H
19
20#include <sys/types.h>
21
22#if !defined(_WIN32)
23#include <pthread.h>
24#else
25#include <windows.h>
26#endif
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32/***********************************************************************/
33/***********************************************************************/
34/***** *****/
35/***** local thread storage *****/
36/***** *****/
37/***********************************************************************/
38/***********************************************************************/
39
40extern pid_t gettid();
41
42#if !defined(_WIN32)
43
44typedef struct {
45 pthread_mutex_t lock;
46 int has_tls;
47 pthread_key_t tls;
48} thread_store_t;
49
50#define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 }
51
52#else // !defined(_WIN32)
53
54typedef struct {
55 int lock_init;
56 int has_tls;
57 DWORD tls;
58 CRITICAL_SECTION lock;
59} thread_store_t;
60
61#define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} }
62
63#endif // !defined(_WIN32)
64
65typedef void (*thread_store_destruct_t)(void* value);
66
67extern void* thread_store_get(thread_store_t* store);
68
69extern void thread_store_set(thread_store_t* store,
70 void* value,
71 thread_store_destruct_t destroy);
72
73/***********************************************************************/
74/***********************************************************************/
75/***** *****/
76/***** mutexes *****/
77/***** *****/
78/***********************************************************************/
79/***********************************************************************/
80
81#if !defined(_WIN32)
82
83typedef pthread_mutex_t mutex_t;
84
85#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
86
87static __inline__ void mutex_lock(mutex_t* lock)
88{
89 pthread_mutex_lock(lock);
90}
91static __inline__ void mutex_unlock(mutex_t* lock)
92{
93 pthread_mutex_unlock(lock);
94}
95static __inline__ int mutex_init(mutex_t* lock)
96{
97 return pthread_mutex_init(lock, NULL);
98}
99static __inline__ void mutex_destroy(mutex_t* lock)
100{
101 pthread_mutex_destroy(lock);
102}
103
104#else // !defined(_WIN32)
105
106typedef struct {
107 int init;
108 CRITICAL_SECTION lock[1];
109} mutex_t;
110
111#define MUTEX_INITIALIZER { 0, {{ NULL, 0, 0, NULL, NULL, 0 }} }
112
113static __inline__ void mutex_lock(mutex_t* lock)
114{
115 if (!lock->init) {
116 lock->init = 1;
117 InitializeCriticalSection( lock->lock );
118 lock->init = 2;
119 } else while (lock->init != 2)
120 Sleep(10);
121
122 EnterCriticalSection(lock->lock);
123}
124
125static __inline__ void mutex_unlock(mutex_t* lock)
126{
127 LeaveCriticalSection(lock->lock);
128}
129static __inline__ int mutex_init(mutex_t* lock)
130{
131 InitializeCriticalSection(lock->lock);
132 lock->init = 2;
133 return 0;
134}
135static __inline__ void mutex_destroy(mutex_t* lock)
136{
137 if (lock->init) {
138 lock->init = 0;
139 DeleteCriticalSection(lock->lock);
140 }
141}
142#endif // !defined(_WIN32)
143
144#ifdef __cplusplus
145}
146#endif
147
148#endif /* _LIBS_CUTILS_THREADS_H */
diff --git a/include/cutils/trace.h b/include/cutils/trace.h
deleted file mode 100644
index fcbdc9b79..000000000
--- a/include/cutils/trace.h
+++ /dev/null
@@ -1,257 +0,0 @@
1/*
2 * Copyright (C) 2012 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#ifndef _LIBS_CUTILS_TRACE_H
18#define _LIBS_CUTILS_TRACE_H
19
20#include <inttypes.h>
21#include <stdatomic.h>
22#include <stdbool.h>
23#include <stdint.h>
24#include <stdio.h>
25#include <sys/cdefs.h>
26#include <sys/types.h>
27#include <unistd.h>
28
29#include <cutils/compiler.h>
30
31__BEGIN_DECLS
32
33/**
34 * The ATRACE_TAG macro can be defined before including this header to trace
35 * using one of the tags defined below. It must be defined to one of the
36 * following ATRACE_TAG_* macros. The trace tag is used to filter tracing in
37 * userland to avoid some of the runtime cost of tracing when it is not desired.
38 *
39 * Defining ATRACE_TAG to be ATRACE_TAG_ALWAYS will result in the tracing always
40 * being enabled - this should ONLY be done for debug code, as userland tracing
41 * has a performance cost even when the trace is not being recorded. Defining
42 * ATRACE_TAG to be ATRACE_TAG_NEVER or leaving ATRACE_TAG undefined will result
43 * in the tracing always being disabled.
44 *
45 * ATRACE_TAG_HAL should be bitwise ORed with the relevant tags for tracing
46 * within a hardware module. For example a camera hardware module would set:
47 * #define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
48 *
49 * Keep these in sync with frameworks/base/core/java/android/os/Trace.java.
50 */
51#define ATRACE_TAG_NEVER 0 // This tag is never enabled.
52#define ATRACE_TAG_ALWAYS (1<<0) // This tag is always enabled.
53#define ATRACE_TAG_GRAPHICS (1<<1)
54#define ATRACE_TAG_INPUT (1<<2)
55#define ATRACE_TAG_VIEW (1<<3)
56#define ATRACE_TAG_WEBVIEW (1<<4)
57#define ATRACE_TAG_WINDOW_MANAGER (1<<5)
58#define ATRACE_TAG_ACTIVITY_MANAGER (1<<6)
59#define ATRACE_TAG_SYNC_MANAGER (1<<7)
60#define ATRACE_TAG_AUDIO (1<<8)
61#define ATRACE_TAG_VIDEO (1<<9)
62#define ATRACE_TAG_CAMERA (1<<10)
63#define ATRACE_TAG_HAL (1<<11)
64#define ATRACE_TAG_APP (1<<12)
65#define ATRACE_TAG_RESOURCES (1<<13)
66#define ATRACE_TAG_DALVIK (1<<14)
67#define ATRACE_TAG_RS (1<<15)
68#define ATRACE_TAG_BIONIC (1<<16)
69#define ATRACE_TAG_POWER (1<<17)
70#define ATRACE_TAG_PACKAGE_MANAGER (1<<18)
71#define ATRACE_TAG_SYSTEM_SERVER (1<<19)
72#define ATRACE_TAG_DATABASE (1<<20)
73#define ATRACE_TAG_NETWORK (1<<21)
74#define ATRACE_TAG_ADB (1<<22)
75#define ATRACE_TAG_LAST ATRACE_TAG_ADB
76
77// Reserved for initialization.
78#define ATRACE_TAG_NOT_READY (1ULL<<63)
79
80#define ATRACE_TAG_VALID_MASK ((ATRACE_TAG_LAST - 1) | ATRACE_TAG_LAST)
81
82#ifndef ATRACE_TAG
83#define ATRACE_TAG ATRACE_TAG_NEVER
84#elif ATRACE_TAG > ATRACE_TAG_VALID_MASK
85#error ATRACE_TAG must be defined to be one of the tags defined in cutils/trace.h
86#endif
87
88/**
89 * Opens the trace file for writing and reads the property for initial tags.
90 * The atrace.tags.enableflags property sets the tags to trace.
91 * This function should not be explicitly called, the first call to any normal
92 * trace function will cause it to be run safely.
93 */
94void atrace_setup();
95
96/**
97 * If tracing is ready, set atrace_enabled_tags to the system property
98 * debug.atrace.tags.enableflags. Can be used as a sysprop change callback.
99 */
100void atrace_update_tags();
101
102/**
103 * Set whether the process is debuggable. By default the process is not
104 * considered debuggable. If the process is not debuggable then application-
105 * level tracing is not allowed unless the ro.debuggable system property is
106 * set to '1'.
107 */
108void atrace_set_debuggable(bool debuggable);
109
110/**
111 * Set whether tracing is enabled for the current process. This is used to
112 * prevent tracing within the Zygote process.
113 */
114void atrace_set_tracing_enabled(bool enabled);
115
116/**
117 * Flag indicating whether setup has been completed, initialized to 0.
118 * Nonzero indicates setup has completed.
119 * Note: This does NOT indicate whether or not setup was successful.
120 */
121extern atomic_bool atrace_is_ready;
122
123/**
124 * Set of ATRACE_TAG flags to trace for, initialized to ATRACE_TAG_NOT_READY.
125 * A value of zero indicates setup has failed.
126 * Any other nonzero value indicates setup has succeeded, and tracing is on.
127 */
128extern uint64_t atrace_enabled_tags;
129
130/**
131 * Handle to the kernel's trace buffer, initialized to -1.
132 * Any other value indicates setup has succeeded, and is a valid fd for tracing.
133 */
134extern int atrace_marker_fd;
135
136/**
137 * atrace_init readies the process for tracing by opening the trace_marker file.
138 * Calling any trace function causes this to be run, so calling it is optional.
139 * This can be explicitly run to avoid setup delay on first trace function.
140 */
141#define ATRACE_INIT() atrace_init()
142static inline void atrace_init()
143{
144 if (CC_UNLIKELY(!atomic_load_explicit(&atrace_is_ready, memory_order_acquire))) {
145 atrace_setup();
146 }
147}
148
149/**
150 * Get the mask of all tags currently enabled.
151 * It can be used as a guard condition around more expensive trace calculations.
152 * Every trace function calls this, which ensures atrace_init is run.
153 */
154#define ATRACE_GET_ENABLED_TAGS() atrace_get_enabled_tags()
155static inline uint64_t atrace_get_enabled_tags()
156{
157 atrace_init();
158 return atrace_enabled_tags;
159}
160
161/**
162 * Test if a given tag is currently enabled.
163 * Returns nonzero if the tag is enabled, otherwise zero.
164 * It can be used as a guard condition around more expensive trace calculations.
165 */
166#define ATRACE_ENABLED() atrace_is_tag_enabled(ATRACE_TAG)
167static inline uint64_t atrace_is_tag_enabled(uint64_t tag)
168{
169 return atrace_get_enabled_tags() & tag;
170}
171
172/**
173 * Trace the beginning of a context. name is used to identify the context.
174 * This is often used to time function execution.
175 */
176#define ATRACE_BEGIN(name) atrace_begin(ATRACE_TAG, name)
177static inline void atrace_begin(uint64_t tag, const char* name)
178{
179 if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
180 void atrace_begin_body(const char*);
181 atrace_begin_body(name);
182 }
183}
184
185/**
186 * Trace the end of a context.
187 * This should match up (and occur after) a corresponding ATRACE_BEGIN.
188 */
189#define ATRACE_END() atrace_end(ATRACE_TAG)
190static inline void atrace_end(uint64_t tag)
191{
192 if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
193 void atrace_end_body();
194 atrace_end_body();
195 }
196}
197
198/**
199 * Trace the beginning of an asynchronous event. Unlike ATRACE_BEGIN/ATRACE_END
200 * contexts, asynchronous events do not need to be nested. The name describes
201 * the event, and the cookie provides a unique identifier for distinguishing
202 * simultaneous events. The name and cookie used to begin an event must be
203 * used to end it.
204 */
205#define ATRACE_ASYNC_BEGIN(name, cookie) \
206 atrace_async_begin(ATRACE_TAG, name, cookie)
207static inline void atrace_async_begin(uint64_t tag, const char* name,
208 int32_t cookie)
209{
210 if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
211 void atrace_async_begin_body(const char*, int32_t);
212 atrace_async_begin_body(name, cookie);
213 }
214}
215
216/**
217 * Trace the end of an asynchronous event.
218 * This should have a corresponding ATRACE_ASYNC_BEGIN.
219 */
220#define ATRACE_ASYNC_END(name, cookie) atrace_async_end(ATRACE_TAG, name, cookie)
221static inline void atrace_async_end(uint64_t tag, const char* name, int32_t cookie)
222{
223 if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
224 void atrace_async_end_body(const char*, int32_t);
225 atrace_async_end_body(name, cookie);
226 }
227}
228
229/**
230 * Traces an integer counter value. name is used to identify the counter.
231 * This can be used to track how a value changes over time.
232 */
233#define ATRACE_INT(name, value) atrace_int(ATRACE_TAG, name, value)
234static inline void atrace_int(uint64_t tag, const char* name, int32_t value)
235{
236 if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
237 void atrace_int_body(const char*, int32_t);
238 atrace_int_body(name, value);
239 }
240}
241
242/**
243 * Traces a 64-bit integer counter value. name is used to identify the
244 * counter. This can be used to track how a value changes over time.
245 */
246#define ATRACE_INT64(name, value) atrace_int64(ATRACE_TAG, name, value)
247static inline void atrace_int64(uint64_t tag, const char* name, int64_t value)
248{
249 if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
250 void atrace_int64_body(const char*, int64_t);
251 atrace_int64_body(name, value);
252 }
253}
254
255__END_DECLS
256
257#endif // _LIBS_CUTILS_TRACE_H
diff --git a/include/cutils/uevent.h b/include/cutils/uevent.h
deleted file mode 100644
index da1c2aae6..000000000
--- a/include/cutils/uevent.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * Copyright (C) 2011 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#ifndef __CUTILS_UEVENT_H
18#define __CUTILS_UEVENT_H
19
20#include <stdbool.h>
21#include <sys/socket.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27int uevent_open_socket(int buf_sz, bool passcred);
28ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length);
29ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer, size_t length, uid_t *uid);
30ssize_t uevent_kernel_recv(int socket, void *buffer, size_t length, bool require_group, uid_t *uid);
31
32#ifdef __cplusplus
33}
34#endif
35
36#endif /* __CUTILS_UEVENT_H */
diff --git a/include/log b/include/log
new file mode 120000
index 000000000..714065f45
--- /dev/null
+++ b/include/log
@@ -0,0 +1 @@
../liblog/include/log \ No newline at end of file
diff --git a/include/log/event_tag_map.h b/include/log/event_tag_map.h
deleted file mode 100644
index 22e62ec98..000000000
--- a/include/log/event_tag_map.h
+++ /dev/null
@@ -1,65 +0,0 @@
1/*
2 * Copyright (C) 2007 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#ifndef _LIBS_CUTILS_EVENTTAGMAP_H
18#define _LIBS_CUTILS_EVENTTAGMAP_H
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#define EVENT_TAG_MAP_FILE "/system/etc/event-log-tags"
25
26struct EventTagMap;
27typedef struct EventTagMap EventTagMap;
28
29/*
30 * Open the specified file as an event log tag map.
31 *
32 * Returns NULL on failure.
33 */
34EventTagMap* android_openEventTagMap(const char* fileName);
35
36/*
37 * Close the map.
38 */
39void android_closeEventTagMap(EventTagMap* map);
40
41/*
42 * Look up a tag by index. Returns the tag string, or NULL if not found.
43 */
44const char* android_lookupEventTag(const EventTagMap* map, unsigned int tag)
45 __attribute__((deprecated("use android_lookupEventTag_len() instead to minimize MAP_PRIVATE copy-on-write memory impact")));
46
47/*
48 * Look up a tag by index. Returns the tag string & string length, or NULL if
49 * not found. Returned string is not guaranteed to be nul terminated.
50 */
51const char* android_lookupEventTag_len(const EventTagMap* map,
52 size_t* len, unsigned int tag);
53
54/*
55 * Look up a format by index. Returns the format string & string length,
56 * or NULL if not found. Returned string is not guaranteed to be nul terminated.
57 */
58const char* android_lookupEventFormat_len(const EventTagMap* map,
59 size_t* len, unsigned int tag);
60
61#ifdef __cplusplus
62}
63#endif
64
65#endif /*_LIBS_CUTILS_EVENTTAGMAP_H*/
diff --git a/include/log/log.h b/include/log/log.h
deleted file mode 100644
index ece9ea6d1..000000000
--- a/include/log/log.h
+++ /dev/null
@@ -1,871 +0,0 @@
1/*
2 * Copyright (C) 2005-2014 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#ifndef _LIBS_LOG_LOG_H
18#define _LIBS_LOG_LOG_H
19
20/* Too many in the ecosystem assume these are included */
21#if !defined(_WIN32)
22#include <pthread.h>
23#endif
24#include <stdint.h> /* uint16_t, int32_t */
25#include <stdio.h>
26#include <sys/types.h>
27#include <time.h>
28#include <unistd.h>
29
30#include <android/log.h>
31#include <log/uio.h> /* helper to define iovec for portability */
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/*
38 * LOG_TAG is the local tag used for the following simplified
39 * logging macros. You can change this preprocessor definition
40 * before using the other macros to change the tag.
41 */
42
43#ifndef LOG_TAG
44#define LOG_TAG NULL
45#endif
46
47/* --------------------------------------------------------------------- */
48
49/*
50 * This file uses ", ## __VA_ARGS__" zero-argument token pasting to
51 * work around issues with debug-only syntax errors in assertions
52 * that are missing format strings. See commit
53 * 19299904343daf191267564fe32e6cd5c165cd42
54 */
55#if defined(__clang__)
56#pragma clang diagnostic push
57#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
58#endif
59
60/*
61 * Send a simple string to the log.
62 */
63int __android_log_buf_write(int bufID, int prio, const char* tag, const char* text);
64int __android_log_buf_print(int bufID, int prio, const char* tag, const char* fmt, ...)
65#if defined(__GNUC__)
66 __attribute__((__format__(printf, 4, 5)))
67#endif
68 ;
69
70/*
71 * Simplified macro to send a verbose system log message using current LOG_TAG.
72 */
73#ifndef SLOGV
74#define __SLOGV(...) \
75 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
76#if LOG_NDEBUG
77#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
78#else
79#define SLOGV(...) __SLOGV(__VA_ARGS__)
80#endif
81#endif
82
83#ifndef SLOGV_IF
84#if LOG_NDEBUG
85#define SLOGV_IF(cond, ...) ((void)0)
86#else
87#define SLOGV_IF(cond, ...) \
88 ( (__predict_false(cond)) \
89 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
90 : (void)0 )
91#endif
92#endif
93
94/*
95 * Simplified macro to send a debug system log message using current LOG_TAG.
96 */
97#ifndef SLOGD
98#define SLOGD(...) \
99 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
100#endif
101
102#ifndef SLOGD_IF
103#define SLOGD_IF(cond, ...) \
104 ( (__predict_false(cond)) \
105 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
106 : (void)0 )
107#endif
108
109/*
110 * Simplified macro to send an info system log message using current LOG_TAG.
111 */
112#ifndef SLOGI
113#define SLOGI(...) \
114 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
115#endif
116
117#ifndef SLOGI_IF
118#define SLOGI_IF(cond, ...) \
119 ( (__predict_false(cond)) \
120 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
121 : (void)0 )
122#endif
123
124/*
125 * Simplified macro to send a warning system log message using current LOG_TAG.
126 */
127#ifndef SLOGW
128#define SLOGW(...) \
129 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
130#endif
131
132#ifndef SLOGW_IF
133#define SLOGW_IF(cond, ...) \
134 ( (__predict_false(cond)) \
135 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
136 : (void)0 )
137#endif
138
139/*
140 * Simplified macro to send an error system log message using current LOG_TAG.
141 */
142#ifndef SLOGE
143#define SLOGE(...) \
144 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
145#endif
146
147#ifndef SLOGE_IF
148#define SLOGE_IF(cond, ...) \
149 ( (__predict_false(cond)) \
150 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
151 : (void)0 )
152#endif
153
154/* --------------------------------------------------------------------- */
155
156/*
157 * Simplified macro to send a verbose radio log message using current LOG_TAG.
158 */
159#ifndef RLOGV
160#define __RLOGV(...) \
161 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
162#if LOG_NDEBUG
163#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
164#else
165#define RLOGV(...) __RLOGV(__VA_ARGS__)
166#endif
167#endif
168
169#ifndef RLOGV_IF
170#if LOG_NDEBUG
171#define RLOGV_IF(cond, ...) ((void)0)
172#else
173#define RLOGV_IF(cond, ...) \
174 ( (__predict_false(cond)) \
175 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
176 : (void)0 )
177#endif
178#endif
179
180/*
181 * Simplified macro to send a debug radio log message using current LOG_TAG.
182 */
183#ifndef RLOGD
184#define RLOGD(...) \
185 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
186#endif
187
188#ifndef RLOGD_IF
189#define RLOGD_IF(cond, ...) \
190 ( (__predict_false(cond)) \
191 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
192 : (void)0 )
193#endif
194
195/*
196 * Simplified macro to send an info radio log message using current LOG_TAG.
197 */
198#ifndef RLOGI
199#define RLOGI(...) \
200 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
201#endif
202
203#ifndef RLOGI_IF
204#define RLOGI_IF(cond, ...) \
205 ( (__predict_false(cond)) \
206 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
207 : (void)0 )
208#endif
209
210/*
211 * Simplified macro to send a warning radio log message using current LOG_TAG.
212 */
213#ifndef RLOGW
214#define RLOGW(...) \
215 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
216#endif
217
218#ifndef RLOGW_IF
219#define RLOGW_IF(cond, ...) \
220 ( (__predict_false(cond)) \
221 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
222 : (void)0 )
223#endif
224
225/*
226 * Simplified macro to send an error radio log message using current LOG_TAG.
227 */
228#ifndef RLOGE
229#define RLOGE(...) \
230 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
231#endif
232
233#ifndef RLOGE_IF
234#define RLOGE_IF(cond, ...) \
235 ( (__predict_false(cond)) \
236 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
237 : (void)0 )
238#endif
239
240/* --------------------------------------------------------------------- */
241
242/*
243 * Event logging.
244 */
245
246/*
247 * The following should not be used directly.
248 */
249
250int __android_log_bwrite(int32_t tag, const void* payload, size_t len);
251int __android_log_btwrite(int32_t tag, char type, const void* payload,
252 size_t len);
253int __android_log_bswrite(int32_t tag, const char* payload);
254
255#define android_bWriteLog(tag, payload, len) \
256 __android_log_bwrite(tag, payload, len)
257#define android_btWriteLog(tag, type, payload, len) \
258 __android_log_btwrite(tag, type, payload, len)
259
260/*
261 * Event log entry types.
262 */
263#ifndef __AndroidEventLogType_defined
264#define __AndroidEventLogType_defined
265typedef enum {
266 /* Special markers for android_log_list_element type */
267 EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
268 EVENT_TYPE_UNKNOWN = '?', /* protocol error */
269
270 /* must match with declaration in java/android/android/util/EventLog.java */
271 EVENT_TYPE_INT = 0, /* int32_t */
272 EVENT_TYPE_LONG = 1, /* int64_t */
273 EVENT_TYPE_STRING = 2,
274 EVENT_TYPE_LIST = 3,
275 EVENT_TYPE_FLOAT = 4,
276} AndroidEventLogType;
277#endif
278#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
279#define typeof_AndroidEventLogType unsigned char
280
281#ifndef LOG_EVENT_INT
282#define LOG_EVENT_INT(_tag, _value) { \
283 int intBuf = _value; \
284 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
285 sizeof(intBuf)); \
286 }
287#endif
288#ifndef LOG_EVENT_LONG
289#define LOG_EVENT_LONG(_tag, _value) { \
290 long long longBuf = _value; \
291 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
292 sizeof(longBuf)); \
293 }
294#endif
295#ifndef LOG_EVENT_FLOAT
296#define LOG_EVENT_FLOAT(_tag, _value) { \
297 float floatBuf = _value; \
298 (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
299 sizeof(floatBuf)); \
300 }
301#endif
302#ifndef LOG_EVENT_STRING
303#define LOG_EVENT_STRING(_tag, _value) \
304 (void) __android_log_bswrite(_tag, _value);
305#endif
306
307#ifndef log_id_t_defined
308#define log_id_t_defined
309typedef enum log_id {
310 LOG_ID_MIN = 0,
311
312 LOG_ID_MAIN = 0,
313 LOG_ID_RADIO = 1,
314 LOG_ID_EVENTS = 2,
315 LOG_ID_SYSTEM = 3,
316 LOG_ID_CRASH = 4,
317 LOG_ID_SECURITY = 5,
318 LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
319
320 LOG_ID_MAX
321} log_id_t;
322#endif
323#define sizeof_log_id_t sizeof(typeof_log_id_t)
324#define typeof_log_id_t unsigned char
325
326/* --------------------------------------------------------------------- */
327
328/*
329 * Native log reading interface section. See logcat for sample code.
330 *
331 * The preferred API is an exec of logcat. Likely uses of this interface
332 * are if native code suffers from exec or filtration being too costly,
333 * access to raw information, or parsing is an issue.
334 */
335
336/*
337 * The userspace structure for version 1 of the logger_entry ABI.
338 */
339#ifndef __struct_logger_entry_defined
340#define __struct_logger_entry_defined
341struct logger_entry {
342 uint16_t len; /* length of the payload */
343 uint16_t __pad; /* no matter what, we get 2 bytes of padding */
344 int32_t pid; /* generating process's pid */
345 int32_t tid; /* generating process's tid */
346 int32_t sec; /* seconds since Epoch */
347 int32_t nsec; /* nanoseconds */
348#ifndef __cplusplus
349 char msg[0]; /* the entry's payload */
350#endif
351};
352#endif
353
354/*
355 * The userspace structure for version 2 of the logger_entry ABI.
356 */
357#ifndef __struct_logger_entry_v2_defined
358#define __struct_logger_entry_v2_defined
359struct logger_entry_v2 {
360 uint16_t len; /* length of the payload */
361 uint16_t hdr_size; /* sizeof(struct logger_entry_v2) */
362 int32_t pid; /* generating process's pid */
363 int32_t tid; /* generating process's tid */
364 int32_t sec; /* seconds since Epoch */
365 int32_t nsec; /* nanoseconds */
366 uint32_t euid; /* effective UID of logger */
367#ifndef __cplusplus
368 char msg[0]; /* the entry's payload */
369#endif
370} __attribute__((__packed__));
371#endif
372
373/*
374 * The userspace structure for version 3 of the logger_entry ABI.
375 */
376#ifndef __struct_logger_entry_v3_defined
377#define __struct_logger_entry_v3_defined
378struct logger_entry_v3 {
379 uint16_t len; /* length of the payload */
380 uint16_t hdr_size; /* sizeof(struct logger_entry_v3) */
381 int32_t pid; /* generating process's pid */
382 int32_t tid; /* generating process's tid */
383 int32_t sec; /* seconds since Epoch */
384 int32_t nsec; /* nanoseconds */
385 uint32_t lid; /* log id of the payload */
386#ifndef __cplusplus
387 char msg[0]; /* the entry's payload */
388#endif
389} __attribute__((__packed__));
390#endif
391
392/*
393 * The userspace structure for version 4 of the logger_entry ABI.
394 */
395#ifndef __struct_logger_entry_v4_defined
396#define __struct_logger_entry_v4_defined
397struct logger_entry_v4 {
398 uint16_t len; /* length of the payload */
399 uint16_t hdr_size; /* sizeof(struct logger_entry_v4) */
400 int32_t pid; /* generating process's pid */
401 uint32_t tid; /* generating process's tid */
402 uint32_t sec; /* seconds since Epoch */
403 uint32_t nsec; /* nanoseconds */
404 uint32_t lid; /* log id of the payload, bottom 4 bits currently */
405 uint32_t uid; /* generating process's uid */
406#ifndef __cplusplus
407 char msg[0]; /* the entry's payload */
408#endif
409};
410#endif
411
412/* struct log_time is a wire-format variant of struct timespec */
413#define NS_PER_SEC 1000000000ULL
414
415#ifndef __struct_log_time_defined
416#define __struct_log_time_defined
417#ifdef __cplusplus
418
419/*
420 * NB: we did NOT define a copy constructor. This will result in structure
421 * no longer being compatible with pass-by-value which is desired
422 * efficient behavior. Also, pass-by-reference breaks C/C++ ABI.
423 */
424struct log_time {
425public:
426 uint32_t tv_sec; /* good to Feb 5 2106 */
427 uint32_t tv_nsec;
428
429 static const uint32_t tv_sec_max = 0xFFFFFFFFUL;
430 static const uint32_t tv_nsec_max = 999999999UL;
431
432 log_time(const timespec& T)
433 {
434 tv_sec = static_cast<uint32_t>(T.tv_sec);
435 tv_nsec = static_cast<uint32_t>(T.tv_nsec);
436 }
437 log_time(uint32_t sec, uint32_t nsec)
438 {
439 tv_sec = sec;
440 tv_nsec = nsec;
441 }
442#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
443#define __struct_log_time_private_defined
444 static const timespec EPOCH;
445#endif
446 log_time()
447 {
448 }
449#ifdef __linux__
450 log_time(clockid_t id)
451 {
452 timespec T;
453 clock_gettime(id, &T);
454 tv_sec = static_cast<uint32_t>(T.tv_sec);
455 tv_nsec = static_cast<uint32_t>(T.tv_nsec);
456 }
457#endif
458 log_time(const char* T)
459 {
460 const uint8_t* c = reinterpret_cast<const uint8_t*>(T);
461 tv_sec = c[0] |
462 (static_cast<uint32_t>(c[1]) << 8) |
463 (static_cast<uint32_t>(c[2]) << 16) |
464 (static_cast<uint32_t>(c[3]) << 24);
465 tv_nsec = c[4] |
466 (static_cast<uint32_t>(c[5]) << 8) |
467 (static_cast<uint32_t>(c[6]) << 16) |
468 (static_cast<uint32_t>(c[7]) << 24);
469 }
470
471 /* timespec */
472 bool operator== (const timespec& T) const
473 {
474 return (tv_sec == static_cast<uint32_t>(T.tv_sec))
475 && (tv_nsec == static_cast<uint32_t>(T.tv_nsec));
476 }
477 bool operator!= (const timespec& T) const
478 {
479 return !(*this == T);
480 }
481 bool operator< (const timespec& T) const
482 {
483 return (tv_sec < static_cast<uint32_t>(T.tv_sec))
484 || ((tv_sec == static_cast<uint32_t>(T.tv_sec))
485 && (tv_nsec < static_cast<uint32_t>(T.tv_nsec)));
486 }
487 bool operator>= (const timespec& T) const
488 {
489 return !(*this < T);
490 }
491 bool operator> (const timespec& T) const
492 {
493 return (tv_sec > static_cast<uint32_t>(T.tv_sec))
494 || ((tv_sec == static_cast<uint32_t>(T.tv_sec))
495 && (tv_nsec > static_cast<uint32_t>(T.tv_nsec)));
496 }
497 bool operator<= (const timespec& T) const
498 {
499 return !(*this > T);
500 }
501
502#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
503 log_time operator-= (const timespec& T);
504 log_time operator- (const timespec& T) const
505 {
506 log_time local(*this);
507 return local -= T;
508 }
509 log_time operator+= (const timespec& T);
510 log_time operator+ (const timespec& T) const
511 {
512 log_time local(*this);
513 return local += T;
514 }
515#endif
516
517 /* log_time */
518 bool operator== (const log_time& T) const
519 {
520 return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
521 }
522 bool operator!= (const log_time& T) const
523 {
524 return !(*this == T);
525 }
526 bool operator< (const log_time& T) const
527 {
528 return (tv_sec < T.tv_sec)
529 || ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec));
530 }
531 bool operator>= (const log_time& T) const
532 {
533 return !(*this < T);
534 }
535 bool operator> (const log_time& T) const
536 {
537 return (tv_sec > T.tv_sec)
538 || ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec));
539 }
540 bool operator<= (const log_time& T) const
541 {
542 return !(*this > T);
543 }
544
545#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
546 log_time operator-= (const log_time& T);
547 log_time operator- (const log_time& T) const
548 {
549 log_time local(*this);
550 return local -= T;
551 }
552 log_time operator+= (const log_time& T);
553 log_time operator+ (const log_time& T) const
554 {
555 log_time local(*this);
556 return local += T;
557 }
558#endif
559
560 uint64_t nsec() const
561 {
562 return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
563 }
564
565#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
566 static const char default_format[];
567
568 /* Add %#q for the fraction of a second to the standard library functions */
569 char* strptime(const char* s, const char* format = default_format);
570#endif
571} __attribute__((__packed__));
572
573#else
574
575typedef struct log_time {
576 uint32_t tv_sec;
577 uint32_t tv_nsec;
578} __attribute__((__packed__)) log_time;
579
580#endif
581#endif
582
583/*
584 * The maximum size of the log entry payload that can be
585 * written to the logger. An attempt to write more than
586 * this amount will result in a truncated log entry.
587 */
588#define LOGGER_ENTRY_MAX_PAYLOAD 4068
589
590/*
591 * The maximum size of a log entry which can be read from the
592 * kernel logger driver. An attempt to read less than this amount
593 * may result in read() returning EINVAL.
594 */
595#define LOGGER_ENTRY_MAX_LEN (5*1024)
596
597#ifndef __struct_log_msg_defined
598#define __struct_log_msg_defined
599struct log_msg {
600 union {
601 unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1];
602 struct logger_entry_v4 entry;
603 struct logger_entry_v4 entry_v4;
604 struct logger_entry_v3 entry_v3;
605 struct logger_entry_v2 entry_v2;
606 struct logger_entry entry_v1;
607 } __attribute__((aligned(4)));
608#ifdef __cplusplus
609 /* Matching log_time operators */
610 bool operator== (const log_msg& T) const
611 {
612 return (entry.sec == T.entry.sec) && (entry.nsec == T.entry.nsec);
613 }
614 bool operator!= (const log_msg& T) const
615 {
616 return !(*this == T);
617 }
618 bool operator< (const log_msg& T) const
619 {
620 return (entry.sec < T.entry.sec)
621 || ((entry.sec == T.entry.sec)
622 && (entry.nsec < T.entry.nsec));
623 }
624 bool operator>= (const log_msg& T) const
625 {
626 return !(*this < T);
627 }
628 bool operator> (const log_msg& T) const
629 {
630 return (entry.sec > T.entry.sec)
631 || ((entry.sec == T.entry.sec)
632 && (entry.nsec > T.entry.nsec));
633 }
634 bool operator<= (const log_msg& T) const
635 {
636 return !(*this > T);
637 }
638 uint64_t nsec() const
639 {
640 return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec;
641 }
642
643 /* packet methods */
644 log_id_t id()
645 {
646 return static_cast<log_id_t>(entry.lid);
647 }
648 char* msg()
649 {
650 unsigned short hdr_size = entry.hdr_size;
651 if (!hdr_size) {
652 hdr_size = sizeof(entry_v1);
653 }
654 if ((hdr_size < sizeof(entry_v1)) || (hdr_size > sizeof(entry))) {
655 return NULL;
656 }
657 return reinterpret_cast<char*>(buf) + hdr_size;
658 }
659 unsigned int len()
660 {
661 return (entry.hdr_size ?
662 entry.hdr_size :
663 static_cast<uint16_t>(sizeof(entry_v1))) +
664 entry.len;
665 }
666#endif
667};
668#endif
669
670#ifndef __ANDROID_USE_LIBLOG_READER_INTERFACE
671#ifndef __ANDROID_API__
672#define __ANDROID_USE_LIBLOG_READER_INTERFACE 3
673#elif __ANDROID_API__ > 23 /* > Marshmallow */
674#define __ANDROID_USE_LIBLOG_READER_INTERFACE 3
675#elif __ANDROID_API__ > 22 /* > Lollipop */
676#define __ANDROID_USE_LIBLOG_READER_INTERFACE 2
677#elif __ANDROID_API__ > 19 /* > KitKat */
678#define __ANDROID_USE_LIBLOG_READER_INTERFACE 1
679#else
680#define __ANDROID_USE_LIBLOG_READER_INTERFACE 0
681#endif
682#endif
683
684#if __ANDROID_USE_LIBLOG_READER_INTERFACE
685
686struct logger;
687
688log_id_t android_logger_get_id(struct logger* logger);
689
690int android_logger_clear(struct logger* logger);
691long android_logger_get_log_size(struct logger* logger);
692int android_logger_set_log_size(struct logger* logger, unsigned long size);
693long android_logger_get_log_readable_size(struct logger* logger);
694int android_logger_get_log_version(struct logger* logger);
695
696struct logger_list;
697
698#if __ANDROID_USE_LIBLOG_READER_INTERFACE > 1
699ssize_t android_logger_get_statistics(struct logger_list* logger_list,
700 char* buf, size_t len);
701ssize_t android_logger_get_prune_list(struct logger_list* logger_list,
702 char* buf, size_t len);
703int android_logger_set_prune_list(struct logger_list* logger_list,
704 char* buf, size_t len);
705#endif
706
707#define ANDROID_LOG_RDONLY O_RDONLY
708#define ANDROID_LOG_WRONLY O_WRONLY
709#define ANDROID_LOG_RDWR O_RDWR
710#define ANDROID_LOG_ACCMODE O_ACCMODE
711#define ANDROID_LOG_NONBLOCK O_NONBLOCK
712#if __ANDROID_USE_LIBLOG_READER_INTERFACE > 2
713#define ANDROID_LOG_WRAP 0x40000000 /* Block until buffer about to wrap */
714#define ANDROID_LOG_WRAP_DEFAULT_TIMEOUT 7200 /* 2 hour default */
715#endif
716#if __ANDROID_USE_LIBLOG_READER_INTERFACE > 1
717#define ANDROID_LOG_PSTORE 0x80000000
718#endif
719
720struct logger_list* android_logger_list_alloc(int mode,
721 unsigned int tail,
722 pid_t pid);
723struct logger_list* android_logger_list_alloc_time(int mode,
724 log_time start,
725 pid_t pid);
726void android_logger_list_free(struct logger_list* logger_list);
727/* In the purest sense, the following two are orthogonal interfaces */
728int android_logger_list_read(struct logger_list* logger_list,
729 struct log_msg* log_msg);
730
731/* Multiple log_id_t opens */
732struct logger* android_logger_open(struct logger_list* logger_list,
733 log_id_t id);
734#define android_logger_close android_logger_free
735/* Single log_id_t open */
736struct logger_list* android_logger_list_open(log_id_t id,
737 int mode,
738 unsigned int tail,
739 pid_t pid);
740#define android_logger_list_close android_logger_list_free
741
742#endif /* __ANDROID_USE_LIBLOG_READER_INTERFACE */
743
744#ifdef __linux__
745
746#ifndef __ANDROID_USE_LIBLOG_CLOCK_INTERFACE
747#ifndef __ANDROID_API__
748#define __ANDROID_USE_LIBLOG_CLOCK_INTERFACE 1
749#elif __ANDROID_API__ > 22 /* > Lollipop */
750#define __ANDROID_USE_LIBLOG_CLOCK_INTERFACE 1
751#else
752#define __ANDROID_USE_LIBLOG_CLOCK_INTERFACE 0
753#endif
754#endif
755
756#if __ANDROID_USE_LIBLOG_CLOCK_INTERFACE
757clockid_t android_log_clockid();
758#endif
759
760#endif /* __linux__ */
761
762/*
763 * log_id_t helpers
764 */
765log_id_t android_name_to_log_id(const char* logName);
766const char* android_log_id_to_name(log_id_t log_id);
767
768/* --------------------------------------------------------------------- */
769
770#ifndef _ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE
771#ifndef __ANDROID_API__
772#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 1
773#elif __ANDROID_API__ > 22 /* > Lollipop */
774#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 1
775#else
776#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 0
777#endif
778#endif
779
780#if __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE
781
782#define android_errorWriteLog(tag, subTag) \
783 __android_log_error_write(tag, subTag, -1, NULL, 0)
784
785#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
786 __android_log_error_write(tag, subTag, uid, data, dataLen)
787
788int __android_log_error_write(int tag, const char* subTag, int32_t uid,
789 const char* data, uint32_t dataLen);
790
791#endif /* __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE */
792
793/* --------------------------------------------------------------------- */
794
795#ifndef __ANDROID_USE_LIBLOG_CLOSE_INTERFACE
796#ifndef __ANDROID_API__
797#define __ANDROID_USE_LIBLOG_CLOSE_INTERFACE 1
798#elif __ANDROID_API__ > 18 /* > JellyBean */
799#define __ANDROID_USE_LIBLOG_CLOSE_INTERFACE 1
800#else
801#define __ANDROID_USE_LIBLOG_CLOSE_INTERFACE 0
802#endif
803#endif
804
805#if __ANDROID_USE_LIBLOG_CLOSE_INTERFACE
806/*
807 * Release any logger resources (a new log write will immediately re-acquire)
808 *
809 * May be used to clean up File descriptors after a Fork, the resources are
810 * all O_CLOEXEC so wil self clean on exec().
811 */
812void __android_log_close();
813#endif
814
815#ifndef __ANDROID_USE_LIBLOG_RATELIMIT_INTERFACE
816#ifndef __ANDROID_API__
817#define __ANDROID_USE_LIBLOG_RATELIMIT_INTERFACE 1
818#elif __ANDROID_API__ > 25 /* > OC */
819#define __ANDROID_USE_LIBLOG_RATELIMIT_INTERFACE 1
820#else
821#define __ANDROID_USE_LIBLOG_RATELIMIT_INTERFACE 0
822#endif
823#endif
824
825#if __ANDROID_USE_LIBLOG_RATELIMIT_INTERFACE
826
827/*
828 * if last is NULL, caller _must_ provide a consistent value for seconds.
829 *
830 * Return -1 if we can not acquire a lock, which below will permit the logging,
831 * error on allowing a log message through.
832 */
833int __android_log_ratelimit(time_t seconds, time_t* last);
834
835/*
836 * Usage:
837 *
838 * // Global default and state
839 * IF_ALOG_RATELIMIT() {
840 * ALOG*(...);
841 * }
842 *
843 * // local state, 10 seconds ratelimit
844 * static time_t local_state;
845 * IF_ALOG_RATELIMIT_LOCAL(10, &local_state) {
846 * ALOG*(...);
847 * }
848 */
849
850#define IF_ALOG_RATELIMIT() \
851 if (__android_log_ratelimit(0, NULL) > 0)
852#define IF_ALOG_RATELIMIT_LOCAL(seconds, state) \
853 if (__android_log_ratelimit(seconds, state) > 0)
854
855#else
856
857/* No ratelimiting as API unsupported */
858#define IF_ALOG_RATELIMIT() if (1)
859#define IF_ALOG_RATELIMIT_LOCAL(...) if (1)
860
861#endif
862
863#if defined(__clang__)
864#pragma clang diagnostic pop
865#endif
866
867#ifdef __cplusplus
868}
869#endif
870
871#endif /* _LIBS_LOG_LOG_H */
diff --git a/include/log/log_event_list.h b/include/log/log_event_list.h
deleted file mode 100644
index 31d49b2f9..000000000
--- a/include/log/log_event_list.h
+++ /dev/null
@@ -1,297 +0,0 @@
1/*
2 * Copyright (C) 2005-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#ifndef _LIBS_LOG_EVENT_LIST_H
18#define _LIBS_LOG_EVENT_LIST_H
19
20#include <stdint.h>
21
22#if (defined(__cplusplus) && defined(_USING_LIBCXX))
23extern "C++" {
24#include <string>
25}
26#endif
27
28#include <log/log.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#ifndef __ANDROID_USE_LIBLOG_EVENT_INTERFACE
35#ifndef __ANDROID_API__
36#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 1
37#elif __ANDROID_API__ > 23 /* > Marshmallow */
38#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 1
39#else
40#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 0
41#endif
42#endif
43
44#if __ANDROID_USE_LIBLOG_EVENT_INTERFACE
45
46/* For manipulating lists of events. */
47
48#define ANDROID_MAX_LIST_NEST_DEPTH 8
49
50/*
51 * The opaque context used to manipulate lists of events.
52 */
53#ifndef __android_log_context_defined
54#define __android_log_context_defined
55typedef struct android_log_context_internal* android_log_context;
56#endif
57
58/*
59 * Elements returned when reading a list of events.
60 */
61#ifndef __android_log_list_element_defined
62#define __android_log_list_element_defined
63typedef struct {
64 AndroidEventLogType type;
65 uint16_t complete;
66 uint16_t len;
67 union {
68 int32_t int32;
69 int64_t int64;
70 char* string;
71 float float32;
72 } data;
73} android_log_list_element;
74#endif
75
76/*
77 * Creates a context associated with an event tag to write elements to
78 * the list of events.
79 */
80android_log_context create_android_logger(uint32_t tag);
81
82/* All lists must be braced by a begin and end call */
83/*
84 * NB: If the first level braces are missing when specifying multiple
85 * elements, we will manufacturer a list to embrace it for your API
86 * convenience. For a single element, it will remain solitary.
87 */
88int android_log_write_list_begin(android_log_context ctx);
89int android_log_write_list_end(android_log_context ctx);
90
91int android_log_write_int32(android_log_context ctx, int32_t value);
92int android_log_write_int64(android_log_context ctx, int64_t value);
93int android_log_write_string8(android_log_context ctx, const char* value);
94int android_log_write_string8_len(android_log_context ctx,
95 const char* value, size_t maxlen);
96int android_log_write_float32(android_log_context ctx, float value);
97
98/* Submit the composed list context to the specified logger id */
99/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
100int android_log_write_list(android_log_context ctx, log_id_t id);
101
102/*
103 * Creates a context from a raw buffer representing a list of events to be read.
104 */
105android_log_context create_android_log_parser(const char* msg, size_t len);
106
107android_log_list_element android_log_read_next(android_log_context ctx);
108android_log_list_element android_log_peek_next(android_log_context ctx);
109
110/* Finished with reader or writer context */
111int android_log_destroy(android_log_context* ctx);
112
113#ifdef __cplusplus
114#ifndef __class_android_log_event_list_defined
115#define __class_android_log_event_list_defined
116/* android_log_list C++ helpers */
117extern "C++" {
118class android_log_event_list {
119friend class __android_log_event_list;
120
121private:
122 android_log_context ctx;
123 int ret;
124
125 android_log_event_list(const android_log_event_list&) = delete;
126 void operator =(const android_log_event_list&) = delete;
127
128public:
129 explicit android_log_event_list(int tag) : ret(0) {
130 ctx = create_android_logger(static_cast<uint32_t>(tag));
131 }
132 explicit android_log_event_list(log_msg& log_msg) : ret(0) {
133 ctx = create_android_log_parser(log_msg.msg() + sizeof(uint32_t),
134 log_msg.entry.len - sizeof(uint32_t));
135 }
136 ~android_log_event_list() { android_log_destroy(&ctx); }
137
138 int close() {
139 int retval = android_log_destroy(&ctx);
140 if (retval < 0) ret = retval;
141 return retval;
142 }
143
144 /* To allow above C calls to use this class as parameter */
145 operator android_log_context() const { return ctx; }
146
147 int status() const { return ret; }
148
149 int begin() {
150 int retval = android_log_write_list_begin(ctx);
151 if (retval < 0) ret = retval;
152 return ret;
153 }
154 int end() {
155 int retval = android_log_write_list_end(ctx);
156 if (retval < 0) ret = retval;
157 return ret;
158 }
159
160 android_log_event_list& operator <<(int32_t value) {
161 int retval = android_log_write_int32(ctx, value);
162 if (retval < 0) ret = retval;
163 return *this;
164 }
165
166 android_log_event_list& operator <<(uint32_t value) {
167 int retval = android_log_write_int32(ctx, static_cast<int32_t>(value));
168 if (retval < 0) ret = retval;
169 return *this;
170 }
171
172 android_log_event_list& operator <<(int64_t value) {
173 int retval = android_log_write_int64(ctx, value);
174 if (retval < 0) ret = retval;
175 return *this;
176 }
177
178 android_log_event_list& operator <<(uint64_t value) {
179 int retval = android_log_write_int64(ctx, static_cast<int64_t>(value));
180 if (retval < 0) ret = retval;
181 return *this;
182 }
183
184 android_log_event_list& operator <<(const char* value) {
185 int retval = android_log_write_string8(ctx, value);
186 if (retval < 0) ret = retval;
187 return *this;
188 }
189
190#if defined(_USING_LIBCXX)
191 android_log_event_list& operator <<(const std::string& value) {
192 int retval = android_log_write_string8_len(ctx,
193 value.data(),
194 value.length());
195 if (retval < 0) ret = retval;
196 return *this;
197 }
198#endif
199
200 android_log_event_list& operator <<(float value) {
201 int retval = android_log_write_float32(ctx, value);
202 if (retval < 0) ret = retval;
203 return *this;
204 }
205
206 int write(log_id_t id = LOG_ID_EVENTS) {
207 int retval = android_log_write_list(ctx, id);
208 if (retval < 0) ret = retval;
209 return ret;
210 }
211
212 int operator <<(log_id_t id) {
213 int retval = android_log_write_list(ctx, id);
214 if (retval < 0) ret = retval;
215 android_log_destroy(&ctx);
216 return ret;
217 }
218
219 /*
220 * Append<Type> methods removes any integer promotion
221 * confusion, and adds access to string with length.
222 * Append methods are also added for all types for
223 * convenience.
224 */
225
226 bool AppendInt(int32_t value) {
227 int retval = android_log_write_int32(ctx, value);
228 if (retval < 0) ret = retval;
229 return ret >= 0;
230 }
231
232 bool AppendLong(int64_t value) {
233 int retval = android_log_write_int64(ctx, value);
234 if (retval < 0) ret = retval;
235 return ret >= 0;
236 }
237
238 bool AppendString(const char* value) {
239 int retval = android_log_write_string8(ctx, value);
240 if (retval < 0) ret = retval;
241 return ret >= 0;
242 }
243
244 bool AppendString(const char* value, size_t len) {
245 int retval = android_log_write_string8_len(ctx, value, len);
246 if (retval < 0) ret = retval;
247 return ret >= 0;
248 }
249
250#if defined(_USING_LIBCXX)
251 bool AppendString(const std::string& value) {
252 int retval = android_log_write_string8_len(ctx,
253 value.data(),
254 value.length());
255 if (retval < 0) ret = retval;
256 return ret;
257 }
258
259 bool Append(const std::string& value) {
260 int retval = android_log_write_string8_len(ctx,
261 value.data(),
262 value.length());
263 if (retval < 0) ret = retval;
264 return ret;
265 }
266#endif
267
268 bool AppendFloat(float value) {
269 int retval = android_log_write_float32(ctx, value);
270 if (retval < 0) ret = retval;
271 return ret >= 0;
272 }
273
274 template <typename Tvalue>
275 bool Append(Tvalue value) { *this << value; return ret >= 0; }
276
277 bool Append(const char* value, size_t len) {
278 int retval = android_log_write_string8_len(ctx, value, len);
279 if (retval < 0) ret = retval;
280 return ret >= 0;
281 }
282
283 android_log_list_element read() { return android_log_read_next(ctx); }
284 android_log_list_element peek() { return android_log_peek_next(ctx); }
285
286};
287}
288#endif
289#endif
290
291#endif /* __ANDROID_USE_LIBLOG_EVENT_INTERFACE */
292
293#ifdef __cplusplus
294}
295#endif
296
297#endif /* _LIBS_LOG_EVENT_LIST_H */
diff --git a/include/log/logd.h b/include/log/logd.h
deleted file mode 100644
index 0e0248e50..000000000
--- a/include/log/logd.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <log/log.h>
diff --git a/include/log/logger.h b/include/log/logger.h
deleted file mode 100644
index 0e0248e50..000000000
--- a/include/log/logger.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <log/log.h>
diff --git a/include/log/logprint.h b/include/log/logprint.h
deleted file mode 100644
index 3509e7f51..000000000
--- a/include/log/logprint.h
+++ /dev/null
@@ -1,163 +0,0 @@
1/*
2 * Copyright (C) 2006 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#ifndef _LOGPRINT_H
18#define _LOGPRINT_H
19
20#include <pthread.h>
21
22#include <android/log.h>
23#include <log/event_tag_map.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29typedef enum {
30 /* Verbs */
31 FORMAT_OFF = 0,
32 FORMAT_BRIEF,
33 FORMAT_PROCESS,
34 FORMAT_TAG,
35 FORMAT_THREAD,
36 FORMAT_RAW,
37 FORMAT_TIME,
38 FORMAT_THREADTIME,
39 FORMAT_LONG,
40 /* Adverbs. The following are modifiers to above format verbs */
41 FORMAT_MODIFIER_COLOR, /* converts priority to color */
42 FORMAT_MODIFIER_TIME_USEC, /* switches from msec to usec time precision */
43 FORMAT_MODIFIER_PRINTABLE, /* converts non-printable to printable escapes */
44 FORMAT_MODIFIER_YEAR, /* Adds year to date */
45 FORMAT_MODIFIER_ZONE, /* Adds zone to date */
46 FORMAT_MODIFIER_EPOCH, /* Print time as seconds since Jan 1 1970 */
47 FORMAT_MODIFIER_MONOTONIC, /* Print cpu time as seconds since start */
48 FORMAT_MODIFIER_UID, /* Adds uid */
49 FORMAT_MODIFIER_DESCRIPT, /* Adds descriptive */
50} AndroidLogPrintFormat;
51
52typedef struct AndroidLogFormat_t AndroidLogFormat;
53
54typedef struct AndroidLogEntry_t {
55 time_t tv_sec;
56 long tv_nsec;
57 android_LogPriority priority;
58 int32_t uid;
59 int32_t pid;
60 int32_t tid;
61 const char* tag;
62 size_t tagLen;
63 size_t messageLen;
64 const char* message;
65} AndroidLogEntry;
66
67AndroidLogFormat* android_log_format_new();
68
69void android_log_format_free(AndroidLogFormat* p_format);
70
71/* currently returns 0 if format is a modifier, 1 if not */
72int android_log_setPrintFormat(AndroidLogFormat* p_format,
73 AndroidLogPrintFormat format);
74
75/**
76 * Returns FORMAT_OFF on invalid string
77 */
78AndroidLogPrintFormat android_log_formatFromString(const char* s);
79
80/**
81 * filterExpression: a single filter expression
82 * eg "AT:d"
83 *
84 * returns 0 on success and -1 on invalid expression
85 *
86 * Assumes single threaded execution
87 *
88 */
89
90int android_log_addFilterRule(AndroidLogFormat* p_format,
91 const char* filterExpression);
92
93/**
94 * filterString: a whitespace-separated set of filter expressions
95 * eg "AT:d *:i"
96 *
97 * returns 0 on success and -1 on invalid expression
98 *
99 * Assumes single threaded execution
100 *
101 */
102
103int android_log_addFilterString(AndroidLogFormat* p_format,
104 const char* filterString);
105
106/**
107 * returns 1 if this log line should be printed based on its priority
108 * and tag, and 0 if it should not
109 */
110int android_log_shouldPrintLine (
111 AndroidLogFormat* p_format, const char* tag, android_LogPriority pri);
112
113/**
114 * Splits a wire-format buffer into an AndroidLogEntry
115 * entry allocated by caller. Pointers will point directly into buf
116 *
117 * Returns 0 on success and -1 on invalid wire format (entry will be
118 * in unspecified state)
119 */
120int android_log_processLogBuffer(struct logger_entry* buf,
121 AndroidLogEntry* entry);
122
123/**
124 * Like android_log_processLogBuffer, but for binary logs.
125 *
126 * If "map" is non-NULL, it will be used to convert the log tag number
127 * into a string.
128 */
129int android_log_processBinaryLogBuffer(struct logger_entry* buf,
130 AndroidLogEntry* entry, const EventTagMap* map, char* messageBuf,
131 int messageBufLen);
132
133/**
134 * Formats a log message into a buffer
135 *
136 * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
137 * If return value != defaultBuffer, caller must call free()
138 * Returns NULL on malloc error
139 */
140
141char* android_log_formatLogLine (
142 AndroidLogFormat* p_format,
143 char* defaultBuffer,
144 size_t defaultBufferSize,
145 const AndroidLogEntry* p_line,
146 size_t* p_outLength);
147
148/**
149 * Either print or do not print log line, based on filter
150 *
151 * Assumes single threaded execution
152 *
153 */
154int android_log_printLogLine(
155 AndroidLogFormat* p_format,
156 int fd,
157 const AndroidLogEntry* entry);
158
159#ifdef __cplusplus
160}
161#endif
162
163#endif /*_LOGPRINT_H*/
diff --git a/include/log/uio.h b/include/log/uio.h
deleted file mode 100644
index 7059da5f7..000000000
--- a/include/log/uio.h
+++ /dev/null
@@ -1,51 +0,0 @@
1/*
2 * Copyright (C) 2007-2014 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#ifndef _LIBS_CUTILS_UIO_H
18#define _LIBS_CUTILS_UIO_H
19
20#if !defined(_WIN32)
21
22#include <sys/uio.h>
23
24#else
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30//
31// Implementation of sys/uio.h for Win32.
32//
33
34#include <stddef.h>
35
36struct iovec {
37 void* iov_base;
38 size_t iov_len;
39};
40
41extern int readv( int fd, struct iovec* vecs, int count );
42extern int writev( int fd, const struct iovec* vecs, int count );
43
44#ifdef __cplusplus
45}
46#endif
47
48#endif
49
50#endif /* _LIBS_UTILS_UIO_H */
51
diff --git a/include/private/android_logger.h b/include/private/android_logger.h
index 9f81b1f06..f187a6d22 100644..120000
--- a/include/private/android_logger.h
+++ b/include/private/android_logger.h
@@ -1,194 +1 @@
1/* ../../liblog/include/private/android_logger.h \ No newline at end of file
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))
29extern "C++" {
30#include <string>
31}
32#endif
33
34#include <log/log_event_list.h>
35#include <log/log.h>
36