aboutsummaryrefslogtreecommitdiffstats
path: root/include/cutils
diff options
context:
space:
mode:
authorSteve Kondik <shade@chemlab.org>2012-11-18 19:19:50 -0800
committerSteve Kondik <shade@chemlab.org>2012-11-18 19:19:50 -0800
commit39d33d8d54ba55e49f9b430f842647a84751cb85 (patch)
treef5a3756ea25d3b87902ae6a6a8df2428509e4246 /include/cutils
parentd8aa8ab7424be375e4408ab360c000ac8b05d15d (diff)
parent31da9db0d1bf3227e3c383aa6ac28bde3c6409e5 (diff)
downloadsystem_core-39d33d8d54ba55e49f9b430f842647a84751cb85.tar.gz
system_core-39d33d8d54ba55e49f9b430f842647a84751cb85.tar.bz2
system_core-39d33d8d54ba55e49f9b430f842647a84751cb85.zip
Merge branch 'jb-mr1-release' of https://android.googlesource.com/platform/system/core into mr1
Conflicts: adb/Android.mk adb/usb_vendors.c include/private/android_filesystem_config.h include/system/audio.h include/system/camera.h init/property_service.c libnetutils/ifc_utils.c mkbootimg/mkbootimg.c rootdir/init.rc Change-Id: Ie42f0c14808e9f8cabd24854bfe15b6667955229
Diffstat (limited to 'include/cutils')
-rw-r--r--include/cutils/atomic-inline.h4
-rw-r--r--include/cutils/atomic-mips.h187
-rw-r--r--include/cutils/fs.h62
-rw-r--r--include/cutils/mspace.h128
-rw-r--r--include/cutils/multiuser.h41
5 files changed, 292 insertions, 130 deletions
diff --git a/include/cutils/atomic-inline.h b/include/cutils/atomic-inline.h
index 49f3e702..0b13138d 100644
--- a/include/cutils/atomic-inline.h
+++ b/include/cutils/atomic-inline.h
@@ -47,8 +47,8 @@ extern "C" {
#include <cutils/atomic-arm.h>
#elif defined(__i386__) || defined(__x86_64__)
#include <cutils/atomic-x86.h>
-#elif defined(__sh__)
-/* implementation is in atomic-android-sh.c */
+#elif defined(__mips__)
+#include <cutils/atomic-mips.h>
#else
#error atomic operations are unsupported
#endif
diff --git a/include/cutils/atomic-mips.h b/include/cutils/atomic-mips.h
new file mode 100644
index 00000000..49144a37
--- /dev/null
+++ b/include/cutils/atomic-mips.h
@@ -0,0 +1,187 @@
+/*
+ * 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_MIPS_H
+#define ANDROID_CUTILS_ATOMIC_MIPS_H
+
+#include <stdint.h>
+
+extern inline void android_compiler_barrier(void)
+{
+ __asm__ __volatile__ ("" : : : "memory");
+}
+
+#if ANDROID_SMP == 0
+extern inline void android_memory_barrier(void)
+{
+ android_compiler_barrier();
+}
+extern inline void android_memory_store_barrier(void)
+{
+ android_compiler_barrier();
+}
+#else
+extern inline void android_memory_barrier(void)
+{
+ __asm__ __volatile__ ("sync" : : : "memory");
+}
+extern inline void android_memory_store_barrier(void)
+{
+ __asm__ __volatile__ ("sync" : : : "memory");
+}
+#endif
+
+extern inline int32_t android_atomic_acquire_load(volatile const int32_t *ptr)
+{
+ int32_t value = *ptr;
+ android_memory_barrier();
+ return value;
+}
+
+extern inline int32_t android_atomic_release_load(volatile const int32_t *ptr)
+{
+ android_memory_barrier();
+ return *ptr;
+}
+
+extern inline void android_atomic_acquire_store(int32_t value,
+ volatile int32_t *ptr)
+{
+ *ptr = value;
+ android_memory_barrier();
+}
+
+extern inline void android_atomic_release_store(int32_t value,
+ volatile int32_t *ptr)
+{
+ android_memory_barrier();
+ *ptr = value;
+}
+
+extern inline int android_atomic_cas(int32_t old_value, int32_t new_value,
+ volatile int32_t *ptr)
+{
+ 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 inline int android_atomic_acquire_cas(int32_t old_value,
+ int32_t new_value,
+ volatile int32_t *ptr)
+{
+ int status = android_atomic_cas(old_value, new_value, ptr);
+ android_memory_barrier();
+ return status;
+}
+
+extern inline int android_atomic_release_cas(int32_t old_value,
+ int32_t new_value,
+ volatile int32_t *ptr)
+{
+ android_memory_barrier();
+ return android_atomic_cas(old_value, new_value, ptr);
+}
+
+
+extern inline int32_t android_atomic_swap(int32_t new_value,
+ volatile int32_t *ptr)
+{
+ 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 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 inline int32_t android_atomic_inc(volatile int32_t *addr)
+{
+ return android_atomic_add(1, addr);
+}
+
+extern inline int32_t android_atomic_dec(volatile int32_t *addr)
+{
+ return android_atomic_add(-1, addr);
+}
+
+extern 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 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/fs.h b/include/cutils/fs.h
new file mode 100644
index 00000000..fd5296bb
--- /dev/null
+++ b/include/cutils/fs.h
@@ -0,0 +1,62 @@
+/*
+ * 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>
+
+/*
+ * 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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CUTILS_FS_H */
diff --git a/include/cutils/mspace.h b/include/cutils/mspace.h
deleted file mode 100644
index 93fe48ee..00000000
--- a/include/cutils/mspace.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * 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 wrapper file for dlmalloc.h that defines prototypes for the
- * mspace_*() functions, which provide an interface for creating
- * multiple heaps.
- */
-
-#ifndef MSPACE_H_
-#define MSPACE_H_
-
-/* It's a pain getting the mallinfo stuff to work
- * with Linux, OSX, and klibc, so just turn it off
- * for now.
- * TODO: make mallinfo work
- */
-#define NO_MALLINFO 1
-
-/* Allow setting the maximum heap footprint.
- */
-#define USE_MAX_ALLOWED_FOOTPRINT 1
-
-#define USE_CONTIGUOUS_MSPACES 1
-#if USE_CONTIGUOUS_MSPACES
-#define HAVE_MMAP 0
-#define HAVE_MORECORE 1
-#define MORECORE_CONTIGUOUS 0
-#endif
-
-#define MSPACES 1
-#define ONLY_MSPACES 1
-#include "../../../../bionic/libc/bionic/dlmalloc.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- mspace_usable_size(void* p);
-
- Returns the number of bytes you can actually use in
- an allocated chunk, which may be more than you requested (although
- often not) due to alignment and minimum size constraints.
- You can use this many bytes without worrying about
- overwriting other allocated objects. This is not a particularly great
- programming practice. mspace_usable_size can be more useful in
- debugging and assertions, for example:
-
- p = mspace_malloc(msp, n);
- assert(mspace_usable_size(msp, p) >= 256);
-*/
-size_t mspace_usable_size(mspace, const void*);
-
-#if USE_CONTIGUOUS_MSPACES
-/*
- Similar to create_mspace(), but the underlying memory is
- guaranteed to be contiguous. No more than max_capacity
- bytes is ever allocated to the mspace.
- */
-mspace create_contiguous_mspace(size_t starting_capacity, size_t max_capacity,
- int locked);
-
-/*
- Identical to create_contiguous_mspace, but labels the mapping 'mspace/name'
- instead of 'mspace'
-*/
-mspace create_contiguous_mspace_with_name(size_t starting_capacity,
- size_t max_capacity, int locked, const char *name);
-
-/*
- Identical to create_contiguous_mspace, but uses previously mapped memory.
-*/
-mspace create_contiguous_mspace_with_base(size_t starting_capacity,
- size_t max_capacity, int locked, void *base);
-
-size_t destroy_contiguous_mspace(mspace msp);
-
-/*
- Returns the position of the "break" within the given mspace.
-*/
-void *contiguous_mspace_sbrk0(mspace msp);
-#endif
-
-/*
- Call the handler for each block in the specified mspace.
- chunkptr and chunklen refer to the heap-level chunk including
- the chunk overhead, and userptr and userlen refer to the
- user-usable part of the chunk. If the chunk is free, userptr
- will be NULL and userlen will be 0. userlen is not guaranteed
- to be the same value passed into malloc() for a given chunk;
- it is >= the requested size.
- */
-void mspace_walk_heap(mspace msp,
- void(*handler)(const void *chunkptr, size_t chunklen,
- const void *userptr, size_t userlen, void *arg), void *harg);
-
-/*
- mspace_walk_free_pages(handler, harg)
-
- Calls the provided handler on each free region in the specified
- mspace. The memory between start and end are guaranteed not to
- contain any important data, so the handler is free to alter the
- contents in any way. This can be used to advise the OS that large
- free regions may be swapped out.
-
- The value in harg will be passed to each call of the handler.
- */
-void mspace_walk_free_pages(mspace msp,
- void(*handler)(void *start, void *end, void *arg), void *harg);
-
-#ifdef __cplusplus
-}; /* end of extern "C" */
-#endif
-
-#endif /* MSPACE_H_ */
diff --git a/include/cutils/multiuser.h b/include/cutils/multiuser.h
new file mode 100644
index 00000000..635ddb13
--- /dev/null
+++ b/include/cutils/multiuser.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 */