diff options
Diffstat (limited to 'include/cutils')
-rw-r--r-- | include/cutils/atomic-inline.h | 6 | ||||
-rw-r--r-- | include/cutils/atomic-mips.h | 17 | ||||
-rw-r--r-- | include/cutils/atomic-mips64.h | 234 | ||||
-rw-r--r-- | include/cutils/atomic-x86_64.h | 226 | ||||
-rw-r--r-- | include/cutils/bitops.h | 4 | ||||
-rw-r--r-- | include/cutils/debugger.h | 5 | ||||
-rw-r--r-- | include/cutils/fs.h | 1 | ||||
-rw-r--r-- | include/cutils/klog.h | 19 | ||||
-rw-r--r-- | include/cutils/list.h | 14 | ||||
-rw-r--r-- | include/cutils/misc.h | 7 | ||||
-rw-r--r-- | include/cutils/properties.h | 59 | ||||
-rw-r--r-- | include/cutils/sockets.h | 2 | ||||
-rw-r--r-- | include/cutils/trace.h | 23 |
13 files changed, 572 insertions, 45 deletions
diff --git a/include/cutils/atomic-inline.h b/include/cutils/atomic-inline.h index ae79e00..007a905 100644 --- a/include/cutils/atomic-inline.h +++ b/include/cutils/atomic-inline.h @@ -47,8 +47,12 @@ extern "C" { #include <cutils/atomic-arm64.h> #elif defined(__arm__) #include <cutils/atomic-arm.h> -#elif defined(__i386__) || defined(__x86_64__) +#elif defined(__i386__) #include <cutils/atomic-x86.h> +#elif defined(__x86_64__) +#include <cutils/atomic-x86_64.h> +#elif defined(__mips64) +#include <cutils/atomic-mips64.h> #elif defined(__mips__) #include <cutils/atomic-mips.h> #else diff --git a/include/cutils/atomic-mips.h b/include/cutils/atomic-mips.h index f9d3e25..1ed833d 100644 --- a/include/cutils/atomic-mips.h +++ b/include/cutils/atomic-mips.h @@ -117,23 +117,6 @@ android_atomic_release_cas(int32_t old_value, extern ANDROID_ATOMIC_INLINE int32_t -android_atomic_swap(int32_t new_value, volatile int32_t *ptr) -{ - int32_t prev, status; - do { - __asm__ __volatile__ ( - " move %[status], %[new_value]\n" - " ll %[prev], (%[ptr])\n" - " sc %[status], (%[ptr])\n" - : [prev] "=&r" (prev), [status] "=&r" (status) - : [ptr] "r" (ptr), [new_value] "r" (new_value) - ); - } while (__builtin_expect(status == 0, 0)); - android_memory_barrier(); - return prev; -} - -extern ANDROID_ATOMIC_INLINE int32_t android_atomic_add(int32_t increment, volatile int32_t *ptr) { int32_t prev, status; diff --git a/include/cutils/atomic-mips64.h b/include/cutils/atomic-mips64.h new file mode 100644 index 0000000..99bbe3a --- /dev/null +++ b/include/cutils/atomic-mips64.h @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2010 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 ANDROID_CUTILS_ATOMIC_MIPS64_H +#define ANDROID_CUTILS_ATOMIC_MIPS64_H + +#include <stdint.h> + +#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 ANDROID_ATOMIC_INLINE void android_memory_barrier(void) +{ + android_compiler_barrier(); +} +extern ANDROID_ATOMIC_INLINE void android_memory_store_barrier(void) +{ + android_compiler_barrier(); +} +#else +extern ANDROID_ATOMIC_INLINE void android_memory_barrier(void) +{ + __asm__ __volatile__ ("sync" : : : "memory"); +} +extern ANDROID_ATOMIC_INLINE void android_memory_store_barrier(void) +{ + __asm__ __volatile__ ("sync" : : : "memory"); +} +#endif + +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 ANDROID_ATOMIC_INLINE +int64_t android_atomic_acquire_load64(volatile const int64_t *ptr) +{ + int64_t value = *ptr; + android_memory_barrier(); + return value; +} + +extern ANDROID_ATOMIC_INLINE +int32_t android_atomic_release_load(volatile const int32_t *ptr) +{ + android_memory_barrier(); + return *ptr; +} + +extern ANDROID_ATOMIC_INLINE +int64_t android_atomic_release_load64(volatile const int64_t *ptr) +{ + android_memory_barrier(); + return *ptr; +} + +extern ANDROID_ATOMIC_INLINE +void android_atomic_acquire_store(int32_t value, volatile int32_t *ptr) +{ + *ptr = value; + android_memory_barrier(); +} + +extern ANDROID_ATOMIC_INLINE +void android_atomic_acquire_store64(int64_t value, volatile int64_t *ptr) +{ + *ptr = value; + android_memory_barrier(); +} + +extern ANDROID_ATOMIC_INLINE +void android_atomic_release_store(int32_t value, volatile int32_t *ptr) +{ + android_memory_barrier(); + *ptr = value; +} + +extern ANDROID_ATOMIC_INLINE +void android_atomic_release_store64(int64_t value, volatile int64_t *ptr) +{ + android_memory_barrier(); + *ptr = value; +} + +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 { + __asm__ __volatile__ ( + " ll %[prev], (%[ptr])\n" + " li %[status], 1\n" + " bne %[prev], %[old], 9f\n" + " move %[status], %[new_value]\n" + " sc %[status], (%[ptr])\n" + "9:\n" + : [prev] "=&r" (prev), [status] "=&r" (status) + : [ptr] "r" (ptr), [old] "r" (old_value), [new_value] "r" (new_value) + ); + } while (__builtin_expect(status == 0, 0)); + return prev != old_value; +} + +extern ANDROID_ATOMIC_INLINE +int64_t android_atomic_cas64(int64_t old_value, int64_t new_value, + volatile int64_t *ptr) +{ + return __sync_val_compare_and_swap(ptr, old_value, new_value) != old_value; +} + +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 ANDROID_ATOMIC_INLINE +int64_t android_atomic_acquire_cas64(int64_t old_value, int64_t new_value, + volatile int64_t *ptr) +{ + int status = android_atomic_cas64(old_value, new_value, ptr); + android_memory_barrier(); + return status; +} + +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 ANDROID_ATOMIC_INLINE +int64_t android_atomic_release_cas64(int64_t old_value, int64_t new_value, + volatile int64_t *ptr) +{ + android_memory_barrier(); + return android_atomic_cas64(old_value, new_value, ptr); +} + +extern ANDROID_ATOMIC_INLINE +int32_t android_atomic_add(int32_t increment, volatile int32_t *ptr) +{ + int32_t prev, status; + android_memory_barrier(); + do { + __asm__ __volatile__ ( + " ll %[prev], (%[ptr])\n" + " addu %[status], %[prev], %[inc]\n" + " sc %[status], (%[ptr])\n" + : [status] "=&r" (status), [prev] "=&r" (prev) + : [ptr] "r" (ptr), [inc] "Ir" (increment) + ); + } while (__builtin_expect(status == 0, 0)); + return prev; +} + +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_inc(volatile int32_t *addr) +{ + return android_atomic_add(1, addr); +} + +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_dec(volatile int32_t *addr) +{ + return android_atomic_add(-1, addr); +} + +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_and(int32_t value, volatile int32_t *ptr) +{ + int32_t prev, status; + android_memory_barrier(); + do { + __asm__ __volatile__ ( + " ll %[prev], (%[ptr])\n" + " and %[status], %[prev], %[value]\n" + " sc %[status], (%[ptr])\n" + : [prev] "=&r" (prev), [status] "=&r" (status) + : [ptr] "r" (ptr), [value] "Ir" (value) + ); + } while (__builtin_expect(status == 0, 0)); + return prev; +} + +extern ANDROID_ATOMIC_INLINE int32_t +android_atomic_or(int32_t value, volatile int32_t *ptr) +{ + int32_t prev, status; + android_memory_barrier(); + do { + __asm__ __volatile__ ( + " ll %[prev], (%[ptr])\n" + " or %[status], %[prev], %[value]\n" + " sc %[status], (%[ptr])\n" + : [prev] "=&r" (prev), [status] "=&r" (status) + : [ptr] "r" (ptr), [value] "Ir" (value) + ); + } while (__builtin_expect(status == 0, 0)); + return prev; +} + +#endif /* ANDROID_CUTILS_ATOMIC_MIPS_H */ diff --git a/include/cutils/atomic-x86_64.h b/include/cutils/atomic-x86_64.h new file mode 100644 index 0000000..5b5c203 --- /dev/null +++ b/include/cutils/atomic-x86_64.h @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef ANDROID_CUTILS_ATOMIC_X86_64_H +#define ANDROID_CUTILS_ATOMIC_X86_64_H + +#include <stdint.h> + +#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 ANDROID_ATOMIC_INLINE +void android_memory_barrier(void) +{ + android_compiler_barrier(); +} +extern ANDROID_ATOMIC_INLINE +void android_memory_store_barrier(void) +{ + android_compiler_barrier(); +} +#else +extern ANDROID_ATOMIC_INLINE +void android_memory_barrier(void) +{ + __asm__ __volatile__ ("mfence" : : : "memory"); +} +extern ANDROID_ATOMIC_INLINE +void android_memory_store_barrier(void) +{ + android_compiler_barrier(); +} +#endif + +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 ANDROID_ATOMIC_INLINE +int64_t android_atomic_acquire_load64(volatile const int64_t *ptr) +{ + int64_t value = *ptr; + android_compiler_barrier(); + return value; +} + +extern ANDROID_ATOMIC_INLINE +int32_t android_atomic_release_load(volatile const int32_t *ptr) +{ + android_memory_barrier(); + return *ptr; +} + +extern ANDROID_ATOMIC_INLINE +int64_t android_atomic_release_load64(volatile const int64_t *ptr) +{ + android_memory_barrier(); + return *ptr; +} + +extern ANDROID_ATOMIC_INLINE +void android_atomic_acquire_store(int32_t value, volatile int32_t *ptr) +{ + *ptr = value; + android_memory_barrier(); +} + +extern ANDROID_ATOMIC_INLINE +void android_atomic_acquire_store64(int64_t value, volatile int64_t *ptr) +{ + *ptr = value; + android_memory_barrier(); +} + +extern ANDROID_ATOMIC_INLINE +void android_atomic_release_store(int32_t value, volatile int32_t *ptr) +{ + android_compiler_barrier(); + *ptr = value; +} + +extern ANDROID_ATOMIC_INLINE +void android_atomic_release_store64(int64_t value, volatile int64_t *ptr) +{ + android_compiler_barrier(); + *ptr = value; +} + +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" + : "=a" (prev) + : "q" (new_value), "m" (*ptr), "0" (old_value) + : "memory"); + return prev != old_value; +} + +extern ANDROID_ATOMIC_INLINE +int64_t android_atomic_cas64(int64_t old_value, int64_t new_value, + volatile int64_t *ptr) +{ + int64_t prev; + __asm__ __volatile__ ("lock; cmpxchgq %1, %2" + : "=a" (prev) + : "q" (new_value), "m" (*ptr), "0" (old_value) + : "memory"); + return prev != old_value; +} + +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 ANDROID_ATOMIC_INLINE +int64_t android_atomic_acquire_cas64(int64_t old_value, int64_t new_value, + volatile int64_t *ptr) +{ + /* Loads are not reordered with other loads. */ + return android_atomic_cas64(old_value, new_value, 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 ANDROID_ATOMIC_INLINE +int64_t android_atomic_release_cas64(int64_t old_value, int64_t new_value, + volatile int64_t *ptr) +{ + /* Stores are not reordered with other stores. */ + return android_atomic_cas64(old_value, new_value, 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) + : : "memory"); + /* increment now holds the old value of *ptr */ + return increment; +} + +extern ANDROID_ATOMIC_INLINE +int32_t android_atomic_inc(volatile int32_t *addr) +{ + return android_atomic_add(1, addr); +} + +extern ANDROID_ATOMIC_INLINE +int32_t android_atomic_dec(volatile int32_t *addr) +{ + return android_atomic_add(-1, addr); +} + +extern ANDROID_ATOMIC_INLINE +int32_t android_atomic_and(int32_t value, volatile int32_t *ptr) +{ + int32_t prev, status; + do { + prev = *ptr; + status = android_atomic_cas(prev, prev & value, ptr); + } while (__builtin_expect(status != 0, 0)); + return prev; +} + +extern ANDROID_ATOMIC_INLINE +int32_t android_atomic_or(int32_t value, volatile int32_t *ptr) +{ + int32_t prev, status; + do { + prev = *ptr; + status = android_atomic_cas(prev, prev | value, ptr); + } while (__builtin_expect(status != 0, 0)); + return prev; +} + +#endif /* ANDROID_CUTILS_ATOMIC_X86_64_H */ diff --git a/include/cutils/bitops.h b/include/cutils/bitops.h index c26dc54..045830d 100644 --- a/include/cutils/bitops.h +++ b/include/cutils/bitops.h @@ -59,7 +59,7 @@ static inline void bitmask_init(unsigned int *bitmask, int num_bits) static inline int bitmask_ffz(unsigned int *bitmask, int num_bits) { int bit, result; - unsigned int i; + size_t i; for (i = 0; i < BITS_TO_WORDS(num_bits); i++) { bit = ffs(~bitmask[i]); @@ -77,7 +77,7 @@ static inline int bitmask_ffz(unsigned int *bitmask, int num_bits) static inline int bitmask_weight(unsigned int *bitmask, int num_bits) { - int i; + size_t i; int weight = 0; for (i = 0; i < BITS_TO_WORDS(num_bits); i++) diff --git a/include/cutils/debugger.h b/include/cutils/debugger.h index 4eda523..ae6bfc4 100644 --- a/include/cutils/debugger.h +++ b/include/cutils/debugger.h @@ -23,7 +23,11 @@ extern "C" { #endif +#if __LP64__ +#define DEBUGGER_SOCKET_NAME "android:debuggerd64" +#else #define DEBUGGER_SOCKET_NAME "android:debuggerd" +#endif typedef enum { // dump a crash @@ -38,6 +42,7 @@ typedef struct { debugger_action_t action; pid_t tid; uintptr_t abort_msg_address; + int32_t original_si_code; } debugger_msg_t; /* Dumps a process backtrace, registers, and stack to a tombstone file (requires root). diff --git a/include/cutils/fs.h b/include/cutils/fs.h index d1d4cf2..70f0b92 100644 --- a/include/cutils/fs.h +++ b/include/cutils/fs.h @@ -18,6 +18,7 @@ #define __CUTILS_FS_H #include <sys/types.h> +#include <unistd.h> /* * TEMP_FAILURE_RETRY is defined by some, but not all, versions of diff --git a/include/cutils/klog.h b/include/cutils/klog.h index ba728ac..3635e89 100644 --- a/include/cutils/klog.h +++ b/include/cutils/klog.h @@ -18,22 +18,31 @@ #define _CUTILS_KLOG_H_ #include <sys/cdefs.h> +#include <stdarg.h> __BEGIN_DECLS void klog_init(void); +int klog_get_level(void); void klog_set_level(int level); void klog_close(void); void klog_write(int level, const char *fmt, ...) __attribute__ ((format(printf, 2, 3))); +void klog_vwrite(int level, const char *fmt, va_list ap); __END_DECLS -#define KLOG_ERROR(tag,x...) klog_write(3, "<3>" tag ": " x) -#define KLOG_WARNING(tag,x...) klog_write(4, "<4>" tag ": " x) -#define KLOG_NOTICE(tag,x...) klog_write(5, "<5>" tag ": " x) -#define KLOG_INFO(tag,x...) klog_write(6, "<6>" tag ": " x) -#define KLOG_DEBUG(tag,x...) klog_write(7, "<7>" tag ": " x) +#define KLOG_ERROR_LEVEL 3 +#define KLOG_WARNING_LEVEL 4 +#define KLOG_NOTICE_LEVEL 5 +#define KLOG_INFO_LEVEL 6 +#define KLOG_DEBUG_LEVEL 7 + +#define KLOG_ERROR(tag,x...) klog_write(KLOG_ERROR_LEVEL, "<3>" tag ": " x) +#define KLOG_WARNING(tag,x...) klog_write(KLOG_WARNING_LEVEL, "<4>" tag ": " x) +#define KLOG_NOTICE(tag,x...) klog_write(KLOG_NOTICE_LEVEL, "<5>" tag ": " x) +#define KLOG_INFO(tag,x...) klog_write(KLOG_INFO_LEVEL, "<6>" tag ": " x) +#define KLOG_DEBUG(tag,x...) klog_write(KLOG_DEBUG_LEVEL, "<7>" tag ": " x) #define KLOG_DEFAULT_LEVEL 3 /* messages <= this level are logged */ diff --git a/include/cutils/list.h b/include/cutils/list.h index 945729a..4ba2cfd 100644 --- a/include/cutils/list.h +++ b/include/cutils/list.h @@ -44,10 +44,10 @@ struct listnode #define list_for_each_reverse(node, list) \ for (node = (list)->prev; node != (list); node = node->prev) -#define list_for_each_safe(node, next, list) \ - for (node = (list)->next, next = node->next; \ +#define list_for_each_safe(node, n, list) \ + for (node = (list)->next, n = node->next; \ node != (list); \ - node = next, next = node->next) + node = n, n = node->next) static inline void list_init(struct listnode *node) { @@ -63,6 +63,14 @@ static inline void list_add_tail(struct listnode *head, struct listnode *item) head->prev = item; } +static inline void list_add_head(struct listnode *head, struct listnode *item) +{ + item->next = head->next; + item->prev = head; + head->next->prev = item; + head->next = item; +} + static inline void list_remove(struct listnode *item) { item->next->prev = item->prev; diff --git a/include/cutils/misc.h b/include/cutils/misc.h index 2c48dfa..0de505f 100644 --- a/include/cutils/misc.h +++ b/include/cutils/misc.h @@ -28,13 +28,6 @@ extern "C" { */ extern void *load_file(const char *fn, unsigned *sz); - /* Connects your process to the system debugger daemon - * so that on a crash it may be logged or interactively - * debugged (depending on system settings). - */ -extern void debuggerd_connect(void); - - /* This is the range of UIDs (and GIDs) that are reserved * for assigning to applications. */ diff --git a/include/cutils/properties.h b/include/cutils/properties.h index 2c70165..798db8b 100644 --- a/include/cutils/properties.h +++ b/include/cutils/properties.h @@ -20,6 +20,7 @@ #include <sys/cdefs.h> #include <stddef.h> #include <sys/system_properties.h> +#include <stdint.h> #ifdef __cplusplus extern "C" { @@ -44,6 +45,64 @@ extern "C" { */ int property_get(const char *key, char *value, const char *default_value); +/* property_get_bool: returns the value of key coerced into a +** boolean. If the property is not set, then the default value is returned. +** +* The following is considered to be true (1): +** "1", "true", "y", "yes", "on" +** +** The following is considered to be false (0): +** "0", "false", "n", "no", "off" +** +** The conversion is whitespace-sensitive (e.g. " off" will not be false). +** +** If no property with this key is set (or the key is NULL) or the boolean +** conversion fails, the default value is returned. +**/ +int8_t property_get_bool(const char *key, int8_t default_value); + +/* property_get_int64: returns the value of key truncated and coerced into a +** int64_t. If the property is not set, then the default value is used. +** +** The numeric conversion is identical to strtoimax with the base inferred: +** - All digits up to the first non-digit characters are read +** - The longest consecutive prefix of digits is converted to a long +** +** Valid strings of digits are: +** - An optional sign character + or - +** - An optional prefix indicating the base (otherwise base 10 is assumed) +** -- 0 prefix is octal +** -- 0x / 0X prefix is hex +** +** Leading/trailing whitespace is ignored. Overflow/underflow will cause +** numeric conversion to fail. +** +** If no property with this key is set (or the key is NULL) or the numeric +** conversion fails, the default value is returned. +**/ +int64_t property_get_int64(const char *key, int64_t default_value); + +/* property_get_int32: returns the value of key truncated and coerced into an +** int32_t. If the property is not set, then the default value is used. +** +** The numeric conversion is identical to strtoimax with the base inferred: +** - All digits up to the first non-digit characters are read +** - The longest consecutive prefix of digits is converted to a long +** +** Valid strings of digits are: +** - An optional sign character + or - +** - An optional prefix indicating the base (otherwise base 10 is assumed) +** -- 0 prefix is octal +** -- 0x / 0X prefix is hex +** +** Leading/trailing whitespace is ignored. Overflow/underflow will cause +** numeric conversion to fail. +** +** If no property with this key is set (or the key is NULL) or the numeric +** conversion fails, the default value is returned. +**/ +int32_t property_get_int32(const char *key, int32_t default_value); + /* property_set: returns 0 on success, < 0 on failure */ int property_set(const char *key, const char *value); diff --git a/include/cutils/sockets.h b/include/cutils/sockets.h index 19cae0c..daf43ec 100644 --- a/include/cutils/sockets.h +++ b/include/cutils/sockets.h @@ -86,6 +86,8 @@ static inline int android_get_control_socket(const char *name) extern int socket_loopback_client(int port, int type); extern int socket_network_client(const char *host, int port, int type); +extern int socket_network_client_timeout(const char *host, int port, int type, + int timeout); extern int socket_loopback_server(int port, int type); extern int socket_local_server(const char *name, int namespaceId, int type); extern int socket_local_server_bind(int s, const char *name, int namespaceId); diff --git a/include/cutils/trace.h b/include/cutils/trace.h index 1c8f107..fd9bc6a 100644 --- a/include/cutils/trace.h +++ b/include/cutils/trace.h @@ -17,13 +17,15 @@ #ifndef _LIBS_CUTILS_TRACE_H #define _LIBS_CUTILS_TRACE_H +#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> #include <sys/cdefs.h> #include <sys/types.h> -#include <stdint.h> -#include <stdbool.h> #include <unistd.h> -#include <cutils/compiler.h> +#include <cutils/compiler.h> #ifdef ANDROID_SMP #include <cutils/atomic-inline.h> #else @@ -67,7 +69,8 @@ __BEGIN_DECLS #define ATRACE_TAG_RESOURCES (1<<13) #define ATRACE_TAG_DALVIK (1<<14) #define ATRACE_TAG_RS (1<<15) -#define ATRACE_TAG_LAST ATRACE_TAG_RS +#define ATRACE_TAG_BIONIC (1<<16) +#define ATRACE_TAG_LAST ATRACE_TAG_BIONIC // Reserved for initialization. #define ATRACE_TAG_NOT_READY (1LL<<63) @@ -217,8 +220,8 @@ static inline void atrace_async_begin(uint64_t tag, const char* name, char buf[ATRACE_MESSAGE_LENGTH]; size_t len; - len = snprintf(buf, ATRACE_MESSAGE_LENGTH, "S|%d|%s|%d", getpid(), - name, cookie); + len = snprintf(buf, ATRACE_MESSAGE_LENGTH, "S|%d|%s|%" PRId32, + getpid(), name, cookie); write(atrace_marker_fd, buf, len); } } @@ -235,8 +238,8 @@ static inline void atrace_async_end(uint64_t tag, const char* name, char buf[ATRACE_MESSAGE_LENGTH]; size_t len; - len = snprintf(buf, ATRACE_MESSAGE_LENGTH, "F|%d|%s|%d", getpid(), - name, cookie); + len = snprintf(buf, ATRACE_MESSAGE_LENGTH, "F|%d|%s|%" PRId32, + getpid(), name, cookie); write(atrace_marker_fd, buf, len); } } @@ -253,7 +256,7 @@ static inline void atrace_int(uint64_t tag, const char* name, int32_t value) char buf[ATRACE_MESSAGE_LENGTH]; size_t len; - len = snprintf(buf, ATRACE_MESSAGE_LENGTH, "C|%d|%s|%d", + len = snprintf(buf, ATRACE_MESSAGE_LENGTH, "C|%d|%s|%" PRId32, getpid(), name, value); write(atrace_marker_fd, buf, len); } @@ -270,7 +273,7 @@ static inline void atrace_int64(uint64_t tag, const char* name, int64_t value) char buf[ATRACE_MESSAGE_LENGTH]; size_t len; - len = snprintf(buf, ATRACE_MESSAGE_LENGTH, "C|%d|%s|%lld", + len = snprintf(buf, ATRACE_MESSAGE_LENGTH, "C|%d|%s|%" PRId64, getpid(), name, value); write(atrace_marker_fd, buf, len); } |