mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-09-14 19:43:53 +08:00
openpilot v0.6 release
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2011, 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_ANDROID_REBOOT_H__
|
||||
#define __CUTILS_ANDROID_REBOOT_H__
|
||||
|
||||
#include <mntent.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/* Commands */
|
||||
#define ANDROID_RB_RESTART 0xDEAD0001
|
||||
#define ANDROID_RB_POWEROFF 0xDEAD0002
|
||||
#define ANDROID_RB_RESTART2 0xDEAD0003
|
||||
|
||||
/* Properties */
|
||||
#define ANDROID_RB_PROPERTY "sys.powerctl"
|
||||
|
||||
int android_reboot(int cmd, int flags, const char *arg);
|
||||
int android_reboot_with_callback(
|
||||
int cmd, int flags, const char *arg,
|
||||
void (*cb_on_remount)(const struct mntent*));
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* __CUTILS_ANDROID_REBOOT_H__ */
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
#include <cutils/atomic.h>
|
||||
|
||||
__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_
|
||||
@@ -0,0 +1,45 @@
|
||||
/* cutils/ashmem.h
|
||||
**
|
||||
** Copyright 2008 The Android Open Source Project
|
||||
**
|
||||
** This file is dual licensed. It may be redistributed and/or modified
|
||||
** under the terms of the Apache 2.0 License OR version 2 of the GNU
|
||||
** General Public License.
|
||||
*/
|
||||
|
||||
#ifndef _CUTILS_ASHMEM_H
|
||||
#define _CUTILS_ASHMEM_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int ashmem_create_region(const char *name, size_t size);
|
||||
int ashmem_set_prot_region(int fd, int prot);
|
||||
int ashmem_pin_region(int fd, size_t offset, size_t len);
|
||||
int ashmem_unpin_region(int fd, size_t offset, size_t len);
|
||||
int ashmem_get_size_region(int fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __ASHMEMIOC /* in case someone included <linux/ashmem.h> too */
|
||||
|
||||
#define ASHMEM_NAME_LEN 256
|
||||
|
||||
#define ASHMEM_NAME_DEF "dev/ashmem"
|
||||
|
||||
/* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */
|
||||
#define ASHMEM_NOT_PURGED 0
|
||||
#define ASHMEM_WAS_PURGED 1
|
||||
|
||||
/* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */
|
||||
#define ASHMEM_IS_UNPINNED 0
|
||||
#define ASHMEM_IS_PINNED 1
|
||||
|
||||
#endif /* ! __ASHMEMIOC */
|
||||
|
||||
#endif /* _CUTILS_ASHMEM_H */
|
||||
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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_H
|
||||
#define ANDROID_CUTILS_ATOMIC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdatomic.h>
|
||||
|
||||
#ifndef ANDROID_ATOMIC_INLINE
|
||||
#define ANDROID_ATOMIC_INLINE static inline
|
||||
#endif
|
||||
|
||||
/*
|
||||
* A handful of basic atomic operations.
|
||||
* THESE ARE HERE FOR LEGACY REASONS ONLY. AVOID.
|
||||
*
|
||||
* PREFERRED ALTERNATIVES:
|
||||
* - Use C++/C/pthread locks/mutexes whenever there is not a
|
||||
* convincing reason to do otherwise. Note that very clever and
|
||||
* complicated, but correct, lock-free code is often slower than
|
||||
* using locks, especially where nontrivial data structures
|
||||
* are involved.
|
||||
* - C11 stdatomic.h.
|
||||
* - Where supported, C++11 std::atomic<T> .
|
||||
*
|
||||
* PLEASE STOP READING HERE UNLESS YOU ARE TRYING TO UNDERSTAND
|
||||
* OR UPDATE OLD CODE.
|
||||
*
|
||||
* The "acquire" and "release" terms can be defined intuitively in terms
|
||||
* of the placement of memory barriers in a simple lock implementation:
|
||||
* - wait until compare-and-swap(lock-is-free --> lock-is-held) succeeds
|
||||
* - barrier
|
||||
* - [do work]
|
||||
* - barrier
|
||||
* - store(lock-is-free)
|
||||
* In very crude terms, the initial (acquire) barrier prevents any of the
|
||||
* "work" from happening before the lock is held, and the later (release)
|
||||
* barrier ensures that all of the work happens before the lock is released.
|
||||
* (Think of cached writes, cache read-ahead, and instruction reordering
|
||||
* around the CAS and store instructions.)
|
||||
*
|
||||
* The barriers must apply to both the compiler and the CPU. Note it is
|
||||
* legal for instructions that occur before an "acquire" barrier to be
|
||||
* moved down below it, and for instructions that occur after a "release"
|
||||
* barrier to be moved up above it.
|
||||
*
|
||||
* The ARM-driven implementation we use here is short on subtlety,
|
||||
* and actually requests a full barrier from the compiler and the CPU.
|
||||
* The only difference between acquire and release is in whether they
|
||||
* are issued before or after the atomic operation with which they
|
||||
* are associated. To ease the transition to C/C++ atomic intrinsics,
|
||||
* you should not rely on this, and instead assume that only the minimal
|
||||
* acquire/release protection is provided.
|
||||
*
|
||||
* NOTE: all int32_t* values are expected to be aligned on 32-bit boundaries.
|
||||
* If they are not, atomicity is not guaranteed.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Basic arithmetic and bitwise operations. These all provide a
|
||||
* barrier with "release" ordering, and return the previous value.
|
||||
*
|
||||
* These have the same characteristics (e.g. what happens on overflow)
|
||||
* as the equivalent non-atomic C operations.
|
||||
*/
|
||||
ANDROID_ATOMIC_INLINE
|
||||
int32_t android_atomic_inc(volatile int32_t* addr)
|
||||
{
|
||||
volatile atomic_int_least32_t* a = (volatile atomic_int_least32_t*)addr;
|
||||
/* Int32_t, if it exists, is the same as int_least32_t. */
|
||||
return atomic_fetch_add_explicit(a, 1, memory_order_release);
|
||||
}
|
||||
|
||||
ANDROID_ATOMIC_INLINE
|
||||
int32_t android_atomic_dec(volatile int32_t* addr)
|
||||
{
|
||||
volatile atomic_int_least32_t* a = (volatile atomic_int_least32_t*)addr;
|
||||
return atomic_fetch_sub_explicit(a, 1, memory_order_release);
|
||||
}
|
||||
|
||||
ANDROID_ATOMIC_INLINE
|
||||
int32_t android_atomic_add(int32_t value, volatile int32_t* addr)
|
||||
{
|
||||
volatile atomic_int_least32_t* a = (volatile atomic_int_least32_t*)addr;
|
||||
return atomic_fetch_add_explicit(a, value, memory_order_release);
|
||||
}
|
||||
|
||||
ANDROID_ATOMIC_INLINE
|
||||
int32_t android_atomic_and(int32_t value, volatile int32_t* addr)
|
||||
{
|
||||
volatile atomic_int_least32_t* a = (volatile atomic_int_least32_t*)addr;
|
||||
return atomic_fetch_and_explicit(a, value, memory_order_release);
|
||||
}
|
||||
|
||||
ANDROID_ATOMIC_INLINE
|
||||
int32_t android_atomic_or(int32_t value, volatile int32_t* addr)
|
||||
{
|
||||
volatile atomic_int_least32_t* a = (volatile atomic_int_least32_t*)addr;
|
||||
return atomic_fetch_or_explicit(a, value, memory_order_release);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform an atomic load with "acquire" or "release" ordering.
|
||||
*
|
||||
* Note that the notion of a "release" ordering for a load does not
|
||||
* really fit into the C11 or C++11 memory model. The extra ordering
|
||||
* is normally observable only by code using memory_order_relaxed
|
||||
* atomics, or data races. In the rare cases in which such ordering
|
||||
* is called for, use memory_order_relaxed atomics and a leading
|
||||
* atomic_thread_fence (typically with memory_order_acquire,
|
||||
* not memory_order_release!) instead. If you do not understand
|
||||
* this comment, you are in the vast majority, and should not be
|
||||
* using release loads or replacing them with anything other than
|
||||
* locks or default sequentially consistent atomics.
|
||||
*/
|
||||
ANDROID_ATOMIC_INLINE
|
||||
int32_t android_atomic_acquire_load(volatile const int32_t* addr)
|
||||
{
|
||||
volatile atomic_int_least32_t* a = (volatile atomic_int_least32_t*)addr;
|
||||
return atomic_load_explicit(a, memory_order_acquire);
|
||||
}
|
||||
|
||||
ANDROID_ATOMIC_INLINE
|
||||
int32_t android_atomic_release_load(volatile const int32_t* addr)
|
||||
{
|
||||
volatile atomic_int_least32_t* a = (volatile atomic_int_least32_t*)addr;
|
||||
atomic_thread_fence(memory_order_seq_cst);
|
||||
/* Any reasonable clients of this interface would probably prefer */
|
||||
/* something weaker. But some remaining clients seem to be */
|
||||
/* abusing this API in strange ways, e.g. by using it as a fence. */
|
||||
/* Thus we are conservative until we can get rid of remaining */
|
||||
/* clients (and this function). */
|
||||
return atomic_load_explicit(a, memory_order_relaxed);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform an atomic store with "acquire" or "release" ordering.
|
||||
*
|
||||
* Note that the notion of an "acquire" ordering for a store does not
|
||||
* really fit into the C11 or C++11 memory model. The extra ordering
|
||||
* is normally observable only by code using memory_order_relaxed
|
||||
* atomics, or data races. In the rare cases in which such ordering
|
||||
* is called for, use memory_order_relaxed atomics and a trailing
|
||||
* atomic_thread_fence (typically with memory_order_release,
|
||||
* not memory_order_acquire!) instead.
|
||||
*/
|
||||
ANDROID_ATOMIC_INLINE
|
||||
void android_atomic_acquire_store(int32_t value, volatile int32_t* addr)
|
||||
{
|
||||
volatile atomic_int_least32_t* a = (volatile atomic_int_least32_t*)addr;
|
||||
atomic_store_explicit(a, value, memory_order_relaxed);
|
||||
atomic_thread_fence(memory_order_seq_cst);
|
||||
/* Again overly conservative to accomodate weird clients. */
|
||||
}
|
||||
|
||||
ANDROID_ATOMIC_INLINE
|
||||
void android_atomic_release_store(int32_t value, volatile int32_t* addr)
|
||||
{
|
||||
volatile atomic_int_least32_t* a = (volatile atomic_int_least32_t*)addr;
|
||||
atomic_store_explicit(a, value, memory_order_release);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare-and-set operation with "acquire" or "release" ordering.
|
||||
*
|
||||
* This returns zero if the new value was successfully stored, which will
|
||||
* only happen when *addr == oldvalue.
|
||||
*
|
||||
* (The return value is inverted from implementations on other platforms,
|
||||
* but matches the ARM ldrex/strex result.)
|
||||
*
|
||||
* Implementations that use the release CAS in a loop may be less efficient
|
||||
* than possible, because we re-issue the memory barrier on each iteration.
|
||||
*/
|
||||
ANDROID_ATOMIC_INLINE
|
||||
int android_atomic_acquire_cas(int32_t oldvalue, int32_t newvalue,
|
||||
volatile int32_t* addr)
|
||||
{
|
||||
volatile atomic_int_least32_t* a = (volatile atomic_int_least32_t*)addr;
|
||||
return (int)(!atomic_compare_exchange_strong_explicit(
|
||||
a, &oldvalue, newvalue,
|
||||
memory_order_acquire,
|
||||
memory_order_acquire));
|
||||
}
|
||||
|
||||
ANDROID_ATOMIC_INLINE
|
||||
int android_atomic_release_cas(int32_t oldvalue, int32_t newvalue,
|
||||
volatile int32_t* addr)
|
||||
{
|
||||
volatile atomic_int_least32_t* a = (volatile atomic_int_least32_t*)addr;
|
||||
return (int)(!atomic_compare_exchange_strong_explicit(
|
||||
a, &oldvalue, newvalue,
|
||||
memory_order_release,
|
||||
memory_order_relaxed));
|
||||
}
|
||||
|
||||
/*
|
||||
* Fence primitives.
|
||||
*/
|
||||
ANDROID_ATOMIC_INLINE
|
||||
void android_compiler_barrier(void)
|
||||
{
|
||||
__asm__ __volatile__ ("" : : : "memory");
|
||||
/* Could probably also be: */
|
||||
/* atomic_signal_fence(memory_order_seq_cst); */
|
||||
}
|
||||
|
||||
ANDROID_ATOMIC_INLINE
|
||||
void android_memory_barrier(void)
|
||||
{
|
||||
atomic_thread_fence(memory_order_seq_cst);
|
||||
}
|
||||
|
||||
/*
|
||||
* Aliases for code using an older version of this header. These are now
|
||||
* deprecated and should not be used. The definitions will be removed
|
||||
* in a future release.
|
||||
*/
|
||||
#define android_atomic_write android_atomic_release_store
|
||||
#define android_atomic_cmpxchg android_atomic_release_cas
|
||||
|
||||
#endif // ANDROID_CUTILS_ATOMIC_H
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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_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;
|
||||
size_t 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 int bitmask_weight(unsigned int *bitmask, int num_bits)
|
||||
{
|
||||
size_t i;
|
||||
int weight = 0;
|
||||
|
||||
for (i = 0; i < BITS_TO_WORDS(num_bits); i++)
|
||||
weight += __builtin_popcount(bitmask[i]);
|
||||
return weight;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static inline int popcountl(unsigned long x)
|
||||
{
|
||||
return __builtin_popcountl(x);
|
||||
}
|
||||
|
||||
static inline int popcountll(unsigned long long x)
|
||||
{
|
||||
return __builtin_popcountll(x);
|
||||
}
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* __CUTILS_BITOPS_H */
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2009 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_COMPILER_H
|
||||
#define ANDROID_CUTILS_COMPILER_H
|
||||
|
||||
/*
|
||||
* helps the compiler's optimizer predicting branches
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define CC_LIKELY( exp ) (__builtin_expect( !!(exp), true ))
|
||||
# define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), false ))
|
||||
#else
|
||||
# define CC_LIKELY( exp ) (__builtin_expect( !!(exp), 1 ))
|
||||
# define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), 0 ))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* exports marked symbols
|
||||
*
|
||||
* if used on a C++ class declaration, this macro must be inserted
|
||||
* after the "class" keyword. For instance:
|
||||
*
|
||||
* template <typename TYPE>
|
||||
* class ANDROID_API Singleton { }
|
||||
*/
|
||||
|
||||
#define ANDROID_API __attribute__((visibility("default")))
|
||||
|
||||
#endif // ANDROID_CUTILS_COMPILER_H
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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_CONFIG_UTILS_H
|
||||
#define __CUTILS_CONFIG_UTILS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct cnode cnode;
|
||||
|
||||
|
||||
struct cnode
|
||||
{
|
||||
cnode *next;
|
||||
cnode *first_child;
|
||||
cnode *last_child;
|
||||
const char *name;
|
||||
const char *value;
|
||||
};
|
||||
|
||||
/* parse a text string into a config node tree */
|
||||
void config_load(cnode *root, char *data);
|
||||
|
||||
/* parse a file into a config node tree */
|
||||
void config_load_file(cnode *root, const char *fn);
|
||||
|
||||
/* create a single config node */
|
||||
cnode* config_node(const char *name, const char *value);
|
||||
|
||||
/* locate a named child of a config node */
|
||||
cnode* config_find(cnode *root, const char *name);
|
||||
|
||||
/* look up a child by name and return the boolean value */
|
||||
int config_bool(cnode *root, const char *name, int _default);
|
||||
|
||||
/* look up a child by name and return the string value */
|
||||
const char* config_str(cnode *root, const char *name, const char *_default);
|
||||
|
||||
/* add a named child to a config node (or modify it if it already exists) */
|
||||
void config_set(cnode *root, const char *name, const char *value);
|
||||
|
||||
/* free a config node tree */
|
||||
void config_free(cnode *root);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 __CUTILS_DEBUGGER_H
|
||||
#define __CUTILS_DEBUGGER_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define DEBUGGER_SOCKET_NAME "android:debuggerd"
|
||||
#define DEBUGGER32_SOCKET_NAME "android:debuggerd32"
|
||||
#define DEBUGGER64_SOCKET_NAME DEBUGGER_SOCKET_NAME
|
||||
|
||||
typedef enum {
|
||||
// dump a crash
|
||||
DEBUGGER_ACTION_CRASH,
|
||||
// dump a tombstone file
|
||||
DEBUGGER_ACTION_DUMP_TOMBSTONE,
|
||||
// dump a backtrace only back to the socket
|
||||
DEBUGGER_ACTION_DUMP_BACKTRACE,
|
||||
} debugger_action_t;
|
||||
|
||||
// Make sure that all values have a fixed size so that this structure
|
||||
// is the same for 32 bit and 64 bit processes.
|
||||
// NOTE: Any changes to this structure must also be reflected in
|
||||
// bionic/linker/debugger.cpp.
|
||||
typedef struct __attribute__((packed)) {
|
||||
int32_t action;
|
||||
pid_t tid;
|
||||
uint64_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).
|
||||
* Stores the tombstone path in the provided buffer.
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
int dump_tombstone(pid_t tid, char* pathbuf, size_t pathlen);
|
||||
|
||||
/* Dumps a process backtrace, registers, and stack to a tombstone file (requires root).
|
||||
* Stores the tombstone path in the provided buffer.
|
||||
* If reading debugger data from debuggerd ever takes longer than timeout_secs
|
||||
* seconds, then stop and return an error.
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
int dump_tombstone_timeout(pid_t tid, char* pathbuf, size_t pathlen, int timeout_secs);
|
||||
|
||||
/* Dumps a process backtrace only to the specified file (requires root).
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
int dump_backtrace_to_file(pid_t tid, int fd);
|
||||
|
||||
/* Dumps a process backtrace only to the specified file (requires root).
|
||||
* If reading debugger data from debuggerd ever takes longer than timeout_secs
|
||||
* seconds, then stop and return an error.
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
int dump_backtrace_to_file_timeout(pid_t tid, int fd, int timeout_secs);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* __CUTILS_DEBUGGER_H */
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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 __CUTILS_FS_H
|
||||
#define __CUTILS_FS_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
* TEMP_FAILURE_RETRY is defined by some, but not all, versions of
|
||||
* <unistd.h>. (Alas, it is not as standard as we'd hoped!) So, if it's
|
||||
* not already defined, then define it here.
|
||||
*/
|
||||
#ifndef TEMP_FAILURE_RETRY
|
||||
/* Used to retry syscalls that can return EINTR. */
|
||||
#define TEMP_FAILURE_RETRY(exp) ({ \
|
||||
typeof (exp) _rc; \
|
||||
do { \
|
||||
_rc = (exp); \
|
||||
} while (_rc == -1 && errno == EINTR); \
|
||||
_rc; })
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Ensure that directory exists with given mode and owners.
|
||||
*/
|
||||
extern int fs_prepare_dir(const char* path, mode_t mode, uid_t uid, gid_t gid);
|
||||
|
||||
/*
|
||||
* Read single plaintext integer from given file, correctly handling files
|
||||
* partially written with fs_write_atomic_int().
|
||||
*/
|
||||
extern int fs_read_atomic_int(const char* path, int* value);
|
||||
|
||||
/*
|
||||
* Write single plaintext integer to given file, creating backup while
|
||||
* in progress.
|
||||
*/
|
||||
extern int fs_write_atomic_int(const char* path, int value);
|
||||
|
||||
/*
|
||||
* Ensure that all directories along given path exist, creating parent
|
||||
* directories as needed. Validates that given path is absolute and that
|
||||
* it contains no relative "." or ".." paths or symlinks. Last path segment
|
||||
* is treated as filename and ignored, unless the path ends with "/".
|
||||
*/
|
||||
extern int fs_mkdirs(const char* path, mode_t mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CUTILS_FS_H */
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Hash map.
|
||||
*/
|
||||
|
||||
#ifndef __HASHMAP_H
|
||||
#define __HASHMAP_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** A hash map. */
|
||||
typedef struct Hashmap Hashmap;
|
||||
|
||||
/**
|
||||
* Creates a new hash map. Returns NULL if memory allocation fails.
|
||||
*
|
||||
* @param initialCapacity number of expected entries
|
||||
* @param hash function which hashes keys
|
||||
* @param equals function which compares keys for equality
|
||||
*/
|
||||
Hashmap* hashmapCreate(size_t initialCapacity,
|
||||
int (*hash)(void* key), bool (*equals)(void* keyA, void* keyB));
|
||||
|
||||
/**
|
||||
* Frees the hash map. Does not free the keys or values themselves.
|
||||
*/
|
||||
void hashmapFree(Hashmap* map);
|
||||
|
||||
/**
|
||||
* Hashes the memory pointed to by key with the given size. Useful for
|
||||
* implementing hash functions.
|
||||
*/
|
||||
int hashmapHash(void* key, size_t keySize);
|
||||
|
||||
/**
|
||||
* Puts value for the given key in the map. Returns pre-existing value if
|
||||
* any.
|
||||
*
|
||||
* If memory allocation fails, this function returns NULL, the map's size
|
||||
* does not increase, and errno is set to ENOMEM.
|
||||
*/
|
||||
void* hashmapPut(Hashmap* map, void* key, void* value);
|
||||
|
||||
/**
|
||||
* Gets a value from the map. Returns NULL if no entry for the given key is
|
||||
* found or if the value itself is NULL.
|
||||
*/
|
||||
void* hashmapGet(Hashmap* map, void* key);
|
||||
|
||||
/**
|
||||
* Returns true if the map contains an entry for the given key.
|
||||
*/
|
||||
bool hashmapContainsKey(Hashmap* map, void* key);
|
||||
|
||||
/**
|
||||
* Gets the value for a key. If a value is not found, this function gets a
|
||||
* value and creates an entry using the given callback.
|
||||
*
|
||||
* If memory allocation fails, the callback is not called, this function
|
||||
* returns NULL, and errno is set to ENOMEM.
|
||||
*/
|
||||
void* hashmapMemoize(Hashmap* map, void* key,
|
||||
void* (*initialValue)(void* key, void* context), void* context);
|
||||
|
||||
/**
|
||||
* Removes an entry from the map. Returns the removed value or NULL if no
|
||||
* entry was present.
|
||||
*/
|
||||
void* hashmapRemove(Hashmap* map, void* key);
|
||||
|
||||
/**
|
||||
* Gets the number of entries in this map.
|
||||
*/
|
||||
size_t hashmapSize(Hashmap* map);
|
||||
|
||||
/**
|
||||
* Invokes the given callback on each entry in the map. Stops iterating if
|
||||
* the callback returns false.
|
||||
*/
|
||||
void hashmapForEach(Hashmap* map,
|
||||
bool (*callback)(void* key, void* value, void* context),
|
||||
void* context);
|
||||
|
||||
/**
|
||||
* Concurrency support.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Locks the hash map so only the current thread can access it.
|
||||
*/
|
||||
void hashmapLock(Hashmap* map);
|
||||
|
||||
/**
|
||||
* Unlocks the hash map so other threads can access it.
|
||||
*/
|
||||
void hashmapUnlock(Hashmap* map);
|
||||
|
||||
/**
|
||||
* Key utilities.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Hashes int keys. 'key' is a pointer to int.
|
||||
*/
|
||||
int hashmapIntHash(void* key);
|
||||
|
||||
/**
|
||||
* Compares two int keys for equality.
|
||||
*/
|
||||
bool hashmapIntEquals(void* keyA, void* keyB);
|
||||
|
||||
/**
|
||||
* For debugging.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets current capacity.
|
||||
*/
|
||||
size_t hashmapCurrentCapacity(Hashmap* map);
|
||||
|
||||
/**
|
||||
* Counts the number of entry collisions.
|
||||
*/
|
||||
size_t hashmapCountCollisions(Hashmap* map);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __HASHMAP_H */
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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_IOSCHED_POLICY_H
|
||||
#define __CUTILS_IOSCHED_POLICY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
IoSchedClass_NONE,
|
||||
IoSchedClass_RT,
|
||||
IoSchedClass_BE,
|
||||
IoSchedClass_IDLE,
|
||||
} IoSchedClass;
|
||||
|
||||
extern int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio);
|
||||
extern int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio);
|
||||
|
||||
extern int android_set_rt_ioprio(int pid, int rt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CUTILS_IOSCHED_POLICY_H */
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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_STRING16_H
|
||||
#define __CUTILS_STRING16_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if __STDC_VERSION__ < 201112L && __cplusplus < 201103L
|
||||
typedef uint16_t char16_t;
|
||||
#endif
|
||||
// otherwise char16_t is a keyword with the right semantics
|
||||
|
||||
extern char * strndup16to8 (const char16_t* s, size_t n);
|
||||
extern size_t strnlen16to8 (const char16_t* s, size_t n);
|
||||
extern char * strncpy16to8 (char *dest, const char16_t*s, size_t n);
|
||||
|
||||
extern char16_t * strdup8to16 (const char* s, size_t *out_len);
|
||||
extern size_t strlen8to16 (const char* utf8Str);
|
||||
extern char16_t * strcpy8to16 (char16_t *dest, const char*s, size_t *out_len);
|
||||
extern char16_t * strcpylen8to16 (char16_t *dest, const char*s, int length,
|
||||
size_t *out_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CUTILS_STRING16_H */
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 _CUTILS_KLOG_H_
|
||||
#define _CUTILS_KLOG_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/uio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
void klog_init(void);
|
||||
int klog_get_level(void);
|
||||
void klog_set_level(int level);
|
||||
/* TODO: void klog_close(void); - and make klog_fd users thread safe. */
|
||||
|
||||
void klog_write(int level, const char *fmt, ...)
|
||||
__attribute__ ((format(printf, 2, 3)));
|
||||
void klog_writev(int level, const struct iovec* iov, int iov_count);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#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 */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2008-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_LIST_H_
|
||||
#define _CUTILS_LIST_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct listnode
|
||||
{
|
||||
struct listnode *next;
|
||||
struct listnode *prev;
|
||||
};
|
||||
|
||||
#define node_to_item(node, container, member) \
|
||||
(container *) (((char*) (node)) - offsetof(container, member))
|
||||
|
||||
#define list_declare(name) \
|
||||
struct listnode name = { \
|
||||
.next = &name, \
|
||||
.prev = &name, \
|
||||
}
|
||||
|
||||
#define list_for_each(node, list) \
|
||||
for (node = (list)->next; node != (list); node = node->next)
|
||||
|
||||
#define list_for_each_reverse(node, list) \
|
||||
for (node = (list)->prev; node != (list); node = node->prev)
|
||||
|
||||
#define list_for_each_safe(node, n, list) \
|
||||
for (node = (list)->next, n = node->next; \
|
||||
node != (list); \
|
||||
node = n, n = node->next)
|
||||
|
||||
static inline void list_init(struct listnode *node)
|
||||
{
|
||||
node->next = node;
|
||||
node->prev = node;
|
||||
}
|
||||
|
||||
static inline void list_add_tail(struct listnode *head, struct listnode *item)
|
||||
{
|
||||
item->next = head;
|
||||
item->prev = head->prev;
|
||||
head->prev->next = 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;
|
||||
item->prev->next = item->next;
|
||||
}
|
||||
|
||||
#define list_empty(list) ((list) == (list)->next)
|
||||
#define list_head(list) ((list)->next)
|
||||
#define list_tail(list) ((list)->prev)
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1 @@
|
||||
#include <log/log.h>
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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_MEMORY_H
|
||||
#define ANDROID_CUTILS_MEMORY_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* size is given in bytes and must be multiple of 2 */
|
||||
void android_memset16(uint16_t* dst, uint16_t value, size_t size);
|
||||
|
||||
/* size is given in bytes and must be multiple of 4 */
|
||||
void android_memset32(uint32_t* dst, uint32_t value, size_t size);
|
||||
|
||||
#if defined(__GLIBC__) || defined(_WIN32)
|
||||
/* Declaration of strlcpy() for platforms that don't already have it. */
|
||||
size_t strlcpy(char *dst, const char *src, size_t size);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // ANDROID_CUTILS_MEMORY_H
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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_MISC_H
|
||||
#define __CUTILS_MISC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Load an entire file into a malloc'd chunk of memory
|
||||
* that is length_of_file + 1 (null terminator). If
|
||||
* sz is non-zero, return the size of the file via sz.
|
||||
* Returns 0 on failure.
|
||||
*/
|
||||
extern void *load_file(const char *fn, unsigned *sz);
|
||||
|
||||
/* This is the range of UIDs (and GIDs) that are reserved
|
||||
* for assigning to applications.
|
||||
*/
|
||||
#define FIRST_APPLICATION_UID 10000
|
||||
#define LAST_APPLICATION_UID 99999
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CUTILS_MISC_H */
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 __CUTILS_MULTIUSER_H
|
||||
#define __CUTILS_MULTIUSER_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// NOTE: keep in sync with android.os.UserId
|
||||
|
||||
#define MULTIUSER_APP_PER_USER_RANGE 100000
|
||||
|
||||
typedef uid_t userid_t;
|
||||
typedef uid_t appid_t;
|
||||
|
||||
extern userid_t multiuser_get_user_id(uid_t uid);
|
||||
extern appid_t multiuser_get_app_id(uid_t uid);
|
||||
extern uid_t multiuser_get_uid(userid_t userId, appid_t appId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CUTILS_MULTIUSER_H */
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2009 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 NATIVE_HANDLE_H_
|
||||
#define NATIVE_HANDLE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct native_handle
|
||||
{
|
||||
int version; /* sizeof(native_handle_t) */
|
||||
int numFds; /* number of file-descriptors at &data[0] */
|
||||
int numInts; /* number of ints at &data[numFds] */
|
||||
int data[0]; /* numFds + numInts ints */
|
||||
} native_handle_t;
|
||||
|
||||
/*
|
||||
* native_handle_close
|
||||
*
|
||||
* closes the file descriptors contained in this native_handle_t
|
||||
*
|
||||
* return 0 on success, or a negative error code on failure
|
||||
*
|
||||
*/
|
||||
int native_handle_close(const native_handle_t* h);
|
||||
|
||||
|
||||
/*
|
||||
* native_handle_create
|
||||
*
|
||||
* creates a native_handle_t and initializes it. must be destroyed with
|
||||
* native_handle_delete().
|
||||
*
|
||||
*/
|
||||
native_handle_t* native_handle_create(int numFds, int numInts);
|
||||
|
||||
/*
|
||||
* native_handle_delete
|
||||
*
|
||||
* frees a native_handle_t allocated with native_handle_create().
|
||||
* This ONLY frees the memory allocated for the native_handle_t, but doesn't
|
||||
* close the file descriptors; which can be achieved with native_handle_close().
|
||||
*
|
||||
* return 0 on success, or a negative error code on failure
|
||||
*
|
||||
*/
|
||||
int native_handle_delete(native_handle_t* h);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NATIVE_HANDLE_H_ */
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 __CUTILS_OPEN_MEMSTREAM_H__
|
||||
#define __CUTILS_OPEN_MEMSTREAM_H__
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
FILE* open_memstream(char** bufp, size_t* sizep);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
#endif /*__CUTILS_OPEN_MEMSTREAM_H__*/
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2011, 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_PARTITION_WIPED_H__
|
||||
#define __CUTILS_PARTITION_WIPED_H__
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int partition_wiped(char *source);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* __CUTILS_PARTITION_WIPED_H__ */
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gives the current process a name.
|
||||
*/
|
||||
|
||||
#ifndef __PROCESS_NAME_H
|
||||
#define __PROCESS_NAME_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Sets the current process name.
|
||||
*
|
||||
* Warning: This leaks a string every time you call it. Use judiciously!
|
||||
*/
|
||||
void set_process_name(const char* process_name);
|
||||
|
||||
/** Gets the current process name. */
|
||||
const char* get_process_name(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PROCESS_NAME_H */
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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_PROPERTIES_H
|
||||
#define __CUTILS_PROPERTIES_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/system_properties.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* System properties are *small* name value pairs managed by the
|
||||
** property service. If your data doesn't fit in the provided
|
||||
** space it is not appropriate for a system property.
|
||||
**
|
||||
** WARNING: system/bionic/include/sys/system_properties.h also defines
|
||||
** these, but with different names. (TODO: fix that)
|
||||
*/
|
||||
#define PROPERTY_KEY_MAX PROP_NAME_MAX
|
||||
#define PROPERTY_VALUE_MAX PROP_VALUE_MAX
|
||||
|
||||
/* property_get: returns the length of the value which will never be
|
||||
** greater than PROPERTY_VALUE_MAX - 1 and will always be zero terminated.
|
||||
** (the length does not include the terminating zero).
|
||||
**
|
||||
** If the property read fails or returns an empty value, the default
|
||||
** value is used (if nonnull).
|
||||
*/
|
||||
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);
|
||||
|
||||
int property_list(void (*propfn)(const char *key, const char *value, void *cookie), void *cookie);
|
||||
|
||||
#if defined(__BIONIC_FORTIFY)
|
||||
|
||||
extern int __property_get_real(const char *, char *, const char *)
|
||||
__asm__(__USER_LABEL_PREFIX__ "property_get");
|
||||
__errordecl(__property_get_too_small_error, "property_get() called with too small of a buffer");
|
||||
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
int property_get(const char *key, char *value, const char *default_value) {
|
||||
size_t bos = __bos(value);
|
||||
if (bos < PROPERTY_VALUE_MAX) {
|
||||
__property_get_too_small_error();
|
||||
}
|
||||
return __property_get_real(key, value, default_value);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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_QTAGUID_H
|
||||
#define __CUTILS_QTAGUID_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Set tags (and owning UIDs) for network sockets.
|
||||
*/
|
||||
extern int qtaguid_tagSocket(int sockfd, int tag, uid_t uid);
|
||||
|
||||
/*
|
||||
* Untag a network socket before closing.
|
||||
*/
|
||||
extern int qtaguid_untagSocket(int sockfd);
|
||||
|
||||
/*
|
||||
* For the given uid, switch counter sets.
|
||||
* The kernel only keeps a limited number of sets.
|
||||
* 2 for now.
|
||||
*/
|
||||
extern int qtaguid_setCounterSet(int counterSetNum, uid_t uid);
|
||||
|
||||
/*
|
||||
* Delete all tag info that relates to the given tag an uid.
|
||||
* If the tag is 0, then ALL info about the uid is freeded.
|
||||
* The delete data also affects active tagged socketd, which are
|
||||
* then untagged.
|
||||
* The calling process can only operate on its own tags.
|
||||
* Unless it is part of the happy AID_NET_BW_ACCT group.
|
||||
* In which case it can clobber everything.
|
||||
*/
|
||||
extern int qtaguid_deleteTagData(int tag, uid_t uid);
|
||||
|
||||
/*
|
||||
* Enable/disable qtaguid functionnality at a lower level.
|
||||
* When pacified, the kernel will accept commands but do nothing.
|
||||
*/
|
||||
extern int qtaguid_setPacifier(int on);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CUTILS_QTAG_UID_H */
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* A simple utility for reading fixed records out of a stream fd
|
||||
*/
|
||||
|
||||
#ifndef _CUTILS_RECORD_STREAM_H
|
||||
#define _CUTILS_RECORD_STREAM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct RecordStream RecordStream;
|
||||
|
||||
extern RecordStream *record_stream_new(int fd, size_t maxRecordLen);
|
||||
extern void record_stream_free(RecordStream *p_rs);
|
||||
|
||||
extern int record_stream_get_next (RecordStream *p_rs, void ** p_outRecord,
|
||||
size_t *p_outRecordLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /*_CUTILS_RECORD_STREAM_H*/
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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_SCHED_POLICY_H
|
||||
#define __CUTILS_SCHED_POLICY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Keep in sync with THREAD_GROUP_* in frameworks/base/core/java/android/os/Process.java */
|
||||
typedef enum {
|
||||
SP_DEFAULT = -1,
|
||||
SP_BACKGROUND = 0,
|
||||
SP_FOREGROUND = 1,
|
||||
SP_SYSTEM = 2, // can't be used with set_sched_policy()
|
||||
SP_AUDIO_APP = 3,
|
||||
SP_AUDIO_SYS = 4,
|
||||
SP_CNT,
|
||||
SP_MAX = SP_CNT - 1,
|
||||
SP_SYSTEM_DEFAULT = SP_FOREGROUND,
|
||||
} SchedPolicy;
|
||||
|
||||
extern int set_cpuset_policy(int tid, SchedPolicy policy);
|
||||
|
||||
/* Assign thread tid to the cgroup associated with the specified policy.
|
||||
* If the thread is a thread group leader, that is it's gettid() == getpid(),
|
||||
* then the other threads in the same thread group are _not_ affected.
|
||||
* On platforms which support gettid(), zero tid means current thread.
|
||||
* Return value: 0 for success, or -errno for error.
|
||||
*/
|
||||
extern int set_sched_policy(int tid, SchedPolicy policy);
|
||||
|
||||
/* Return the policy associated with the cgroup of thread tid via policy pointer.
|
||||
* On platforms which support gettid(), zero tid means current thread.
|
||||
* Return value: 0 for success, or -1 for error and set errno.
|
||||
*/
|
||||
extern int get_sched_policy(int tid, SchedPolicy *policy);
|
||||
|
||||
/* Return a displayable string corresponding to policy.
|
||||
* Return value: non-NULL NUL-terminated name of unspecified length;
|
||||
* the caller is responsible for displaying the useful part of the string.
|
||||
*/
|
||||
extern const char *get_sched_policy_name(SchedPolicy policy);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CUTILS_SCHED_POLICY_H */
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2006 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_SOCKETS_H
|
||||
#define __CUTILS_SOCKETS_H
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef HAVE_WINSOCK
|
||||
#include <winsock2.h>
|
||||
typedef int socklen_t;
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#define ANDROID_SOCKET_ENV_PREFIX "ANDROID_SOCKET_"
|
||||
#define ANDROID_SOCKET_DIR "/dev/socket"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* android_get_control_socket - simple helper function to get the file
|
||||
* descriptor of our init-managed Unix domain socket. `name' is the name of the
|
||||
* socket, as given in init.rc. Returns -1 on error.
|
||||
*
|
||||
* This is inline and not in libcutils proper because we want to use this in
|
||||
* third-party daemons with minimal modification.
|
||||
*/
|
||||
static inline int android_get_control_socket(const char *name)
|
||||
{
|
||||
char key[64];
|
||||
snprintf(key, sizeof(key), ANDROID_SOCKET_ENV_PREFIX "%s", name);
|
||||
|
||||
const char* val = getenv(key);
|
||||
if (!val) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
int fd = strtol(val, NULL, 10);
|
||||
if (errno) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
/*
|
||||
* See also android.os.LocalSocketAddress.Namespace
|
||||
*/
|
||||
// Linux "abstract" (non-filesystem) namespace
|
||||
#define ANDROID_SOCKET_NAMESPACE_ABSTRACT 0
|
||||
// Android "reserved" (/dev/socket) namespace
|
||||
#define ANDROID_SOCKET_NAMESPACE_RESERVED 1
|
||||
// Normal filesystem namespace
|
||||
#define ANDROID_SOCKET_NAMESPACE_FILESYSTEM 2
|
||||
|
||||
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);
|
||||
extern int socket_local_client_connect(int fd,
|
||||
const char *name, int namespaceId, int type);
|
||||
extern int socket_local_client(const char *name, int namespaceId, int type);
|
||||
extern int socket_inaddr_any_server(int port, int type);
|
||||
|
||||
/*
|
||||
* socket_peer_is_trusted - Takes a socket which is presumed to be a
|
||||
* connected local socket (e.g. AF_LOCAL) and returns whether the peer
|
||||
* (the userid that owns the process on the other end of that socket)
|
||||
* is one of the two trusted userids, root or shell.
|
||||
*
|
||||
* Note: This only works as advertised on the Android OS and always
|
||||
* just returns true when called on other operating systems.
|
||||
*/
|
||||
extern bool socket_peer_is_trusted(int fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CUTILS_SOCKETS_H */
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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_STR_PARMS_H
|
||||
#define __CUTILS_STR_PARMS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
struct str_parms;
|
||||
|
||||
struct str_parms *str_parms_create(void);
|
||||
struct str_parms *str_parms_create_str(const char *_string);
|
||||
void str_parms_destroy(struct str_parms *str_parms);
|
||||
|
||||
void str_parms_del(struct str_parms *str_parms, const char *key);
|
||||
|
||||
int str_parms_add_str(struct str_parms *str_parms, const char *key,
|
||||
const char *value);
|
||||
int str_parms_add_int(struct str_parms *str_parms, const char *key, int value);
|
||||
|
||||
int str_parms_add_float(struct str_parms *str_parms, const char *key,
|
||||
float value);
|
||||
|
||||
// Returns non-zero if the str_parms contains the specified key.
|
||||
int str_parms_has_key(struct str_parms *str_parms, const char *key);
|
||||
|
||||
// Gets value associated with the specified key (if present), placing it in the buffer
|
||||
// pointed to by the out_val parameter. Returns the length of the returned string value.
|
||||
// If 'key' isn't in the parms, then return -ENOENT (-2) and leave 'out_val' untouched.
|
||||
int str_parms_get_str(struct str_parms *str_parms, const char *key,
|
||||
char *out_val, int len);
|
||||
int str_parms_get_int(struct str_parms *str_parms, const char *key,
|
||||
int *out_val);
|
||||
int str_parms_get_float(struct str_parms *str_parms, const char *key,
|
||||
float *out_val);
|
||||
|
||||
char *str_parms_to_str(struct str_parms *str_parms);
|
||||
|
||||
/* debug */
|
||||
void str_parms_dump(struct str_parms *str_parms);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* __CUTILS_STR_PARMS_H */
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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_THREADS_H
|
||||
#define _LIBS_CUTILS_THREADS_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***********************************************************************/
|
||||
/***********************************************************************/
|
||||
/***** *****/
|
||||
/***** local thread storage *****/
|
||||
/***** *****/
|
||||
/***********************************************************************/
|
||||
/***********************************************************************/
|
||||
|
||||
extern pid_t gettid();
|
||||
|
||||
#if !defined(_WIN32)
|
||||
|
||||
typedef struct {
|
||||
pthread_mutex_t lock;
|
||||
int has_tls;
|
||||
pthread_key_t tls;
|
||||
} thread_store_t;
|
||||
|
||||
#define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 }
|
||||
|
||||
#else // !defined(_WIN32)
|
||||
|
||||
typedef struct {
|
||||
int lock_init;
|
||||
int has_tls;
|
||||
DWORD tls;
|
||||
CRITICAL_SECTION lock;
|
||||
} thread_store_t;
|
||||
|
||||
#define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} }
|
||||
|
||||
#endif // !defined(_WIN32)
|
||||
|
||||
typedef void (*thread_store_destruct_t)(void* value);
|
||||
|
||||
extern void* thread_store_get(thread_store_t* store);
|
||||
|
||||
extern void thread_store_set(thread_store_t* store,
|
||||
void* value,
|
||||
thread_store_destruct_t destroy);
|
||||
|
||||
/***********************************************************************/
|
||||
/***********************************************************************/
|
||||
/***** *****/
|
||||
/***** mutexes *****/
|
||||
/***** *****/
|
||||
/***********************************************************************/
|
||||
/***********************************************************************/
|
||||
|
||||
#if !defined(_WIN32)
|
||||
|
||||
typedef pthread_mutex_t mutex_t;
|
||||
|
||||
#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
||||
|
||||
static __inline__ void mutex_lock(mutex_t* lock)
|
||||
{
|
||||
pthread_mutex_lock(lock);
|
||||
}
|
||||
static __inline__ void mutex_unlock(mutex_t* lock)
|
||||
{
|
||||
pthread_mutex_unlock(lock);
|
||||
}
|
||||
static __inline__ int mutex_init(mutex_t* lock)
|
||||
{
|
||||
return pthread_mutex_init(lock, NULL);
|
||||
}
|
||||
static __inline__ void mutex_destroy(mutex_t* lock)
|
||||
{
|
||||
pthread_mutex_destroy(lock);
|
||||
}
|
||||
|
||||
#else // !defined(_WIN32)
|
||||
|
||||
typedef struct {
|
||||
int init;
|
||||
CRITICAL_SECTION lock[1];
|
||||
} mutex_t;
|
||||
|
||||
#define MUTEX_INITIALIZER { 0, {{ NULL, 0, 0, NULL, NULL, 0 }} }
|
||||
|
||||
static __inline__ void mutex_lock(mutex_t* lock)
|
||||
{
|
||||
if (!lock->init) {
|
||||
lock->init = 1;
|
||||
InitializeCriticalSection( lock->lock );
|
||||
lock->init = 2;
|
||||
} else while (lock->init != 2)
|
||||
Sleep(10);
|
||||
|
||||
EnterCriticalSection(lock->lock);
|
||||
}
|
||||
|
||||
static __inline__ void mutex_unlock(mutex_t* lock)
|
||||
{
|
||||
LeaveCriticalSection(lock->lock);
|
||||
}
|
||||
static __inline__ int mutex_init(mutex_t* lock)
|
||||
{
|
||||
InitializeCriticalSection(lock->lock);
|
||||
lock->init = 2;
|
||||
return 0;
|
||||
}
|
||||
static __inline__ void mutex_destroy(mutex_t* lock)
|
||||
{
|
||||
if (lock->init) {
|
||||
lock->init = 0;
|
||||
DeleteCriticalSection(lock->lock);
|
||||
}
|
||||
}
|
||||
#endif // !defined(_WIN32)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LIBS_CUTILS_THREADS_H */
|
||||
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* 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 <inttypes.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cutils/compiler.h>
|
||||
|
||||
__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_APP (1<<12)
|
||||
#define ATRACE_TAG_RESOURCES (1<<13)
|
||||
#define ATRACE_TAG_DALVIK (1<<14)
|
||||
#define ATRACE_TAG_RS (1<<15)
|
||||
#define ATRACE_TAG_BIONIC (1<<16)
|
||||
#define ATRACE_TAG_POWER (1<<17)
|
||||
#define ATRACE_TAG_LAST ATRACE_TAG_POWER
|
||||
|
||||
// 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
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Set whether the process is debuggable. By default the process is not
|
||||
* considered debuggable. If the process is not debuggable then application-
|
||||
* level tracing is not allowed unless the ro.debuggable system property is
|
||||
* set to '1'.
|
||||
*/
|
||||
void atrace_set_debuggable(bool debuggable);
|
||||
|
||||
/**
|
||||
* Set whether tracing is enabled for the current process. This is used to
|
||||
* prevent tracing within the Zygote process.
|
||||
*/
|
||||
void atrace_set_tracing_enabled(bool enabled);
|
||||
|
||||
/**
|
||||
* 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 atomic_bool 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(!atomic_load_explicit(&atrace_is_ready, memory_order_acquire))) {
|
||||
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))) {
|
||||
void atrace_begin_body(const char*);
|
||||
atrace_begin_body(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trace the beginning of an asynchronous event. Unlike ATRACE_BEGIN/ATRACE_END
|
||||
* contexts, asynchronous events do not need to be nested. The name describes
|
||||
* the event, and the cookie provides a unique identifier for distinguishing
|
||||
* simultaneous events. The name and cookie used to begin an event must be
|
||||
* used to end it.
|
||||
*/
|
||||
#define ATRACE_ASYNC_BEGIN(name, cookie) \
|
||||
atrace_async_begin(ATRACE_TAG, name, cookie)
|
||||
static inline void atrace_async_begin(uint64_t tag, const char* name,
|
||||
int32_t cookie)
|
||||
{
|
||||
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
|
||||
void atrace_async_begin_body(const char*, int32_t);
|
||||
atrace_async_begin_body(name, cookie);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trace the end of an asynchronous event.
|
||||
* This should have a corresponding ATRACE_ASYNC_BEGIN.
|
||||
*/
|
||||
#define ATRACE_ASYNC_END(name, cookie) atrace_async_end(ATRACE_TAG, name, cookie)
|
||||
static inline void atrace_async_end(uint64_t tag, const char* name, int32_t cookie)
|
||||
{
|
||||
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
|
||||
void atrace_async_end_body(const char*, int32_t);
|
||||
atrace_async_end_body(name, cookie);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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))) {
|
||||
void atrace_int_body(const char*, int32_t);
|
||||
atrace_int_body(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Traces a 64-bit integer counter value. name is used to identify the
|
||||
* counter. This can be used to track how a value changes over time.
|
||||
*/
|
||||
#define ATRACE_INT64(name, value) atrace_int64(ATRACE_TAG, name, value)
|
||||
static inline void atrace_int64(uint64_t tag, const char* name, int64_t value)
|
||||
{
|
||||
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
|
||||
void atrace_int64_body(const char*, int64_t);
|
||||
atrace_int64_body(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBS_CUTILS_TRACE_H
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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_UEVENT_H
|
||||
#define __CUTILS_UEVENT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int uevent_open_socket(int buf_sz, bool passcred);
|
||||
ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length);
|
||||
ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer, size_t length, uid_t *uid);
|
||||
ssize_t uevent_kernel_recv(int socket, void *buffer, size_t length, bool require_group, uid_t *uid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CUTILS_UEVENT_H */
|
||||
Reference in New Issue
Block a user