Commit Graph

1327 Commits

Author SHA1 Message Date
Patryk Duda 4b94fc3da2 llvm: Add support for selecting runtime library
This patch adds Kconfig options to select either GNU libgcc or LLVM
compiler-rt. The 'rtlib' flag is provided in a config file, so this
patch introduces 'clang_libgcc.cfg' and 'clang_compiler_rt.cfg' which
enable appropriate library. The file is selected by concatenating
the 'clang_' prefix with library name.

Signed-off-by: Patryk Duda <pdk@semihalf.com>
2023-08-03 19:35:11 +02:00
Christopher Friedt f9ecc9a658 posix: mutex: return ETIMEDOUT from pthread_mutex_timedlock()
The normative spec for `pthread_mutex_timedlock()` says that
it should return `ETIMEDOUT` when a timeout occurs. However,
currently it returns `EAGAIN`, which reflects what is returned
by `k_mutex_lock()`.

Inspect and update the return value to account for this slight
difference.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-08-02 12:04:34 -04:00
Keith Packard d47025bd84 libc/picolibc: Remove unused read_stdin/write_stdout hooks
Picolibc doesn't need these two syscall implementations as it uses
zephyr_fputc instead. Make sure that zephyr_putc is declared correctly.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-08-02 10:35:18 +02:00
Christopher Friedt 73bf557a95 posix: pthread: thread return value not set by pthread_join()
Ensure that the thread return value is set by `pthread_join()`
when `status` is non-NULL.

Additionally, we have an opportunity to synchronously clean
up thread stacks in `pthread_join()`, which is preferable.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-07-30 19:17:49 -04:00
Christopher Friedt 52f00882d1 posix: pthread: report appropriate return value instead of 0
Discovered this while implementing c11 threads, but there
was a regression recently that made it so that `pthread_join()`
would report success when attempting to join a thread that had
been detached with `pthread_detach()`.

Technically now that is undefined behaviour, but historically,
we have reported `EINVAL`, which was the older specified
return value.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-07-30 12:51:12 -04:00
ferar alashkar 595bcda87c lib: os: dec: add misra-c2012 compliance changes
1. change explicit type cast of essential character type, complying with
required [misra-c2012-10.2] rule which states; Expressions of
essentially character type shall not be used inappropriately in addition
and subtraction operations, and

2. add explicit boolean type to 'if' statement controlling expression,
consolidating it with 'buflen' type, thus improving code readability and
maintainability , complying with required [misra-c2012-14.4] rule which
states; ; The controlling expression of an if statement and the
controlling expression of an iteration-statement shall have essentially
boolean type, and

3. add enclosing parentheses enforcing and clarifying precedence of
operators, improving code readability and maintainability, complying
with *advisory* [misra-c2012-12.1] rule which states; The precedence of
operators within expressions should be made explicit.

Found as a coding guideline violation (Rules 10.2, 14.4), and coding
guideline recommendation (Rule 12.1) by static code scanning tool.

Note: Tested on STM32L5 Nucleo-144 board (stm32l552xx).

Signed-off-by: ferar alashkar <ferar.alashkar@gmail.com>
2023-07-28 11:15:44 +02:00
ferar alashkar dddc034923 lib: os: hex: correct explicit cast type
change explicit type cast of essential character type, complying with
required [misra-c2012-10.2] rule which states; Expressions of
essentially character type shall not be used inappropriately in addition
and subtraction operations.

Found as a coding guideline violation (Rule 10.2) by static code
scanning tool.

Note: Tested on STM32L5 Nucleo-144 board (stm32l552xx).

Signed-off-by: ferar alashkar <ferar.alashkar@gmail.com>
2023-07-28 11:15:19 +02:00
ferar alashkar bba6a1d69e lib: os: hex: add explicit unsigned suffices
add explicit unsigned suffices to various immediate numbers, matching
them to size_t, complying with required [misra-c2012-10.4] rule which
states; Both operands of an operator in which the usual arithmetic
conversions are performed shall have the same essential type category.

Found as a coding guideline violation (Rule 10.4) by static code
scanning tool.

Note: Tested on STM32L5 Nucleo-144 board (stm32l552xx).

