Compare commits
44 Commits
android-4.
...
tools_r22.
Author | SHA1 | Date | |
---|---|---|---|
![]() |
98c726ec9b | ||
![]() |
24053a461e | ||
![]() |
df7436e709 | ||
![]() |
afa310427e | ||
![]() |
3c4b50fd8c | ||
![]() |
a21e696d90 | ||
![]() |
99b859cf78 | ||
![]() |
8240bed918 | ||
![]() |
4e3ed44db1 | ||
![]() |
bd8e6749b7 | ||
![]() |
eb8f36223e | ||
![]() |
93501d3ab8 | ||
![]() |
2557433d8e | ||
![]() |
5227bb363d | ||
![]() |
1f216e30b6 | ||
![]() |
22f5ef6b84 | ||
![]() |
bdbdbb8319 | ||
![]() |
153d92765b | ||
![]() |
33dd7c116d | ||
![]() |
c6135ba76d | ||
![]() |
e85c183424 | ||
![]() |
a31ddef36d | ||
![]() |
41f08abf3d | ||
![]() |
713fe6463e | ||
![]() |
c44205cf71 | ||
![]() |
7843d44a59 | ||
![]() |
bb34907ff5 | ||
![]() |
87c358524e | ||
![]() |
c8039337e3 | ||
![]() |
4eacb34132 | ||
![]() |
9b06cc3c1b | ||
![]() |
cf0529946a | ||
![]() |
bd6dc6a886 | ||
![]() |
5f45d583b0 | ||
![]() |
c5cf53701a | ||
![]() |
59a13c122e | ||
![]() |
c85e0dbb0b | ||
![]() |
0e79b91962 | ||
![]() |
5e4a2f3174 | ||
![]() |
55bdef8677 | ||
![]() |
ff9b7aa695 | ||
![]() |
5e9b20f721 | ||
![]() |
c933493ac2 | ||
![]() |
aec2ffbc5a |
@@ -62,7 +62,6 @@ libc_common_src_files := \
|
||||
string/strcspn.c \
|
||||
string/strdup.c \
|
||||
string/strpbrk.c \
|
||||
string/__strrchr_chk.c \
|
||||
string/strsep.c \
|
||||
string/strspn.c \
|
||||
string/strstr.c \
|
||||
@@ -181,6 +180,25 @@ libc_common_src_files := \
|
||||
netbsd/nameser/ns_print.c \
|
||||
netbsd/nameser/ns_samedomain.c \
|
||||
|
||||
# Fortify implementations of libc functions.
|
||||
libc_common_src_files += \
|
||||
bionic/__fgets_chk.cpp \
|
||||
bionic/__memcpy_chk.cpp \
|
||||
bionic/__memmove_chk.cpp \
|
||||
bionic/__memset_chk.cpp \
|
||||
bionic/__strcat_chk.cpp \
|
||||
bionic/__strchr_chk.cpp \
|
||||
bionic/__strcpy_chk.cpp \
|
||||
bionic/__strlcat_chk.cpp \
|
||||
bionic/__strlcpy_chk.cpp \
|
||||
bionic/__strlen_chk.cpp \
|
||||
bionic/__strncat_chk.cpp \
|
||||
bionic/__strncpy_chk.cpp \
|
||||
bionic/__strrchr_chk.cpp \
|
||||
bionic/__umask_chk.cpp \
|
||||
bionic/__vsnprintf_chk.cpp \
|
||||
bionic/__vsprintf_chk.cpp \
|
||||
|
||||
libc_bionic_src_files := \
|
||||
bionic/abort.cpp \
|
||||
bionic/assert.cpp \
|
||||
@@ -189,16 +207,12 @@ libc_bionic_src_files := \
|
||||
bionic/__errno.c \
|
||||
bionic/eventfd_read.cpp \
|
||||
bionic/eventfd_write.cpp \
|
||||
bionic/__fgets_chk.cpp \
|
||||
bionic/futimens.cpp \
|
||||
bionic/getauxval.cpp \
|
||||
bionic/getcwd.cpp \
|
||||
bionic/libc_init_common.cpp \
|
||||
bionic/libc_logging.cpp \
|
||||
bionic/libgen.cpp \
|
||||
bionic/__memcpy_chk.cpp \
|
||||
bionic/__memmove_chk.cpp \
|
||||
bionic/__memset_chk.cpp \
|
||||
bionic/mmap.cpp \
|
||||
bionic/pthread_attr.cpp \
|
||||
bionic/pthread_detach.cpp \
|
||||
@@ -221,24 +235,13 @@ libc_bionic_src_files := \
|
||||
bionic/signalfd.cpp \
|
||||
bionic/sigwait.cpp \
|
||||
bionic/statvfs.cpp \
|
||||
bionic/__strcat_chk.cpp \
|
||||
bionic/__strchr_chk.cpp \
|
||||
bionic/__strcpy_chk.cpp \
|
||||
bionic/strerror.cpp \
|
||||
bionic/strerror_r.cpp \
|
||||
bionic/__strlcat_chk.cpp \
|
||||
bionic/__strlcpy_chk.cpp \
|
||||
bionic/__strlen_chk.cpp \
|
||||
bionic/__strncat_chk.cpp \
|
||||
bionic/__strncpy_chk.cpp \
|
||||
bionic/strsignal.cpp \
|
||||
bionic/stubs.cpp \
|
||||
bionic/sysconf.cpp \
|
||||
bionic/tdestroy.cpp \
|
||||
bionic/tmpfile.cpp \
|
||||
bionic/__umask_chk.cpp \
|
||||
bionic/__vsnprintf_chk.cpp \
|
||||
bionic/__vsprintf_chk.cpp \
|
||||
bionic/wait.cpp \
|
||||
bionic/wchar.cpp \
|
||||
|
||||
@@ -283,7 +286,12 @@ libc_upstream_freebsd_src_files := \
|
||||
upstream-freebsd/lib/libc/stdio/tempnam.c \
|
||||
upstream-freebsd/lib/libc/stdio/tmpnam.c \
|
||||
upstream-freebsd/lib/libc/stdio/wsetup.c \
|
||||
upstream-freebsd/lib/libc/stdlib/abs.c \
|
||||
upstream-freebsd/lib/libc/stdlib/getopt_long.c \
|
||||
upstream-freebsd/lib/libc/stdlib/imaxabs.c \
|
||||
upstream-freebsd/lib/libc/stdlib/imaxdiv.c \
|
||||
upstream-freebsd/lib/libc/stdlib/labs.c \
|
||||
upstream-freebsd/lib/libc/stdlib/llabs.c \
|
||||
upstream-freebsd/lib/libc/stdlib/qsort.c \
|
||||
upstream-freebsd/lib/libc/stdlib/realpath.c \
|
||||
upstream-freebsd/lib/libc/string/wcpcpy.c \
|
||||
@@ -511,7 +519,8 @@ endif # !arm
|
||||
|
||||
ifeq ($(TARGET_ARCH),x86)
|
||||
libc_common_cflags += -DSOFTFLOAT
|
||||
libc_crt_target_cflags :=
|
||||
libc_crt_target_cflags := -m32
|
||||
libc_crt_target_ldflags := -melf_i386
|
||||
ifeq ($(ARCH_X86_HAVE_SSE2),true)
|
||||
libc_crt_target_cflags += -DUSE_SSE2=1
|
||||
endif
|
||||
@@ -641,7 +650,7 @@ ALL_GENERATED_SOURCES += $(GEN)
|
||||
GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
|
||||
$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
|
||||
@mkdir -p $(dir $@)
|
||||
$(hide) $(TARGET_LD) -r -o $@ $^
|
||||
$(hide) $(TARGET_LD) $(libc_crt_target_ldflags) -r -o $@ $^
|
||||
ALL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o
|
||||
@@ -656,7 +665,7 @@ ALL_GENERATED_SOURCES += $(GEN)
|
||||
GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
|
||||
$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
|
||||
@mkdir -p $(dir $@)
|
||||
$(hide) $(TARGET_LD) -r -o $@ $^
|
||||
$(hide) $(TARGET_LD) $(libc_crt_target_ldflags) -r -o $@ $^
|
||||
ALL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
# We rename crtend.o to crtend_android.o to avoid a
|
||||
|
26
libc/CAVEATS
26
libc/CAVEATS
@@ -1,26 +0,0 @@
|
||||
Bionic is a very small C library because we have decided to *not* implement various features
|
||||
of the POSIX standard. we only add functions on a as-needed basis, and there are a few things
|
||||
we wish we'll never put in there.
|
||||
|
||||
this file is here to document explicitely what we don't want to support in Bionic:
|
||||
|
||||
- C++ exceptions are not supported. on embedded systems, they lead to extremely larger and
|
||||
slower code for no good reason (even when so-called zero-cost exception schemes are
|
||||
implemented, they enforce very large numbers of registers spills to the stack, even
|
||||
in functions that do not throw an exception themselves).
|
||||
|
||||
- pthread cancellation is *not* supported. this seemingly simple "feature" is the source
|
||||
of much bloat and complexity in a C library. Besides, you'd better write correct
|
||||
multi-threaded code instead of relying on this stuff.
|
||||
|
||||
- pthread_once() doesn't support C++ exceptions thrown from the init function, or the init
|
||||
function doing a fork().
|
||||
|
||||
- locales and wide characters are not supported. we use ICU for all this i18n stuff, which
|
||||
is much better than the ill-designed related C libraries functions.
|
||||
|
||||
- at the moment, several user-account-related functions like getpwd are stubbed and return
|
||||
the values corresponding to root. this will be fixed when we'll be able to have distinct
|
||||
users on the Android filesystem. :-(
|
||||
|
||||
see bionic/stubs.c for the details
|
@@ -21,10 +21,22 @@ _LIBC_ARCH_COMMON_SRC_FILES := \
|
||||
# These are used by the static and dynamic versions of the libc
|
||||
# respectively.
|
||||
_LIBC_ARCH_STATIC_SRC_FILES := \
|
||||
arch-arm/bionic/exidx_static.c
|
||||
arch-arm/bionic/exidx_static.c \
|
||||
bionic/dl_iterate_phdr_static.c \
|
||||
|
||||
_LIBC_ARCH_DYNAMIC_SRC_FILES := \
|
||||
arch-arm/bionic/exidx_dynamic.c
|
||||
arch-arm/bionic/exidx_dynamic.c \
|
||||
|
||||
# Remove the C++ fortify function implementations for which there is an
|
||||
# arm assembler version.
|
||||
_LIBC_FORTIFY_FILES_TO_REMOVE := \
|
||||
bionic/__memcpy_chk.cpp \
|
||||
bionic/__memset_chk.cpp \
|
||||
bionic/__strcpy_chk.cpp \
|
||||
bionic/__strcat_chk.cpp \
|
||||
|
||||
libc_common_src_files := \
|
||||
$(filter-out $(_LIBC_FORTIFY_FILES_TO_REMOVE),$(libc_common_src_files))
|
||||
|
||||
ifeq ($(strip $(wildcard bionic/libc/arch-arm/$(TARGET_CPU_VARIANT)/$(TARGET_CPU_VARIANT).mk)),)
|
||||
$(error "TARGET_CPU_VARIANT not set or set to an unknown value. Possible values are cortex-a7, cortex-a8, cortex-a9, cortex-a15, krait. Use generic for devices that do not have a CPU similar to any of the supported cpu variants.")
|
||||
|
@@ -32,7 +32,7 @@ extern int __cxa_atexit(void (*)(void*), void*, void* );
|
||||
|
||||
/* The "C++ ABI for ARM" document states that static C++ constructors,
|
||||
* which are called from the .init_array, should manually call
|
||||
* __aeabi_atexit() to register static destructors explicitely.
|
||||
* __aeabi_atexit() to register static destructors explicitly.
|
||||
*
|
||||
* Note that 'dso_handle' is the address of a magic linker-generate
|
||||
* variable from the shared object that contains the constructor/destructor
|
||||
|
215
libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
Normal file
215
libc/arch-arm/cortex-a15/bionic/__strcat_chk.S
Normal file
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
.syntax unified
|
||||
|
||||
.thumb
|
||||
.thumb_func
|
||||
|
||||
// Get the length of src string, then get the source of the dst string.
|
||||
// Check that the two lengths together don't exceed the threshold, then
|
||||
// do a memcpy of the data.
|
||||
ENTRY(__strcat_chk)
|
||||
.cfi_startproc
|
||||
pld [r0, #0]
|
||||
push {r0, lr}
|
||||
.cfi_def_cfa_offset 8
|
||||
.cfi_rel_offset r0, 0
|
||||
.cfi_rel_offset lr, 4
|
||||
push {r4, r5}
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_rel_offset r4, 0
|
||||
.cfi_rel_offset r5, 0
|
||||
|
||||
mov lr, r2
|
||||
|
||||
// Save the dst register to r5
|
||||
mov r5, r0
|
||||
|
||||
// Zero out r4
|
||||
eor r4, r4, r4
|
||||
|
||||
// r1 contains the address of the string to count.
|
||||
.L_strlen_start:
|
||||
mov r0, r1
|
||||
ands r3, r1, #7
|
||||
beq .L_mainloop
|
||||
|
||||
// Align to a double word (64 bits).
|
||||
rsb r3, r3, #8
|
||||
lsls ip, r3, #31
|
||||
beq .L_align_to_32
|
||||
|
||||
ldrb r2, [r1], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
|
||||
.L_align_to_32:
|
||||
bcc .L_align_to_64
|
||||
ands ip, r3, #2
|
||||
beq .L_align_to_64
|
||||
|
||||
ldrb r2, [r1], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
ldrb r2, [r1], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
|
||||
.L_align_to_64:
|
||||
tst r3, #4
|
||||
beq .L_mainloop
|
||||
ldr r3, [r1], #4
|
||||
|
||||
sub ip, r3, #0x01010101
|
||||
bic ip, ip, r3
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
|
||||
.p2align 2
|
||||
.L_mainloop:
|
||||
ldrd r2, r3, [r1], #8
|
||||
|
||||
pld [r1, #64]
|
||||
|
||||
sub ip, r2, #0x01010101
|
||||
bic ip, ip, r2
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_first_register
|
||||
|
||||
sub ip, r3, #0x01010101
|
||||
bic ip, ip, r3
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
b .L_mainloop
|
||||
|
||||
.L_update_count_and_finish:
|
||||
sub r3, r1, r0
|
||||
sub r3, r3, #1
|
||||
b .L_finish
|
||||
|
||||
.L_zero_in_first_register:
|
||||
sub r3, r1, r0
|
||||
lsls r2, ip, #17
|
||||
bne .L_sub8_and_finish
|
||||
bcs .L_sub7_and_finish
|
||||
lsls ip, ip, #1
|
||||
bne .L_sub6_and_finish
|
||||
|
||||
sub r3, r3, #5
|
||||
b .L_finish
|
||||
|
||||
.L_sub8_and_finish:
|
||||
sub r3, r3, #8
|
||||
b .L_finish
|
||||
|
||||
.L_sub7_and_finish:
|
||||
sub r3, r3, #7
|
||||
b .L_finish
|
||||
|
||||
.L_sub6_and_finish:
|
||||
sub r3, r3, #6
|
||||
b .L_finish
|
||||
|
||||
.L_zero_in_second_register:
|
||||
sub r3, r1, r0
|
||||
lsls r2, ip, #17
|
||||
bne .L_sub4_and_finish
|
||||
bcs .L_sub3_and_finish
|
||||
lsls ip, ip, #1
|
||||
bne .L_sub2_and_finish
|
||||
|
||||
sub r3, r3, #1
|
||||
b .L_finish
|
||||
|
||||
.L_sub4_and_finish:
|
||||
sub r3, r3, #4
|
||||
b .L_finish
|
||||
|
||||
.L_sub3_and_finish:
|
||||
sub r3, r3, #3
|
||||
b .L_finish
|
||||
|
||||
.L_sub2_and_finish:
|
||||
sub r3, r3, #2
|
||||
|
||||
.L_finish:
|
||||
cmp r4, #0
|
||||
bne .L_strlen_done
|
||||
|
||||
// Time to get the dst string length.
|
||||
mov r1, r5
|
||||
|
||||
// Save the original source address to r5.
|
||||
mov r5, r0
|
||||
|
||||
// Save the current length (adding 1 for the terminator).
|
||||
add r4, r3, #1
|
||||
b .L_strlen_start
|
||||
|
||||
// r0 holds the pointer to the dst string.
|
||||
// r3 holds the dst string length.
|
||||
// r4 holds the src string length + 1.
|
||||
.L_strlen_done:
|
||||
add r2, r3, r4
|
||||
cmp r2, lr
|
||||
bgt .L_fortify_check_failed
|
||||
|
||||
// Set up the registers for the memcpy code.
|
||||
mov r1, r5
|
||||
pld [r1, #64]
|
||||
mov r2, r4
|
||||
add r0, r0, r3
|
||||
pop {r4, r5}
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore r4
|
||||
.cfi_restore r5
|
||||
|
||||
#include "memcpy_base.S"
|
||||
|
||||
.L_fortify_check_failed:
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_rel_offset r4, 0
|
||||
.cfi_rel_offset r5, 4
|
||||
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+4)
|
||||
|
||||
.cfi_endproc
|
||||
END(__strcat_chk)
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "strcat buffer overflow"
|
176
libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
Normal file
176
libc/arch-arm/cortex-a15/bionic/__strcpy_chk.S
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
.syntax unified
|
||||
|
||||
.thumb
|
||||
.thumb_func
|
||||
|
||||
// Get the length of the source string first, then do a memcpy of the data
|
||||
// instead of a strcpy.
|
||||
ENTRY(__strcpy_chk)
|
||||
.cfi_startproc
|
||||
pld [r0, #0]
|
||||
push {r0, lr}
|
||||
.cfi_def_cfa_offset 8
|
||||
.cfi_rel_offset r0, 0
|
||||
.cfi_rel_offset lr, 4
|
||||
|
||||
mov lr, r2
|
||||
mov r0, r1
|
||||
|
||||
ands r3, r1, #7
|
||||
beq .L_mainloop
|
||||
|
||||
// Align to a double word (64 bits).
|
||||
rsb r3, r3, #8
|
||||
lsls ip, r3, #31
|
||||
beq .L_align_to_32
|
||||
|
||||
ldrb r2, [r0], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
|
||||
.L_align_to_32:
|
||||
bcc .L_align_to_64
|
||||
ands ip, r3, #2
|
||||
beq .L_align_to_64
|
||||
|
||||
ldrb r2, [r0], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
ldrb r2, [r0], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
|
||||
.L_align_to_64:
|
||||
tst r3, #4
|
||||
beq .L_mainloop
|
||||
ldr r3, [r0], #4
|
||||
|
||||
sub ip, r3, #0x01010101
|
||||
bic ip, ip, r3
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
|
||||
.p2align 2
|
||||
.L_mainloop:
|
||||
ldrd r2, r3, [r0], #8
|
||||
|
||||
pld [r0, #64]
|
||||
|
||||
sub ip, r2, #0x01010101
|
||||
bic ip, ip, r2
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_first_register
|
||||
|
||||
sub ip, r3, #0x01010101
|
||||
bic ip, ip, r3
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
b .L_mainloop
|
||||
|
||||
.L_update_count_and_finish:
|
||||
sub r3, r0, r1
|
||||
sub r3, r3, #1
|
||||
b .L_check_size
|
||||
|
||||
.L_zero_in_first_register:
|
||||
sub r3, r0, r1
|
||||
lsls r2, ip, #17
|
||||
bne .L_sub8_and_finish
|
||||
bcs .L_sub7_and_finish
|
||||
lsls ip, ip, #1
|
||||
bne .L_sub6_and_finish
|
||||
|
||||
sub r3, r3, #5
|
||||
b .L_check_size
|
||||
|
||||
.L_sub8_and_finish:
|
||||
sub r3, r3, #8
|
||||
b .L_check_size
|
||||
|
||||
.L_sub7_and_finish:
|
||||
sub r3, r3, #7
|
||||
b .L_check_size
|
||||
|
||||
.L_sub6_and_finish:
|
||||
sub r3, r3, #6
|
||||
b .L_check_size
|
||||
|
||||
.L_zero_in_second_register:
|
||||
sub r3, r0, r1
|
||||
lsls r2, ip, #17
|
||||
bne .L_sub4_and_finish
|
||||
bcs .L_sub3_and_finish
|
||||
lsls ip, ip, #1
|
||||
bne .L_sub2_and_finish
|
||||
|
||||
sub r3, r3, #1
|
||||
b .L_check_size
|
||||
|
||||
.L_sub4_and_finish:
|
||||
sub r3, r3, #4
|
||||
b .L_check_size
|
||||
|
||||
.L_sub3_and_finish:
|
||||
sub r3, r3, #3
|
||||
b .L_check_size
|
||||
|
||||
.L_sub2_and_finish:
|
||||
sub r3, r3, #2
|
||||
|
||||
.L_check_size:
|
||||
pld [r1, #0]
|
||||
pld [r1, #64]
|
||||
ldr r0, [sp]
|
||||
cmp r3, lr
|
||||
bge .L_fortify_check_failed
|
||||
|
||||
// Add 1 for copy length to get the string terminator.
|
||||
add r2, r3, #1
|
||||
|
||||
#include "memcpy_base.S"
|
||||
|
||||
.L_fortify_check_failed:
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+4)
|
||||
|
||||
.cfi_endproc
|
||||
END(__strcpy_chk)
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "strcpy buffer overflow"
|
@@ -53,272 +53,54 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* Prototype: void *memcpy (void *dst, const void *src, size_t count). */
|
||||
// Prototype: void *memcpy (void *dst, const void *src, size_t count).
|
||||
|
||||
// This version is tuned for the Cortex-A15 processor.
|
||||
|
||||
#include <machine/cpu-features.h>
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
.text
|
||||
.syntax unified
|
||||
.fpu neon
|
||||
|
||||
#define CACHE_LINE_SIZE 64
|
||||
ENTRY(__memcpy_chk)
|
||||
.cfi_startproc
|
||||
cmp r2, r3
|
||||
bgt __memcpy_chk_fail
|
||||
|
||||
// Fall through to memcpy...
|
||||
.cfi_endproc
|
||||
END(__memcpy_chk)
|
||||
|
||||
ENTRY(memcpy)
|
||||
// Assumes that n >= 0, and dst, src are valid pointers.
|
||||
// For any sizes less than 832 use the neon code that doesn't
|
||||
// care about the src alignment. This avoids any checks
|
||||
// for src alignment, and offers the best improvement since
|
||||
// smaller sized copies are dominated by the overhead of
|
||||
// the pre and post main loop.
|
||||
// For larger copies, if src and dst cannot both be aligned to
|
||||
// word boundaries, use the neon code.
|
||||
// For all other copies, align dst to a double word boundary
|
||||
// and copy using LDRD/STRD instructions.
|
||||
|
||||
// Save registers (r0 holds the return value):
|
||||
// optimized push {r0, lr}.
|
||||
.save {r0, lr}
|
||||
pld [r1, #(CACHE_LINE_SIZE*16)]
|
||||
.cfi_startproc
|
||||
pld [r1, #64]
|
||||
push {r0, lr}
|
||||
.cfi_def_cfa_offset 8
|
||||
.cfi_rel_offset r0, 0
|
||||
.cfi_rel_offset lr, 4
|
||||
|
||||
cmp r2, #16
|
||||
blo copy_less_than_16_unknown_align
|
||||
|
||||
cmp r2, #832
|
||||
bge check_alignment
|
||||
|
||||
copy_unknown_alignment:
|
||||
// Unknown alignment of src and dst.
|
||||
// Assumes that the first few bytes have already been prefetched.
|
||||
|
||||
// Align destination to 128 bits. The mainloop store instructions
|
||||
// require this alignment or they will throw an exception.
|
||||
rsb r3, r0, #0
|
||||
ands r3, r3, #0xF
|
||||
beq 2f
|
||||
|
||||
// Copy up to 15 bytes (count in r3).
|
||||
sub r2, r2, r3
|
||||
movs ip, r3, lsl #31
|
||||
|
||||
itt mi
|
||||
ldrbmi lr, [r1], #1
|
||||
strbmi lr, [r0], #1
|
||||
itttt cs
|
||||
ldrbcs ip, [r1], #1
|
||||
ldrbcs lr, [r1], #1
|
||||
strbcs ip, [r0], #1
|
||||
strbcs lr, [r0], #1
|
||||
|
||||
movs ip, r3, lsl #29
|
||||
bge 1f
|
||||
// Copies 4 bytes, dst 32 bits aligned before, at least 64 bits after.
|
||||
vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
|
||||
vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0, :32]!
|
||||
1: bcc 2f
|
||||
// Copies 8 bytes, dst 64 bits aligned before, at least 128 bits after.
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0, :64]!
|
||||
|
||||
2: // Make sure we have at least 64 bytes to copy.
|
||||
subs r2, r2, #64
|
||||
blo 2f
|
||||
|
||||
1: // The main loop copies 64 bytes at a time.
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
vld1.8 {d4 - d7}, [r1]!
|
||||
pld [r1, #(CACHE_LINE_SIZE*4)]
|
||||
subs r2, r2, #64
|
||||
vst1.8 {d0 - d3}, [r0, :128]!
|
||||
vst1.8 {d4 - d7}, [r0, :128]!
|
||||
bhs 1b
|
||||
|
||||
2: // Fix-up the remaining count and make sure we have >= 32 bytes left.
|
||||
adds r2, r2, #32
|
||||
blo 3f
|
||||
|
||||
// 32 bytes. These cache lines were already preloaded.
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
sub r2, r2, #32
|
||||
vst1.8 {d0 - d3}, [r0, :128]!
|
||||
3: // Less than 32 left.
|
||||
add r2, r2, #32
|
||||
tst r2, #0x10
|
||||
beq copy_less_than_16_unknown_align
|
||||
// Copies 16 bytes, destination 128 bits aligned.
|
||||
vld1.8 {d0, d1}, [r1]!
|
||||
vst1.8 {d0, d1}, [r0, :128]!
|
||||
|
||||
copy_less_than_16_unknown_align:
|
||||
// Copy up to 15 bytes (count in r2).
|
||||
movs ip, r2, lsl #29
|
||||
bcc 1f
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0]!
|
||||
1: bge 2f
|
||||
vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
|
||||
vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0]!
|
||||
|
||||
2: // Copy 0 to 4 bytes.
|
||||
lsls r2, r2, #31
|
||||
itt ne
|
||||
ldrbne lr, [r1], #1
|
||||
strbne lr, [r0], #1
|
||||
itttt cs
|
||||
ldrbcs ip, [r1], #1
|
||||
ldrbcs lr, [r1]
|
||||
strbcs ip, [r0], #1
|
||||
strbcs lr, [r0]
|
||||
|
||||
pop {r0, pc}
|
||||
|
||||
check_alignment:
|
||||
// If src and dst cannot both be aligned to a word boundary,
|
||||
// use the unaligned copy version.
|
||||
eor r3, r0, r1
|
||||
ands r3, r3, #0x3
|
||||
bne copy_unknown_alignment
|
||||
|
||||
// To try and improve performance, stack layout changed,
|
||||
// i.e., not keeping the stack looking like users expect
|
||||
// (highest numbered register at highest address).
|
||||
// TODO: Add debug frame directives.
|
||||
// We don't need exception unwind directives, because the code below
|
||||
// does not throw any exceptions and does not call any other functions.
|
||||
// Generally, newlib functions like this lack debug information for
|
||||
// assembler source.
|
||||
.save {r4, r5}
|
||||
strd r4, r5, [sp, #-8]!
|
||||
.save {r6, r7}
|
||||
strd r6, r7, [sp, #-8]!
|
||||
.save {r8, r9}
|
||||
strd r8, r9, [sp, #-8]!
|
||||
|
||||
// Optimized for already aligned dst code.
|
||||
ands ip, r0, #3
|
||||
bne dst_not_word_aligned
|
||||
|
||||
word_aligned:
|
||||
// Align the destination buffer to 8 bytes, to make sure double
|
||||
// loads and stores don't cross a cache line boundary,
|
||||
// as they are then more expensive even if the data is in the cache
|
||||
// (require two load/store issue cycles instead of one).
|
||||
// If only one of the buffers is not 8 bytes aligned,
|
||||
// then it's more important to align dst than src,
|
||||
// because there is more penalty for stores
|
||||
// than loads that cross a cacheline boundary.
|
||||
// This check and realignment are only done if there is >= 832
|
||||
// bytes to copy.
|
||||
|
||||
// Dst is word aligned, but check if it is already double word aligned.
|
||||
ands r3, r0, #4
|
||||
beq 1f
|
||||
ldr r3, [r1], #4
|
||||
str r3, [r0], #4
|
||||
sub r2, #4
|
||||
|
||||
1: // Can only get here if > 64 bytes to copy, so don't do check r2.
|
||||
sub r2, #64
|
||||
|
||||
2: // Every loop iteration copies 64 bytes.
|
||||
.irp offset, #0, #8, #16, #24, #32
|
||||
ldrd r4, r5, [r1, \offset]
|
||||
strd r4, r5, [r0, \offset]
|
||||
.endr
|
||||
|
||||
ldrd r4, r5, [r1, #40]
|
||||
ldrd r6, r7, [r1, #48]
|
||||
ldrd r8, r9, [r1, #56]
|
||||
|
||||
// Keep the pld as far from the next load as possible.
|
||||
// The amount to prefetch was determined experimentally using
|
||||
// large sizes, and verifying the prefetch size does not affect
|
||||
// the smaller copies too much.
|
||||
// WARNING: If the ldrd and strd instructions get too far away
|
||||
// from each other, performance suffers. Three loads
|
||||
// in a row is the best tradeoff.
|
||||
pld [r1, #(CACHE_LINE_SIZE*16)]
|
||||
strd r4, r5, [r0, #40]
|
||||
strd r6, r7, [r0, #48]
|
||||
strd r8, r9, [r0, #56]
|
||||
|
||||
add r0, r0, #64
|
||||
add r1, r1, #64
|
||||
subs r2, r2, #64
|
||||
bge 2b
|
||||
|
||||
// Fix-up the remaining count and make sure we have >= 32 bytes left.
|
||||
adds r2, r2, #32
|
||||
blo 4f
|
||||
|
||||
// Copy 32 bytes. These cache lines were already preloaded.
|
||||
.irp offset, #0, #8, #16, #24
|
||||
ldrd r4, r5, [r1, \offset]
|
||||
strd r4, r5, [r0, \offset]
|
||||
.endr
|
||||
add r1, r1, #32
|
||||
add r0, r0, #32
|
||||
sub r2, r2, #32
|
||||
4: // Less than 32 left.
|
||||
add r2, r2, #32
|
||||
tst r2, #0x10
|
||||
beq 5f
|
||||
// Copy 16 bytes.
|
||||
.irp offset, #0, #8
|
||||
ldrd r4, r5, [r1, \offset]
|
||||
strd r4, r5, [r0, \offset]
|
||||
.endr
|
||||
add r1, r1, #16
|
||||
add r0, r0, #16
|
||||
|
||||
5: // Copy up to 15 bytes (count in r2).
|
||||
movs ip, r2, lsl #29
|
||||
bcc 1f
|
||||
// Copy 8 bytes.
|
||||
ldrd r4, r5, [r1], #8
|
||||
strd r4, r5, [r0], #8
|
||||
1: bge 2f
|
||||
// Copy 4 bytes.
|
||||
ldr r4, [r1], #4
|
||||
str r4, [r0], #4
|
||||
2: // Copy 0 to 4 bytes.
|
||||
lsls r2, r2, #31
|
||||
itt ne
|
||||
ldrbne lr, [r1], #1
|
||||
strbne lr, [r0], #1
|
||||
itttt cs
|
||||
ldrbcs ip, [r1], #1
|
||||
ldrbcs lr, [r1]
|
||||
strbcs ip, [r0], #1
|
||||
strbcs lr, [r0]
|
||||
|
||||
// Restore registers: optimized pop {r0, pc}
|
||||
ldrd r8, r9, [sp], #8
|
||||
ldrd r6, r7, [sp], #8
|
||||
ldrd r4, r5, [sp], #8
|
||||
pop {r0, pc}
|
||||
|
||||
dst_not_word_aligned:
|
||||
// Align dst to word.
|
||||
rsb ip, ip, #4
|
||||
cmp ip, #2
|
||||
|
||||
itt gt
|
||||
ldrbgt lr, [r1], #1
|
||||
strbgt lr, [r0], #1
|
||||
|
||||
itt ge
|
||||
ldrbge lr, [r1], #1
|
||||
strbge lr, [r0], #1
|
||||
|
||||
ldrb lr, [r1], #1
|
||||
strb lr, [r0], #1
|
||||
|
||||
sub r2, r2, ip
|
||||
|
||||
// Src is guaranteed to be at least word aligned by this point.
|
||||
b word_aligned
|
||||
#include "memcpy_base.S"
|
||||
.cfi_endproc
|
||||
END(memcpy)
|
||||
|
||||
.cfi_startproc
|
||||
__memcpy_chk_fail:
|
||||
// Preserve lr for backtrace.
|
||||
push {lr}
|
||||
.cfi_def_cfa_offset 4
|
||||
.cfi_rel_offset lr, 0
|
||||
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+8)
|
||||
.cfi_endproc
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "memcpy buffer overflow"
|
||||
|
303
libc/arch-arm/cortex-a15/bionic/memcpy_base.S
Normal file
303
libc/arch-arm/cortex-a15/bionic/memcpy_base.S
Normal file
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2013 ARM Ltd
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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. The name of the company may not be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ARM LTD ``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 ARM LTD 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.
|
||||
*/
|
||||
|
||||
// Assumes that n >= 0, and dst, src are valid pointers.
|
||||
// For any sizes less than 832 use the neon code that doesn't
|
||||
// care about the src alignment. This avoids any checks
|
||||
// for src alignment, and offers the best improvement since
|
||||
// smaller sized copies are dominated by the overhead of
|
||||
// the pre and post main loop.
|
||||
// For larger copies, if src and dst cannot both be aligned to
|
||||
// word boundaries, use the neon code.
|
||||
// For all other copies, align dst to a double word boundary
|
||||
// and copy using LDRD/STRD instructions.
|
||||
|
||||
cmp r2, #16
|
||||
blo .L_copy_less_than_16_unknown_align
|
||||
|
||||
cmp r2, #832
|
||||
bge .L_check_alignment
|
||||
|
||||
.L_copy_unknown_alignment:
|
||||
// Unknown alignment of src and dst.
|
||||
// Assumes that the first few bytes have already been prefetched.
|
||||
|
||||
// Align destination to 128 bits. The mainloop store instructions
|
||||
// require this alignment or they will throw an exception.
|
||||
rsb r3, r0, #0
|
||||
ands r3, r3, #0xF
|
||||
beq 2f
|
||||
|
||||
// Copy up to 15 bytes (count in r3).
|
||||
sub r2, r2, r3
|
||||
movs ip, r3, lsl #31
|
||||
|
||||
itt mi
|
||||
ldrbmi lr, [r1], #1
|
||||
strbmi lr, [r0], #1
|
||||
itttt cs
|
||||
ldrbcs ip, [r1], #1
|
||||
ldrbcs lr, [r1], #1
|
||||
strbcs ip, [r0], #1
|
||||
strbcs lr, [r0], #1
|
||||
|
||||
movs ip, r3, lsl #29
|
||||
bge 1f
|
||||
// Copies 4 bytes, dst 32 bits aligned before, at least 64 bits after.
|
||||
vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
|
||||
vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0, :32]!
|
||||
1: bcc 2f
|
||||
// Copies 8 bytes, dst 64 bits aligned before, at least 128 bits after.
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0, :64]!
|
||||
|
||||
2: // Make sure we have at least 64 bytes to copy.
|
||||
subs r2, r2, #64
|
||||
blo 2f
|
||||
|
||||
1: // The main loop copies 64 bytes at a time.
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
vld1.8 {d4 - d7}, [r1]!
|
||||
pld [r1, #(64*4)]
|
||||
subs r2, r2, #64
|
||||
vst1.8 {d0 - d3}, [r0, :128]!
|
||||
vst1.8 {d4 - d7}, [r0, :128]!
|
||||
bhs 1b
|
||||
|
||||
2: // Fix-up the remaining count and make sure we have >= 32 bytes left.
|
||||
adds r2, r2, #32
|
||||
blo 3f
|
||||
|
||||
// 32 bytes. These cache lines were already preloaded.
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
sub r2, r2, #32
|
||||
vst1.8 {d0 - d3}, [r0, :128]!
|
||||
3: // Less than 32 left.
|
||||
add r2, r2, #32
|
||||
tst r2, #0x10
|
||||
beq .L_copy_less_than_16_unknown_align
|
||||
// Copies 16 bytes, destination 128 bits aligned.
|
||||
vld1.8 {d0, d1}, [r1]!
|
||||
vst1.8 {d0, d1}, [r0, :128]!
|
||||
|
||||
.L_copy_less_than_16_unknown_align:
|
||||
// Copy up to 15 bytes (count in r2).
|
||||
movs ip, r2, lsl #29
|
||||
bcc 1f
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0]!
|
||||
1: bge 2f
|
||||
vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
|
||||
vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0]!
|
||||
|
||||
2: // Copy 0 to 4 bytes.
|
||||
lsls r2, r2, #31
|
||||
itt ne
|
||||
ldrbne lr, [r1], #1
|
||||
strbne lr, [r0], #1
|
||||
itttt cs
|
||||
ldrbcs ip, [r1], #1
|
||||
ldrbcs lr, [r1]
|
||||
strbcs ip, [r0], #1
|
||||
strbcs lr, [r0]
|
||||
|
||||
pop {r0, pc}
|
||||
|
||||
.L_check_alignment:
|
||||
// If src and dst cannot both be aligned to a word boundary,
|
||||
// use the unaligned copy version.
|
||||
eor r3, r0, r1
|
||||
ands r3, r3, #0x3
|
||||
bne .L_copy_unknown_alignment
|
||||
|
||||
// To try and improve performance, stack layout changed,
|
||||
// i.e., not keeping the stack looking like users expect
|
||||
// (highest numbered register at highest address).
|
||||
// TODO: Add debug frame directives.
|
||||
// We don't need exception unwind directives, because the code below
|
||||
// does not throw any exceptions and does not call any other functions.
|
||||
// Generally, newlib functions like this lack debug information for
|
||||
// assembler source.
|
||||
.save {r4, r5}
|
||||
strd r4, r5, [sp, #-8]!
|
||||
.save {r6, r7}
|
||||
strd r6, r7, [sp, #-8]!
|
||||
.save {r8, r9}
|
||||
strd r8, r9, [sp, #-8]!
|
||||
|
||||
// Optimized for already aligned dst code.
|
||||
ands ip, r0, #3
|
||||
bne .L_dst_not_word_aligned
|
||||
|
||||
.L_word_aligned:
|
||||
// Align the destination buffer to 8 bytes, to make sure double
|
||||
// loads and stores don't cross a cache line boundary,
|
||||
// as they are then more expensive even if the data is in the cache
|
||||
// (require two load/store issue cycles instead of one).
|
||||
// If only one of the buffers is not 8 bytes aligned,
|
||||
// then it's more important to align dst than src,
|
||||
// because there is more penalty for stores
|
||||
// than loads that cross a cacheline boundary.
|
||||
// This check and realignment are only done if there is >= 832
|
||||
// bytes to copy.
|
||||
|
||||
// Dst is word aligned, but check if it is already double word aligned.
|
||||
ands r3, r0, #4
|
||||
beq 1f
|
||||
ldr r3, [r1], #4
|
||||
str r3, [r0], #4
|
||||
sub r2, #4
|
||||
|
||||
1: // Can only get here if > 64 bytes to copy, so don't do check r2.
|
||||
sub r2, #64
|
||||
|
||||
2: // Every loop iteration copies 64 bytes.
|
||||
.irp offset, #0, #8, #16, #24, #32
|
||||
ldrd r4, r5, [r1, \offset]
|
||||
strd r4, r5, [r0, \offset]
|
||||
.endr
|
||||
|
||||
ldrd r4, r5, [r1, #40]
|
||||
ldrd r6, r7, [r1, #48]
|
||||
ldrd r8, r9, [r1, #56]
|
||||
|
||||
// Keep the pld as far from the next load as possible.
|
||||
// The amount to prefetch was determined experimentally using
|
||||
// large sizes, and verifying the prefetch size does not affect
|
||||
// the smaller copies too much.
|
||||
// WARNING: If the ldrd and strd instructions get too far away
|
||||
// from each other, performance suffers. Three loads
|
||||
// in a row is the best tradeoff.
|
||||
pld [r1, #(64*16)]
|
||||
strd r4, r5, [r0, #40]
|
||||
strd r6, r7, [r0, #48]
|
||||
strd r8, r9, [r0, #56]
|
||||
|
||||
add r0, r0, #64
|
||||
add r1, r1, #64
|
||||
subs r2, r2, #64
|
||||
bge 2b
|
||||
|
||||
// Fix-up the remaining count and make sure we have >= 32 bytes left.
|
||||
adds r2, r2, #32
|
||||
blo 4f
|
||||
|
||||
// Copy 32 bytes. These cache lines were already preloaded.
|
||||
.irp offset, #0, #8, #16, #24
|
||||
ldrd r4, r5, [r1, \offset]
|
||||
strd r4, r5, [r0, \offset]
|
||||
.endr
|
||||
add r1, r1, #32
|
||||
add r0, r0, #32
|
||||
sub r2, r2, #32
|
||||
4: // Less than 32 left.
|
||||
add r2, r2, #32
|
||||
tst r2, #0x10
|
||||
beq 5f
|
||||
// Copy 16 bytes.
|
||||
.irp offset, #0, #8
|
||||
ldrd r4, r5, [r1, \offset]
|
||||
strd r4, r5, [r0, \offset]
|
||||
.endr
|
||||
add r1, r1, #16
|
||||
add r0, r0, #16
|
||||
|
||||
5: // Copy up to 15 bytes (count in r2).
|
||||
movs ip, r2, lsl #29
|
||||
bcc 1f
|
||||
// Copy 8 bytes.
|
||||
ldrd r4, r5, [r1], #8
|
||||
strd r4, r5, [r0], #8
|
||||
1: bge 2f
|
||||
// Copy 4 bytes.
|
||||
ldr r4, [r1], #4
|
||||
str r4, [r0], #4
|
||||
2: // Copy 0 to 4 bytes.
|
||||
lsls r2, r2, #31
|
||||
itt ne
|
||||
ldrbne lr, [r1], #1
|
||||
strbne lr, [r0], #1
|
||||
itttt cs
|
||||
ldrbcs ip, [r1], #1
|
||||
ldrbcs lr, [r1]
|
||||
strbcs ip, [r0], #1
|
||||
strbcs lr, [r0]
|
||||
|
||||
// Restore registers: optimized pop {r0, pc}
|
||||
ldrd r8, r9, [sp], #8
|
||||
ldrd r6, r7, [sp], #8
|
||||
ldrd r4, r5, [sp], #8
|
||||
pop {r0, pc}
|
||||
|
||||
.L_dst_not_word_aligned:
|
||||
// Align dst to word.
|
||||
rsb ip, ip, #4
|
||||
cmp ip, #2
|
||||
|
||||
itt gt
|
||||
ldrbgt lr, [r1], #1
|
||||
strbgt lr, [r0], #1
|
||||
|
||||
itt ge
|
||||
ldrbge lr, [r1], #1
|
||||
strbge lr, [r0], #1
|
||||
|
||||
ldrb lr, [r1], #1
|
||||
strb lr, [r0], #1
|
||||
|
||||
sub r2, r2, ip
|
||||
|
||||
// Src is guaranteed to be at least word aligned by this point.
|
||||
b .L_word_aligned
|
@@ -28,30 +28,59 @@
|
||||
|
||||
#include <machine/cpu-features.h>
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
/*
|
||||
* Optimized memset() for ARM.
|
||||
/*
|
||||
* Optimized memset() for ARM.
|
||||
*
|
||||
* memset() returns its first argument.
|
||||
*/
|
||||
*/
|
||||
|
||||
.fpu neon
|
||||
.syntax unified
|
||||
|
||||
ENTRY(__memset_chk)
|
||||
.cfi_startproc
|
||||
cmp r2, r3
|
||||
bls .L_done
|
||||
|
||||
// Preserve lr for backtrace.
|
||||
push {lr}
|
||||
.cfi_def_cfa_offset 4
|
||||
.cfi_rel_offset lr, 0
|
||||
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+8)
|
||||
|
||||
.cfi_endproc
|
||||
END(__memset_chk)
|
||||
|
||||
ENTRY(bzero)
|
||||
.cfi_startproc
|
||||
mov r2, r1
|
||||
mov r1, #0
|
||||
.L_done:
|
||||
// Fall through to memset...
|
||||
.cfi_endproc
|
||||
END(bzero)
|
||||
|
||||
ENTRY(memset)
|
||||
.save {r0}
|
||||
.cfi_startproc
|
||||
stmfd sp!, {r0}
|
||||
.cfi_def_cfa_offset 4
|
||||
.cfi_rel_offset r0, 0
|
||||
|
||||
// The new algorithm is slower for copies < 16 so use the old
|
||||
// neon code in that case.
|
||||
cmp r2, #16
|
||||
blo set_less_than_16_unknown_align
|
||||
blo .L_set_less_than_16_unknown_align
|
||||
|
||||
// Use strd which requires an even and odd register so move the
|
||||
// values so that:
|
||||
@@ -65,17 +94,17 @@ ENTRY(memset)
|
||||
orr r1, r1, r1, lsr #8
|
||||
orr r1, r1, r1, lsr #16
|
||||
|
||||
check_alignment:
|
||||
.L_check_alignment:
|
||||
// Align destination to a double word to avoid the strd crossing
|
||||
// a cache line boundary.
|
||||
ands ip, r3, #7
|
||||
bne do_double_word_align
|
||||
bne .L_do_double_word_align
|
||||
|
||||
double_word_aligned:
|
||||
.L_double_word_aligned:
|
||||
mov r0, r1
|
||||
|
||||
subs r2, #64
|
||||
blo set_less_than_64
|
||||
blo .L_set_less_than_64
|
||||
|
||||
1: // Main loop sets 64 bytes at a time.
|
||||
.irp offset, #0, #8, #16, #24, #32, #40, #48, #56
|
||||
@@ -86,39 +115,39 @@ double_word_aligned:
|
||||
subs r2, #64
|
||||
bge 1b
|
||||
|
||||
set_less_than_64:
|
||||
.L_set_less_than_64:
|
||||
// Restore r2 to the count of bytes left to set.
|
||||
add r2, #64
|
||||
lsls ip, r2, #27
|
||||
bcc set_less_than_32
|
||||
bcc .L_set_less_than_32
|
||||
// Set 32 bytes.
|
||||
.irp offset, #0, #8, #16, #24
|
||||
strd r0, r1, [r3, \offset]
|
||||
.endr
|
||||
add r3, #32
|
||||
|
||||
set_less_than_32:
|
||||
bpl set_less_than_16
|
||||
.L_set_less_than_32:
|
||||
bpl .L_set_less_than_16
|
||||
// Set 16 bytes.
|
||||
.irp offset, #0, #8
|
||||
strd r0, r1, [r3, \offset]
|
||||
.endr
|
||||
add r3, #16
|
||||
|
||||
set_less_than_16:
|
||||
.L_set_less_than_16:
|
||||
// Less than 16 bytes to set.
|
||||
lsls ip, r2, #29
|
||||
bcc set_less_than_8
|
||||
bcc .L_set_less_than_8
|
||||
|
||||
// Set 8 bytes.
|
||||
strd r0, r1, [r3], #8
|
||||
|
||||
set_less_than_8:
|
||||
bpl set_less_than_4
|
||||
.L_set_less_than_8:
|
||||
bpl .L_set_less_than_4
|
||||
// Set 4 bytes
|
||||
str r1, [r3], #4
|
||||
|
||||
set_less_than_4:
|
||||
.L_set_less_than_4:
|
||||
lsls ip, r2, #31
|
||||
it ne
|
||||
strbne r1, [r3], #1
|
||||
@@ -129,7 +158,7 @@ set_less_than_4:
|
||||
ldmfd sp!, {r0}
|
||||
bx lr
|
||||
|
||||
do_double_word_align:
|
||||
.L_do_double_word_align:
|
||||
rsb ip, ip, #8
|
||||
sub r2, r2, ip
|
||||
movs r0, ip, lsl #31
|
||||
@@ -141,11 +170,11 @@ do_double_word_align:
|
||||
|
||||
// Dst is at least word aligned by this point.
|
||||
cmp ip, #4
|
||||
blo double_word_aligned
|
||||
blo .L_double_word_aligned
|
||||
str r1, [r3], #4
|
||||
b double_word_aligned
|
||||
b .L_double_word_aligned
|
||||
|
||||
set_less_than_16_unknown_align:
|
||||
.L_set_less_than_16_unknown_align:
|
||||
// Set up to 15 bytes.
|
||||
vdup.8 d0, r1
|
||||
movs ip, r2, lsl #29
|
||||
@@ -161,4 +190,9 @@ set_less_than_16_unknown_align:
|
||||
strbcs r1, [r0], #1
|
||||
ldmfd sp!, {r0}
|
||||
bx lr
|
||||
.cfi_endproc
|
||||
END(memset)
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "memset buffer overflow"
|
||||
|
@@ -4,5 +4,7 @@ $(call libc-add-cpu-variant-src,STRCAT,arch-arm/cortex-a15/bionic/strcat.S)
|
||||
$(call libc-add-cpu-variant-src,STRCMP,arch-arm/cortex-a15/bionic/strcmp.S)
|
||||
$(call libc-add-cpu-variant-src,STRCPY,arch-arm/cortex-a15/bionic/strcpy.S)
|
||||
$(call libc-add-cpu-variant-src,STRLEN,arch-arm/cortex-a15/bionic/strlen.S)
|
||||
$(call libc-add-cpu-variant-src,__STRCAT_CHK,arch-arm/cortex-a15/bionic/__strcat_chk.S)
|
||||
$(call libc-add-cpu-variant-src,__STRCPY_CHK,arch-arm/cortex-a15/bionic/__strcpy_chk.S)
|
||||
|
||||
include bionic/libc/arch-arm/generic/generic.mk
|
||||
|
218
libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
Normal file
218
libc/arch-arm/cortex-a9/bionic/__strcat_chk.S
Normal file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
.syntax unified
|
||||
.fpu neon
|
||||
.thumb
|
||||
.thumb_func
|
||||
|
||||
// Get the length of src string, then get the source of the dst string.
|
||||
// Check that the two lengths together don't exceed the threshold, then
|
||||
// do a memcpy of the data.
|
||||
ENTRY(__strcat_chk)
|
||||
.cfi_startproc
|
||||
pld [r0, #0]
|
||||
push {r0, lr}
|
||||
.cfi_def_cfa_offset 8
|
||||
.cfi_rel_offset r0, 0
|
||||
.cfi_rel_offset lr, 4
|
||||
push {r4, r5}
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_rel_offset r4, 0
|
||||
.cfi_rel_offset r5, 4
|
||||
|
||||
mov lr, r2
|
||||
|
||||
// Save the dst register to r5
|
||||
mov r5, r0
|
||||
|
||||
// Zero out r4
|
||||
eor r4, r4, r4
|
||||
|
||||
// r1 contains the address of the string to count.
|
||||
.L_strlen_start:
|
||||
mov r0, r1
|
||||
|
||||
ands r3, r0, #7
|
||||
bne .L_align_src
|
||||
|
||||
.p2align 2
|
||||
.L_mainloop:
|
||||
ldmia r1!, {r2, r3}
|
||||
|
||||
pld [r1, #64]
|
||||
|
||||
sub ip, r2, #0x01010101
|
||||
bic ip, ip, r2
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_first_register
|
||||
|
||||
sub ip, r3, #0x01010101
|
||||
bic ip, ip, r3
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
b .L_mainloop
|
||||
|
||||
.L_zero_in_first_register:
|
||||
sub r3, r1, r0
|
||||
// Check for zero in byte 0.
|
||||
lsls r2, ip, #17
|
||||
beq .L_check_byte1_reg1
|
||||
|
||||
sub r3, r3, #8
|
||||
b .L_finish
|
||||
|
||||
.L_check_byte1_reg1:
|
||||
bcc .L_check_byte2_reg1
|
||||
|
||||
sub r3, r3, #7
|
||||
b .L_finish
|
||||
|
||||
.L_check_byte2_reg1:
|
||||
// Check for zero in byte 2.
|
||||
tst ip, #0x800000
|
||||
it ne
|
||||
subne r3, r3, #6
|
||||
bne .L_finish
|
||||
sub r3, r3, #5
|
||||
b .L_finish
|
||||
|
||||
.L_zero_in_second_register:
|
||||
sub r3, r1, r0
|
||||
// Check for zero in byte 0.
|
||||
lsls r2, ip, #17
|
||||
beq .L_check_byte1_reg2
|
||||
|
||||
sub r3, r3, #4
|
||||
b .L_finish
|
||||
|
||||
.L_check_byte1_reg2:
|
||||
bcc .L_check_byte2_reg2
|
||||
|
||||
sub r3, r3, #3
|
||||
b .L_finish
|
||||
|
||||
.L_check_byte2_reg2:
|
||||
// Check for zero in byte 2.
|
||||
tst ip, #0x800000
|
||||
it ne
|
||||
subne r3, r3, #2
|
||||
bne .L_finish
|
||||
sub r3, r3, #1
|
||||
b .L_finish
|
||||
|
||||
.L_align_src:
|
||||
// Align to a double word (64 bits).
|
||||
rsb r3, r3, #8
|
||||
lsls ip, r3, #31
|
||||
beq .L_align_to_32
|
||||
|
||||
ldrb r2, [r1], #1
|
||||
cbz r2, .L_done
|
||||
|
||||
.L_align_to_32:
|
||||
bcc .L_align_to_64
|
||||
|
||||
ldrb r2, [r1], #1
|
||||
cbz r2, .L_done
|
||||
ldrb r2, [r1], #1
|
||||
cbz r2, .L_done
|
||||
|
||||
.L_align_to_64:
|
||||
tst r3, #4
|
||||
beq .L_mainloop
|
||||
ldr r2, [r1], #4
|
||||
|
||||
sub ip, r2, #0x01010101
|
||||
bic ip, ip, r2
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
b .L_mainloop
|
||||
|
||||
.L_done:
|
||||
sub r3, r1, r0
|
||||
sub r3, r3, #1
|
||||
|
||||
.L_finish:
|
||||
cmp r4, #0
|
||||
bne .L_strlen_done
|
||||
|
||||
// Time to get the dst string length.
|
||||
mov r1, r5
|
||||
|
||||
// Save the original source address to r5.
|
||||
mov r5, r0
|
||||
|
||||
// Save the current length (adding 1 for the terminator).
|
||||
add r4, r3, #1
|
||||
b .L_strlen_start
|
||||
|
||||
// r0 holds the pointer to the dst string.
|
||||
// r3 holds the dst string length.
|
||||
// r4 holds the src string length + 1.
|
||||
.L_strlen_done:
|
||||
add r2, r3, r4
|
||||
cmp r2, lr
|
||||
bgt .L_fortify_check_failed
|
||||
|
||||
// Set up the registers for the memcpy code.
|
||||
mov r1, r5
|
||||
pld [r1, #64]
|
||||
mov r2, r4
|
||||
add r0, r0, r3
|
||||
pop {r4, r5}
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore r4
|
||||
.cfi_restore r5
|
||||
|
||||
#include "memcpy_base.S"
|
||||
|
||||
.L_fortify_check_failed:
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_rel_offset r4, 0
|
||||
.cfi_rel_offset r5, 4
|
||||
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+4)
|
||||
|
||||
.cfi_endproc
|
||||
END(__strcat_chk)
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "strcat buffer overflow"
|
178
libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
Normal file
178
libc/arch-arm/cortex-a9/bionic/__strcpy_chk.S
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
.syntax unified
|
||||
.fpu neon
|
||||
.thumb
|
||||
.thumb_func
|
||||
|
||||
// Get the length of the source string first, then do a memcpy of the data
|
||||
// instead of a strcpy.
|
||||
ENTRY(__strcpy_chk)
|
||||
.cfi_startproc
|
||||
pld [r0, #0]
|
||||
push {r0, lr}
|
||||
.cfi_def_cfa_offset 8
|
||||
.cfi_rel_offset r0, 0
|
||||
.cfi_rel_offset lr, 4
|
||||
|
||||
mov lr, r2
|
||||
mov r0, r1
|
||||
|
||||
ands r3, r0, #7
|
||||
bne .L_align_src
|
||||
|
||||
.p2align 2
|
||||
.L_mainloop:
|
||||
ldmia r0!, {r2, r3}
|
||||
|
||||
pld [r0, #64]
|
||||
|
||||
sub ip, r2, #0x01010101
|
||||
bic ip, ip, r2
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_first_register
|
||||
|
||||
sub ip, r3, #0x01010101
|
||||
bic ip, ip, r3
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
b .L_mainloop
|
||||
|
||||
.L_zero_in_first_register:
|
||||
sub r3, r0, r1
|
||||
// Check for zero in byte 0.
|
||||
lsls r2, ip, #17
|
||||
beq .L_check_byte1_reg1
|
||||
|
||||
sub r3, r3, #8
|
||||
b .L_check_size
|
||||
|
||||
.L_check_byte1_reg1:
|
||||
bcc .L_check_byte2_reg1
|
||||
|
||||
sub r3, r3, #7
|
||||
b .L_check_size
|
||||
|
||||
.L_check_byte2_reg1:
|
||||
// Check for zero in byte 2.
|
||||
tst ip, #0x800000
|
||||
it ne
|
||||
subne r3, r3, #6
|
||||
bne .L_check_size
|
||||
sub r3, r3, #5
|
||||
b .L_check_size
|
||||
|
||||
.L_zero_in_second_register:
|
||||
sub r3, r0, r1
|
||||
// Check for zero in byte 0.
|
||||
lsls r2, ip, #17
|
||||
beq .L_check_byte1_reg2
|
||||
|
||||
sub r3, r3, #4
|
||||
b .L_check_size
|
||||
|
||||
.L_check_byte1_reg2:
|
||||
bcc .L_check_byte2_reg2
|
||||
|
||||
sub r3, r3, #3
|
||||
b .L_check_size
|
||||
|
||||
.L_check_byte2_reg2:
|
||||
// Check for zero in byte 2.
|
||||
tst ip, #0x800000
|
||||
it ne
|
||||
subne r3, r3, #2
|
||||
bne .L_check_size
|
||||
sub r3, r3, #1
|
||||
b .L_check_size
|
||||
|
||||
.L_align_src:
|
||||
// Align to a double word (64 bits).
|
||||
rsb r3, r3, #8
|
||||
lsls ip, r3, #31
|
||||
beq .L_align_to_32
|
||||
|
||||
ldrb r2, [r0], #1
|
||||
cbz r2, .L_done
|
||||
|
||||
.L_align_to_32:
|
||||
bcc .L_align_to_64
|
||||
|
||||
ldrb r2, [r0], #1
|
||||
cbz r2, .L_done
|
||||
ldrb r2, [r0], #1
|
||||
cbz r2, .L_done
|
||||
|
||||
.L_align_to_64:
|
||||
tst r3, #4
|
||||
beq .L_mainloop
|
||||
ldr r2, [r0], #4
|
||||
|
||||
sub ip, r2, #0x01010101
|
||||
bic ip, ip, r2
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
b .L_mainloop
|
||||
|
||||
.L_done:
|
||||
sub r3, r0, r1
|
||||
sub r3, r3, #1
|
||||
|
||||
.L_check_size:
|
||||
pld [r1, #0]
|
||||
pld [r1, #64]
|
||||
ldr r0, [sp]
|
||||
cmp r3, lr
|
||||
bge .L_fortify_check_failed
|
||||
|
||||
// Add 1 for copy length to get the string terminator.
|
||||
add r2, r3, #1
|
||||
|
||||
#include "memcpy_base.S"
|
||||
|
||||
.L_fortify_check_failed:
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+4)
|
||||
|
||||
.cfi_endproc
|
||||
END(__strcpy_chk)
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "strcpy buffer overflow"
|
@@ -26,8 +26,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <machine/cpu-features.h>
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
/*
|
||||
* This code assumes it is running on a processor that supports all arm v7
|
||||
@@ -35,177 +35,51 @@
|
||||
* cache line.
|
||||
*/
|
||||
|
||||
.text
|
||||
.syntax unified
|
||||
.fpu neon
|
||||
.thumb
|
||||
.thumb_func
|
||||
|
||||
#define CACHE_LINE_SIZE 32
|
||||
ENTRY(__memcpy_chk)
|
||||
.cfi_startproc
|
||||
cmp r2, r3
|
||||
bgt __memcpy_chk_fail
|
||||
|
||||
// Fall through to memcpy...
|
||||
.cfi_endproc
|
||||
END(__memcpy_chk)
|
||||
|
||||
ENTRY(memcpy)
|
||||
.save {r0, lr}
|
||||
/* start preloading as early as possible */
|
||||
pld [r1, #(CACHE_LINE_SIZE * 0)]
|
||||
stmfd sp!, {r0, lr}
|
||||
pld [r1, #(CACHE_LINE_SIZE * 2)]
|
||||
.cfi_startproc
|
||||
pld [r1, #0]
|
||||
stmfd sp!, {r0, lr}
|
||||
.cfi_def_cfa_offset 8
|
||||
.cfi_rel_offset r0, 0
|
||||
.cfi_rel_offset lr, 4
|
||||
pld [r1, #64]
|
||||
|
||||
// Check so divider is at least 16 bytes, needed for alignment code.
|
||||
cmp r2, #16
|
||||
blo 5f
|
||||
|
||||
|
||||
/* check if buffers are aligned. If so, run arm-only version */
|
||||
eor r3, r0, r1
|
||||
ands r3, r3, #0x3
|
||||
beq 11f
|
||||
|
||||
/* Check the upper size limit for Neon unaligned memory access in memcpy */
|
||||
cmp r2, #224
|
||||
blo 3f
|
||||
|
||||
/* align destination to 16 bytes for the write-buffer */
|
||||
rsb r3, r0, #0
|
||||
ands r3, r3, #0xF
|
||||
beq 3f
|
||||
|
||||
/* copy up to 15-bytes (count in r3) */
|
||||
sub r2, r2, r3
|
||||
movs ip, r3, lsl #31
|
||||
ldrmib lr, [r1], #1
|
||||
strmib lr, [r0], #1
|
||||
ldrcsb ip, [r1], #1
|
||||
ldrcsb lr, [r1], #1
|
||||
strcsb ip, [r0], #1
|
||||
strcsb lr, [r0], #1
|
||||
movs ip, r3, lsl #29
|
||||
bge 1f
|
||||
// copies 4 bytes, destination 32-bits aligned
|
||||
vld1.32 {d0[0]}, [r1]!
|
||||
vst1.32 {d0[0]}, [r0, :32]!
|
||||
1: bcc 2f
|
||||
// copies 8 bytes, destination 64-bits aligned
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0, :64]!
|
||||
2:
|
||||
/* preload immediately the next cache line, which we may need */
|
||||
pld [r1, #(CACHE_LINE_SIZE * 0)]
|
||||
pld [r1, #(CACHE_LINE_SIZE * 2)]
|
||||
3:
|
||||
/* make sure we have at least 64 bytes to copy */
|
||||
subs r2, r2, #64
|
||||
blo 2f
|
||||
|
||||
/* preload all the cache lines we need */
|
||||
pld [r1, #(CACHE_LINE_SIZE * 4)]
|
||||
pld [r1, #(CACHE_LINE_SIZE * 6)]
|
||||
|
||||
1: /* The main loop copies 64 bytes at a time */
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
vld1.8 {d4 - d7}, [r1]!
|
||||
pld [r1, #(CACHE_LINE_SIZE * 6)]
|
||||
subs r2, r2, #64
|
||||
vst1.8 {d0 - d3}, [r0]!
|
||||
vst1.8 {d4 - d7}, [r0]!
|
||||
bhs 1b
|
||||
|
||||
2: /* fix-up the remaining count and make sure we have >= 32 bytes left */
|
||||
add r2, r2, #64
|
||||
subs r2, r2, #32
|
||||
blo 4f
|
||||
|
||||
3: /* 32 bytes at a time. These cache lines were already preloaded */
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
subs r2, r2, #32
|
||||
vst1.8 {d0 - d3}, [r0]!
|
||||
bhs 3b
|
||||
|
||||
4: /* less than 32 left */
|
||||
add r2, r2, #32
|
||||
tst r2, #0x10
|
||||
beq 5f
|
||||
// copies 16 bytes, 128-bits aligned
|
||||
vld1.8 {d0, d1}, [r1]!
|
||||
vst1.8 {d0, d1}, [r0]!
|
||||
5: /* copy up to 15-bytes (count in r2) */
|
||||
movs ip, r2, lsl #29
|
||||
bcc 1f
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0]!
|
||||
1: bge 2f
|
||||
vld1.32 {d0[0]}, [r1]!
|
||||
vst1.32 {d0[0]}, [r0]!
|
||||
2: movs ip, r2, lsl #31
|
||||
ldrmib r3, [r1], #1
|
||||
ldrcsb ip, [r1], #1
|
||||
ldrcsb lr, [r1], #1
|
||||
strmib r3, [r0], #1
|
||||
strcsb ip, [r0], #1
|
||||
strcsb lr, [r0], #1
|
||||
|
||||
ldmfd sp!, {r0, lr}
|
||||
bx lr
|
||||
11:
|
||||
/* Simple arm-only copy loop to handle aligned copy operations */
|
||||
stmfd sp!, {r4, r5, r6, r7, r8}
|
||||
pld [r1, #(CACHE_LINE_SIZE * 4)]
|
||||
|
||||
/* Check alignment */
|
||||
rsb r3, r1, #0
|
||||
ands r3, #3
|
||||
beq 2f
|
||||
|
||||
/* align source to 32 bits. We need to insert 2 instructions between
|
||||
* a ldr[b|h] and str[b|h] because byte and half-word instructions
|
||||
* stall 2 cycles.
|
||||
*/
|
||||
movs r12, r3, lsl #31
|
||||
sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */
|
||||
ldrmib r3, [r1], #1
|
||||
ldrcsb r4, [r1], #1
|
||||
ldrcsb r5, [r1], #1
|
||||
strmib r3, [r0], #1
|
||||
strcsb r4, [r0], #1
|
||||
strcsb r5, [r0], #1
|
||||
|
||||
2:
|
||||
subs r2, r2, #64
|
||||
blt 4f
|
||||
|
||||
3: /* Main copy loop, copying 64 bytes at a time */
|
||||
pld [r1, #(CACHE_LINE_SIZE * 8)]
|
||||
ldmia r1!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
stmia r0!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
ldmia r1!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
stmia r0!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
subs r2, r2, #64
|
||||
bge 3b
|
||||
|
||||
4: /* Check if there are > 32 bytes left */
|
||||
adds r2, r2, #64
|
||||
subs r2, r2, #32
|
||||
blt 5f
|
||||
|
||||
/* Copy 32 bytes */
|
||||
ldmia r1!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
stmia r0!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
subs r2, #32
|
||||
|
||||
5: /* Handle any remaining bytes */
|
||||
adds r2, #32
|
||||
beq 6f
|
||||
|
||||
movs r12, r2, lsl #28
|
||||
ldmcsia r1!, {r3, r4, r5, r6} /* 16 bytes */
|
||||
ldmmiia r1!, {r7, r8} /* 8 bytes */
|
||||
stmcsia r0!, {r3, r4, r5, r6}
|
||||
stmmiia r0!, {r7, r8}
|
||||
movs r12, r2, lsl #30
|
||||
ldrcs r3, [r1], #4 /* 4 bytes */
|
||||
ldrmih r4, [r1], #2 /* 2 bytes */
|
||||
strcs r3, [r0], #4
|
||||
strmih r4, [r0], #2
|
||||
tst r2, #0x1
|
||||
ldrneb r3, [r1] /* last byte */
|
||||
strneb r3, [r0]
|
||||
6:
|
||||
ldmfd sp!, {r4, r5, r6, r7, r8}
|
||||
ldmfd sp!, {r0, pc}
|
||||
#include "memcpy_base.S"
|
||||
.cfi_endproc
|
||||
END(memcpy)
|
||||
|
||||
.cfi_startproc
|
||||
__memcpy_chk_fail:
|
||||
// Preserve lr for backtrace.
|
||||
push {lr}
|
||||
.cfi_def_cfa_offset 4
|
||||
.cfi_rel_offset lr, 0
|
||||
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+4)
|
||||
.cfi_endproc
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "memcpy buffer overflow"
|
||||
|
206
libc/arch-arm/cortex-a9/bionic/memcpy_base.S
Normal file
206
libc/arch-arm/cortex-a9/bionic/memcpy_base.S
Normal file
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code assumes it is running on a processor that supports all arm v7
|
||||
* instructions, that supports neon instructions, and that has a 32 byte
|
||||
* cache line.
|
||||
*/
|
||||
|
||||
// Check so divider is at least 16 bytes, needed for alignment code.
|
||||
cmp r2, #16
|
||||
blo 5f
|
||||
|
||||
|
||||
/* check if buffers are aligned. If so, run arm-only version */
|
||||
eor r3, r0, r1
|
||||
ands r3, r3, #0x3
|
||||
beq 11f
|
||||
|
||||
/* Check the upper size limit for Neon unaligned memory access in memcpy */
|
||||
cmp r2, #224
|
||||
blo 3f
|
||||
|
||||
/* align destination to 16 bytes for the write-buffer */
|
||||
rsb r3, r0, #0
|
||||
ands r3, r3, #0xF
|
||||
beq 3f
|
||||
|
||||
/* copy up to 15-bytes (count in r3) */
|
||||
sub r2, r2, r3
|
||||
movs ip, r3, lsl #31
|
||||
itt mi
|
||||
ldrbmi lr, [r1], #1
|
||||
strbmi lr, [r0], #1
|
||||
itttt cs
|
||||
ldrbcs ip, [r1], #1
|
||||
ldrbcs lr, [r1], #1
|
||||
strbcs ip, [r0], #1
|
||||
strbcs lr, [r0], #1
|
||||
movs ip, r3, lsl #29
|
||||
bge 1f
|
||||
// copies 4 bytes, destination 32-bits aligned
|
||||
vld1.32 {d0[0]}, [r1]!
|
||||
vst1.32 {d0[0]}, [r0, :32]!
|
||||
1: bcc 2f
|
||||
// copies 8 bytes, destination 64-bits aligned
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0, :64]!
|
||||
2:
|
||||
/* preload immediately the next cache line, which we may need */
|
||||
pld [r1, #0]
|
||||
pld [r1, #(32 * 2)]
|
||||
3:
|
||||
/* make sure we have at least 64 bytes to copy */
|
||||
subs r2, r2, #64
|
||||
blo 2f
|
||||
|
||||
/* preload all the cache lines we need */
|
||||
pld [r1, #(32 * 4)]
|
||||
pld [r1, #(32 * 6)]
|
||||
|
||||
1: /* The main loop copies 64 bytes at a time */
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
vld1.8 {d4 - d7}, [r1]!
|
||||
pld [r1, #(32 * 6)]
|
||||
subs r2, r2, #64
|
||||
vst1.8 {d0 - d3}, [r0]!
|
||||
vst1.8 {d4 - d7}, [r0]!
|
||||
bhs 1b
|
||||
|
||||
2: /* fix-up the remaining count and make sure we have >= 32 bytes left */
|
||||
add r2, r2, #64
|
||||
subs r2, r2, #32
|
||||
blo 4f
|
||||
|
||||
3: /* 32 bytes at a time. These cache lines were already preloaded */
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
subs r2, r2, #32
|
||||
vst1.8 {d0 - d3}, [r0]!
|
||||
bhs 3b
|
||||
|
||||
4: /* less than 32 left */
|
||||
add r2, r2, #32
|
||||
tst r2, #0x10
|
||||
beq 5f
|
||||
// copies 16 bytes, 128-bits aligned
|
||||
vld1.8 {d0, d1}, [r1]!
|
||||
vst1.8 {d0, d1}, [r0]!
|
||||
5: /* copy up to 15-bytes (count in r2) */
|
||||
movs ip, r2, lsl #29
|
||||
bcc 1f
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0]!
|
||||
1: bge 2f
|
||||
vld1.32 {d0[0]}, [r1]!
|
||||
vst1.32 {d0[0]}, [r0]!
|
||||
2: movs ip, r2, lsl #31
|
||||
itt mi
|
||||
ldrbmi r3, [r1], #1
|
||||
strbmi r3, [r0], #1
|
||||
itttt cs
|
||||
ldrbcs ip, [r1], #1
|
||||
ldrbcs lr, [r1], #1
|
||||
strbcs ip, [r0], #1
|
||||
strbcs lr, [r0], #1
|
||||
|
||||
ldmfd sp!, {r0, lr}
|
||||
bx lr
|
||||
11:
|
||||
/* Simple arm-only copy loop to handle aligned copy operations */
|
||||
stmfd sp!, {r4, r5, r6, r7, r8}
|
||||
pld [r1, #(32 * 4)]
|
||||
|
||||
/* Check alignment */
|
||||
rsb r3, r1, #0
|
||||
ands r3, #3
|
||||
beq 2f
|
||||
|
||||
/* align source to 32 bits. We need to insert 2 instructions between
|
||||
* a ldr[b|h] and str[b|h] because byte and half-word instructions
|
||||
* stall 2 cycles.
|
||||
*/
|
||||
movs r12, r3, lsl #31
|
||||
sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */
|
||||
itt mi
|
||||
ldrbmi r3, [r1], #1
|
||||
strbmi r3, [r0], #1
|
||||
itttt cs
|
||||
ldrbcs r4, [r1], #1
|
||||
ldrbcs r5, [r1], #1
|
||||
strbcs r4, [r0], #1
|
||||
strbcs r5, [r0], #1
|
||||
|
||||
2:
|
||||
subs r2, r2, #64
|
||||
blt 4f
|
||||
|
||||
3: /* Main copy loop, copying 64 bytes at a time */
|
||||
pld [r1, #(32 * 8)]
|
||||
ldmia r1!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
stmia r0!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
ldmia r1!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
stmia r0!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
subs r2, r2, #64
|
||||
bge 3b
|
||||
|
||||
4: /* Check if there are > 32 bytes left */
|
||||
adds r2, r2, #64
|
||||
subs r2, r2, #32
|
||||
blt 5f
|
||||
|
||||
/* Copy 32 bytes */
|
||||
ldmia r1!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
stmia r0!, {r3, r4, r5, r6, r7, r8, r12, lr}
|
||||
subs r2, #32
|
||||
|
||||
5: /* Handle any remaining bytes */
|
||||
adds r2, #32
|
||||
beq 6f
|
||||
|
||||
movs r12, r2, lsl #28
|
||||
itt cs
|
||||
ldmiacs r1!, {r3, r4, r5, r6} /* 16 bytes */
|
||||
stmiacs r0!, {r3, r4, r5, r6}
|
||||
itt mi
|
||||
ldmiami r1!, {r7, r8} /* 8 bytes */
|
||||
stmiami r0!, {r7, r8}
|
||||
movs r12, r2, lsl #30
|
||||
itt cs
|
||||
ldrcs r3, [r1], #4 /* 4 bytes */
|
||||
strcs r3, [r0], #4
|
||||
itt mi
|
||||
ldrhmi r4, [r1], #2 /* 2 bytes */
|
||||
strhmi r4, [r0], #2
|
||||
tst r2, #0x1
|
||||
itt ne
|
||||
ldrbne r3, [r1] /* last byte */
|
||||
strbne r3, [r0]
|
||||
6:
|
||||
ldmfd sp!, {r4, r5, r6, r7, r8}
|
||||
ldmfd sp!, {r0, pc}
|
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <machine/cpu-features.h>
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
/*
|
||||
* This code assumes it is running on a processor that supports all arm v7
|
||||
@@ -36,19 +37,49 @@
|
||||
|
||||
.fpu neon
|
||||
|
||||
ENTRY(__memset_chk)
|
||||
.cfi_startproc
|
||||
cmp r2, r3
|
||||
bls .L_done
|
||||
|
||||
// Preserve lr for backtrace.
|
||||
push {lr}
|
||||
.cfi_def_cfa_offset 4
|
||||
.cfi_rel_offset lr, 0
|
||||
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+8)
|
||||
|
||||
.cfi_endproc
|
||||
END(__memset_chk)
|
||||
|
||||
ENTRY(bzero)
|
||||
.cfi_startproc
|
||||
mov r2, r1
|
||||
mov r1, #0
|
||||
|
||||
.L_done:
|
||||
// Fall through to memset...
|
||||
.cfi_endproc
|
||||
END(bzero)
|
||||
|
||||
/* memset() returns its first argument. */
|
||||
ENTRY(memset)
|
||||
.cfi_startproc
|
||||
# The neon memset only wins for less than 132.
|
||||
cmp r2, #132
|
||||
bhi 11f
|
||||
|
||||
.save {r0}
|
||||
stmfd sp!, {r0}
|
||||
.cfi_def_cfa_offset 4
|
||||
.cfi_rel_offset r0, 0
|
||||
|
||||
vdup.8 q0, r1
|
||||
|
||||
@@ -86,8 +117,15 @@ ENTRY(memset)
|
||||
* offset = (4-(src&3))&3 = -src & 3
|
||||
*/
|
||||
|
||||
.save {r0, r4-r7, lr}
|
||||
stmfd sp!, {r0, r4-r7, lr}
|
||||
.cfi_def_cfa_offset 24
|
||||
.cfi_rel_offset r0, 0
|
||||
.cfi_rel_offset r4, 4
|
||||
.cfi_rel_offset r5, 8
|
||||
.cfi_rel_offset r6, 12
|
||||
.cfi_rel_offset r7, 16
|
||||
.cfi_rel_offset lr, 20
|
||||
|
||||
rsb r3, r0, #0
|
||||
ands r3, r3, #3
|
||||
cmp r3, r2
|
||||
@@ -149,4 +187,9 @@ ENTRY(memset)
|
||||
strcsb r1, [r0]
|
||||
ldmfd sp!, {r0, r4-r7, lr}
|
||||
bx lr
|
||||
.cfi_endproc
|
||||
END(memset)
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "memset buffer overflow"
|
||||
|
@@ -4,5 +4,7 @@ $(call libc-add-cpu-variant-src,STRCAT,arch-arm/cortex-a9/bionic/strcat.S)
|
||||
$(call libc-add-cpu-variant-src,STRCMP,arch-arm/cortex-a9/bionic/strcmp.S)
|
||||
$(call libc-add-cpu-variant-src,STRCPY,arch-arm/cortex-a9/bionic/strcpy.S)
|
||||
$(call libc-add-cpu-variant-src,STRLEN,arch-arm/cortex-a9/bionic/strlen.S)
|
||||
$(call libc-add-cpu-variant-src,__STRCAT_CHK,arch-arm/cortex-a9/bionic/__strcat_chk.S)
|
||||
$(call libc-add-cpu-variant-src,__STRCPY_CHK,arch-arm/cortex-a9/bionic/__strcpy_chk.S)
|
||||
|
||||
include bionic/libc/arch-arm/generic/generic.mk
|
||||
|
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <machine/cpu-features.h>
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
/*
|
||||
* Optimized memcpy() for ARM.
|
||||
@@ -36,6 +37,13 @@
|
||||
* so we have to preserve R0.
|
||||
*/
|
||||
|
||||
ENTRY(__memcpy_chk)
|
||||
cmp r2, r3
|
||||
bgt fortify_check_failed
|
||||
|
||||
// Fall through to memcpy...
|
||||
END(__memcpy_chk)
|
||||
|
||||
ENTRY(memcpy)
|
||||
/* The stack must always be 64-bits aligned to be compliant with the
|
||||
* ARM ABI. Since we have to save R0, we might as well save R4
|
||||
@@ -377,4 +385,20 @@ copy_last_3_and_return:
|
||||
add sp, sp, #28
|
||||
ldmfd sp!, {r0, r4, lr}
|
||||
bx lr
|
||||
|
||||
// Only reached when the __memcpy_chk check fails.
|
||||
fortify_check_failed:
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+8)
|
||||
END(memcpy)
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "memcpy buffer overflow"
|
||||
|
@@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
/*
|
||||
* Optimized memset() for ARM.
|
||||
@@ -34,9 +35,28 @@
|
||||
* memset() returns its first argument.
|
||||
*/
|
||||
|
||||
ENTRY(__memset_chk)
|
||||
cmp r2, r3
|
||||
bls done
|
||||
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+8)
|
||||
|
||||
END(__memset_chk)
|
||||
|
||||
ENTRY(bzero)
|
||||
mov r2, r1
|
||||
mov r1, #0
|
||||
|
||||
done:
|
||||
// Fall through to memset...
|
||||
END(bzero)
|
||||
|
||||
ENTRY(memset)
|
||||
@@ -107,3 +127,7 @@ ENTRY(memset)
|
||||
ldmfd sp!, {r0, r4-r7, lr}
|
||||
bx lr
|
||||
END(memset)
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "memset buffer overflow"
|
||||
|
@@ -4,3 +4,5 @@ $(call libc-add-cpu-variant-src,STRCAT,string/strcat.c)
|
||||
$(call libc-add-cpu-variant-src,STRCMP,arch-arm/generic/bionic/strcmp.S)
|
||||
$(call libc-add-cpu-variant-src,STRCPY,arch-arm/generic/bionic/strcpy.S)
|
||||
$(call libc-add-cpu-variant-src,STRLEN,arch-arm/generic/bionic/strlen.c)
|
||||
$(call libc-add-cpu-variant-src,__STRCAT_CHK,bionic/__strcat_chk.cpp)
|
||||
$(call libc-add-cpu-variant-src,__STRCPY_CHK,bionic/__strcpy_chk.cpp)
|
||||
|
215
libc/arch-arm/krait/bionic/__strcat_chk.S
Normal file
215
libc/arch-arm/krait/bionic/__strcat_chk.S
Normal file
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
.syntax unified
|
||||
|
||||
.thumb
|
||||
.thumb_func
|
||||
|
||||
// Get the length of src string, then get the source of the dst string.
|
||||
// Check that the two lengths together don't exceed the threshold, then
|
||||
// do a memcpy of the data.
|
||||
ENTRY(__strcat_chk)
|
||||
.cfi_startproc
|
||||
pld [r0, #0]
|
||||
push {r0, lr}
|
||||
.cfi_def_cfa_offset 8
|
||||
.cfi_rel_offset r0, 0
|
||||
.cfi_rel_offset lr, 4
|
||||
push {r4, r5}
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_rel_offset r4, 0
|
||||
.cfi_rel_offset r5, 4
|
||||
|
||||
mov lr, r2
|
||||
|
||||
// Save the dst register to r5
|
||||
mov r5, r0
|
||||
|
||||
// Zero out r4
|
||||
eor r4, r4, r4
|
||||
|
||||
// r1 contains the address of the string to count.
|
||||
.L_strlen_start:
|
||||
mov r0, r1
|
||||
ands r3, r1, #7
|
||||
beq .L_mainloop
|
||||
|
||||
// Align to a double word (64 bits).
|
||||
rsb r3, r3, #8
|
||||
lsls ip, r3, #31
|
||||
beq .L_align_to_32
|
||||
|
||||
ldrb r2, [r1], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
|
||||
.L_align_to_32:
|
||||
bcc .L_align_to_64
|
||||
ands ip, r3, #2
|
||||
beq .L_align_to_64
|
||||
|
||||
ldrb r2, [r1], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
ldrb r2, [r1], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
|
||||
.L_align_to_64:
|
||||
tst r3, #4
|
||||
beq .L_mainloop
|
||||
ldr r3, [r1], #4
|
||||
|
||||
sub ip, r3, #0x01010101
|
||||
bic ip, ip, r3
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
|
||||
.p2align 2
|
||||
.L_mainloop:
|
||||
ldrd r2, r3, [r1], #8
|
||||
|
||||
pld [r1, #64]
|
||||
|
||||
sub ip, r2, #0x01010101
|
||||
bic ip, ip, r2
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_first_register
|
||||
|
||||
sub ip, r3, #0x01010101
|
||||
bic ip, ip, r3
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
b .L_mainloop
|
||||
|
||||
.L_update_count_and_finish:
|
||||
sub r3, r1, r0
|
||||
sub r3, r3, #1
|
||||
b .L_finish
|
||||
|
||||
.L_zero_in_first_register:
|
||||
sub r3, r1, r0
|
||||
lsls r2, ip, #17
|
||||
bne .L_sub8_and_finish
|
||||
bcs .L_sub7_and_finish
|
||||
lsls ip, ip, #1
|
||||
bne .L_sub6_and_finish
|
||||
|
||||
sub r3, r3, #5
|
||||
b .L_finish
|
||||
|
||||
.L_sub8_and_finish:
|
||||
sub r3, r3, #8
|
||||
b .L_finish
|
||||
|
||||
.L_sub7_and_finish:
|
||||
sub r3, r3, #7
|
||||
b .L_finish
|
||||
|
||||
.L_sub6_and_finish:
|
||||
sub r3, r3, #6
|
||||
b .L_finish
|
||||
|
||||
.L_zero_in_second_register:
|
||||
sub r3, r1, r0
|
||||
lsls r2, ip, #17
|
||||
bne .L_sub4_and_finish
|
||||
bcs .L_sub3_and_finish
|
||||
lsls ip, ip, #1
|
||||
bne .L_sub2_and_finish
|
||||
|
||||
sub r3, r3, #1
|
||||
b .L_finish
|
||||
|
||||
.L_sub4_and_finish:
|
||||
sub r3, r3, #4
|
||||
b .L_finish
|
||||
|
||||
.L_sub3_and_finish:
|
||||
sub r3, r3, #3
|
||||
b .L_finish
|
||||
|
||||
.L_sub2_and_finish:
|
||||
sub r3, r3, #2
|
||||
|
||||
.L_finish:
|
||||
cmp r4, #0
|
||||
bne .L_strlen_done
|
||||
|
||||
// Time to get the dst string length.
|
||||
mov r1, r5
|
||||
|
||||
// Save the original source address to r5.
|
||||
mov r5, r0
|
||||
|
||||
// Save the current length (adding 1 for the terminator).
|
||||
add r4, r3, #1
|
||||
b .L_strlen_start
|
||||
|
||||
// r0 holds the pointer to the dst string.
|
||||
// r3 holds the dst string length.
|
||||
// r4 holds the src string length + 1.
|
||||
.L_strlen_done:
|
||||
add r2, r3, r4
|
||||
cmp r2, lr
|
||||
bgt .L_fortify_check_failed
|
||||
|
||||
// Set up the registers for the memcpy code.
|
||||
mov r1, r5
|
||||
pld [r1, #64]
|
||||
mov r2, r4
|
||||
add r0, r0, r3
|
||||
pop {r4, r5}
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore r4
|
||||
.cfi_restore r5
|
||||
|
||||
#include "memcpy_base.S"
|
||||
|
||||
.L_fortify_check_failed:
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_rel_offset r4, 0
|
||||
.cfi_rel_offset r5, 4
|
||||
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+4)
|
||||
|
||||
.cfi_endproc
|
||||
END(__strcat_chk)
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "strcat buffer overflow"
|
175
libc/arch-arm/krait/bionic/__strcpy_chk.S
Normal file
175
libc/arch-arm/krait/bionic/__strcpy_chk.S
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
.syntax unified
|
||||
|
||||
.thumb
|
||||
.thumb_func
|
||||
|
||||
// Get the length of the source string first, then do a memcpy of the data
|
||||
// instead of a strcpy.
|
||||
ENTRY(__strcpy_chk)
|
||||
.cfi_startproc
|
||||
pld [r0, #0]
|
||||
push {r0, lr}
|
||||
.cfi_def_cfa_offset 8
|
||||
.cfi_rel_offset r0, 0
|
||||
.cfi_rel_offset lr, 4
|
||||
|
||||
mov lr, r2
|
||||
mov r0, r1
|
||||
|
||||
ands r3, r1, #7
|
||||
beq .L_mainloop
|
||||
|
||||
// Align to a double word (64 bits).
|
||||
rsb r3, r3, #8
|
||||
lsls ip, r3, #31
|
||||
beq .L_align_to_32
|
||||
|
||||
ldrb r2, [r0], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
|
||||
.L_align_to_32:
|
||||
bcc .L_align_to_64
|
||||
ands ip, r3, #2
|
||||
beq .L_align_to_64
|
||||
|
||||
ldrb r2, [r0], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
ldrb r2, [r0], #1
|
||||
cbz r2, .L_update_count_and_finish
|
||||
|
||||
.L_align_to_64:
|
||||
tst r3, #4
|
||||
beq .L_mainloop
|
||||
ldr r3, [r0], #4
|
||||
|
||||
sub ip, r3, #0x01010101
|
||||
bic ip, ip, r3
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
|
||||
.p2align 2
|
||||
.L_mainloop:
|
||||
ldrd r2, r3, [r0], #8
|
||||
|
||||
pld [r0, #64]
|
||||
|
||||
sub ip, r2, #0x01010101
|
||||
bic ip, ip, r2
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_first_register
|
||||
|
||||
sub ip, r3, #0x01010101
|
||||
bic ip, ip, r3
|
||||
ands ip, ip, #0x80808080
|
||||
bne .L_zero_in_second_register
|
||||
b .L_mainloop
|
||||
|
||||
.L_update_count_and_finish:
|
||||
sub r3, r0, r1
|
||||
sub r3, r3, #1
|
||||
b .L_check_size
|
||||
|
||||
.L_zero_in_first_register:
|
||||
sub r3, r0, r1
|
||||
lsls r2, ip, #17
|
||||
bne .L_sub8_and_finish
|
||||
bcs .L_sub7_and_finish
|
||||
lsls ip, ip, #1
|
||||
bne .L_sub6_and_finish
|
||||
|
||||
sub r3, r3, #5
|
||||
b .L_check_size
|
||||
|
||||
.L_sub8_and_finish:
|
||||
sub r3, r3, #8
|
||||
b .L_check_size
|
||||
|
||||
.L_sub7_and_finish:
|
||||
sub r3, r3, #7
|
||||
b .L_check_size
|
||||
|
||||
.L_sub6_and_finish:
|
||||
sub r3, r3, #6
|
||||
b .L_check_size
|
||||
|
||||
.L_zero_in_second_register:
|
||||
sub r3, r0, r1
|
||||
lsls r2, ip, #17
|
||||
bne .L_sub4_and_finish
|
||||
bcs .L_sub3_and_finish
|
||||
lsls ip, ip, #1
|
||||
bne .L_sub2_and_finish
|
||||
|
||||
sub r3, r3, #1
|
||||
b .L_check_size
|
||||
|
||||
.L_sub4_and_finish:
|
||||
sub r3, r3, #4
|
||||
b .L_check_size
|
||||
|
||||
.L_sub3_and_finish:
|
||||
sub r3, r3, #3
|
||||
b .L_check_size
|
||||
|
||||
.L_sub2_and_finish:
|
||||
sub r3, r3, #2
|
||||
|
||||
.L_check_size:
|
||||
pld [r1, #0]
|
||||
pld [r1, #64]
|
||||
ldr r0, [sp]
|
||||
cmp r3, lr
|
||||
bge .L_fortify_check_failed
|
||||
|
||||
// Add 1 for copy length to get the string terminator.
|
||||
add r2, r3, #1
|
||||
|
||||
#include "memcpy_base.S"
|
||||
|
||||
.L_fortify_check_failed:
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+4)
|
||||
.cfi_endproc
|
||||
END(__strcpy_chk)
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "strcpy buffer overflow"
|
@@ -28,8 +28,8 @@
|
||||
|
||||
/* Assumes neon instructions and a cache line size of 32 bytes. */
|
||||
|
||||
#include <machine/cpu-features.h>
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
/*
|
||||
* This code assumes it is running on a processor that supports all arm v7
|
||||
@@ -38,109 +38,50 @@
|
||||
*/
|
||||
|
||||
.text
|
||||
.syntax unified
|
||||
.fpu neon
|
||||
.thumb
|
||||
.thumb_func
|
||||
|
||||
#define CACHE_LINE_SIZE 32
|
||||
ENTRY(__memcpy_chk)
|
||||
.cfi_startproc
|
||||
cmp r2, r3
|
||||
bgt __memcpy_chk_fail
|
||||
|
||||
// Fall through to memcpy...
|
||||
.cfi_endproc
|
||||
END(__memcpy_chk)
|
||||
|
||||
ENTRY(memcpy)
|
||||
.save {r0, lr}
|
||||
/* start preloading as early as possible */
|
||||
pld [r1, #(CACHE_LINE_SIZE*0)]
|
||||
stmfd sp!, {r0, lr}
|
||||
pld [r1, #(CACHE_LINE_SIZE*2)]
|
||||
.cfi_startproc
|
||||
pld [r1, #64]
|
||||
stmfd sp!, {r0, lr}
|
||||
.cfi_def_cfa_offset 8
|
||||
.cfi_rel_offset r0, 0
|
||||
.cfi_rel_offset lr, 4
|
||||
|
||||
/* do we have at least 16-bytes to copy (needed for alignment below) */
|
||||
cmp r2, #16
|
||||
blo 5f
|
||||
|
||||
/* align destination to cache-line for the write-buffer */
|
||||
rsb r3, r0, #0
|
||||
ands r3, r3, #0xF
|
||||
beq 0f
|
||||
|
||||
/* copy up to 15-bytes (count in r3) */
|
||||
sub r2, r2, r3
|
||||
movs ip, r3, lsl #31
|
||||
ldrmib lr, [r1], #1
|
||||
strmib lr, [r0], #1
|
||||
ldrcsb ip, [r1], #1
|
||||
ldrcsb lr, [r1], #1
|
||||
strcsb ip, [r0], #1
|
||||
strcsb lr, [r0], #1
|
||||
movs ip, r3, lsl #29
|
||||
bge 1f
|
||||
// copies 4 bytes, destination 32-bits aligned
|
||||
vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
|
||||
vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0, :32]!
|
||||
1: bcc 2f
|
||||
// copies 8 bytes, destination 64-bits aligned
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0, :64]!
|
||||
2:
|
||||
|
||||
0: /* preload immediately the next cache line, which we may need */
|
||||
pld [r1, #(CACHE_LINE_SIZE*0)]
|
||||
pld [r1, #(CACHE_LINE_SIZE*2)]
|
||||
|
||||
/* make sure we have at least 64 bytes to copy */
|
||||
subs r2, r2, #64
|
||||
blo 2f
|
||||
|
||||
/* Preload all the cache lines we need.
|
||||
* NOTE: The number of pld below depends on CACHE_LINE_SIZE,
|
||||
* ideally we would increase the distance in the main loop to
|
||||
* avoid the goofy code below. In practice this doesn't seem to make
|
||||
* a big difference.
|
||||
* NOTE: The value CACHE_LINE_SIZE * 8 was chosen through
|
||||
* experimentation.
|
||||
*/
|
||||
pld [r1, #(CACHE_LINE_SIZE*4)]
|
||||
pld [r1, #(CACHE_LINE_SIZE*6)]
|
||||
pld [r1, #(CACHE_LINE_SIZE*8)]
|
||||
|
||||
1: /* The main loop copies 64 bytes at a time */
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
vld1.8 {d4 - d7}, [r1]!
|
||||
pld [r1, #(CACHE_LINE_SIZE*8)]
|
||||
subs r2, r2, #64
|
||||
vst1.8 {d0 - d3}, [r0, :128]!
|
||||
vst1.8 {d4 - d7}, [r0, :128]!
|
||||
bhs 1b
|
||||
|
||||
2: /* fix-up the remaining count and make sure we have >= 32 bytes left */
|
||||
add r2, r2, #64
|
||||
subs r2, r2, #32
|
||||
blo 4f
|
||||
|
||||
3: /* 32 bytes at a time. These cache lines were already preloaded */
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
subs r2, r2, #32
|
||||
vst1.8 {d0 - d3}, [r0, :128]!
|
||||
bhs 3b
|
||||
4: /* less than 32 left */
|
||||
add r2, r2, #32
|
||||
tst r2, #0x10
|
||||
beq 5f
|
||||
// copies 16 bytes, 128-bits aligned
|
||||
vld1.8 {d0, d1}, [r1]!
|
||||
vst1.8 {d0, d1}, [r0, :128]!
|
||||
|
||||
5: /* copy up to 15-bytes (count in r2) */
|
||||
movs ip, r2, lsl #29
|
||||
bcc 1f
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0]!
|
||||
1: bge 2f
|
||||
vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
|
||||
vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0]!
|
||||
2: movs ip, r2, lsl #31
|
||||
ldrmib r3, [r1], #1
|
||||
ldrcsb ip, [r1], #1
|
||||
ldrcsb lr, [r1], #1
|
||||
strmib r3, [r0], #1
|
||||
strcsb ip, [r0], #1
|
||||
strcsb lr, [r0], #1
|
||||
|
||||
ldmfd sp!, {r0, lr}
|
||||
bx lr
|
||||
#include "memcpy_base.S"
|
||||
.cfi_endproc
|
||||
END(memcpy)
|
||||
|
||||
.cfi_startproc
|
||||
__memcpy_chk_fail:
|
||||
// Preserve lr for backtrace.
|
||||
push {lr}
|
||||
.cfi_def_cfa_offset 4
|
||||
.cfi_rel_offset lr, 0
|
||||
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+4)
|
||||
.cfi_endproc
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "memcpy buffer overflow"
|
||||
|
117
libc/arch-arm/krait/bionic/memcpy_base.S
Normal file
117
libc/arch-arm/krait/bionic/memcpy_base.S
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This code assumes it is running on a processor that supports all arm v7
|
||||
* instructions, that supports neon instructions, and that has a 32 byte
|
||||
* cache line.
|
||||
*/
|
||||
|
||||
// Assumes neon instructions and a cache line size of 32 bytes.
|
||||
|
||||
/* do we have at least 16-bytes to copy (needed for alignment below) */
|
||||
cmp r2, #16
|
||||
blo 5f
|
||||
|
||||
/* align destination to cache-line for the write-buffer */
|
||||
rsb r3, r0, #0
|
||||
ands r3, r3, #0xF
|
||||
beq 2f
|
||||
|
||||
/* copy up to 15-bytes (count in r3) */
|
||||
sub r2, r2, r3
|
||||
movs ip, r3, lsl #31
|
||||
itt mi
|
||||
ldrbmi lr, [r1], #1
|
||||
strbmi lr, [r0], #1
|
||||
itttt cs
|
||||
ldrbcs ip, [r1], #1
|
||||
ldrbcs lr, [r1], #1
|
||||
strbcs ip, [r0], #1
|
||||
strbcs lr, [r0], #1
|
||||
movs ip, r3, lsl #29
|
||||
bge 1f
|
||||
// copies 4 bytes, destination 32-bits aligned
|
||||
vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
|
||||
vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0, :32]!
|
||||
1: bcc 2f
|
||||
// copies 8 bytes, destination 64-bits aligned
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0, :64]!
|
||||
|
||||
2: /* make sure we have at least 64 bytes to copy */
|
||||
subs r2, r2, #64
|
||||
blo 2f
|
||||
|
||||
1: /* The main loop copies 64 bytes at a time */
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
vld1.8 {d4 - d7}, [r1]!
|
||||
pld [r1, #(32*2)]
|
||||
subs r2, r2, #64
|
||||
vst1.8 {d0 - d3}, [r0, :128]!
|
||||
vst1.8 {d4 - d7}, [r0, :128]!
|
||||
bhs 1b
|
||||
|
||||
2: /* fix-up the remaining count and make sure we have >= 32 bytes left */
|
||||
adds r2, r2, #32
|
||||
blo 4f
|
||||
|
||||
/* Copy 32 bytes. These cache lines were already preloaded */
|
||||
vld1.8 {d0 - d3}, [r1]!
|
||||
sub r2, r2, #32
|
||||
vst1.8 {d0 - d3}, [r0, :128]!
|
||||
|
||||
4: /* less than 32 left */
|
||||
add r2, r2, #32
|
||||
tst r2, #0x10
|
||||
beq 5f
|
||||
// copies 16 bytes, 128-bits aligned
|
||||
vld1.8 {d0, d1}, [r1]!
|
||||
vst1.8 {d0, d1}, [r0, :128]!
|
||||
|
||||
5: /* copy up to 15-bytes (count in r2) */
|
||||
movs ip, r2, lsl #29
|
||||
bcc 1f
|
||||
vld1.8 {d0}, [r1]!
|
||||
vst1.8 {d0}, [r0]!
|
||||
1: bge 2f
|
||||
vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
|
||||
vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0]!
|
||||
2: movs ip, r2, lsl #31
|
||||
itt mi
|
||||
ldrbmi r3, [r1], #1
|
||||
strbmi r3, [r0], #1
|
||||
itttt cs
|
||||
ldrbcs ip, [r1], #1
|
||||
ldrbcs lr, [r1], #1
|
||||
strbcs ip, [r0], #1
|
||||
strbcs lr, [r0], #1
|
||||
|
||||
ldmfd sp!, {r0, lr}
|
||||
bx lr
|
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <machine/cpu-features.h>
|
||||
#include <machine/asm.h>
|
||||
#include "libc_events.h"
|
||||
|
||||
/*
|
||||
* This code assumes it is running on a processor that supports all arm v7
|
||||
@@ -37,15 +38,45 @@
|
||||
|
||||
.fpu neon
|
||||
|
||||
ENTRY(__memset_chk)
|
||||
.cfi_startproc
|
||||
cmp r2, r3
|
||||
bls .L_done
|
||||
|
||||
// Preserve lr for backtrace.
|
||||
push {lr}
|
||||
.cfi_def_cfa_offset 4
|
||||
.cfi_rel_offset lr, 0
|
||||
|
||||
ldr r0, error_message
|
||||
ldr r1, error_code
|
||||
1:
|
||||
add r0, pc
|
||||
bl __fortify_chk_fail
|
||||
error_code:
|
||||
.word BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW
|
||||
error_message:
|
||||
.word error_string-(1b+8)
|
||||
|
||||
.cfi_endproc
|
||||
END(__memset_chk)
|
||||
|
||||
ENTRY(bzero)
|
||||
.cfi_startproc
|
||||
mov r2, r1
|
||||
mov r1, #0
|
||||
|
||||
.L_done:
|
||||
// Fall through to memset...
|
||||
.cfi_endproc
|
||||
END(bzero)
|
||||
|
||||
/* memset() returns its first argument. */
|
||||
ENTRY(memset)
|
||||
.save {r0}
|
||||
.cfi_startproc
|
||||
stmfd sp!, {r0}
|
||||
.cfi_def_cfa_offset 4
|
||||
.cfi_rel_offset r0, 0
|
||||
|
||||
vdup.8 q0, r1
|
||||
|
||||
@@ -78,4 +109,9 @@ ENTRY(memset)
|
||||
strcsb r1, [r0], #1
|
||||
ldmfd sp!, {r0}
|
||||
bx lr
|
||||
.cfi_endproc
|
||||
END(memset)
|
||||
|
||||
.data
|
||||
error_string:
|
||||
.string "memset buffer overflow"
|
||||
|
@@ -1,6 +1,8 @@
|
||||
$(call libc-add-cpu-variant-src,MEMCPY,arch-arm/krait/bionic/memcpy.S)
|
||||
$(call libc-add-cpu-variant-src,MEMSET,arch-arm/krait/bionic/memset.S)
|
||||
$(call libc-add-cpu-variant-src,STRCMP,arch-arm/krait/bionic/strcmp.S)
|
||||
$(call libc-add-cpu-variant-src,__STRCAT_CHK,arch-arm/krait/bionic/__strcat_chk.S)
|
||||
$(call libc-add-cpu-variant-src,__STRCPY_CHK,arch-arm/krait/bionic/__strcpy_chk.S)
|
||||
# Use cortex-a15 versions of strcat/strcpy/strlen.
|
||||
$(call libc-add-cpu-variant-src,STRCAT,arch-arm/cortex-a15/bionic/strcat.S)
|
||||
$(call libc-add-cpu-variant-src,STRCPY,arch-arm/cortex-a15/bionic/strcpy.S)
|
||||
|
@@ -72,7 +72,7 @@ _LIBC_ARCH_COMMON_SRC_FILES += \
|
||||
arch-x86/string/bzero.S \
|
||||
bionic/memrchr.c \
|
||||
bionic/memchr.c \
|
||||
string/strchr.cpp \
|
||||
bionic/strchr.cpp \
|
||||
string/strrchr.c \
|
||||
string/index.c \
|
||||
bionic/strnlen.c \
|
||||
|
@@ -41,13 +41,51 @@
|
||||
* This strncpy check is called if _FORTIFY_SOURCE is defined and
|
||||
* greater than 0.
|
||||
*/
|
||||
extern "C" char *__strncpy_chk (char *dest, const char *src,
|
||||
extern "C" char* __strncpy_chk(char* __restrict dest, const char* __restrict src,
|
||||
size_t len, size_t dest_len)
|
||||
{
|
||||
if (__predict_false(len > dest_len)) {
|
||||
__fortify_chk_fail("strncpy buffer overflow",
|
||||
BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW);
|
||||
}
|
||||
if (__predict_false(len > dest_len)) {
|
||||
__fortify_chk_fail("strncpy dest buffer overflow",
|
||||
BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW);
|
||||
}
|
||||
|
||||
return strncpy(dest, src, len);
|
||||
return strncpy(dest, src, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* __strncpy_chk2
|
||||
*
|
||||
* This is a variant of __strncpy_chk, but it also checks to make
|
||||
* sure we don't read beyond the end of "src". The code for this is
|
||||
* based on the original version of strncpy, but modified to check
|
||||
* how much we read from "src" at the end of the copy operation.
|
||||
*/
|
||||
extern "C" char* __strncpy_chk2(char* __restrict dst, const char* __restrict src,
|
||||
size_t n, size_t dest_len, size_t src_len)
|
||||
{
|
||||
if (__predict_false(n > dest_len)) {
|
||||
__fortify_chk_fail("strncpy dest buffer overflow",
|
||||
BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW);
|
||||
}
|
||||
if (n != 0) {
|
||||
char* d = dst;
|
||||
const char* s = src;
|
||||
|
||||
do {
|
||||
if ((*d++ = *s++) == 0) {
|
||||
/* NUL pad the remaining n-1 bytes */
|
||||
while (--n != 0) {
|
||||
*d++ = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while (--n != 0);
|
||||
|
||||
size_t s_copy_len = static_cast<size_t>(s - src);
|
||||
if (__predict_false(s_copy_len > src_len)) {
|
||||
__fortify_chk_fail("strncpy read beyond end of src buffer", 0);
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
@@ -31,18 +31,17 @@
|
||||
#include <string.h>
|
||||
#include "libc_logging.h"
|
||||
|
||||
char *
|
||||
__strrchr_chk(const char *p, int ch, size_t s_len)
|
||||
extern "C" char* __strrchr_chk(const char *p, int ch, size_t s_len)
|
||||
{
|
||||
char *save;
|
||||
char *save;
|
||||
|
||||
for (save = NULL;; ++p, s_len--) {
|
||||
if (s_len == 0)
|
||||
__fortify_chk_fail("strrchr read beyond buffer", 0);
|
||||
if (*p == (char) ch)
|
||||
save = (char *)p;
|
||||
if (!*p)
|
||||
return(save);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
for (save = NULL;; ++p, s_len--) {
|
||||
if (s_len == 0)
|
||||
__fortify_chk_fail("strrchr read beyond buffer", 0);
|
||||
if (*p == (char) ch)
|
||||
save = (char *)p;
|
||||
if (!*p)
|
||||
return(save);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
@@ -36,7 +36,13 @@ int pthread_getcpuclockid(pthread_t t, clockid_t* clockid) {
|
||||
return ESRCH;
|
||||
}
|
||||
|
||||
enum { CLOCK_IDTYPE_BITS = 3 };
|
||||
*clockid = CLOCK_THREAD_CPUTIME_ID | (thread->tid << CLOCK_IDTYPE_BITS);
|
||||
// The tid is stored in the top bits, but negated.
|
||||
clockid_t result = ~static_cast<clockid_t>(thread->tid) << 3;
|
||||
// Bits 0 and 1: clock type (0 = CPUCLOCK_PROF, 1 = CPUCLOCK_VIRT, 2 = CPUCLOCK_SCHED).
|
||||
result |= 2;
|
||||
// Bit 2: thread (set) or process (clear)?
|
||||
result |= (1 << 2);
|
||||
|
||||
*clockid = result;
|
||||
return 0;
|
||||
}
|
||||
|
@@ -325,6 +325,8 @@ static void *to_prop_obj(prop_off_t off)
|
||||
{
|
||||
if (off > pa_data_size)
|
||||
return NULL;
|
||||
if (!__system_property_area__)
|
||||
return NULL;
|
||||
|
||||
return __system_property_area__->data + off;
|
||||
}
|
||||
@@ -384,6 +386,8 @@ static const prop_info *find_property(prop_bt *trie, const char *name,
|
||||
{
|
||||
const char *remaining_name = name;
|
||||
|
||||
if (!trie) return NULL;
|
||||
|
||||
while (true) {
|
||||
char *sep = strchr(remaining_name, '.');
|
||||
bool want_subtree = (sep != NULL);
|
||||
|
@@ -42,14 +42,14 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#define _U 0x01
|
||||
#define _L 0x02
|
||||
#define _N 0x04
|
||||
#define _S 0x08
|
||||
#define _P 0x10
|
||||
#define _C 0x20
|
||||
#define _X 0x40
|
||||
#define _B 0x80
|
||||
#define _CTYPE_U 0x01
|
||||
#define _CTYPE_L 0x02
|
||||
#define _CTYPE_N 0x04
|
||||
#define _CTYPE_S 0x08
|
||||
#define _CTYPE_P 0x10
|
||||
#define _CTYPE_C 0x20
|
||||
#define _CTYPE_X 0x40
|
||||
#define _CTYPE_B 0x80
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
@@ -101,57 +101,57 @@ int _toupper(int);
|
||||
|
||||
__CTYPE_INLINE int isalnum(int c)
|
||||
{
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N)));
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_CTYPE_U|_CTYPE_L|_CTYPE_N)));
|
||||
}
|
||||
|
||||
__CTYPE_INLINE int isalpha(int c)
|
||||
{
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L)));
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_CTYPE_U|_CTYPE_L)));
|
||||
}
|
||||
|
||||
__CTYPE_INLINE int iscntrl(int c)
|
||||
{
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _C));
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_C));
|
||||
}
|
||||
|
||||
__CTYPE_INLINE int isdigit(int c)
|
||||
{
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N));
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_N));
|
||||
}
|
||||
|
||||
__CTYPE_INLINE int isgraph(int c)
|
||||
{
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N)));
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N)));
|
||||
}
|
||||
|
||||
__CTYPE_INLINE int islower(int c)
|
||||
{
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _L));
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_L));
|
||||
}
|
||||
|
||||
__CTYPE_INLINE int isprint(int c)
|
||||
{
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B)));
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N|_CTYPE_B)));
|
||||
}
|
||||
|
||||
__CTYPE_INLINE int ispunct(int c)
|
||||
{
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _P));
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_P));
|
||||
}
|
||||
|
||||
__CTYPE_INLINE int isspace(int c)
|
||||
{
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S));
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_S));
|
||||
}
|
||||
|
||||
__CTYPE_INLINE int isupper(int c)
|
||||
{
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _U));
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _CTYPE_U));
|
||||
}
|
||||
|
||||
__CTYPE_INLINE int isxdigit(int c)
|
||||
{
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_N|_X)));
|
||||
return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_CTYPE_N|_CTYPE_X)));
|
||||
}
|
||||
|
||||
__CTYPE_INLINE int tolower(int c)
|
||||
|
@@ -249,13 +249,16 @@ typedef struct {
|
||||
} imaxdiv_t;
|
||||
|
||||
__BEGIN_DECLS
|
||||
intmax_t imaxabs(intmax_t);
|
||||
imaxdiv_t imaxdiv(intmax_t, intmax_t);
|
||||
|
||||
intmax_t imaxabs(intmax_t) __pure2;
|
||||
imaxdiv_t imaxdiv(intmax_t, intmax_t) __pure2;
|
||||
|
||||
intmax_t strtoimax(const char *, char **, int);
|
||||
uintmax_t strtoumax(const char *, char **, int);
|
||||
|
||||
intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n);
|
||||
uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _INTTYPES_H_ */
|
||||
|
@@ -43,11 +43,11 @@ struct dl_phdr_info {
|
||||
ElfW(Half) dlpi_phnum;
|
||||
};
|
||||
|
||||
int dl_iterate_phdr(int (*cb)(struct dl_phdr_info*, size_t, void*), void*);
|
||||
|
||||
#ifdef __arm__
|
||||
typedef long unsigned int* _Unwind_Ptr;
|
||||
_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int* pcount);
|
||||
#else
|
||||
int dl_iterate_phdr(int (*cb)(struct dl_phdr_info*, size_t, void*), void*);
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
@@ -77,17 +77,9 @@ static __inline__ double atof(const char *nptr)
|
||||
return (strtod(nptr, NULL));
|
||||
}
|
||||
|
||||
static __inline__ int abs(int __n) {
|
||||
return (__n < 0) ? -__n : __n;
|
||||
}
|
||||
|
||||
static __inline__ long labs(long __n) {
|
||||
return (__n < 0L) ? -__n : __n;
|
||||
}
|
||||
|
||||
static __inline__ long long llabs(long long __n) {
|
||||
return (__n < 0LL) ? -__n : __n;
|
||||
}
|
||||
extern int abs(int) __pure2;
|
||||
extern long labs(long) __pure2;
|
||||
extern long long llabs(long long) __pure2;
|
||||
|
||||
extern char * realpath(const char *path, char *resolved);
|
||||
extern int system(const char * string);
|
||||
|
@@ -46,6 +46,8 @@ extern void memswap(void *, void *, size_t);
|
||||
|
||||
extern char* index(const char *, int) __purefunc;
|
||||
extern char* strchr(const char *, int) __purefunc;
|
||||
extern char* __strchr_chk(const char *, int, size_t);
|
||||
|
||||
extern char* strrchr(const char *, int) __purefunc;
|
||||
|
||||
extern size_t strlen(const char *) __purefunc;
|
||||
@@ -94,8 +96,8 @@ __BIONIC_FORTIFY_INLINE
|
||||
void* memcpy(void* __restrict dest, const void* __restrict src, size_t copy_amount) {
|
||||
char *d = (char *) dest;
|
||||
const char *s = (const char *) src;
|
||||
size_t s_len = __builtin_object_size(s, 0);
|
||||
size_t d_len = __builtin_object_size(d, 0);
|
||||
size_t s_len = __bos0(s);
|
||||
size_t d_len = __bos0(d);
|
||||
|
||||
if (__builtin_constant_p(copy_amount) && (copy_amount > d_len)) {
|
||||
__memcpy_dest_size_error();
|
||||
@@ -110,7 +112,7 @@ void* memcpy(void* __restrict dest, const void* __restrict src, size_t copy_amou
|
||||
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
void* memmove(void *dest, const void *src, size_t len) {
|
||||
return __builtin___memmove_chk(dest, src, len, __builtin_object_size (dest, 0));
|
||||
return __builtin___memmove_chk(dest, src, len, __bos0(dest));
|
||||
}
|
||||
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
@@ -119,14 +121,26 @@ char* strcpy(char* __restrict dest, const char* __restrict src) {
|
||||
}
|
||||
|
||||
__errordecl(__strncpy_error, "strncpy called with size bigger than buffer");
|
||||
extern char* __strncpy_chk2(char* __restrict, const char* __restrict, size_t, size_t, size_t);
|
||||
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
char* strncpy(char* __restrict dest, const char* __restrict src, size_t n) {
|
||||
size_t bos = __bos(dest);
|
||||
if (__builtin_constant_p(n) && (n > bos)) {
|
||||
size_t bos_dest = __bos(dest);
|
||||
size_t bos_src = __bos(src);
|
||||
if (__builtin_constant_p(n) && (n > bos_dest)) {
|
||||
__strncpy_error();
|
||||
}
|
||||
return __builtin___strncpy_chk(dest, src, n, bos);
|
||||
|
||||
if (bos_src == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
|
||||
return __builtin___strncpy_chk(dest, src, n, bos_dest);
|
||||
}
|
||||
|
||||
size_t slen = __builtin_strlen(src);
|
||||
if (__builtin_constant_p(slen)) {
|
||||
return __builtin___strncpy_chk(dest, src, n, bos_dest);
|
||||
}
|
||||
|
||||
return __strncpy_chk2(dest, src, n, bos_dest, bos_src);
|
||||
}
|
||||
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
@@ -141,7 +155,7 @@ char *strncat(char* __restrict dest, const char* __restrict src, size_t n) {
|
||||
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
void* memset(void *s, int c, size_t n) {
|
||||
return __builtin___memset_chk(s, c, n, __builtin_object_size (s, 0));
|
||||
return __builtin___memset_chk(s, c, n, __bos0(s));
|
||||
}
|
||||
|
||||
extern size_t __strlcpy_real(char* __restrict, const char* __restrict, size_t)
|
||||
@@ -226,8 +240,6 @@ size_t strlen(const char *s) {
|
||||
return __strlen_chk(s, bos);
|
||||
}
|
||||
|
||||
extern char* __strchr_chk(const char *, int, size_t);
|
||||
|
||||
__BIONIC_FORTIFY_INLINE
|
||||
char* strchr(const char *s, int c) {
|
||||
size_t bos = __bos(s);
|
||||
|
@@ -526,6 +526,14 @@
|
||||
#define __BIONIC__ 1
|
||||
#include <android/api-level.h>
|
||||
|
||||
/*
|
||||
* When _FORTIFY_SOURCE is defined, automatic bounds checking is
|
||||
* added to commonly used libc functions. If a buffer overrun is
|
||||
* detected, the program is safely aborted.
|
||||
*
|
||||
* See
|
||||
* http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html for details.
|
||||
*/
|
||||
#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
|
||||
#define __BIONIC_FORTIFY 1
|
||||
#if _FORTIFY_SOURCE == 2
|
||||
@@ -533,6 +541,7 @@
|
||||
#else
|
||||
#define __bos(s) __builtin_object_size((s), 0)
|
||||
#endif
|
||||
#define __bos0(s) __builtin_object_size((s), 0)
|
||||
|
||||
#define __BIONIC_FORTIFY_INLINE \
|
||||
extern inline \
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1874,10 +1874,10 @@ static bool _using_default_dns(const char *iface)
|
||||
if (iface == NULL || *iface == '\0') return true;
|
||||
|
||||
if_len = _resolv_get_default_iface(buf, sizeof(buf));
|
||||
if (if_len + 1 <= sizeof(buf)) {
|
||||
if (strcmp(buf, iface) != 0) return false;
|
||||
if (if_len != 0 && if_len + 1 <= sizeof(buf)) {
|
||||
if (strcmp(buf, iface) == 0) return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
|
@@ -2426,18 +2426,16 @@ _resolv_get_default_iface(char* buff, int buffLen)
|
||||
|
||||
ifname = _get_default_iface_locked(); // never null, but may be empty
|
||||
|
||||
// if default interface not set. Get first cache with an interface
|
||||
// if default interface not set give up.
|
||||
if (ifname[0] == '\0') {
|
||||
ifname = _find_any_iface_name_locked(); // may be null
|
||||
pthread_mutex_unlock(&_res_cache_list_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// if we got the default iface or if (no-default) the find_any call gave an answer
|
||||
if (ifname) {
|
||||
len = strlen(ifname);
|
||||
if (len < buffLen) {
|
||||
strncpy(buff, ifname, len);
|
||||
buff[len] = '\0';
|
||||
}
|
||||
len = strlen(ifname);
|
||||
if (len < buffLen) {
|
||||
strncpy(buff, ifname, len);
|
||||
buff[len] = '\0';
|
||||
} else {
|
||||
buff[0] = '\0';
|
||||
}
|
||||
|
48
libc/private/libc_events.h
Normal file
48
libc/private/libc_events.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LIBC_EVENTS_H
|
||||
#define _LIBC_EVENTS_H
|
||||
|
||||
|
||||
// This is going to be included in assembler code so only allow #define
|
||||
// values instead of defining an enum.
|
||||
|
||||
#define BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW 80100
|
||||
#define BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW 80105
|
||||
#define BIONIC_EVENT_MEMMOVE_BUFFER_OVERFLOW 80110
|
||||
#define BIONIC_EVENT_STRNCAT_BUFFER_OVERFLOW 80115
|
||||
#define BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW 80120
|
||||
#define BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW 80125
|
||||
#define BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW 80130
|
||||
|
||||
#define BIONIC_EVENT_RESOLVER_OLD_RESPONSE 80300
|
||||
#define BIONIC_EVENT_RESOLVER_WRONG_SERVER 80305
|
||||
#define BIONIC_EVENT_RESOLVER_WRONG_QUERY 80310
|
||||
|
||||
#endif // _LIBC_EVENTS_H
|
@@ -36,19 +36,7 @@
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
enum {
|
||||
BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW = 80100,
|
||||
BIONIC_EVENT_STRCAT_BUFFER_OVERFLOW = 80105,
|
||||
BIONIC_EVENT_MEMMOVE_BUFFER_OVERFLOW = 80110,
|
||||
BIONIC_EVENT_STRNCAT_BUFFER_OVERFLOW = 80115,
|
||||
BIONIC_EVENT_STRNCPY_BUFFER_OVERFLOW = 80120,
|
||||
BIONIC_EVENT_MEMSET_BUFFER_OVERFLOW = 80125,
|
||||
BIONIC_EVENT_STRCPY_BUFFER_OVERFLOW = 80130,
|
||||
|
||||
BIONIC_EVENT_RESOLVER_OLD_RESPONSE = 80300,
|
||||
BIONIC_EVENT_RESOLVER_WRONG_SERVER = 80305,
|
||||
BIONIC_EVENT_RESOLVER_WRONG_QUERY = 80310,
|
||||
};
|
||||
#include "libc_events.h"
|
||||
|
||||
enum {
|
||||
ANDROID_LOG_UNKNOWN = 0,
|
||||
|
@@ -36,6 +36,15 @@
|
||||
#include <ctype.h>
|
||||
#include "ctype_private.h"
|
||||
|
||||
#define _U _CTYPE_U
|
||||
#define _L _CTYPE_L
|
||||
#define _N _CTYPE_N
|
||||
#define _S _CTYPE_S
|
||||
#define _P _CTYPE_P
|
||||
#define _C _CTYPE_C
|
||||
#define _X _CTYPE_X
|
||||
#define _B _CTYPE_B
|
||||
|
||||
const char _C_ctype_[1 + CTYPE_NUM_CHARS] = {
|
||||
0,
|
||||
_C, _C, _C, _C, _C, _C, _C, _C,
|
||||
@@ -77,6 +86,8 @@ const char _C_ctype_[1 + CTYPE_NUM_CHARS] = {
|
||||
const char *_ctype_ = _C_ctype_;
|
||||
|
||||
|
||||
// TODO: fix the header file so we don't have to duplicate all this inlined stuff.
|
||||
|
||||
#if 1 /* ndef NDEBUG */
|
||||
int isalnum(int c)
|
||||
{
|
||||
@@ -155,4 +166,3 @@ int toascii(int c)
|
||||
#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
|
||||
|
||||
#endif /* !NDBEUG */
|
||||
|
||||
|
@@ -1812,14 +1812,14 @@ time2sub(struct tm * const tmp,
|
||||
} else dir = tmcomp(&mytm, &yourtm);
|
||||
if (dir != 0) {
|
||||
if (t == lo) {
|
||||
++t;
|
||||
if (t <= lo)
|
||||
if (t == time_t_max)
|
||||
return WRONG;
|
||||
++t;
|
||||
++lo;
|
||||
} else if (t == hi) {
|
||||
--t;
|
||||
if (t >= hi)
|
||||
if (t == time_t_min)
|
||||
return WRONG;
|
||||
--t;
|
||||
--hi;
|
||||
}
|
||||
if (lo > hi)
|
||||
|
@@ -304,6 +304,16 @@ const char * scheck(const char * string, const char * format);
|
||||
#define TYPE_SIGNED(type) (((type) -1) < 0)
|
||||
#endif /* !defined TYPE_SIGNED */
|
||||
|
||||
/* The minimum and maximum finite time values. */
|
||||
static time_t const time_t_min =
|
||||
(TYPE_SIGNED(time_t)
|
||||
? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)
|
||||
: 0);
|
||||
static time_t const time_t_max =
|
||||
(TYPE_SIGNED(time_t)
|
||||
? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1))
|
||||
: -1);
|
||||
|
||||
/*
|
||||
** Since the definition of TYPE_INTEGRAL contains floating point numbers,
|
||||
** it cannot be used in preprocessor directives.
|
||||
|
43
libc/upstream-freebsd/lib/libc/stdlib/abs.c
Normal file
43
libc/upstream-freebsd/lib/libc/stdlib/abs.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* 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 University 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 REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)abs.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
abs(j)
|
||||
int j;
|
||||
{
|
||||
return(j < 0 ? -j : j);
|
||||
}
|
36
libc/upstream-freebsd/lib/libc/stdlib/imaxabs.c
Normal file
36
libc/upstream-freebsd/lib/libc/stdlib/imaxabs.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/*-
|
||||
* Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
intmax_t
|
||||
imaxabs(intmax_t j)
|
||||
{
|
||||
return (j < 0 ? -j : j);
|
||||
}
|
45
libc/upstream-freebsd/lib/libc/stdlib/imaxdiv.c
Normal file
45
libc/upstream-freebsd/lib/libc/stdlib/imaxdiv.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*-
|
||||
* Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/* See comments in div.c for implementation details. */
|
||||
imaxdiv_t
|
||||
imaxdiv(intmax_t numer, intmax_t denom)
|
||||
{
|
||||
imaxdiv_t retval;
|
||||
|
||||
retval.quot = numer / denom;
|
||||
retval.rem = numer % denom;
|
||||
if (numer >= 0 && retval.rem < 0) {
|
||||
retval.quot++;
|
||||
retval.rem -= denom;
|
||||
}
|
||||
return (retval);
|
||||
}
|
43
libc/upstream-freebsd/lib/libc/stdlib/labs.c
Normal file
43
libc/upstream-freebsd/lib/libc/stdlib/labs.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* 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 University 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 REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)labs.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
long
|
||||
labs(j)
|
||||
long j;
|
||||
{
|
||||
return(j < 0 ? -j : j);
|
||||
}
|
36
libc/upstream-freebsd/lib/libc/stdlib/llabs.c
Normal file
36
libc/upstream-freebsd/lib/libc/stdlib/llabs.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/*-
|
||||
* Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
long long
|
||||
llabs(long long j)
|
||||
{
|
||||
return (j < 0 ? -j : j);
|
||||
}
|
@@ -30,12 +30,8 @@ void android_update_LD_LIBRARY_PATH(const char* ld_library_path) { }
|
||||
|
||||
void *dl_unwind_find_exidx(void *pc, int *pcount) { return 0; }
|
||||
|
||||
#elif defined(__i386__) || defined(__mips__)
|
||||
#endif
|
||||
|
||||
/* we munge the cb definition so we don't have to include any headers here.
|
||||
* It won't affect anything since these are just symbols anyway */
|
||||
int dl_iterate_phdr(int (*cb)(void *info, void *size, void *data), void *data) { return 0; }
|
||||
|
||||
#else
|
||||
#error Unsupported architecture. Only mips, arm and x86 are supported.
|
||||
#endif
|
||||
|
@@ -146,11 +146,10 @@ int dlclose(void* handle) {
|
||||
}
|
||||
|
||||
#if defined(ANDROID_ARM_LINKER)
|
||||
// 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667
|
||||
// 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890
|
||||
// 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667777777777888 8888888
|
||||
// 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890123456789012 3456789
|
||||
#define ANDROID_LIBDL_STRTAB \
|
||||
"dlopen\0dlclose\0dlsym\0dlerror\0dladdr\0android_update_LD_LIBRARY_PATH\0dl_unwind_find_exidx\0"
|
||||
|
||||
"dlopen\0dlclose\0dlsym\0dlerror\0dladdr\0android_update_LD_LIBRARY_PATH\0dl_iterate_phdr\0dl_unwind_find_exidx\0"
|
||||
#elif defined(ANDROID_X86_LINKER) || defined(ANDROID_MIPS_LINKER)
|
||||
// 0000000 00011111 111112 22222222 2333333 3333444444444455555555556666666 6667
|
||||
// 0123456 78901234 567890 12345678 9012345 6789012345678901234567890123456 7890
|
||||
@@ -181,10 +180,9 @@ static Elf32_Sym gLibDlSymtab[] = {
|
||||
ELF32_SYM_INITIALIZER(21, &dlerror, 1),
|
||||
ELF32_SYM_INITIALIZER(29, &dladdr, 1),
|
||||
ELF32_SYM_INITIALIZER(36, &android_update_LD_LIBRARY_PATH, 1),
|
||||
#if defined(ANDROID_ARM_LINKER)
|
||||
ELF32_SYM_INITIALIZER(67, &dl_unwind_find_exidx, 1),
|
||||
#elif defined(ANDROID_X86_LINKER) || defined(ANDROID_MIPS_LINKER)
|
||||
ELF32_SYM_INITIALIZER(67, &dl_iterate_phdr, 1),
|
||||
#if defined(ANDROID_ARM_LINKER)
|
||||
ELF32_SYM_INITIALIZER(83, &dl_unwind_find_exidx, 1),
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -207,7 +205,11 @@ static Elf32_Sym gLibDlSymtab[] = {
|
||||
// Note that adding any new symbols here requires
|
||||
// stubbing them out in libdl.
|
||||
static unsigned gLibDlBuckets[1] = { 1 };
|
||||
#if defined(ANDROID_ARM_LINKER)
|
||||
static unsigned gLibDlChains[9] = { 0, 2, 3, 4, 5, 6, 7, 8, 0 };
|
||||
#else
|
||||
static unsigned gLibDlChains[8] = { 0, 2, 3, 4, 5, 6, 7, 0 };
|
||||
#endif
|
||||
|
||||
// This is used by the dynamic linker. Every process gets these symbols for free.
|
||||
soinfo libdl_info = {
|
||||
@@ -223,8 +225,8 @@ soinfo libdl_info = {
|
||||
strtab: ANDROID_LIBDL_STRTAB,
|
||||
symtab: gLibDlSymtab,
|
||||
|
||||
nbucket: 1,
|
||||
nchain: 8,
|
||||
nbucket: sizeof(gLibDlBuckets)/sizeof(unsigned),
|
||||
nchain: sizeof(gLibDlChains)/sizeof(unsigned),
|
||||
bucket: gLibDlBuckets,
|
||||
chain: gLibDlChains,
|
||||
|
||||
|
@@ -414,7 +414,7 @@ _Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int *pcount)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#elif defined(ANDROID_X86_LINKER) || defined(ANDROID_MIPS_LINKER)
|
||||
#endif
|
||||
|
||||
/* Here, we only have to provide a callback to iterate across all the
|
||||
* loaded libraries. gcc_eh does the rest. */
|
||||
@@ -437,8 +437,6 @@ dl_iterate_phdr(int (*cb)(dl_phdr_info *info, size_t size, void *data),
|
||||
return rv;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static Elf32_Sym* soinfo_elf_lookup(soinfo* si, unsigned hash, const char* name) {
|
||||
Elf32_Sym* symtab = si->symtab;
|
||||
const char* strtab = si->strtab;
|
||||
@@ -1085,17 +1083,15 @@ static int soinfo_relocate(soinfo* si, Elf32_Rel* rel, unsigned count,
|
||||
}
|
||||
|
||||
#ifdef ANDROID_MIPS_LINKER
|
||||
static int mips_relocate_got(soinfo* si, soinfo* needed[]) {
|
||||
unsigned *got;
|
||||
unsigned local_gotno, gotsym, symtabno;
|
||||
Elf32_Sym *symtab, *sym;
|
||||
unsigned g;
|
||||
|
||||
got = si->plt_got;
|
||||
local_gotno = si->mips_local_gotno;
|
||||
gotsym = si->mips_gotsym;
|
||||
symtabno = si->mips_symtabno;
|
||||
symtab = si->symtab;
|
||||
static bool mips_relocate_got(soinfo* si, soinfo* needed[]) {
|
||||
unsigned* got = si->plt_got;
|
||||
if (got == NULL) {
|
||||
return true;
|
||||
}
|
||||
unsigned local_gotno = si->mips_local_gotno;
|
||||
unsigned gotsym = si->mips_gotsym;
|
||||
unsigned symtabno = si->mips_symtabno;
|
||||
Elf32_Sym* symtab = si->symtab;
|
||||
|
||||
/*
|
||||
* got[0] is address of lazy resolver function
|
||||
@@ -1106,7 +1102,7 @@ static int mips_relocate_got(soinfo* si, soinfo* needed[]) {
|
||||
*/
|
||||
|
||||
if ((si->flags & FLAG_LINKER) == 0) {
|
||||
g = 0;
|
||||
size_t g = 0;
|
||||
got[g++] = 0xdeadbeef;
|
||||
if (got[g] & 0x80000000) {
|
||||
got[g++] = 0xdeadfeed;
|
||||
@@ -1120,9 +1116,9 @@ static int mips_relocate_got(soinfo* si, soinfo* needed[]) {
|
||||
}
|
||||
|
||||
/* Now for the global GOT entries */
|
||||
sym = symtab + gotsym;
|
||||
Elf32_Sym* sym = symtab + gotsym;
|
||||
got = si->plt_got + local_gotno;
|
||||
for (g = gotsym; g < symtabno; g++, sym++, got++) {
|
||||
for (size_t g = gotsym; g < symtabno; g++, sym++, got++) {
|
||||
const char* sym_name;
|
||||
Elf32_Sym* s;
|
||||
soinfo* lsi;
|
||||
@@ -1136,7 +1132,7 @@ static int mips_relocate_got(soinfo* si, soinfo* needed[]) {
|
||||
s = &symtab[g];
|
||||
if (ELF32_ST_BIND(s->st_info) != STB_WEAK) {
|
||||
DL_ERR("cannot locate \"%s\"...", sym_name);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
*got = 0;
|
||||
}
|
||||
@@ -1148,7 +1144,7 @@ static int mips_relocate_got(soinfo* si, soinfo* needed[]) {
|
||||
*got = lsi->load_bias + s->st_value;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1556,7 +1552,7 @@ static bool soinfo_link_image(soinfo* si) {
|
||||
}
|
||||
|
||||
#ifdef ANDROID_MIPS_LINKER
|
||||
if (mips_relocate_got(si, needed)) {
|
||||
if (!mips_relocate_got(si, needed)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
@@ -147,7 +147,8 @@ bool ElfReader::ReadElfHeader() {
|
||||
return false;
|
||||
}
|
||||
if (rc != sizeof(header_)) {
|
||||
DL_ERR("\"%s\" is too small to be an ELF executable", name_);
|
||||
DL_ERR("\"%s\" is too small to be an ELF executable. Expected at least %d bytes, only found %d bytes.",
|
||||
name_, sizeof(header_), rc);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@@ -122,13 +122,36 @@ include $(BUILD_NATIVE_TEST)
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := bionic-unit-tests-static
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
|
||||
LOCAL_CFLAGS += $(test_c_flags)
|
||||
LOCAL_FORCE_STATIC_EXECUTABLE := true
|
||||
LOCAL_SRC_FILES := $(test_src_files)
|
||||
LOCAL_STATIC_LIBRARIES += libstlport_static libstdc++ libm libc bionic-unit-tests-unwind-test-impl
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES := $(test_fortify_static_libraries)
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += libBionicTests
|
||||
LOCAL_STATIC_LIBRARIES += libstlport_static libstdc++ libm libc
|
||||
include $(BUILD_NATIVE_TEST)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# We build the static unit tests as a library so they can be used both for
|
||||
# bionic-unit-tests-static and also as part of CTS.
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := libBionicTests
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
|
||||
LOCAL_CFLAGS += $(test_c_flags)
|
||||
LOCAL_SRC_FILES := $(test_src_files)
|
||||
LOCAL_CFLAGS += \
|
||||
-DGTEST_OS_LINUX_ANDROID \
|
||||
-DGTEST_HAS_STD_STRING \
|
||||
|
||||
LOCAL_C_INCLUDES += \
|
||||
bionic bionic/libstdc++/include \
|
||||
external/gtest/include \
|
||||
external/stlport/stlport \
|
||||
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES := \
|
||||
$(test_fortify_static_libraries) \
|
||||
bionic-unit-tests-unwind-test-impl \
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Test library for the unit tests.
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -157,7 +180,7 @@ include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := bionic-unit-tests-glibc
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
|
||||
LOCAL_CFLAGS += $(test_c_flags)
|
||||
LOCAL_LDFLAGS += -lpthread -ldl
|
||||
LOCAL_LDFLAGS += -lpthread -ldl -lrt
|
||||
LOCAL_LDFLAGS += $(test_dynamic_ldflags)
|
||||
LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
|
||||
LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host
|
||||
|
@@ -48,6 +48,19 @@ TEST(DEATHTEST, strncpy_fortified2) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __clang__
|
||||
// This test is disabled in clang because clang doesn't properly detect
|
||||
// this buffer overflow. TODO: Fix clang.
|
||||
TEST(DEATHTEST, strncpy2_fortified2) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
foo myfoo;
|
||||
memset(&myfoo, 0, sizeof(myfoo));
|
||||
myfoo.one[0] = 'A'; // not null terminated string
|
||||
ASSERT_EXIT(strncpy(myfoo.b, myfoo.one, sizeof(myfoo.b)),
|
||||
testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef __clang__
|
||||
// This test is disabled in clang because clang doesn't properly detect
|
||||
// this buffer overflow. TODO: Fix clang.
|
||||
@@ -481,6 +494,14 @@ TEST(DEATHTEST, strncpy_fortified) {
|
||||
ASSERT_EXIT(strncpy(bufb, bufa, n), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(DEATHTEST, strncpy2_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char dest[11];
|
||||
char src[10];
|
||||
memcpy(src, "0123456789", sizeof(src)); // src is not null terminated
|
||||
ASSERT_EXIT(strncpy(dest, src, sizeof(dest)), testing::KilledBySignal(SIGABRT), "");
|
||||
}
|
||||
|
||||
TEST(DEATHTEST, snprintf_fortified) {
|
||||
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
||||
char bufa[15];
|
||||
@@ -657,3 +678,42 @@ TEST(TEST_NAME, strcat2) {
|
||||
ASSERT_EQ('7', buf[8]);
|
||||
ASSERT_EQ('\0', buf[9]);
|
||||
}
|
||||
|
||||
TEST(TEST_NAME, strncpy) {
|
||||
char src[10];
|
||||
char dst[10];
|
||||
memcpy(src, "0123456789", sizeof(src)); // non null terminated string
|
||||
strncpy(dst, src, sizeof(dst));
|
||||
ASSERT_EQ('0', dst[0]);
|
||||
ASSERT_EQ('1', dst[1]);
|
||||
ASSERT_EQ('2', dst[2]);
|
||||
ASSERT_EQ('3', dst[3]);
|
||||
ASSERT_EQ('4', dst[4]);
|
||||
ASSERT_EQ('5', dst[5]);
|
||||
ASSERT_EQ('6', dst[6]);
|
||||
ASSERT_EQ('7', dst[7]);
|
||||
ASSERT_EQ('8', dst[8]);
|
||||
ASSERT_EQ('9', dst[9]);
|
||||
}
|
||||
|
||||
TEST(TEST_NAME, strncpy2) {
|
||||
char src[10];
|
||||
char dst[15];
|
||||
memcpy(src, "012345678\0", sizeof(src));
|
||||
strncpy(dst, src, sizeof(dst));
|
||||
ASSERT_EQ('0', dst[0]);
|
||||
ASSERT_EQ('1', dst[1]);
|
||||
ASSERT_EQ('2', dst[2]);
|
||||
ASSERT_EQ('3', dst[3]);
|
||||
ASSERT_EQ('4', dst[4]);
|
||||
ASSERT_EQ('5', dst[5]);
|
||||
ASSERT_EQ('6', dst[6]);
|
||||
ASSERT_EQ('7', dst[7]);
|
||||
ASSERT_EQ('8', dst[8]);
|
||||
ASSERT_EQ('\0', dst[9]);
|
||||
ASSERT_EQ('\0', dst[10]);
|
||||
ASSERT_EQ('\0', dst[11]);
|
||||
ASSERT_EQ('\0', dst[12]);
|
||||
ASSERT_EQ('\0', dst[13]);
|
||||
ASSERT_EQ('\0', dst[14]);
|
||||
}
|
||||
|
@@ -32,10 +32,10 @@ struct LocalPropertyTestState {
|
||||
LocalPropertyTestState(int nprops) : nprops(nprops), valid(false) {
|
||||
static const char prop_name_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_";
|
||||
|
||||
char dir_template[] = "/data/nativetest/prop-XXXXXX";
|
||||
char dir_template[] = "/data/local/tmp/prop-XXXXXX";
|
||||
char *dirname = mkdtemp(dir_template);
|
||||
if (!dirname) {
|
||||
perror("making temp file for test state failed (is /data/nativetest writable?)");
|
||||
perror("making temp file for test state failed (is /data/local/tmp writable?)");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -278,6 +278,16 @@ TEST(pthread, pthread_detach__no_such_thread) {
|
||||
ASSERT_EQ(ESRCH, pthread_detach(dead_thread));
|
||||
}
|
||||
|
||||
TEST(pthread, pthread_getcpuclockid__clock_gettime) {
|
||||
pthread_t t;
|
||||
ASSERT_EQ(0, pthread_create(&t, NULL, SleepFn, reinterpret_cast<void*>(5)));
|
||||
|
||||
clockid_t c;
|
||||
ASSERT_EQ(0, pthread_getcpuclockid(t, &c));
|
||||
timespec ts;
|
||||
ASSERT_EQ(0, clock_gettime(c, &ts));
|
||||
}
|
||||
|
||||
TEST(pthread, pthread_getcpuclockid__no_such_thread) {
|
||||
pthread_t dead_thread;
|
||||
MakeDeadThread(dead_thread);
|
||||
|
@@ -35,7 +35,7 @@ TEST(statvfs, statvfs) {
|
||||
#endif
|
||||
|
||||
#if __BIONIC__
|
||||
ASSERT_EQ(0, statvfs("/data/data", &sb));
|
||||
ASSERT_EQ(0, statvfs("/data/local/tmp", &sb));
|
||||
ASSERT_NE(0U, sb.f_bfree);
|
||||
ASSERT_NE(0U, sb.f_ffree);
|
||||
ASSERT_NE(0U, sb.f_fsid);
|
||||
@@ -59,7 +59,7 @@ TEST(statvfs, fstatvfs) {
|
||||
#endif
|
||||
|
||||
#if __BIONIC__
|
||||
fd = open("/data/data", O_RDONLY);
|
||||
fd = open("/data/local/tmp", O_RDONLY);
|
||||
ASSERT_EQ(0, fstatvfs(fd, &sb));
|
||||
close(fd);
|
||||
ASSERT_NE(0U, sb.f_bfree);
|
||||
|
@@ -28,10 +28,10 @@ extern void *__system_property_area__;
|
||||
|
||||
struct LocalPropertyTestState {
|
||||
LocalPropertyTestState() : valid(false) {
|
||||
char dir_template[] = "/data/nativetest/prop-XXXXXX";
|
||||
char dir_template[] = "/data/local/tmp/prop-XXXXXX";
|
||||
char *dirname = mkdtemp(dir_template);
|
||||
if (!dirname) {
|
||||
perror("making temp file for test state failed (is /data/nativetest writable?)");
|
||||
perror("making temp file for test state failed (is /data/local/tmp writable?)");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -54,3 +54,16 @@ TEST(time, gmtime) {
|
||||
ASSERT_EQ(0, broken_down->tm_mon);
|
||||
ASSERT_EQ(1970, broken_down->tm_year + 1900);
|
||||
}
|
||||
|
||||
#ifdef __BIONIC__
|
||||
TEST(time, mktime_10310929) {
|
||||
struct tm t;
|
||||
memset(&t, 0, sizeof(tm));
|
||||
t.tm_year = 200;
|
||||
t.tm_mon = 2;
|
||||
t.tm_mday = 10;
|
||||
|
||||
ASSERT_EQ(-1, mktime(&t));
|
||||
ASSERT_EQ(-1, mktime_tz(&t, "UTC"));
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user