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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>