Signed-off-by: ferar alashkar <ferar.alashkar@gmail.com>
2023-07-28 11:15:12 +02:00
Damian Krolik 74859013f1 lib: cpp: name the choice group for selecting C++ standard
Add a name to the choice group for selecting the C++
standard to be able to override the default standard in
Kconfig.* files.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
2023-07-27 22:33:14 -04:00
Gerard Marull-Paretas b51dd4ade0 lib: hash: use new c++ Kconfig symbols
SYS_HASH_MAP_CXX was using deprecated C++ symbols.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-07-26 14:53:51 +02:00
Carlo Caione 561a80d109 shared_multi_heap: Use a data struct
Embed all the helper structs in one single data struct for easy access
indexed on the memory attr.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-07-26 07:56:39 -04:00
Carlo Caione 5d6d93c3b5 shared_multi_heap: Rename heap counter
We are calling the heap counter `attr_cnt` and that is misleading.
Rename it.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-07-26 07:56:39 -04:00
Carlo Caione b7e252c2db shared_multi_heap: Use proper enum instead of int
We have an enum for the memory attr, use that instead of a generic
unsigned int.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-07-26 07:56:39 -04:00
Christopher Friedt 115efa2e35 pthread: facilitate dynamically allocated thread stacks
This change allows users to call pthread_create() with
the pthread_attr_t argument equal to NULL.

If Zephyr is configured with `CONFIG_DYNAMIC_THREAD`, then a
suitable thread stack will be allocated via
k_thread_stack_alloc(). The allocated thread stack is
automatically freed via k_thread_stack_free().

This makes the Zephyr implementation of pthread_create()
compliant with the normative spec.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2023-07-24 12:59:43 -04:00
Christopher Friedt 748683fae6 posix: eventfd: remove redundant conditional
Since the argument is a 32-bit unsigned int, all possible
values satisfy the condition that intval < UINT64_MAX - 1.

Remove the redundant conditional.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-07-21 06:33:19 -04:00
Daniel Leung 4c80949ecf libc: remove no longer valid kconfig comment
After commit 9a0aebc5fd,
the exclusion of qemu_x86_tiny is no longer and the "depends on"
option was removed. However, the comment about that remained.
Remove the comment as it is no longer valid.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-07-20 12:58:36 -04:00
Jai Arora 82f5db37d2 posix: Changes pthread_equal to regular type function
Patch changes pthread_equal function from static inline to regular
function type

Fix for issue#59942

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
2023-07-20 16:24:16 +02:00
Yong Cong Sin 43c549305b posix: signal: check RTSIG limit
Use build assert to make sure that the realtime signal
constants are configured properly in the Kconfig.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-07-18 15:35:42 -04:00
Yong Cong Sin 335acf817d posix: signal: implement strsignal
Implementation and ztest for strsignal.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-07-18 15:35:42 -04:00
Yong Cong Sin ff4b81e5e5 posix: signal: implement sigismember
Implementation and ztest for sigismember.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-07-18 15:35:42 -04:00
Yong Cong Sin 88cd494430 posix: signal: implement sigdelset
Implementation and ztest for sigdelset.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-07-18 15:35:42 -04:00
Yong Cong Sin 8011449542 posix: signal: implement sigaddset
Implementation and ztest for sigaddset.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-07-18 15:35:42 -04:00
Yong Cong Sin b9720e27c0 posix: signal: implement sigfillset
Implementation and ztest for sigfillset.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-07-18 15:35:42 -04:00
Yong Cong Sin 6910eb4a9b posix: signal: implement sigemptyset
Implementation and ztest for sigemptyset.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-07-18 15:35:42 -04:00
Yong Cong Sin e3c49b9573 posix: signal: add initial header
Initial header for the signal APIs.
APIs to be implemented in later commit.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-07-18 15:35:42 -04:00
Markus Fuchs c0d7218ef2 json: Skip unknown fields on parsing
Skip child objects and arrays that are not specified in the given object
descriptor when parsing a JSON input string.
This patch adds support for extra child arrays which previously were not
supported by the parser as opposed to additional child objects.

Fixes #47988

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2023-07-18 11:03:21 +00:00
Lawrence King 7dae27a90d libc: minimal: math sqrt: sqrtf: fix numeric accuracy of sqrt and sqrtf.
Changed initial guess from a simple x/3 to dividing the exponent by 2.
This makes large or small numbers like 10e10 and 01e-10 converge in a few
loops.

Added a loop counter to ensure that the algorithm breaks out of the loop in
the case that the algorithm doesn't converge (toggling between two
numbers).

