aboutsummaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2024-01-18libc: move libc rand to separate module to speedup rebuildsYurii Shutkin
rand.c depends on a module seed define that is randomly changed every build, so moving rand.c into a separate module saves rebuild time as the rest libc stays untouched. Change-Id: Id2ebf3489e107c43c4d07048bea50b505de3d87a Test: build Bug: 319455354
2023-07-21Reset thread cookie upon exitPer Larsen
Once a thread cookie has been corrupted, we cannot use the existing test facility to exit a thread on panics without resetting its cookie such that it can exit without triggering additional panics. We only do so for test threads that have the exit-on-panic flag set. If this flag is set, we are also more lenient w.r.t. the thread state. In thread_resched, the call to get_top_thread is moved past the first call to thread_cookie_check. This is necessary to cleanly exit a test thread with a corrupted cookie because thread_preempt might have put said thread at the head of its run queue. Bug: 215740695 Change-Id: I68a95cff523f323370c5fc55851679e146214684 Signed-off-by: Per Larsen <perlarsen@google.com>
2023-06-16lib/libc: Update formatting for printfRaphael Herouart
- indirect width specification via %*s of %*d or alike was not supported - Passing (NULL, 0, ...) to snprintf to know formatted string length was not supported These are necessary for running kernel Benchmarks Bug: None Change-Id: I229583854168298ccb7e31cff818f58a378cdb30
2023-06-15Revert "lib/libc: Update formatting for printf" Raphaël Hérouart
This reverts commit fe29d82177f010e149cec97f22cf83b3129aebf5. Reason for revert: because of non-compliant stdlib not having abs? Change-Id: I4499b738e4a3a4618f71220bf3869746ac1da093
2023-06-13lib/libc: Update formatting for printfRaphael Herouart
- indirect width specification via %*s of %*d or alike was not supported - Passing (NULL, 0, ...) to snprintf to know formatted string length was not supported These are necessary for running kernel Benchmarks Bug: None Change-Id: I3722847d33e8f51adbe474354340341fdfba5877
2023-04-18lib/libc: Add io_handle.h headerAndrei Homescu
Add the io_handle.h header to our libc instead of importing the one from trusty/kernel since that doesn't always work correctly. Bug: 230134581 Change-Id: Idc325e9a81d5a3efd0f3a62742e98a9334c8e973
2023-04-13lib/libc: Use lk stdio instead of muslAndrei Homescu
Update lk stdio for use instead of musl's implementation in libc-trusty. Bug: 230134581 Change-Id: Icdd15292e6197446999333dd252cf079b04f67a0
2023-04-13lib/libc: Add missing internal stdlib.h include to atoi.cAndrei Homescu
atoi.c assumes the lk libc version of stdlib.h has been included. That was no longer the case after switching to musl, so include it explicitly from that source file. Bug: 230134581 Change-Id: I780f3f690645bcdfc75a53bd71da3e8b682f6467
2022-12-06lib: heap: miniheap: fix uninitialized variablesArmelle Laine
Bug: 252870906 Change-Id: I59b8f246e29ecead08ae653ce6e7cf9fc6101840
2022-12-04lib/libc: Replace long => uintptr_t in mem{cpy,move}Andrei Homescu
The lk implementations of mem{cpy,move} internally cast some pointers to long, which triggers UBSan. This replaces the target type with uintptr_t which fixes the issue (and it matches the original char* pointer types better). Bug: 231151995 Change-Id: Ia915baae1f167204aaffe4998d4f75a9e516677a
2022-12-03lib: heap: prevent Illegal memory access during heap initArmelle Laine
Bug: 252874494 Change-Id: I2a728996f0839fc869904c69e1d2b4946a8040bc
2022-12-03lib: heap: cmpctmalloc: fix misleading return statementArmelle Laine
Bug: 252874485 Change-Id: Id0e653111b1454c251dd8d0e79a5fccf84d6fe36
2022-12-01lib: binary_search_tree: expose as libraryDavid Anekstein
Bug: 260484725 Change-Id: Ic6bc8f034007cdc441b908014671b66281873986
2022-10-28lib/libc: Add option to replace LK libc with muslAyrton Munoz
This commit adds an LK_LIBC_IMPLEMENTATION build flag that can be set to `musl` or `lk` to select the kernel's libc. The default (musl) is set in engine.mk to allow projects that want to keep using lk to override it. This is also required to allow conditionally building tests in kerneltests-inc.mk as libc-trusty/test only compiles with musl (LK libc is missing many headers and function definitions). When a libc module is selected in kernel/rules.mk we also define an LK_LIBC_IMPLEMENTATION_IS_[LK,MUSL] macro to allow conditionally compiling code based on which libc is used if it's necessary. This commit also moves off_t and ssize_t from lk/types.h to LK's sys/types.h to only keep the LK definitions (which differ from musl on some archs) when using LK libc. It also includes inttypes.h in lk/types.h (used by both musl and LK) to allow using the PRI macros it defines. Bug: 230134581 Change-Id: I7a6c4b6d50d206241775e83961ee166689906515
2022-10-28lib/libc: Add fd_io_handle and file_io_handleAyrton Munoz
LK's libc exposes the FILE struct's definition which app/consoletest and libtrusty use to access the `io_handle_t`s corresponding to stdout/stderr. On the other hande, musl only exposes an opaque type for FILE. This commit adds two new functions for accessing the `io_handle_t`s given a file descriptor or a FILE*. These functions also have equivalents for musl defined in libc-trusty. This allows us to modify the modules that map fd or FILE* to io_handle_t with a call to one of the new functions and select the definition based on which libc implementation is chosen. Bug: 230134581 Change-Id: I2052258614b42413cc6ea040bd29b42249cc7c04
2022-10-25lib/console: Conditionally compile panic_shell_startAyrton Munoz
Bug: 230134581 Change-Id: I90a71ed2ccfae048a754d43099dbcbee69913b5b
2022-10-25Revert "lib/libc: Alias __errno_location to __geterrno"Ayrton Munoz
This reverts commit cc15b8c55f329b1a37fc6c51cb4fc88bd111d458. Reason for revert: aosp/2118665 no longer uses LK's errno implementation so won't need these aliases. Change-Id: I61d42cad7172e4d579f61edf3e7ee5a846ed08c9
2022-10-20lib/libc: Make DEBUG_ASSERT use asserted expression in all casesAyrton Munoz
When LK_DEBUGLEVEL is less than 2 the variable asserted in DEBUG_ASSERT must be used afterwards to avoid a `variable set but not used` error. This change allows defining variables which only need to be asserted. It also fixes a few cases in miniheap that did not compile because of conditionally defined struct fields/variables. This fixes the generic-arm* targets when switching to musl. Bug: 230134581 Change-Id: I9753d238470caabaaebd5fb02558fc37ebce94ba
2022-10-20lib/heap: Remove new.cpp provided by LK's lib/heapAyrton Munoz
When WITH_CPP_SUPPORT is set, we use libcxx which provides a proper implementation of the functions in this new.cpp. Bug: 230134581 Change-Id: Iaf6274cb630bd87b35cc73da2021a8f7ba328952
2022-10-17include/compiler.h: Replace countof macro with inline function in C++Ayrton Munoz
libcxx's locale.cpp defines an internal countof function so this commit replaces that macro with an inline function definition whenever compiler.h is included in C++. It also adds the countof macro in two host tests that call countof on pointers to empty arrays since zero-sized arrays are not permitted in C++. Bug: 230134581 Change-Id: I4d8dc311f86a1e6df5231ca4a16587023becca58
2022-09-28Switch to PRIxPTR format specifier macrosAyrton Munoz
LK defines uintptr_t as `unsigned long` for every arch, but musl defines it as `unsigned int` for ARM so this switches %lx to PRIxPTR when printing `uintptr_t`s. It also adds PRI macros for the paddr_t, vaddr_t and addr_t typedefs and changes the definition of PRIxPTR_USER when IS_64BIT is false. Bug: 230134581 Change-Id: I8bb5adef690a65adf426816f51313db3b1df9c3a
2022-09-23lib/heap: Implement posix_memalignAyrton Munoz
Bug: 230134581 Change-Id: If0d543f1372fa4423a88ea6ded9d7a1373347762
2022-09-23lib/libc: Make vfprintf definition match muslAyrton Munoz
Musl's stdio.h defines `vfprintf` as an inline function that calls `vfprintf_worker` with a fourth argument that determines whether address-like values should be printed or not. To use musl for the kernel, this commit renames the `vfprintf` definition in stdio.c to `vfprintf_worker` and changes the function signature to match musl. Bug: 230134581 Change-Id: I94dd4100c06b0a23d55a0ccdbcd3e2dee4f40a10
2022-09-23lib/libc: Rename _printf and _vprintf to printf and vprintfAyrton Munoz
LK's stdio.h previously defined a printf macro which expanded to _printf when DISABLE_DEBUG_OUTPUT was 0. However libcxx expects a symbol named printf in the global namespace so this commit renames _printf to printf to allow compiling C++ while still being able to disable debug output. Bug: 230134581 Change-Id: I0b2d017c70302389606d7548408ccc40c95b36da
2022-09-23Fix incorrect includes of string headersFrances Wingerter
Bug: 213374369 Change-Id: I51175838f3b6272400a8c24f1250310374a4b6b3
2022-09-08[lib][libc] Improving log filtering capabilitiesOrlando Arbildo
Adding modifiers to override filtering. We are using the same modifier used by printk in the linux kernel to override filtering of pointers (%px), and extending it to also %dx, %ux and %xx. We are also removing the override of RELEASE_BUILD on code because this is now taken care on test build makefiles. Bug: 234061145 Test: Added host unit tests for both test-debug and release like builds. Change-Id: I120cd7ef6664ec02ec02c2324cfa9bac3445e6a6
2022-09-08[lib][libc] Adding filtered snprintf functionsOrlando Arbildo
Adding snprintf_filtered function to be able to also filter data when using snprintf. This capability is first being used to cleanup conditionally compiled code that is part of the same topic. Bug: 234061145 Test: build.py Change-Id: I6d9908f9b42aeaebf630c63c69f21a2f87e7e4bc
2022-09-07lib/libc: Alias __errno_location to __geterrnoAyrton Munoz
Musl defines the errno macro as (*__errno_location()) so this commit aliases __errno_location to __geterrno. Musl also internally defines the errno macro as (*___errno_location) in src/include/errno.h so this aliases both to the LK implementation __geterrno. Bug: 230134581 Change-Id: I30527f0fc9016f3e608a15f41f636fb05f04f373
2022-09-07lib/libc: Move LK-specific libc headers to new directoryAyrton Munoz
This change moves LK libc headers that musl requires to `lib/libc/include_common` and adds the directory to `GLOBAL_INCLUDES`. This allows using these headers without duplicating them in the kernel musl module. Bug: 230134581 Change-Id: I0dc97cd2ad1bad5bf5792ffcd615e04499ca6caf
2022-07-22Revert "include/debug.h: Namespace LK debug levels by prefixing ..."Andrei Homescu
Revert submission 2161077-trusty-kernel-namespace-debuglevels Reason for revert: broke downstream builds Reverted Changes: I07fc3efe4:include/debug.h: Namespace LK debug levels by pref... Ibbc7a15ed:lib/trusty: Namespace LK debug levels by prefixing... Change-Id: I260f73bf06708db7944b200dc669d5c935a4136d
2022-07-20include/debug.h: Namespace LK debug levels by prefixing macro definitionsAyrton Munoz
The debug level macros defined by LK conflict with the LogSeverity enum variants in libbase. This commit prefixes the `level` argument passed to dprintf with `LK_DEBUGLEVEL_` to avoid this conflict without having to change every place dprintf is used. Bug: 230134581 Change-Id: I07fc3efe428555649799bdef7b269c1cd31678d2
2022-06-07[lib][libc] Modifying printf to not print address-like valuesOrlando Arbildo
Modified printf implementation to not print numerical values if the number is > +/-4096 for %x, %u, %d and %p when doing a release build. This change affects printf and fprintf function families. Bug: 218483110 Test: Added host unit tests for both test-debug and release like builds. Change-Id: I95f66393752878f9aa606f9af568cd36787dd660
2022-04-27[lib][io] Capture early Trusty boot logsMarco Nelissen
Capture early boot logs and then send them to each print callback that is registered. This allows early Trusty boot logs to be seen without requiring uart. Bug: 221868606 Test: boot, see logs Change-Id: I40ab533d475fe3500271dc867f152b9356fae456
2022-01-26[lib][libc] Use a build-time random value as the seedAndrei Homescu
Set the seed for the kernel's rand() implementation to a random value computed at build-time, so we get some minimal randomness from that RNG. Bug: 80147716 Change-Id: If5f7915a892b825cb7eba46554f2cb29b8ad2eda
2020-10-26[lib][heap] Remove heap_delayed_freeArve Hjønnevåg
It is no longer needed. Bug: 165825378 Change-Id: I0790cafca29072e0d93b396cd664c006571000ae
2020-10-26[lib][debug] Release thread-lock if panic is called with it heldArve Hjønnevåg
Bug: 165823021 Change-Id: I5633e2009431289eeee3de46b01f008bd3d3e0ee
2020-08-10[lib][debug] Dump backtrace on panicTri Vo
Also remove backtraces on faults, as they have become redundant. Bug: 149918767 Change-Id: Ieb4017ad34fb1ff0943c32485b91e420134e3a3d
2020-07-30[kernel] Add thread flag to exit thread on panicArve Hjønnevåg
If panic is called from a thread after thread_set_flag_exit_on_panic(thread, true) has been called for that thread. The thread will exit with ERR_FAULT as the return code instead of halting the system. This can be used to test error paths that are normally not testable, e.g. exception handling. Bug: 147698516 Change-Id: I455898d8d3b5b3ee005969893bb4cb09d4b88a48
2020-07-28Update language to comply with Android’s inclusive language guidanceWenhao Wang
Remove usage of term "sanity check". See https://source.android.com/setup/contribute/respectful-code for reference. Bug: 161896447 Change-Id: I67cf0d794095af85e3f875179ad06c4c0badd7f8
2020-07-27Update language to comply with Android’s inclusive language guidanceMatthew Maurer
Remove usage of term "dummy". See https://source.android.com/setup/contribute/respectful-code for reference. Bug: 161896447 Change-Id: Ib5c811fa74f4847399cdef755809bfedd5046833
2020-05-27[lib][io] Disable serial console when callbacks are registeredArve Hjønnevåg
Speeds up trusty debug output once the trusty log driver has started in linux. Change-Id: I00863bc2c1ce513faa73bd38766ad28334de1d58
2020-03-18Split debug.h into another panic.hWenhao Wang
BoringSSL has a static function called hexdump, which conflicts the one declared in debug.h. debug.h is included indirectly through assert.h. And the function "panic" is the only function used by assert.h. So we create a panic.h that contains function panic such that debug.h is exluded from assert.h. Bug: 151183243 Change-Id: I83d905048832de12e78702ac0b4c6acafd1c6572
2020-02-21Rename function nameWenhao Wang
CSPRNG has function named rand_add_entropy, which causes a name collision. We rename it as libc_trusty_rand_add_entropy, which will be called by CSPRNG's rand_add_entropy. Bug: 149958771 Change-Id: I09b7213b52376805d21651535ad2d5b5f1564cf7
2019-12-06More fixes for -Wimplicit-fallthroughNick Bray
Bug: 139945549 Change-Id: Ia0495b1b32be87f4cd4b1a4e34cb9f931b8493fa
2019-10-30bstree: Add balancing codeArve Hjønnevåg
Add self balancing code. Balance tree after insert and delete according to WAVL rules. Bug: 141329802 Change-Id: Ic8d43b3b4b173c7ecdb0c48a2c58de0a28d501c4
2019-10-30Add binary search treeArve Hjønnevåg
Add api, basic implementation and tests. TODO: Add balancing code Bug: 141329802 Change-Id: I819bd2ffc35d139f1f6f357eb71bba839c7b2bd9
2019-10-25[kernel][timer] Replace lk_bigtime_t with lk_time_ns_tArve Hjønnevåg
Replace lk_bigtime_t with lk_time_ns_t in preparation for supporting higher resolution timers. lk_bigtime_t was 64 bits, but stored micro seconds. Storing nano seconds gives us hundreds of years range and most hardware has timer ticks shorter than the 1us we could return before. Bug: 131099439 Change-Id: I4b9bda393c3a2a0eb81798a7e935b8701d099f8f
2019-09-05Provide bcmp in the kernelMatthew Maurer
New Clang will call out to bcmp instead of memcmp in some situations. Providing bcmp allows us to use these newer compilers. Bug: 140579848 Change-Id: I0b1d8443e2366a8f258177516e782a26087b86a2
2019-08-05[lib][dpc] Rewrite DPC implementationMichael Ryleev
The DPC (deferred procedure call) service in LK allows to queue work that will be executed at later time in context of DPC kernel thread. This CL reanimates this service (it does not compile as is) to use on devices with small memory footprint. Bug: 134153475 Change-Id: I4dded43e6ba8a83204f51c39a8e07a47f2d0d621
2019-08-02[lib][debug] Fix UBSan issueZhong,Fangjian
Use unsigned char to replace char to avoid potential conversion overflow Bug: 119111590 Change-Id: I1d70d9acd371a8c9877ae76bfe82a74c9dac7cd9