diff options
Diffstat (limited to 'libcutils')
-rw-r--r-- | libcutils/Android.mk | 60 | ||||
-rw-r--r-- | libcutils/arch-mips/android_memset.S | 323 | ||||
-rw-r--r-- | libcutils/arch-mips/android_memset.c | 31 | ||||
-rw-r--r-- | libcutils/fs_config.c | 134 | ||||
-rw-r--r-- | libcutils/iosched_policy.c | 2 | ||||
-rw-r--r-- | libcutils/str_parms.c | 50 | ||||
-rw-r--r-- | libcutils/strlcpy.c (renamed from libcutils/memory.c) | 45 | ||||
-rw-r--r-- | libcutils/tests/Android.mk | 69 | ||||
-rw-r--r-- | libcutils/tests/test_str_parms.cpp | 57 | ||||
-rw-r--r-- | libcutils/trace-dev.c (renamed from libcutils/trace.c) | 0 | ||||
-rw-r--r-- | libcutils/trace-host.c | 35 |
11 files changed, 611 insertions, 195 deletions
diff --git a/libcutils/Android.mk b/libcutils/Android.mk index d890319..c636196 100644 --- a/libcutils/Android.mk +++ b/libcutils/Android.mk @@ -22,6 +22,7 @@ commonSources := \ native_handle.c \ config_utils.c \ load_file.c \ + strlcpy.c \ open_memstream.c \ strdup16to8.c \ strdup8to16.c \ @@ -31,6 +32,7 @@ commonSources := \ sched_policy.c \ iosched_policy.c \ str_parms.c \ + fs_config.c # some files must not be compiled when building against Mingw # they correspond to features not used by our host development tools @@ -59,7 +61,8 @@ ifneq ($(WINDOWS_HOST_ONLY),1) sockets.c \ commonHostSources += \ - ashmem-host.c + ashmem-host.c \ + trace-host.c endif @@ -73,7 +76,6 @@ ifneq ($(HOST_OS),windows) LOCAL_CFLAGS += -Werror endif LOCAL_MULTILIB := both -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk include $(BUILD_HOST_STATIC_LIBRARY) include $(CLEAR_VARS) @@ -84,22 +86,8 @@ ifneq ($(HOST_OS),windows) LOCAL_CFLAGS += -Werror endif LOCAL_MULTILIB := both -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk include $(BUILD_HOST_SHARED_LIBRARY) -# Tests for host -# ======================================================== -include $(CLEAR_VARS) -LOCAL_MODULE := tst_str_parms -LOCAL_CFLAGS += -DTEST_STR_PARMS -ifneq ($(HOST_OS),windows) -LOCAL_CFLAGS += -Werror -endif -LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c -LOCAL_STATIC_LIBRARIES := liblog -LOCAL_MODULE_TAGS := optional -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk -include $(BUILD_HOST_EXECUTABLE) # Shared and static library for target @@ -112,32 +100,19 @@ LOCAL_SRC_FILES := $(commonSources) \ ashmem-dev.c \ debugger.c \ klog.c \ - memory.c \ partition_utils.c \ properties.c \ qtaguid.c \ - trace.c \ + trace-dev.c \ uevent.c \ -LOCAL_SRC_FILES_arm += \ - arch-arm/memset32.S \ - # arch-arm/memset32.S does not compile with Clang. LOCAL_CLANG_ASFLAGS_arm += -no-integrated-as -LOCAL_SRC_FILES_arm64 += \ - arch-arm64/android_memset.S \ - -ifndef ARCH_MIPS_REV6 -LOCAL_SRC_FILES_mips += \ - arch-mips/android_memset.c \ - -LOCAL_CFLAGS_mips += -DHAVE_MEMSET16 -DHAVE_MEMSET32 -endif - -# TODO: switch mips64 back to using arch-mips/android_memset.c -LOCAL_SRC_FILES_mips64 += \ -# arch-mips/android_memset.c \ +LOCAL_SRC_FILES_arm += arch-arm/memset32.S +LOCAL_SRC_FILES_arm64 += arch-arm64/android_memset.S +LOCAL_SRC_FILES_mips += arch-mips/android_memset.S +LOCAL_SRC_FILES_mips64 += arch-mips/android_memset.S LOCAL_SRC_FILES_x86 += \ arch-x86/android_memset16.S \ @@ -147,16 +122,9 @@ LOCAL_SRC_FILES_x86_64 += \ arch-x86_64/android_memset16.S \ arch-x86_64/android_memset32.S \ -LOCAL_CFLAGS_arm += -DHAVE_MEMSET16 -DHAVE_MEMSET32 -LOCAL_CFLAGS_arm64 += -DHAVE_MEMSET16 -DHAVE_MEMSET32 -#LOCAL_CFLAGS_mips64 += -DHAVE_MEMSET16 -DHAVE_MEMSET32 -LOCAL_CFLAGS_x86 += -DHAVE_MEMSET16 -DHAVE_MEMSET32 -LOCAL_CFLAGS_x86_64 += -DHAVE_MEMSET16 -DHAVE_MEMSET32 - LOCAL_C_INCLUDES := $(libcutils_c_includes) LOCAL_STATIC_LIBRARIES := liblog LOCAL_CFLAGS += -Werror -std=gnu90 -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) @@ -167,16 +135,6 @@ LOCAL_WHOLE_STATIC_LIBRARIES := libcutils liblog LOCAL_SHARED_LIBRARIES := liblog LOCAL_CFLAGS += -Werror LOCAL_C_INCLUDES := $(libcutils_c_includes) -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk include $(BUILD_SHARED_LIBRARY) -include $(CLEAR_VARS) -LOCAL_MODULE := tst_str_parms -LOCAL_CFLAGS += -DTEST_STR_PARMS -Werror -LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c -LOCAL_SHARED_LIBRARIES := liblog -LOCAL_MODULE_TAGS := optional -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk -include $(BUILD_EXECUTABLE) - include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/libcutils/arch-mips/android_memset.S b/libcutils/arch-mips/android_memset.S new file mode 100644 index 0000000..6811de0 --- /dev/null +++ b/libcutils/arch-mips/android_memset.S @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2009 + * MIPS Technologies, Inc., California. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/************************************************************************ + * + * memset.S, version "64h" with 1 cache line horizon for "pref 30" and 14 nops + * Version: "043009" + * + ************************************************************************/ + + +/************************************************************************ + * Include files + ************************************************************************/ + +#include <machine/asm.h> +#define END(f) .cfi_endproc; .size f, .-f; .end f + +/* + * This routine could be optimized for MIPS64. The current code only + * uses MIPS32 instructions. + */ + +#if defined(__MIPSEB__) +# define SWHI swl /* high part is left in big-endian */ +# define SWLO swr /* low part is right in big-endian */ +#endif + +#if defined(__MIPSEL__) +# define SWHI swr /* high part is right in little-endian */ +# define SWLO swl /* low part is left in little-endian */ +#endif + +#if !(defined(XGPROF) || defined(XPROF)) +#undef SETUP_GP +#define SETUP_GP +#endif + +#ifdef NDEBUG +#define DBG # +#else +#define DBG +#endif + +/* + * void android_memset16(uint16_t* dst, uint16_t value, size_t size); + */ + +LEAF(android_memset16,0) + .set noreorder +DBG /* Check parameters */ +DBG andi t0,a0,1 # a0 must be halfword aligned +DBG tne t0,zero +DBG andi t2,a2,1 # a2 must be even +DBG tne t2,zero + +#ifdef FIXARGS + # ensure count is even +#if (__mips==32) && (__mips_isa_rev>=2) + ins a2,zero,0,1 +#else + ori a2,1 + xori a2,1 +#endif +#endif + +#if (__mips==32) && (__mips_isa_rev>=2) + ins a1,a1,16,16 +#else + andi a1,0xffff + sll t3,a1,16 + or a1,t3 +#endif + + beqz a2,.Ldone + andi t1,a0,2 + beqz t1,.Lalignok + addu t0,a0,a2 # t0 is the "past the end" address + sh a1,0(a0) # store one halfword to get aligned + addu a0,2 + subu a2,2 +.Lalignok: + slti t1,a2,4 # .Laligned for 4 or more bytes + beqz t1,.Laligned + sne t1,a2,2 # one more halfword? + bnez t1,.Ldone + nop + sh a1,0(a0) +.Ldone: + j ra + nop + .set reorder +END(android_memset16) + +/* + * void android_memset32(uint32_t* dst, uint32_t value, size_t size); + */ + +LEAF(android_memset32,0) + .set noreorder +DBG /* Check parameters */ +DBG andi t0,a0,3 # a0 must be word aligned +DBG tne t0,zero +DBG andi t2,a2,3 # a2 must be a multiple of 4 bytes +DBG tne t2,zero + +#ifdef FIXARGS + # ensure count is a multiple of 4 +#if (__mips==32) && (__mips_isa_rev>=2) + ins $a2,$0,0,2 +#else + ori a2,3 + xori a2,3 +#endif +#endif + + bnez a2,.Laligned # any work to do? + addu t0,a0,a2 # t0 is the "past the end" address + + j ra + nop + .set reorder +END(android_memset32) + +LEAF(memset,0) + + .set noreorder + .set noat + + addu t0,a0,a2 # t0 is the "past the end" address + slti AT,a2,4 # is a2 less than 4? + bne AT,zero,.Llast4 # if yes, go to last4 + move v0,a0 # memset returns the dst pointer + + beq a1,zero,.Lset0 + subu v1,zero,a0 + + # smear byte into 32 bit word +#if (__mips==32) && (__mips_isa_rev>=2) + ins a1, a1, 8, 8 # Replicate fill byte into half-word. + ins a1, a1, 16, 16 # Replicate fill byte into word. +#else + and a1,0xff + sll AT,a1,8 + or a1,AT + sll AT,a1,16 + or a1,AT +#endif + +.Lset0: + andi v1,v1,0x3 # word-unaligned address? + beq v1,zero,.Laligned # v1 is the unalignment count + subu a2,a2,v1 + SWHI a1,0(a0) + addu a0,a0,v1 + +# Here we have the "word-aligned" a0 (until the "last4") +.Laligned: + andi t8,a2,0x3f # any 64-byte chunks? + # t8 is the byte count past 64-byte chunks + beq a2,t8,.Lchk8w # when a2==t8, no 64-byte chunks + # There will be at most 1 32-byte chunk then + subu a3,a2,t8 # subtract from a2 the reminder + # Here a3 counts bytes in 16w chunks + addu a3,a0,a3 # Now a3 is the final dst after 64-byte chunks + +# Find out, if there are any 64-byte chunks after which will be still at least +# 96 bytes left. The value "96" is calculated as needed buffer for +# "pref 30,64(a0)" prefetch, which can be used as "pref 30,0(a0)" after +# incrementing "a0" by 64. +# For "a2" below 160 there will be no such "pref 30 safe" 64-byte chunk. +# + sltiu v1,a2,160 + bgtz v1,.Lloop16w_nopref30 # skip "pref 30,0(a0)" + subu t7,a2,96 # subtract "pref 30 unsafe" region + # below we have at least 1 64-byte chunk which is "pref 30 safe" + andi t6,t7,0x3f # t6 is past "64-byte safe chunks" reminder + subu t5,t7,t6 # subtract from t7 the reminder + # Here t5 counts bytes in 16w "safe" chunks + addu t4,a0,t5 # Now t4 is the dst after 64-byte "safe" chunks + +# Don't use "pref 30,0(a0)" for a0 in a "middle" of a cache line +# pref 30,0(a0) +# Here we are in the region, where it is safe to use "pref 30,64(a0)" +.Lloop16w: + addiu a0,a0,64 + pref 30,-32(a0) # continue setting up the dest, addr 64-32 + sw a1,-64(a0) + sw a1,-60(a0) + sw a1,-56(a0) + sw a1,-52(a0) + sw a1,-48(a0) + sw a1,-44(a0) + sw a1,-40(a0) + sw a1,-36(a0) + nop + nop # the extra nop instructions help to balance + nop # cycles needed for "store" + "fill" + "evict" + nop # For 64byte store there are needed 8 fill + nop # and 8 evict cycles, i.e. at least 32 instr. + nop + nop + pref 30,0(a0) # continue setting up the dest, addr 64-0 + sw a1,-32(a0) + sw a1,-28(a0) + sw a1,-24(a0) + sw a1,-20(a0) + sw a1,-16(a0) + sw a1,-12(a0) + sw a1,-8(a0) + sw a1,-4(a0) + nop + nop + nop + nop # NOTE: adding 14 nop-s instead of 12 nop-s + nop # gives better results for "fast" memory + nop + bne a0,t4,.Lloop16w + nop + + beq a0,a3,.Lchk8w # maybe no more 64-byte chunks? + nop # this "delayed slot" is useless ... + +.Lloop16w_nopref30: # there could be up to 3 "64-byte nopref30" chunks + addiu a0,a0,64 + sw a1,-64(a0) + sw a1,-60(a0) + sw a1,-56(a0) + sw a1,-52(a0) + sw a1,-48(a0) + sw a1,-44(a0) + sw a1,-40(a0) + sw a1,-36(a0) + sw a1,-32(a0) + sw a1,-28(a0) + sw a1,-24(a0) + sw a1,-20(a0) + sw a1,-16(a0) + sw a1,-12(a0) + sw a1,-8(a0) + bne a0,a3,.Lloop16w_nopref30 + sw a1,-4(a0) + +.Lchk8w: # t8 here is the byte count past 64-byte chunks + + andi t7,t8,0x1f # is there a 32-byte chunk? + # the t7 is the reminder count past 32-bytes + beq t8,t7,.Lchk1w # when t8==t7, no 32-byte chunk + move a2,t7 + + sw a1,0(a0) + sw a1,4(a0) + sw a1,8(a0) + sw a1,12(a0) + sw a1,16(a0) + sw a1,20(a0) + sw a1,24(a0) + sw a1,28(a0) + addiu a0,a0,32 + +.Lchk1w: + andi t8,a2,0x3 # now t8 is the reminder past 1w chunks + beq a2,t8,.Llast4aligned + subu a3,a2,t8 # a3 is the count of bytes in 1w chunks + addu a3,a0,a3 # now a3 is the dst address past the 1w chunks + +# copying in words (4-byte chunks) +.LwordCopy_loop: + addiu a0,a0,4 + bne a0,a3,.LwordCopy_loop + sw a1,-4(a0) + +# store last 0-3 bytes +# this will repeat the last store if the memset finishes on a word boundary +.Llast4aligned: + j ra + SWLO a1,-1(t0) + +.Llast4: + beq a0,t0,.Llast4e +.Llast4l: + addiu a0,a0,1 + bne a0,t0,.Llast4l + sb a1,-1(a0) +.Llast4e: + j ra + nop + + .set at + .set reorder + +END(memset) + + +/************************************************************************ + * Implementation : Static functions + ************************************************************************/ diff --git a/libcutils/arch-mips/android_memset.c b/libcutils/arch-mips/android_memset.c deleted file mode 100644 index bbc99fe..0000000 --- a/libcutils/arch-mips/android_memset.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -#include <cutils/memory.h> - -/* Use mips-assembler versions supplied by bionic/libc/arch-mips/string/memset.S: */ -void _memset16(uint16_t* dst, uint16_t value, size_t size); -void _memset32(uint32_t* dst, uint32_t value, size_t size); - -void android_memset16(uint16_t* dst, uint16_t value, size_t size) -{ - _memset16(dst, value, size); -} - -void android_memset32(uint32_t* dst, uint32_t value, size_t size) -{ - _memset32(dst, value, size); -} diff --git a/libcutils/fs_config.c b/libcutils/fs_config.c new file mode 100644 index 0000000..659f614 --- /dev/null +++ b/libcutils/fs_config.c @@ -0,0 +1,134 @@ +/* + * 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. + */ + +/* This file is used to define the properties of the filesystem +** images generated by build tools (mkbootfs and mkyaffs2image) and +** by the device side of adb. +*/ + +#include <stdint.h> +#include <string.h> +#include <sys/stat.h> + +#include <private/android_filesystem_config.h> + +/* Rules for directories. +** These rules are applied based on "first match", so they +** should start with the most specific path and work their +** way up to the root. +*/ + +static const struct fs_path_config android_dirs[] = { + { 00770, AID_SYSTEM, AID_CACHE, 0, "cache" }, + { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" }, + { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private" }, + { 00771, AID_ROOT, AID_ROOT, 0, "data/dalvik-cache" }, + { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/data" }, + { 00771, AID_SHELL, AID_SHELL, 0, "data/local/tmp" }, + { 00771, AID_SHELL, AID_SHELL, 0, "data/local" }, + { 01771, AID_SYSTEM, AID_MISC, 0, "data/misc" }, + { 00770, AID_DHCP, AID_DHCP, 0, "data/misc/dhcp" }, + { 00771, AID_SHARED_RELRO, AID_SHARED_RELRO, 0, "data/misc/shared_relro" }, + { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media" }, + { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" }, + { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" }, + { 00750, AID_ROOT, AID_SHELL, 0, "sbin" }, + { 00755, AID_ROOT, AID_SHELL, 0, "system/bin" }, + { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" }, + { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" }, + { 00755, AID_ROOT, AID_ROOT, 0, "system/etc/ppp" }, + { 00755, AID_ROOT, AID_SHELL, 0, "vendor" }, + { 00777, AID_ROOT, AID_ROOT, 0, "sdcard" }, + { 00755, AID_ROOT, AID_ROOT, 0, 0 }, +}; + +/* Rules for files. +** These rules are applied based on "first match", so they +** should start with the most specific path and work their +** way up to the root. Prefixes ending in * denotes wildcard +** and will allow partial matches. +*/ +static const struct fs_path_config android_files[] = { + { 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.rc" }, + { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.sh" }, + { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.ril" }, + { 00550, AID_DHCP, AID_SHELL, 0, "system/etc/dhcpcd/dhcpcd-run-hooks" }, + { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/ppp/*" }, + { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.*" }, + { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" }, + { 00644, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/*" }, + { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" }, + { 00644, AID_APP, AID_APP, 0, "data/data/*" }, + + /* the following five files are INTENTIONALLY set-uid, but they + * are NOT included on user builds. */ + { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" }, + { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/librank" }, + { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procrank" }, + { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" }, + { 04770, AID_ROOT, AID_RADIO, 0, "system/bin/pppd-ril" }, + + /* the following files have enhanced capabilities and ARE included in user builds. */ + { 00750, AID_ROOT, AID_SHELL, (1ULL << CAP_SETUID) | (1ULL << CAP_SETGID), "system/bin/run-as" }, + { 00700, AID_SYSTEM, AID_SHELL, (1ULL << CAP_BLOCK_SUSPEND), "system/bin/inputflinger" }, + + { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/uncrypt" }, + { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/install-recovery.sh" }, + { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" }, + { 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" }, + { 00755, AID_ROOT, AID_ROOT, 0, "system/lib64/valgrind/*" }, + { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" }, + { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/bin/*" }, + { 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" }, + { 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" }, + { 00755, AID_ROOT, AID_ROOT, 0, "bin/*" }, + { 00750, AID_ROOT, AID_SHELL, 0, "init*" }, + { 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" }, + { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" }, + { 00644, AID_ROOT, AID_ROOT, 0, 0 }, +}; + +void fs_config(const char *path, int dir, + unsigned *uid, unsigned *gid, unsigned *mode, uint64_t *capabilities) +{ + const struct fs_path_config *pc; + int plen; + + if (path[0] == '/') { + path++; + } + + pc = dir ? android_dirs : android_files; + plen = strlen(path); + for(; pc->prefix; pc++){ + int len = strlen(pc->prefix); + if (dir) { + if(plen < len) continue; + if(!strncmp(pc->prefix, path, len)) break; + continue; + } + /* If name ends in * then allow partial matches. */ + if (pc->prefix[len -1] == '*') { + if(!strncmp(pc->prefix, path, len - 1)) break; + } else if (plen == len){ + if(!strncmp(pc->prefix, path, len)) break; + } + } + *uid = pc->uid; + *gid = pc->gid; + *mode = (*mode & (~07777)) | pc->mode; + *capabilities = pc->capabilities; +} diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.c index a6da9ca..8946d3c 100644 --- a/libcutils/iosched_policy.c +++ b/libcutils/iosched_policy.c @@ -1,5 +1,5 @@ /* -** Copyright 2007-2014, The Android Open Source Project +** Copyright 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. diff --git a/libcutils/str_parms.c b/libcutils/str_parms.c index dfe8c4b..924289a 100644 --- a/libcutils/str_parms.c +++ b/libcutils/str_parms.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2013 The Android Open Source Project + * 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. @@ -357,51 +357,3 @@ void str_parms_dump(struct str_parms *str_parms) { hashmapForEach(str_parms->map, dump_entry, str_parms); } - -#ifdef TEST_STR_PARMS -static void test_str_parms_str(const char *str) -{ - struct str_parms *str_parms; - char *out_str; - - str_parms = str_parms_create_str(str); - str_parms_add_str(str_parms, "dude", "woah"); - str_parms_add_str(str_parms, "dude", "woah"); - str_parms_del(str_parms, "dude"); - str_parms_dump(str_parms); - out_str = str_parms_to_str(str_parms); - str_parms_destroy(str_parms); - ALOGI("%s: '%s' stringified is '%s'", __func__, str, out_str); - free(out_str); -} - -int main(void) -{ - test_str_parms_str(""); - test_str_parms_str(";"); - test_str_parms_str("="); - test_str_parms_str("=;"); - test_str_parms_str("=bar"); - test_str_parms_str("=bar;"); - test_str_parms_str("foo="); - test_str_parms_str("foo=;"); - test_str_parms_str("foo=bar"); - test_str_parms_str("foo=bar;"); - test_str_parms_str("foo=bar;baz"); - test_str_parms_str("foo=bar;baz="); - test_str_parms_str("foo=bar;baz=bat"); - test_str_parms_str("foo=bar;baz=bat;"); - test_str_parms_str("foo=bar;baz=bat;foo=bar"); - - // hashmapPut reports errors by setting errno to ENOMEM. - // Test that we're not confused by running in an environment where this is already true. - errno = ENOMEM; - test_str_parms_str("foo=bar;baz="); - if (errno != ENOMEM) { - abort(); - } - test_str_parms_str("foo=bar;baz="); - - return 0; -} -#endif diff --git a/libcutils/memory.c b/libcutils/strlcpy.c index 6486b45..c66246c 100644 --- a/libcutils/memory.c +++ b/libcutils/strlcpy.c @@ -1,43 +1,4 @@ /* - * 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. - */ - -#include <cutils/memory.h> - -#if !HAVE_MEMSET16 -void android_memset16(uint16_t* dst, uint16_t value, size_t size) -{ - size >>= 1; - while (size--) { - *dst++ = value; - } -} -#endif - -#if !HAVE_MEMSET32 -void android_memset32(uint32_t* dst, uint32_t value, size_t size) -{ - size >>= 2; - while (size--) { - *dst++ = value; - } -} -#endif - -#if !HAVE_STRLCPY -/* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> * * Permission to use, copy, modify, and distribute this software for any @@ -54,8 +15,13 @@ void android_memset32(uint32_t* dst, uint32_t value, size_t size) */ #include <sys/types.h> + +#if defined(__GLIBC__) || defined(_WIN32) + #include <string.h> +#include <cutils/memory.h> + /* Implementation of strlcpy() for platforms that don't already have it. */ /* @@ -88,4 +54,5 @@ strlcpy(char *dst, const char *src, size_t siz) return(s - src - 1); /* count does not include NUL */ } + #endif diff --git a/libcutils/tests/Android.mk b/libcutils/tests/Android.mk index 5a54698..cf70345 100644 --- a/libcutils/tests/Android.mk +++ b/libcutils/tests/Android.mk @@ -15,38 +15,59 @@ LOCAL_PATH := $(call my-dir) test_src_files := \ + test_str_parms.cpp \ + +test_target_only_src_files := \ MemsetTest.cpp \ PropertiesTest.cpp \ +test_libraries := libcutils liblog + + +# +# Target. +# + include $(CLEAR_VARS) -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk LOCAL_MODULE := libcutils_test -LOCAL_SRC_FILES := $(test_src_files) -LOCAL_SHARED_LIBRARIES := \ - libcutils \ - liblog \ - libutils \ +LOCAL_SRC_FILES := $(test_src_files) $(test_target_only_src_files) +LOCAL_SHARED_LIBRARIES := $(test_libraries) +LOCAL_MULTILIB := both +LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 +LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 +include $(BUILD_NATIVE_TEST) +include $(CLEAR_VARS) +LOCAL_MODULE := libcutils_test_static +LOCAL_FORCE_STATIC_EXECUTABLE := true +LOCAL_SRC_FILES := $(test_src_files) $(test_target_only_src_files) +LOCAL_STATIC_LIBRARIES := libc $(test_libraries) +LOCAL_CXX_STL := libc++_static LOCAL_MULTILIB := both LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 include $(BUILD_NATIVE_TEST) -# The static libcutils tests cannot be built when using libc++ because there are -# multiple symbol definition errors between libc++ and libgcc. b/18389856 -#include $(CLEAR_VARS) -#LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk -#LOCAL_MODULE := libcutils_test_static -#LOCAL_FORCE_STATIC_EXECUTABLE := true -#LOCAL_SRC_FILES := $(test_src_files) -#LOCAL_STATIC_LIBRARIES := \ -# libc \ -# libcutils \ -# liblog \ -# libutils \ - -#LOCAL_CXX_STL := stlport_static -#LOCAL_MULTILIB := both -#LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 -#LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 -#include $(BUILD_NATIVE_TEST) + +# +# Host. +# + +include $(CLEAR_VARS) +LOCAL_MODULE := libcutils_test +LOCAL_SRC_FILES := $(test_src_files) +LOCAL_SHARED_LIBRARIES := $(test_libraries) +LOCAL_MULTILIB := both +LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 +LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 +include $(BUILD_HOST_NATIVE_TEST) + +include $(CLEAR_VARS) +LOCAL_MODULE := libcutils_test_static +LOCAL_SRC_FILES := $(test_src_files) +LOCAL_STATIC_LIBRARIES := $(test_libraries) +LOCAL_CXX_STL := libc++_static +LOCAL_MULTILIB := both +LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32 +LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64 +include $(BUILD_HOST_NATIVE_TEST) diff --git a/libcutils/tests/test_str_parms.cpp b/libcutils/tests/test_str_parms.cpp new file mode 100644 index 0000000..d8f639b --- /dev/null +++ b/libcutils/tests/test_str_parms.cpp @@ -0,0 +1,57 @@ +/* + * 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. + */ + +#include <cutils/str_parms.h> +#include <gtest/gtest.h> + +static void test_str_parms_str(const char* str, const char* expected) { + str_parms* str_parms = str_parms_create_str(str); + str_parms_add_str(str_parms, "dude", "woah"); + str_parms_add_str(str_parms, "dude", "woah"); + str_parms_del(str_parms, "dude"); + str_parms_dump(str_parms); + char* out_str = str_parms_to_str(str_parms); + str_parms_destroy(str_parms); + ASSERT_STREQ(expected, out_str) << str; + free(out_str); +} + +TEST(str_parms, smoke) { + test_str_parms_str("", ""); + test_str_parms_str(";", ""); + test_str_parms_str("=", ""); + test_str_parms_str("=;", ""); + test_str_parms_str("=bar", ""); + test_str_parms_str("=bar;", ""); + test_str_parms_str("foo=", "foo="); + test_str_parms_str("foo=;", "foo="); + test_str_parms_str("foo=bar", "foo=bar"); + test_str_parms_str("foo=bar;", "foo=bar"); + test_str_parms_str("foo=bar;baz", "foo=bar;baz="); + test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); + test_str_parms_str("foo=bar;baz=bat", "foo=bar;baz=bat"); + test_str_parms_str("foo=bar;baz=bat;", "foo=bar;baz=bat"); + test_str_parms_str("foo=bar1;baz=bat;foo=bar2", "foo=bar2;baz=bat"); +} + +TEST(str_parms, put_ENOMEM) { + // hashmapPut reports errors by setting errno to ENOMEM. + // Test that we're not confused by running in an environment where this is already true. + errno = ENOMEM; + test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); + ASSERT_EQ(ENOMEM, errno); + test_str_parms_str("foo=bar;baz=", "foo=bar;baz="); +} diff --git a/libcutils/trace.c b/libcutils/trace-dev.c index 4396625..4396625 100644 --- a/libcutils/trace.c +++ b/libcutils/trace-dev.c diff --git a/libcutils/trace-host.c b/libcutils/trace-host.c new file mode 100644 index 0000000..b87e543 --- /dev/null +++ b/libcutils/trace-host.c @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#include <cutils/trace.h> + +#ifndef __unused +#define __unused __attribute__((__unused__)) +#endif + +volatile int32_t atrace_is_ready = 1; +int atrace_marker_fd = -1; +uint64_t atrace_enabled_tags = 0; + +void atrace_set_debuggable(bool debuggable __unused) { } +void atrace_set_tracing_enabled(bool enabled __unused) { } +void atrace_update_tags() { } +void atrace_setup() { } +void atrace_begin_body(const char* name __unused) { } +void atrace_async_begin_body(const char* name __unused, int32_t cookie __unused) { } +void atrace_async_end_body(const char* name __unused, int32_t cookie __unused) { } +void atrace_int_body(const char* name __unused, int32_t value __unused) { } +void atrace_int64_body(const char* name __unused, int64_t value __unused) { } |