Added test cases for sqrt and sqrtf in libc. Tested with a range of numbers
between 10e10 and 10e-10. Verify good accuracy in test case.

Closes: #55962

Signed-off-by: Lawrence King <lawrencek52@gmail.com>
2023-07-14 12:42:41 -04:00
Jaxson Han 0df7bd26ed lib: posix: pthread_rwlock: Fix a racy issue
Multiple reader threads unlocking the read lock simultaneously might
cause the program hang because it's possible that no thread is
identified as the last one to active the writer thread.

To fix the issue, swap the k_sem_give sequence.

Signed-off-by: Jaxson Han <jaxson.han@arm.com>
2023-07-12 09:25:26 +02:00
Keith Packard 021923b58a libc/picolibc: Use mutexes instead of semaphores for non-recursive locks
Picolibc has both recursive and non-recursive mutex uses. The bulk of the
library locking uses the global libc lock, which is a recursive mutex as
that greatly simplifies the implementation.

The only use of non-recursive mutexes is in the stdio code when dealing
with file system I/O via fopen.

Using mutexes for both APIs is valid; the assumption picolibc makes is that
the non-recursive mutexes are somehow cheaper or faster and should be
preferred. However, in Zephyr, recursive mutexes are the default and the
non-recursive locks for picolibc were implemented using semaphores.

Switch the non-recursive picolibc locks to just invoking the existing
recursive functions using mutexes. This avoids pulling in another lock
implementation, saving a bit of space.

This also lets the kernel.memory_protection.mem_map test work on
qemu_x86_tiny where the amount of memory available is 320kB and that is
nearly filled by this test case, leaving too little space for allocating
pages in the k_mem_map_unmap test.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-07-10 15:11:15 +02:00
Harshil Bhatt 8b2a41904d posix: implement timer_getoverrun()
Address missing POSIX function and tests #59956

Signed-off-by: Harshil Bhatt <harshilbhatt2001@gmail.com>
2023-07-10 09:30:33 +02:00
Yong Cong Sin 4580708f54 posix: implement uname
Add implementation for posix uname.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2023-07-09 16:57:16 -04:00
Harshil Bhatt 78c8176c4d posix: Implement pthread_barrieratter functions
Added pthread_barrieratter_init() #59936,
pthread_barrieratter_destroy() #59935,
pthread_barrieratter_getpshared() #59937 and
pthread_barrieratter_setpshared() #59939.

Signed-off-by: Harshil Bhatt <harshilbhatt2001@gmail.com>
2023-07-09 10:40:57 -04:00
Christopher Friedt 694cd58647 posix: pthread: fixes for coverity 321140 and 321092
The `pthread_once_lock` `k_mutex` is statically initialized and
only visible within file scope. Coverity identified it as unsafe
because the return values of `pthread_mutex_lock()` and
`pthread_mutex_unlock()` were unchecked. However, if those
functions were to fail here, it would be indicative that
something far worse has happened.

In any case, we add assertions that these functions
succeed rather than silently ignoring with `(void)`, which
ensures that we have coverage when assertions are enabled,
in test, while removing unneeded code with assertions disable,
in production.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-07-09 08:20:32 -04:00
Christopher Friedt 1434296915 posix: spinlock: additional kconfig for k_spinlock being size 0
The `struct k_spinlock` size is zero bytes under certain
circumstances. This is a bit of a problem, because it breaks a
number of assumptions about things in C.

That should be fixed when #59922 is addressed.

