diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/corkscrew/map_info.h | 6 | ||||
-rw-r--r-- | include/cutils/aref.h | 62 | ||||
-rw-r--r-- | include/cutils/atomic-arm.h | 82 | ||||
-rw-r--r-- | include/cutils/atomic-mips.h | 66 | ||||
-rw-r--r-- | include/cutils/atomic-x86.h | 63 | ||||
-rw-r--r-- | include/cutils/bitops.h | 69 | ||||
-rw-r--r-- | include/cutils/log.h | 83 | ||||
-rw-r--r-- | include/cutils/trace.h | 203 | ||||
-rw-r--r-- | include/cutils/tztime.h | 39 | ||||
-rw-r--r-- | include/cutils/zygote.h | 1 | ||||
-rw-r--r-- | include/netutils/dhcp.h | 11 | ||||
-rw-r--r-- | include/private/android_filesystem_config.h | 6 | ||||
-rw-r--r-- | include/system/audio.h | 1 | ||||
-rw-r--r-- | include/sysutils/FrameworkListener.h | 3 | ||||
-rw-r--r-- | include/usbhost/usbhost.h | 13 |
15 files changed, 575 insertions, 133 deletions
diff --git a/include/corkscrew/map_info.h b/include/corkscrew/map_info.h index ea1d35f..c9b241d 100644 --- a/include/corkscrew/map_info.h +++ b/include/corkscrew/map_info.h @@ -32,6 +32,7 @@ typedef struct map_info { uintptr_t start; uintptr_t end; bool is_readable; + bool is_writable; bool is_executable; void* data; // arbitrary data associated with the map by the user, initially NULL char name[]; @@ -46,9 +47,10 @@ void free_map_info_list(map_info_t* milist); /* Finds the memory map that contains the specified address. */ const map_info_t* find_map_info(const map_info_t* milist, uintptr_t addr); -/* Returns true if the addr is in an readable map. */ +/* Returns true if the addr is in a readable map. */ bool is_readable_map(const map_info_t* milist, uintptr_t addr); - +/* Returns true if the addr is in a writable map. */ +bool is_writable_map(const map_info_t* milist, uintptr_t addr); /* Returns true if the addr is in an executable map. */ bool is_executable_map(const map_info_t* milist, uintptr_t addr); diff --git a/include/cutils/aref.h b/include/cutils/aref.h new file mode 100644 index 0000000..460ac02 --- /dev/null +++ b/include/cutils/aref.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _CUTILS_AREF_H_ +#define _CUTILS_AREF_H_ + +#include <stddef.h> +#include <sys/cdefs.h> + +#ifdef ANDROID_SMP +#include <cutils/atomic-inline.h> +#else +#include <cutils/atomic.h> +#endif + +__BEGIN_DECLS + +#define AREF_TO_ITEM(aref, container, member) \ + (container *) (((char*) (aref)) - offsetof(container, member)) + +struct aref +{ + volatile int32_t count; +}; + +static inline void aref_init(struct aref *r) +{ + r->count = 1; +} + +static inline int32_t aref_count(struct aref *r) +{ + return r->count; +} + +static inline void aref_get(struct aref *r) +{ + android_atomic_inc(&r->count); +} + +static inline void aref_put(struct aref *r, void (*release)(struct aref *)) +{ + if (android_atomic_dec(&r->count) == 1) + release(r); +} + +__END_DECLS + +#endif // _CUTILS_AREF_H_ diff --git a/include/cutils/atomic-arm.h b/include/cutils/atomic-arm.h index 16fe512..795afd3 100644 --- a/include/cutils/atomic-arm.h +++ b/include/cutils/atomic-arm.h @@ -20,72 +20,78 @@ #include <stdint.h> #include <machine/cpu-features.h> -extern inline void android_compiler_barrier(void) +#ifndef ANDROID_ATOMIC_INLINE +#define ANDROID_ATOMIC_INLINE inline __attribute__((always_inline)) +#endif + +extern ANDROID_ATOMIC_INLINE void android_compiler_barrier(void) { __asm__ __volatile__ ("" : : : "memory"); } #if ANDROID_SMP == 0 -extern inline void android_memory_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_barrier(void) { android_compiler_barrier(); } -extern inline void android_memory_store_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_store_barrier(void) { android_compiler_barrier(); } #elif defined(__ARM_HAVE_DMB) -extern inline void android_memory_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_barrier(void) { __asm__ __volatile__ ("dmb" : : : "memory"); } -extern inline void android_memory_store_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_store_barrier(void) { __asm__ __volatile__ ("dmb st" : : : "memory"); } #elif defined(__ARM_HAVE_LDREX_STREX) -extern inline void android_memory_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_barrier(void) { __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r" (0) : "memory"); } -extern inline void android_memory_store_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_store_barrier(void) { android_memory_barrier(); } #else -extern inline void android_memory_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_barrier(void) { typedef void (kuser_memory_barrier)(void); (*(kuser_memory_barrier *)0xffff0fa0)(); } -extern inline void android_memory_store_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_store_barrier(void) { android_memory_barrier(); } #endif -extern inline int32_t android_atomic_acquire_load(volatile const int32_t *ptr) +extern ANDROID_ATOMIC_INLINE +int32_t android_atomic_acquire_load(volatile const int32_t *ptr) { int32_t value = *ptr; android_memory_barrier(); return value; } -extern inline int32_t android_atomic_release_load(volatile const int32_t *ptr) +extern ANDROID_ATOMIC_INLINE +int32_t android_atomic_release_load(volatile const int32_t *ptr) { android_memory_barrier(); return *ptr; } -extern inline void android_atomic_acquire_store(int32_t value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE void +android_atomic_acquire_store(int32_t value, volatile int32_t *ptr) { *ptr = value; android_memory_barrier(); } -extern inline void android_atomic_release_store(int32_t value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE void +android_atomic_release_store(int32_t value, volatile int32_t *ptr) { android_memory_barrier(); *ptr = value; @@ -95,8 +101,8 @@ extern inline void android_atomic_release_store(int32_t value, extern int android_atomic_cas(int32_t old_value, int32_t new_value, volatile int32_t *ptr); #elif defined(__ARM_HAVE_LDREX_STREX) -extern inline int android_atomic_cas(int32_t old_value, int32_t new_value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int +android_atomic_cas(int32_t old_value, int32_t new_value, volatile int32_t *ptr) { int32_t prev, status; do { @@ -111,8 +117,8 @@ extern inline int android_atomic_cas(int32_t old_value, int32_t new_value, return prev != old_value; } #else -extern inline int android_atomic_cas(int32_t old_value, int32_t new_value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int +android_atomic_cas(int32_t old_value, int32_t new_value, volatile int32_t *ptr) { typedef int (kuser_cmpxchg)(int32_t, int32_t, volatile int32_t *); int32_t prev, status; @@ -127,18 +133,20 @@ extern inline int android_atomic_cas(int32_t old_value, int32_t new_value, } #endif -extern inline int android_atomic_acquire_cas(int32_t old_value, - int32_t new_value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int +android_atomic_acquire_cas(int32_t old_value, + int32_t new_value, + volatile int32_t *ptr) { int status = android_atomic_cas(old_value, new_value, ptr); android_memory_barrier(); return status; } -extern inline int android_atomic_release_cas(int32_t old_value, - int32_t new_value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int +android_atomic_release_cas(int32_t old_value, + int32_t new_value, + volatile int32_t *ptr) { android_memory_barrier(); return android_atomic_cas(old_value, new_value, ptr); @@ -149,8 +157,8 @@ extern inline int android_atomic_release_cas(int32_t old_value, extern int32_t android_atomic_add(int32_t increment, volatile int32_t *ptr); #elif defined(__ARM_HAVE_LDREX_STREX) -extern inline int32_t android_atomic_add(int32_t increment, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_add(int32_t increment, volatile int32_t *ptr) { int32_t prev, tmp, status; android_memory_barrier(); @@ -166,8 +174,8 @@ extern inline int32_t android_atomic_add(int32_t increment, return prev; } #else -extern inline int32_t android_atomic_add(int32_t increment, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_add(int32_t increment, volatile int32_t *ptr) { int32_t prev, status; android_memory_barrier(); @@ -179,12 +187,12 @@ extern inline int32_t android_atomic_add(int32_t increment, } #endif -extern inline int32_t android_atomic_inc(volatile int32_t *addr) +extern ANDROID_ATOMIC_INLINE int32_t android_atomic_inc(volatile int32_t *addr) { return android_atomic_add(1, addr); } -extern inline int32_t android_atomic_dec(volatile int32_t *addr) +extern ANDROID_ATOMIC_INLINE int32_t android_atomic_dec(volatile int32_t *addr) { return android_atomic_add(-1, addr); } @@ -192,7 +200,8 @@ extern inline int32_t android_atomic_dec(volatile int32_t *addr) #if defined(__thumb__) extern int32_t android_atomic_and(int32_t value, volatile int32_t *ptr); #elif defined(__ARM_HAVE_LDREX_STREX) -extern inline int32_t android_atomic_and(int32_t value, volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_and(int32_t value, volatile int32_t *ptr) { int32_t prev, tmp, status; android_memory_barrier(); @@ -208,7 +217,8 @@ extern inline int32_t android_atomic_and(int32_t value, volatile int32_t *ptr) return prev; } #else -extern inline int32_t android_atomic_and(int32_t value, volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_and(int32_t value, volatile int32_t *ptr) { int32_t prev, status; android_memory_barrier(); @@ -223,7 +233,8 @@ extern inline int32_t android_atomic_and(int32_t value, volatile int32_t *ptr) #if defined(__thumb__) extern int32_t android_atomic_or(int32_t value, volatile int32_t *ptr); #elif defined(__ARM_HAVE_LDREX_STREX) -extern inline int32_t android_atomic_or(int32_t value, volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_or(int32_t value, volatile int32_t *ptr) { int32_t prev, tmp, status; android_memory_barrier(); @@ -239,7 +250,8 @@ extern inline int32_t android_atomic_or(int32_t value, volatile int32_t *ptr) return prev; } #else -extern inline int32_t android_atomic_or(int32_t value, volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_or(int32_t value, volatile int32_t *ptr) { int32_t prev, status; android_memory_barrier(); diff --git a/include/cutils/atomic-mips.h b/include/cutils/atomic-mips.h index 49144a3..f9d3e25 100644 --- a/include/cutils/atomic-mips.h +++ b/include/cutils/atomic-mips.h @@ -19,60 +19,66 @@ #include <stdint.h> -extern inline void android_compiler_barrier(void) +#ifndef ANDROID_ATOMIC_INLINE +#define ANDROID_ATOMIC_INLINE inline __attribute__((always_inline)) +#endif + +extern ANDROID_ATOMIC_INLINE void android_compiler_barrier(void) { __asm__ __volatile__ ("" : : : "memory"); } #if ANDROID_SMP == 0 -extern inline void android_memory_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_barrier(void) { android_compiler_barrier(); } -extern inline void android_memory_store_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_store_barrier(void) { android_compiler_barrier(); } #else -extern inline void android_memory_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_barrier(void) { __asm__ __volatile__ ("sync" : : : "memory"); } -extern inline void android_memory_store_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_store_barrier(void) { __asm__ __volatile__ ("sync" : : : "memory"); } #endif -extern inline int32_t android_atomic_acquire_load(volatile const int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_acquire_load(volatile const int32_t *ptr) { int32_t value = *ptr; android_memory_barrier(); return value; } -extern inline int32_t android_atomic_release_load(volatile const int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_release_load(volatile const int32_t *ptr) { android_memory_barrier(); return *ptr; } -extern inline void android_atomic_acquire_store(int32_t value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE void +android_atomic_acquire_store(int32_t value, volatile int32_t *ptr) { *ptr = value; android_memory_barrier(); } -extern inline void android_atomic_release_store(int32_t value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE void +android_atomic_release_store(int32_t value, volatile int32_t *ptr) { android_memory_barrier(); *ptr = value; } -extern inline int android_atomic_cas(int32_t old_value, int32_t new_value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int +android_atomic_cas(int32_t old_value, int32_t new_value, volatile int32_t *ptr) { int32_t prev, status; do { @@ -90,26 +96,28 @@ extern inline int android_atomic_cas(int32_t old_value, int32_t new_value, return prev != old_value; } -extern inline int android_atomic_acquire_cas(int32_t old_value, - int32_t new_value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int +android_atomic_acquire_cas(int32_t old_value, + int32_t new_value, + volatile int32_t *ptr) { int status = android_atomic_cas(old_value, new_value, ptr); android_memory_barrier(); return status; } -extern inline int android_atomic_release_cas(int32_t old_value, - int32_t new_value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int +android_atomic_release_cas(int32_t old_value, + int32_t new_value, + volatile int32_t *ptr) { android_memory_barrier(); return android_atomic_cas(old_value, new_value, ptr); } -extern inline int32_t android_atomic_swap(int32_t new_value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_swap(int32_t new_value, volatile int32_t *ptr) { int32_t prev, status; do { @@ -125,8 +133,8 @@ extern inline int32_t android_atomic_swap(int32_t new_value, return prev; } -extern inline int32_t android_atomic_add(int32_t increment, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_add(int32_t increment, volatile int32_t *ptr) { int32_t prev, status; android_memory_barrier(); @@ -142,17 +150,20 @@ extern inline int32_t android_atomic_add(int32_t increment, return prev; } -extern inline int32_t android_atomic_inc(volatile int32_t *addr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_inc(volatile int32_t *addr) { return android_atomic_add(1, addr); } -extern inline int32_t android_atomic_dec(volatile int32_t *addr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_dec(volatile int32_t *addr) { return android_atomic_add(-1, addr); } -extern inline int32_t android_atomic_and(int32_t value, volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_and(int32_t value, volatile int32_t *ptr) { int32_t prev, status; android_memory_barrier(); @@ -168,7 +179,8 @@ extern inline int32_t android_atomic_and(int32_t value, volatile int32_t *ptr) return prev; } -extern inline int32_t android_atomic_or(int32_t value, volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_or(int32_t value, volatile int32_t *ptr) { int32_t prev, status; android_memory_barrier(); diff --git a/include/cutils/atomic-x86.h b/include/cutils/atomic-x86.h index 438012e..9480f57 100644 --- a/include/cutils/atomic-x86.h +++ b/include/cutils/atomic-x86.h @@ -19,60 +19,66 @@ #include <stdint.h> -extern inline void android_compiler_barrier(void) +#ifndef ANDROID_ATOMIC_INLINE +#define ANDROID_ATOMIC_INLINE inline __attribute__((always_inline)) +#endif + +extern ANDROID_ATOMIC_INLINE void android_compiler_barrier(void) { __asm__ __volatile__ ("" : : : "memory"); } #if ANDROID_SMP == 0 -extern inline void android_memory_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_barrier(void) { android_compiler_barrier(); } -extern inline void android_memory_store_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_store_barrier(void) { android_compiler_barrier(); } #else -extern inline void android_memory_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_barrier(void) { __asm__ __volatile__ ("mfence" : : : "memory"); } -extern inline void android_memory_store_barrier(void) +extern ANDROID_ATOMIC_INLINE void android_memory_store_barrier(void) { android_compiler_barrier(); } #endif -extern inline int32_t android_atomic_acquire_load(volatile const int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_acquire_load(volatile const int32_t *ptr) { int32_t value = *ptr; android_compiler_barrier(); return value; } -extern inline int32_t android_atomic_release_load(volatile const int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_release_load(volatile const int32_t *ptr) { android_memory_barrier(); return *ptr; } -extern inline void android_atomic_acquire_store(int32_t value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE void +android_atomic_acquire_store(int32_t value, volatile int32_t *ptr) { *ptr = value; android_memory_barrier(); } -extern inline void android_atomic_release_store(int32_t value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE void +android_atomic_release_store(int32_t value, volatile int32_t *ptr) { android_compiler_barrier(); *ptr = value; } -extern inline int android_atomic_cas(int32_t old_value, int32_t new_value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int +android_atomic_cas(int32_t old_value, int32_t new_value, volatile int32_t *ptr) { int32_t prev; __asm__ __volatile__ ("lock; cmpxchgl %1, %2" @@ -82,24 +88,26 @@ extern inline int android_atomic_cas(int32_t old_value, int32_t new_value, return prev != old_value; } -extern inline int android_atomic_acquire_cas(int32_t old_value, - int32_t new_value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int +android_atomic_acquire_cas(int32_t old_value, + int32_t new_value, + volatile int32_t *ptr) { /* Loads are not reordered with other loads. */ return android_atomic_cas(old_value, new_value, ptr); } -extern inline int android_atomic_release_cas(int32_t old_value, - int32_t new_value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int +android_atomic_release_cas(int32_t old_value, + int32_t new_value, + volatile int32_t *ptr) { /* Stores are not reordered with other stores. */ return android_atomic_cas(old_value, new_value, ptr); } -extern inline int32_t android_atomic_add(int32_t increment, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_add(int32_t increment, volatile int32_t *ptr) { __asm__ __volatile__ ("lock; xaddl %0, %1" : "+r" (increment), "+m" (*ptr) @@ -108,18 +116,20 @@ extern inline int32_t android_atomic_add(int32_t increment, return increment; } -extern inline int32_t android_atomic_inc(volatile int32_t *addr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_inc(volatile int32_t *addr) { return android_atomic_add(1, addr); } -extern inline int32_t android_atomic_dec(volatile int32_t *addr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_dec(volatile int32_t *addr) { return android_atomic_add(-1, addr); } -extern inline int32_t android_atomic_and(int32_t value, - volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_and(int32_t value, volatile int32_t *ptr) { int32_t prev, status; do { @@ -129,7 +139,8 @@ extern inline int32_t android_atomic_and(int32_t value, return prev; } -extern inline int32_t android_atomic_or(int32_t value, volatile int32_t *ptr) +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_or(int32_t value, volatile int32_t *ptr) { int32_t prev, status; do { diff --git a/include/cutils/bitops.h b/include/cutils/bitops.h index 1b3b762..eb44236 100644 --- a/include/cutils/bitops.h +++ b/include/cutils/bitops.h @@ -17,10 +17,79 @@ #ifndef __CUTILS_BITOPS_H #define __CUTILS_BITOPS_H +#include <stdbool.h> +#include <string.h> +#include <strings.h> #include <sys/cdefs.h> __BEGIN_DECLS +/* + * Bitmask Operations + * + * Note this doesn't provide any locking/exclusion, and isn't atomic. + * Additionally no bounds checking is done on the bitmask array. + * + * Example: + * + * int num_resources; + * unsigned int resource_bits[BITS_TO_WORDS(num_resources)]; + * bitmask_init(resource_bits, num_resources); + * ... + * int bit = bitmask_ffz(resource_bits, num_resources); + * bitmask_set(resource_bits, bit); + * ... + * if (bitmask_test(resource_bits, bit)) { ... } + * ... + * bitmask_clear(resource_bits, bit); + * + */ + +#define BITS_PER_WORD (sizeof(unsigned int) * 8) +#define BITS_TO_WORDS(x) (((x) + BITS_PER_WORD - 1) / BITS_PER_WORD) +#define BIT_IN_WORD(x) ((x) % BITS_PER_WORD) +#define BIT_WORD(x) ((x) / BITS_PER_WORD) +#define BIT_MASK(x) (1 << BIT_IN_WORD(x)) + +static inline void bitmask_init(unsigned int *bitmask, int num_bits) +{ + memset(bitmask, 0, BITS_TO_WORDS(num_bits)*sizeof(unsigned int)); +} + +static inline int bitmask_ffz(unsigned int *bitmask, int num_bits) +{ + int bit, result; + unsigned int i; + + for (i = 0; i < BITS_TO_WORDS(num_bits); i++) { + bit = ffs(~bitmask[i]); + if (bit) { + // ffs is 1-indexed, return 0-indexed result + bit--; + result = BITS_PER_WORD * i + bit; + if (result >= num_bits) + return -1; + return result; + } + } + return -1; +} + +static inline void bitmask_set(unsigned int *bitmask, int bit) +{ + bitmask[BIT_WORD(bit)] |= BIT_MASK(bit); +} + +static inline void bitmask_clear(unsigned int *bitmask, int bit) +{ + bitmask[BIT_WORD(bit)] &= ~BIT_MASK(bit); +} + +static inline bool bitmask_test(unsigned int *bitmask, int bit) +{ + return bitmask[BIT_WORD(bit)] & BIT_MASK(bit); +} + static inline int popcount(unsigned int x) { return __builtin_popcount(x); diff --git a/include/cutils/log.h b/include/cutils/log.h index 878952e..8b045c7 100644 --- a/include/cutils/log.h +++ b/include/cutils/log.h @@ -279,7 +279,88 @@ extern "C" { : (void)0 ) #endif - +// --------------------------------------------------------------------- + +/* + * Simplified macro to send a verbose radio log message using the current LOG_TAG. + */ +#ifndef RLOGV +#if LOG_NDEBUG +#define RLOGV(...) ((void)0) +#else +#define RLOGV(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) +#endif +#endif + +#define CONDITION(cond) (__builtin_expect((cond)!=0, 0)) + +#ifndef RLOGV_IF +#if LOG_NDEBUG +#define RLOGV_IF(cond, ...) ((void)0) +#else +#define RLOGV_IF(cond, ...) \ + ( (CONDITION(cond)) \ + ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ + : (void)0 ) +#endif +#endif + +/* + * Simplified macro to send a debug radio log message using the current LOG_TAG. + */ +#ifndef RLOGD +#define RLOGD(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) +#endif + +#ifndef RLOGD_IF +#define RLOGD_IF(cond, ...) \ + ( (CONDITION(cond)) \ + ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ + : (void)0 ) +#endif + +/* + * Simplified macro to send an info radio log message using the current LOG_TAG. + */ +#ifndef RLOGI +#define RLOGI(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) +#endif + +#ifndef RLOGI_IF +#define RLOGI_IF(cond, ...) \ + ( (CONDITION(cond)) \ + ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \ + : (void)0 ) +#endif + +/* + * Simplified macro to send a warning radio log message using the current LOG_TAG. + */ +#ifndef RLOGW +#define RLOGW(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) +#endif + +#ifndef RLOGW_IF +#define RLOGW_IF(cond, ...) \ + ( (CONDITION(cond)) \ + ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \ + : (void)0 ) +#endif + +/* + * Simplified macro to send an error radio log message using the current LOG_TAG. + */ +#ifndef RLOGE +#define RLOGE(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) +#endif + +#ifndef RLOGE_IF +#define RLOGE_IF(cond, ...) \ + ( (CONDITION(cond)) \ + ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ + : (void)0 ) +#endif + // --------------------------------------------------------------------- diff --git a/include/cutils/trace.h b/include/cutils/trace.h new file mode 100644 index 0000000..1db3903 --- /dev/null +++ b/include/cutils/trace.h @@ -0,0 +1,203 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _LIBS_CUTILS_TRACE_H +#define _LIBS_CUTILS_TRACE_H + +#include <sys/cdefs.h> +#include <sys/types.h> +#include <stdint.h> +#include <unistd.h> +#include <cutils/compiler.h> + +#ifdef ANDROID_SMP +#include <cutils/atomic-inline.h> +#else +#include <cutils/atomic.h> +#endif + +__BEGIN_DECLS + +/** + * The ATRACE_TAG macro can be defined before including this header to trace + * using one of the tags defined below. It must be defined to one of the + * following ATRACE_TAG_* macros. The trace tag is used to filter tracing in + * userland to avoid some of the runtime cost of tracing when it is not desired. + * + * Defining ATRACE_TAG to be ATRACE_TAG_ALWAYS will result in the tracing always + * being enabled - this should ONLY be done for debug code, as userland tracing + * has a performance cost even when the trace is not being recorded. Defining + * ATRACE_TAG to be ATRACE_TAG_NEVER or leaving ATRACE_TAG undefined will result + * in the tracing always being disabled. + * + * ATRACE_TAG_HAL should be bitwise ORed with the relevant tags for tracing + * within a hardware module. For example a camera hardware module would set: + * #define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL) + * + * Keep these in sync with frameworks/base/core/java/android/os/Trace.java. + */ +#define ATRACE_TAG_NEVER 0 // This tag is never enabled. +#define ATRACE_TAG_ALWAYS (1<<0) // This tag is always enabled. +#define ATRACE_TAG_GRAPHICS (1<<1) +#define ATRACE_TAG_INPUT (1<<2) +#define ATRACE_TAG_VIEW (1<<3) +#define ATRACE_TAG_WEBVIEW (1<<4) +#define ATRACE_TAG_WINDOW_MANAGER (1<<5) +#define ATRACE_TAG_ACTIVITY_MANAGER (1<<6) +#define ATRACE_TAG_SYNC_MANAGER (1<<7) +#define ATRACE_TAG_AUDIO (1<<8) +#define ATRACE_TAG_VIDEO (1<<9) +#define ATRACE_TAG_CAMERA (1<<10) +#define ATRACE_TAG_HAL (1<<11) +#define ATRACE_TAG_LAST ATRACE_TAG_HAL + +// Reserved for initialization. +#define ATRACE_TAG_NOT_READY (1LL<<63) + +#define ATRACE_TAG_VALID_MASK ((ATRACE_TAG_LAST - 1) | ATRACE_TAG_LAST) + +#ifndef ATRACE_TAG +#define ATRACE_TAG ATRACE_TAG_NEVER +#elif ATRACE_TAG > ATRACE_TAG_VALID_MASK +#error ATRACE_TAG must be defined to be one of the tags defined in cutils/trace.h +#endif + +/** + * Maximum size of a message that can be logged to the trace buffer. + * Note this message includes a tag, the pid, and the string given as the name. + * Names should be kept short to get the most use of the trace buffer. + */ +#define ATRACE_MESSAGE_LENGTH 1024 + +/** + * Opens the trace file for writing and reads the property for initial tags. + * The atrace.tags.enableflags property sets the tags to trace. + * This function should not be explicitly called, the first call to any normal + * trace function will cause it to be run safely. + */ +void atrace_setup(); + +/** + * If tracing is ready, set atrace_enabled_tags to the system property + * debug.atrace.tags.enableflags. Can be used as a sysprop change callback. + */ +void atrace_update_tags(); + +/** + * Flag indicating whether setup has been completed, initialized to 0. + * Nonzero indicates setup has completed. + * Note: This does NOT indicate whether or not setup was successful. + */ +extern int32_t atrace_is_ready; + +/** + * Set of ATRACE_TAG flags to trace for, initialized to ATRACE_TAG_NOT_READY. + * A value of zero indicates setup has failed. + * Any other nonzero value indicates setup has succeeded, and tracing is on. + */ +extern uint64_t atrace_enabled_tags; + +/** + * Handle to the kernel's trace buffer, initialized to -1. + * Any other value indicates setup has succeeded, and is a valid fd for tracing. + */ +extern int atrace_marker_fd; + +/** + * atrace_init readies the process for tracing by opening the trace_marker file. + * Calling any trace function causes this to be run, so calling it is optional. + * This can be explicitly run to avoid setup delay on first trace function. + */ +#define ATRACE_INIT() atrace_init() +static inline void atrace_init() +{ + if (CC_UNLIKELY(!android_atomic_acquire_load(&atrace_is_ready))) { + atrace_setup(); + } +} + +/** + * Get the mask of all tags currently enabled. + * It can be used as a guard condition around more expensive trace calculations. + * Every trace function calls this, which ensures atrace_init is run. + */ +#define ATRACE_GET_ENABLED_TAGS() atrace_get_enabled_tags() +static inline uint64_t atrace_get_enabled_tags() +{ + atrace_init(); + return atrace_enabled_tags; +} + +/** + * Test if a given tag is currently enabled. + * Returns nonzero if the tag is enabled, otherwise zero. + * It can be used as a guard condition around more expensive trace calculations. + */ +#define ATRACE_ENABLED() atrace_is_tag_enabled(ATRACE_TAG) +static inline uint64_t atrace_is_tag_enabled(uint64_t tag) +{ + return atrace_get_enabled_tags() & tag; +} + +/** + * Trace the beginning of a context. name is used to identify the context. + * This is often used to time function execution. + */ +#define ATRACE_BEGIN(name) atrace_begin(ATRACE_TAG, name) +static inline void atrace_begin(uint64_t tag, const char* name) +{ + if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) { + char buf[ATRACE_MESSAGE_LENGTH]; + size_t len; + + len = snprintf(buf, ATRACE_MESSAGE_LENGTH, "B|%d|%s", getpid(), name); + write(atrace_marker_fd, buf, len); + } +} + +/** + * Trace the end of a context. + * This should match up (and occur after) a corresponding ATRACE_BEGIN. + */ +#define ATRACE_END() atrace_end(ATRACE_TAG) +static inline void atrace_end(uint64_t tag) +{ + if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) { + char c = 'E'; + write(atrace_marker_fd, &c, 1); + } +} + +/** + * Traces an integer counter value. name is used to identify the counter. + * This can be used to track how a value changes over time. + */ +#define ATRACE_INT(name, value) atrace_int(ATRACE_TAG, name, value) +static inline void atrace_int(uint64_t tag, const char* name, int32_t value) +{ + if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) { + char buf[ATRACE_MESSAGE_LENGTH]; + size_t len; + + len = snprintf(buf, ATRACE_MESSAGE_LENGTH, "C|%d|%s|%d", + getpid(), name, value); + write(atrace_marker_fd, buf, len); + } +} + +__END_DECLS + +#endif // _LIBS_CUTILS_TRACE_H diff --git a/include/cutils/tztime.h b/include/cutils/tztime.h index 36ac25d..dbdbd60 100644 --- a/include/cutils/tztime.h +++ b/include/cutils/tztime.h @@ -17,45 +17,8 @@ #ifndef _CUTILS_TZTIME_H #define _CUTILS_TZTIME_H -#include <time.h> - -#ifdef __cplusplus -extern "C" { -#endif - -time_t mktime_tz(struct tm * const tmp, char const * tz); -void localtime_tz(const time_t * const timep, struct tm * tmp, const char* tz); - -#ifdef HAVE_ANDROID_OS - -/* the following is defined in the Bionic C library on Android, but the - * declarations are only available through a platform-private header - */ +// TODO: fix both callers to just include <bionic_time.h> themselves. #include <bionic_time.h> -#else /* !HAVE_ANDROID_OS */ - -struct strftime_locale { - const char *mon[12]; /* short names */ - const char *month[12]; /* long names */ - const char *standalone_month[12]; /* long standalone names */ - const char *wday[7]; /* short names */ - const char *weekday[7]; /* long names */ - const char *X_fmt; - const char *x_fmt; - const char *c_fmt; - const char *am; - const char *pm; - const char *date_fmt; -}; - -size_t strftime_tz(char *s, size_t max, const char *format, const struct tm *tm, const struct strftime_locale *locale); - -#endif /* !HAVE_ANDROID_OS */ - -#ifdef __cplusplus -} -#endif - #endif /* __CUTILS_TZTIME_H */ diff --git a/include/cutils/zygote.h b/include/cutils/zygote.h index 22721a6..a7480d3 100644 --- a/include/cutils/zygote.h +++ b/include/cutils/zygote.h @@ -23,7 +23,6 @@ extern "C" { int zygote_run_oneshot(int sendStdio, int argc, const char **argv); int zygote_run(int argc, const char **argv); -int zygote_run_wait(int argc, const char **argv, void (*post_run_func)(int)); #ifdef __cplusplus } diff --git a/include/netutils/dhcp.h b/include/netutils/dhcp.h index d25e58f..bd2c957 100644 --- a/include/netutils/dhcp.h +++ b/include/netutils/dhcp.h @@ -27,11 +27,18 @@ extern int dhcp_do_request(const char *ifname, char *ipaddr, char *gateway, uint32_t *prefixLength, - char *dns1, - char *dns2, + char *dns[], char *server, uint32_t *lease, char *vendorInfo); +extern int dhcp_do_request_renew(const char *ifname, + char *ipaddr, + char *gateway, + uint32_t *prefixLength, + char *dns[], + char *server, + uint32_t *lease, + char *vendorInfo); extern int dhcp_stop(const char *ifname); extern int dhcp_release_lease(const char *ifname); extern char *dhcp_get_errmsg(); diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h index 1159a15..746bec3 100644 --- a/include/private/android_filesystem_config.h +++ b/include/private/android_filesystem_config.h @@ -62,6 +62,7 @@ #define AID_DRMRPC 1026 /* group for drm rpc */ #define AID_NFC 1027 /* nfc subsystem */ #define AID_SDCARD_R 1028 /* external storage read access */ +#define AID_CLAT 1029 /* clat part of nat464 */ #define AID_LOOP_RADIO 1030 /* loop radio devices */ #define AID_SHELL 2000 /* adb and debug shell user */ @@ -141,6 +142,7 @@ static const struct android_id_info android_ids[] = { { "loop_radio", AID_LOOP_RADIO, }, { "misc", AID_MISC, }, { "nobody", AID_NOBODY, }, + { "clat", AID_CLAT, }, }; #define android_id_count \ @@ -236,6 +238,10 @@ static inline void fs_config(const char *path, int dir, struct fs_path_config *pc; int plen; + if (path[0] == '/') { + path++; + } + pc = dir ? android_dirs : android_files; plen = strlen(path); for(; pc->prefix; pc++){ diff --git a/include/system/audio.h b/include/system/audio.h index d246070..da235dd 100644 --- a/include/system/audio.h +++ b/include/system/audio.h @@ -239,6 +239,7 @@ enum { AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT, AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT), + AUDIO_CHANNEL_IN_FRONT_BACK = (AUDIO_CHANNEL_IN_FRONT | AUDIO_CHANNEL_IN_BACK), AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT | AUDIO_CHANNEL_IN_FRONT | diff --git a/include/sysutils/FrameworkListener.h b/include/sysutils/FrameworkListener.h index 756bacf..f1a4b43 100644 --- a/include/sysutils/FrameworkListener.h +++ b/include/sysutils/FrameworkListener.h @@ -23,10 +23,11 @@ class SocketClient; class FrameworkListener : public SocketListener { public: - static const int CMD_ARGS_MAX = 16; + static const int CMD_ARGS_MAX = 26; /* 1 out of errorRate will be dropped */ int errorRate; + private: int mCommandCount; bool mWithSeq; diff --git a/include/usbhost/usbhost.h b/include/usbhost/usbhost.h index 9a6b59c..1d67c12 100644 --- a/include/usbhost/usbhost.h +++ b/include/usbhost/usbhost.h @@ -72,6 +72,19 @@ struct usb_host_context *usb_host_init(void); /* Call this to cleanup the USB host library. */ void usb_host_cleanup(struct usb_host_context *context); +/* Call this to get the inotify file descriptor. */ +int usb_host_get_fd(struct usb_host_context *context); + +/* Call this to initialize the usb host context. */ +int usb_host_load(struct usb_host_context *context, + usb_device_added_cb added_cb, + usb_device_removed_cb removed_cb, + usb_discovery_done_cb discovery_done_cb, + void *client_data); + +/* Call this to read and handle occuring usb event. */ +int usb_host_read_event(struct usb_host_context *context); + /* Call this to monitor the USB bus for new and removed devices. * This is intended to be called from a dedicated thread, * as it will not return until one of the callbacks returns true. |