| 2e48af98 | 04-Sep-2019 |
Jens Wiklander <jens.wiklander@linaro.org> |
util.h: add the macro ROUNDUP_OVERFLOW()
Adds the macro ROUNDUP_OVERFLOW() which rounds up like ROUNDUP() but also checks the result for overflow and returns true on overflow.
Reviewed-by: Etienne
util.h: add the macro ROUNDUP_OVERFLOW()
Adds the macro ROUNDUP_OVERFLOW() which rounds up like ROUNDUP() but also checks the result for overflow and returns true on overflow.
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jerome Forissier <jerome@forissier.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| 02b0fca7 | 04-Sep-2019 |
Jerome Forissier <jerome@forissier.org> |
libutils: bget_malloc.c: copy statistics using memcpy_unckecked()
When CFG_CORE_SANITIZE_KADDRESS=y, most OP-TEE files are built with address sanitizer flags except bget_malloc.c. As a result, the m
libutils: bget_malloc.c: copy statistics using memcpy_unckecked()
When CFG_CORE_SANITIZE_KADDRESS=y, most OP-TEE files are built with address sanitizer flags except bget_malloc.c. As a result, the memcpy() function in memcpy.c is instrumented, whereas the malloc context structure (malloc_ctx) in bget_malloc.c is not. This causes the following panic:
$ xtest --stats --alloc
E/TC:0 0 Panic at core/kernel/asan.c:189 <check_access> E/TC:0 0 Call stack: E/TC:0 0 0x0e125c3d print_kernel_stack at optee_os/core/arch/arm/kernel/unwind_arm32.c:450 E/TC:0 0 0x0e13fcfb __do_panic at optee_os/core/kernel/panic.c:32 (discriminator 1) E/TC:0 0 0x0e13e099 check_access at optee_os/core/kernel/asan.c:187 (discriminator 2) E/TC:0 0 0x0e13e10f check_load at optee_os/core/kernel/asan.c:199 E/TC:0 0 0x0e13e187 __asan_load4_noabort at optee_os/core/kernel/asan.c:231 E/TC:0 0 0x0e185d15 memcpy at optee_os/lib/libutils/isoc/newlib/memcpy.c:112 E/TC:0 0 0x0e184a3f gen_malloc_get_stats at optee_os/lib/libutils/isoc/bget_malloc.c:234 [...]
Introduce memcpy_unchecked() (which evaluates to asan_memcpy_unchecked() when ASAN is enabled and memcpy() otherwise) to fix the issue.
Signed-off-by: Jerome Forissier <jerome@forissier.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
show more ...
|
| 53b7629f | 03-Sep-2019 |
Volodymyr Babchuk <volodymyr_babchuk@epam.com> |
core: don't use __bss and __data attributes
Manual placement in .data or .bss section breaks GCC Address Sanitizer, because it refuses to track variables, that are stored in user sections. Even if t
core: don't use __bss and __data attributes
Manual placement in .data or .bss section breaks GCC Address Sanitizer, because it refuses to track variables, that are stored in user sections. Even if those sections are actually not user-defined, but generic .bss and .data.
Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Jerome Forissier <jerome@forissier.org> Tested-by: Jerome Forissier <jerome@forissier.org> (HiKey960, ASAN) Tested-by: Jerome Forissier <jerome@forissier.org> (QEMU, GP, ASAN)
show more ...
|
| 757331fc | 21-Aug-2019 |
Jens Wiklander <jens.wiklander@linaro.org> |
Replace ASM with compiler-builtin __ASSEMBLER__
The C preprocessor predefines __ASSEMBLER__ with value 1 when when preprocessing assembly language, see [1]. Instead of using a special defines, let's
Replace ASM with compiler-builtin __ASSEMBLER__
The C preprocessor predefines __ASSEMBLER__ with value 1 when when preprocessing assembly language, see [1]. Instead of using a special defines, let's use the define already provided.
Link: [1] https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| 35bf2630 | 29-Jul-2019 |
Justin Chadwell <justin.chadwell@arm.com> |
Remove unnecessary __aeabi functions
Some of the aeabi functions provided are undocumented and are not called from anywhere. This patch removes them entirely.
Reviewed-by: Jens Wiklander <jens.wikl
Remove unnecessary __aeabi functions
Some of the aeabi functions provided are undocumented and are not called from anywhere. This patch removes them entirely.
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Justin Chadwell <justin.chadwell@arm.com>
show more ...
|
| e3d56a52 | 05-Jul-2019 |
Jerome Forissier <jerome.forissier@linaro.org> |
libutils: import bcmp() from newlib
Recent versions of Clang (later than 8.0.0) may replace calls to memcmp() by bcmp(). Therefore, provide an implementation of this function to avoid unresolved sym
libutils: import bcmp() from newlib
Recent versions of Clang (later than 8.0.0) may replace calls to memcmp() by bcmp(). Therefore, provide an implementation of this function to avoid unresolved symbol errors. The same issue was fixed in a similar way in the Linux kernel [1].
Link: [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5f074f3e192f10c9fade898b9b3b8812e3d83342 Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| ff7c2da6 | 03-Apr-2019 |
Jerome Forissier <jerome.forissier@linaro.org> |
Force alignment of assembler functions (FUNC and LOCAL_FUNC) to 4 bytes
The Clang assembler will not align all the functions containing arm32 code (as opposed to thumb) on 4-byte boundaries, contrar
Force alignment of assembler functions (FUNC and LOCAL_FUNC) to 4 bytes
The Clang assembler will not align all the functions containing arm32 code (as opposed to thumb) on 4-byte boundaries, contrary to GCC. For example, with the current code, the syscall wrappers in libutee are like so:
# GCC 8.2.1 $ arm-linux-gnueabihf-objdump -x utee_syscalls_a32.o | \ grep '\.text\.utee_.*\*\*' | head -3 3 .text.utee_panic 00000014 00000000 00000000 00000034 2**2 6 .text.utee_return 00000014 00000000 00000000 0000005c 2**2 9 .text.utee_log 00000014 00000000 00000000 00000078 2**2
# Clang 8.0.0 $ arm-linux-gnueabihf-objdump -x utee_syscalls_a32.o | \ grep '\.text\.utee_.*\*\*' | head -3 1 .text.utee_panic 00000014 00000000 00000000 00000034 2**0 4 .text.utee_return 00000014 00000000 00000000 0000005c 2**0 6 .text.utee_log 00000014 00000000 00000000 00000078 2**0
The bad alignment constraint can cause run time exceptions. Add a ".balign 4" to FUNC and LOCAL_FUNC to fix that.
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| 9de8272e | 25-Mar-2019 |
Jerome Forissier <jerome.forissier@linaro.org> |
Remove deprecated ldm/stm instructions
Some uses of SP, PC and LR in the register list of Load/Store Multiple instructions is forbidden (Thumb) or deprecated (ARM) as per the ARM ARM DDI 0406 C.d. F
Remove deprecated ldm/stm instructions
Some uses of SP, PC and LR in the register list of Load/Store Multiple instructions is forbidden (Thumb) or deprecated (ARM) as per the ARM ARM DDI 0406 C.d. For the LDM instructions, SP should not be in the list, and the list should not contain both PC and LR. See sections:
[A8.8.58] LDM/LDMIA/LDMFD (Thumb) [A8.8.59] LDM/LDMIA/LDMFD (ARM) [A8.8.60] LDMDA/LDMFA [A8.8.61] LDMDB/LDMEA [A8.8.62] LDMIB/LDMED
For the STM instructions, neither SP nor PC should be in the list. See sections:
[A8.8.200] STM (STMIA, STMEA) [A8.8.201] STMDA (STMED) [A8.8.202] STMDB (STMFD) [A8.8.203] STMIB (STMFA)
Clang warns on the deprecated constructs. Use ldr/str instead.
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| b6d69a43 | 25-Mar-2019 |
Jerome Forissier <jerome.forissier@linaro.org> |
libutils: ctype.h: do not define functions as builtins
Our <ctype.h> defines a number of functions as macros that evaluate to the builtin function of the same name, for instance:
#define isalpha(_
libutils: ctype.h: do not define functions as builtins
Our <ctype.h> defines a number of functions as macros that evaluate to the builtin function of the same name, for instance:
#define isalpha(__c) __builtin_isalpha(__c)
There are two problems with this:
1. It gets in the way of the application developer and makes some compiler flags irrelevant (-fno-builtin*, [1]). 2. Different compilers do not support the same set of builtin functions so having the defines can result in build errors.
Therefore, user regular prototypes in <ctype.h>. Also build libutils without the -ffreestanding flag because it implies -fno-builtin and therefore may needlessly disable optimizations. The libutils environment cannot be considered "free standing" since it implements the standard header files with the expected semantics.
Our implementations of the <ctypes.h> functions (isalnum(), isalpha(), etc.) are defined with the __builtin_ prefix. This is not needed and is arguably wrong. Indeed, we want the functions in libutils to be present without the prefix, which GCC happens to be doing regardless. However, this __builtin_ prefix in the .c files makes things more complicated to support Clang. Therefore, remove it.
Link: [1] https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html (-fno-builtin) Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| 146a256b | 05-Jul-2019 |
Jerome Forissier <jerome.forissier@linaro.org> |
libutils/newlib: sort sub.mk in alphabetical order
Sort "src-y" lines by alphabetical order.
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@l
libutils/newlib: sort sub.mk in alphabetical order
Sort "src-y" lines by alphabetical order.
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| d3642135 | 25-Mar-2019 |
Jerome Forissier <jerome.forissier@linaro.org> |
libutils: asm.S: remove .func/.endfunc directives
The .func and .endfunc directives are ignored unless the file is compiled with debugging enabled and --gstabs. Since we do not use this debugging fo
libutils: asm.S: remove .func/.endfunc directives
The .func and .endfunc directives are ignored unless the file is compiled with debugging enabled and --gstabs. Since we do not use this debugging format, .func and .endfunc are effectively no-ops.
The Clang compiler does not recognize these directives. Therefore, in preparation for Clang support, remove them.
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| c96d7091 | 01-Jul-2019 |
Sumit Garg <sumit.garg@linaro.org> |
ftrace: Enable support for 32 bit apps
By default 32 bit trusted applications are compiled in thumb mode but thumb mode doesn't support function graph tracing due to missing frame pointer support re
ftrace: Enable support for 32 bit apps
By default 32 bit trusted applications are compiled in thumb mode but thumb mode doesn't support function graph tracing due to missing frame pointer support required to trace function call chain. So rather compile trusted applications in ARM mode in case function tracing is enabled.
Signed-off-by: Sumit Garg <sumit.garg@linaro.org> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
show more ...
|
| 3dd0e94e | 18-Jun-2019 |
Jens Wiklander <jens.wiklander@linaro.org> |
libutils: add trace_vprintf()
Adds the trace_vprintf() helper function.
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> |
| 7cc6dea7 | 03-Jun-2019 |
Jens Wiklander <jens.wiklander@linaro.org> |
libutils: sys/queue.h: add STAILQ_REMOVE_AFTER()
Import macro STAILQ_REMOVE_AFTER from FreeBSD.
Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklande
libutils: sys/queue.h: add STAILQ_REMOVE_AFTER()
Import macro STAILQ_REMOVE_AFTER from FreeBSD.
Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| 9d6ac097 | 10-Jun-2019 |
Sumit Garg <sumit.garg@linaro.org> |
ftrace: arm64: handle special setjmp()/longjmp() apis
setjmp()/longjmp() user-space apis are used to perform a nonlocal goto which transfer execution from one function to a predetermined location in
ftrace: arm64: handle special setjmp()/longjmp() apis
setjmp()/longjmp() user-space apis are used to perform a nonlocal goto which transfer execution from one function to a predetermined location in another function. This is a special case as compared to normal "C" function calls. So this patch enables ftrace to generate function graph for these apis.
Signed-off-by: Sumit Garg <sumit.garg@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org> Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey960)
show more ...
|
| 78e8a97d | 23-May-2019 |
Jens Wiklander <jens.wiklander@linaro.org> |
Move reg_pair_*() to util.h
Moves the two functions reg_pair_to_64() and reg_pair_from_64() from the core only .h file <kernel/misc.h> to the libutils .h file util.h to make the functions available
Move reg_pair_*() to util.h
Moves the two functions reg_pair_to_64() and reg_pair_from_64() from the core only .h file <kernel/misc.h> to the libutils .h file util.h to make the functions available from TAs.
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| 95d0db1e | 15-May-2019 |
Jens Wiklander <jens.wiklander@linaro.org> |
core: add system wide mempool_default
Adds system wide mempool_default for temporary large memory allocations.
Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere
core: add system wide mempool_default
Adds system wide mempool_default for temporary large memory allocations.
Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| 7c8b181a | 25-Feb-2019 |
Jerome Forissier <jerome.forissier@linaro.org> |
libutils: add memzero_explicit()
Adds a new function: memzero_explicit(s, count) which is equivalent to memset(s, 0, count) except that it cannot be optimized away by the compiler.
memset() being a
libutils: add memzero_explicit()
Adds a new function: memzero_explicit(s, count) which is equivalent to memset(s, 0, count) except that it cannot be optimized away by the compiler.
memset() being a built-in function, the compiler is free to perform optimizations such as simply discarding a call when it considers that the call cannot have any observable effect from the program's point of view. A typical example is clearing local data before returning from a function. memset() is likely to have no effect in this case while memzero_explicit() will work as expected.
Calling memset() directly from memzero_explicit() would work as long as link time optimization (LTO) is not applied. With LTO however, the compiler could inline the call to memzero_explicit() and find out that dead store optimization applies. In order to avoid that, we use a method mentioned in [1] which consists in using a volatile function pointer. This method is considered "effective in practice" with all the commonly used compilers.
Link: [1] https://www.usenix.org/system/files/conference/usenixsecurity17/sec17-yang.pdf Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
show more ...
|
| 4e570655 | 13-Feb-2019 |
Jerome Forissier <jerome.forissier@linaro.org> |
libutils: add free_wipe()
Adds function free_wipe(void *ptr) to clear a buffer before returning it to the heap. The pattern used to overwrite the data is 0x55. Users have to #include <stdlib_ext.h>
libutils: add free_wipe()
Adds function free_wipe(void *ptr) to clear a buffer before returning it to the heap. The pattern used to overwrite the data is 0x55. Users have to #include <stdlib_ext.h> to import the declaration.
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Joakim Bech <joakim.bech@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
show more ...
|
| c2ce4186 | 12-Apr-2019 |
Jens Wiklander <jens.wiklander@linaro.org> |
Introduce CFG_CORE_DUMP_OOM
Introduces CFG_CORE_DUMP_OOM which if y will print an error and dump the stack on memory allocation failures using malloc() and friends.
Reviewed-by: Jerome Forissier <j
Introduce CFG_CORE_DUMP_OOM
Introduces CFG_CORE_DUMP_OOM which if y will print an error and dump the stack on memory allocation failures using malloc() and friends.
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| b0d497fa | 20-Dec-2018 |
Jerome Forissier <jerome.forissier@linaro.org> |
libutils: export PRIxVA_WIDTH and add PRIxPA_WIDTH
Export two macros that are useful to print virtual or physical addresses with the full width required by the native type, that is, 0x + 8 character
libutils: export PRIxVA_WIDTH and add PRIxPA_WIDTH
Export two macros that are useful to print virtual or physical addresses with the full width required by the native type, that is, 0x + 8 characters when the pointer size is 32 bits, and 0x + 16 characters when it is 64 bits.
Example:
vaddr_t va = 0x1234;
DMSG("va=0x%0*" PRIxVA, PRIxVA_WIDTH, va);
The above code will print "va=0x00001234" if vaddr_t is 32 bits, and "va=0x0000000000001234" if vaddr_t is 64 bits.
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| e72ad0e2 | 07-Mar-2019 |
Etienne Carriere <etienne.carriere@st.com> |
libutil: add UDIV_ROUND_NEAREST() macro
Default integer division rounds down. Here the interest is to round to the nearest unsigned integer.
This is inspired from [1].
Link: [1] https://chromium.g
libutil: add UDIV_ROUND_NEAREST() macro
Default integer division rounds down. Here the interest is to round to the nearest unsigned integer.
This is inspired from [1].
Link: [1] https://chromium.googlesource.com/chromiumos/platform/ec/+/master/include/util.h
Signed-off-by: Etienne Carriere <etienne.carriere@st.com> Signed-off-by: Nicolas Le Bayon <nicolas.le.bayon@st.com> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
show more ...
|
| 48e10604 | 14-Feb-2019 |
Jerome Forissier <jerome.forissier@linaro.org> |
libutils: remove buf_compare_ct()
Now that we have consttime_memcmp(), buf_compare_ct() is redundant. Every time buf_compare_ct() is used, consttime_memcmp() may be used instead.
This commit remove
libutils: remove buf_compare_ct()
Now that we have consttime_memcmp(), buf_compare_ct() is redundant. Every time buf_compare_ct() is used, consttime_memcmp() may be used instead.
This commit removes buf_compare_ct(). A compatibility wrapper is kept in <string_ext.h> to avoid knowingly breaking the build of any TA that may use it.
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| b7da54b3 | 08-Feb-2019 |
Jerome Forissier <jerome.forissier@linaro.org> |
libutils: Import isc_tsmemcmp() from NTP as consttime_memcmp()
This patch imports a constant-time byte sequence comparison function from the NTP source tree [1]. Contrary to our buf_compare_ct() fun
libutils: Import isc_tsmemcmp() from NTP as consttime_memcmp()
This patch imports a constant-time byte sequence comparison function from the NTP source tree [1]. Contrary to our buf_compare_ct() function, which has only two possible outcomes (zero or non-zero), the new function is a direct replacement for memcmp() because it returns three possible states (< 0, 0, > 0).
Link: [1] http://bk.ntp.org/ntp-stable/lib/isc/tsmemcmp.c Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Suggested-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Joakim Bech <joakim.bech@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
show more ...
|
| 9c7ce04d | 14-Feb-2019 |
Yunjong Jeong <yunjong@kaist.ac.kr> |
libutils: isoc: implement more ctypes functions
Implement missing functions from ctypes.h.
Signed-off-by: Yunjong Jeong <yunjong@kaist.ac.kr> Acked-by: Jerome Forissier <jerome.forissier@linaro.org> |