This change is just a hotfix to correct the specific condition
where we will need workarounds in other source files.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-07-06 16:45:26 +00:00
Christopher Friedt 13dcf2e4ed posix: split supported features into separate Kconfig files
This change is setting up for switching over to proper POSIX
option requirements, feature test macros, and a dependency
structure that is reflective of the standard.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-07-06 11:47:07 -04:00
Christopher Friedt 4fcf197c50 posix: rename some files for brevity
Most of the posix source files can be easily identified by a
short name. I.e. most of the `pthread_` prefixed files do not
need the `pthread_` prefix.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-07-06 11:47:07 -04:00
Christopher Friedt e11856fbfe posix: add Meta copyright as appropriate
A significant enough portion of these files has been
changed to justify adding Meta copyright as well as
that of the original author.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-07-06 11:47:07 -04:00
Keith Packard 4e7930b099 libc/picolibc: Remove -T /dev/null linker arguments
Now that the gcc compiler driver uses the -T flag instead of -Wl,-T, we can
remove the hack here that kept the picolibc specs file from inserting the
picolibc linker script.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-07-06 11:43:09 +02:00
Christopher Friedt 452205ff61 posix: pthread: implement pthread spinlocks
pthread_spinlock_t support is part of the base threading
requirement.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-07-05 21:06:55 -04:00
Alberto Escolar Piedras 7e37482a77 libC: PICOLIBC_SUPPORTED: Enable for NATIVE_LIBRARY
It is possible to build with the PICOLIBC_MODULE
with the POSIX arch targets which use the native
simulator as runner.
Update filtering accordingly.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-07-05 07:01:19 -04:00
Alberto Escolar Piedras 2e6396cf20 libC: STDOUT_CONSOLE narrow filtering by type of native build
It is possible to build with STDOUT_CONSOLE with
the embedded C libraries with the POSIX arch.
Narrow down the filtering accordingly.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-07-05 07:01:19 -04:00
Alberto Escolar Piedras 56dc20eb1d Kconfig: Tidy up dependants of NATIVE_APPLICATION
So they depend or select on the right NATIVE_BUILD
instead of NATIVE_APPLICATION.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-07-05 07:01:19 -04:00
Najumon Ba f25dfcf88c lib: acpi: added acpi support using acpica lib
Add ACPI support for Zephyr using acpica open source
project. ACPI subsystem use to discover and configure
hardware components, perform power management (e.g. putting
unused hardware components to sleep), auto configuration (e.g.
Plug and Play and hot swapping) etc.

Signed-off-by: Najumon Ba <najumon.ba@intel.com>
2023-06-30 17:53:01 +03:00
Markus Fuchs 8757c71bd0 json: Fix 64-bit support
This patch fixes encoding arrays of objects on 64-bit targets.

Fixes #36696

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2023-06-29 21:03:48 +02:00
Markus Fuchs ae6aa6165c json: Fix multidimensional array support
This patch fixes support for encoding and decoding multidimensional arrays
as described by the JSON_OBJ_DESCR_ARRAY_ARRAY() macro.

Currently, the JSON array encoding and decoding functions, arr_encode()
and arr_parse(), expect array elements to be of object or primitive type.
However, arrays may be nested and so an array's elements may also be
arrays.

In order to support nested arrays, two special cases must be considered:

1. The array of objects/arrays sub-descriptor is described by two
`json_obj_descr` structs and so two instead of one `json_obj_descr`
structs must be skipped when iterating over the JSON descriptor to get to
an array's elements.
2. The implicit array item count field has to be considered for the
parent itself and all its child array items when calculating an element's
size.

Fixes #50801

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2023-06-29 21:03:48 +02:00
Vincent van Beveren 2ae521a5f5 posix: fs: Fixes stat command to return file information
Fixes #58911. Previously the stat command returned
information on the filesystem, but not the file itself.
Because block size is still set this function is
backwards compatible with the previous faulty
behavior.

Signed-off-by: Vincent van Beveren <v.van.beveren@nikhef.nl>
2023-06-23 17:04:34 -04:00
Alberto Escolar Piedras 3454d8f727 lib POSIX: Enable selectively for POSIX ARCH
The POSIX API compatibility shim can be used for some
of the POSIX ARCH targets.
Narrow the Kconfig filtering accordingly.

Note that the recommended configuration when building
with the native simulator is still to use an embedded
C library. Using the host C library will in some cases
cause undesired behaviour.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-06-22 19:46:43 -04:00
Alberto Escolar Piedras 0517c85dcc libC COMMON_LIBC_MALLOC_ARENA_SIZE: provide default for POSIX ARCH
Provide a sensible default for the POSIX architecture,
as now it is possible to build with it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-06-22 17:16:17 -04:00
Alberto Escolar Piedras 590e8efd4b libC pico hooks: Fix for POSIX arch
The spin loop in _exit() needs a Z_SPIN_DELAY() for the
POSIX architecture, so it does not hang the whole
executable on that infinite loop but only the thread
that exit'ed.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-06-22 17:16:17 -04:00
Alberto Escolar Piedras 8eff5b6c01 libC minimal: Fix for POSIX arch
The spin loop in _exit() needs a Z_SPIN_DELAY() for the
posix architecture, so it does not hang the whole
executable on that infinite loop but only the thread
that exit'ed.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-06-22 17:16:17 -04:00