This commit reworks the C++ standard library configurations such that:
* the separation between the Zephyr minimal C++ library and the fully
featured C++ standard libraries, such as GNU libstdc++, is clear.
This is done by deprecating the Kconfig `CONFIG_LIB_CPLUSPLUS`
symbol, which implies that the minimal C++ library is selected when
set to `n`, and introducing the `CONFIG_MINIMAL_LIBCPP` symbol.
* the type of the selected C++ standard library is clear. This is done
by introducing a Kconfig choice, `LIBCPP_IMPLEMENTATION`, for the C++
standard library type and providing the choice symbols for each
library type supported, such as `CONFIG_MINIMAL_LIBCPP` and
`CONFIG_GLIBCXX_LIBCPP`.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
The Kconfig `CONFIG_RTTI` symbol enables the C++ Run-Time Type
Information (RTTI) support and is a feature of the standard C++
library; therefore, it should be prefixed with `CPP_` as with the rest
of the C++-specific symbols.
This commit renames the Kconfig `CONFIG_RTTI` symbol to
`CONFIG_CPP_RTTI` in order to better align with the other existing C++
Kconfig symbols, and deprecates the old `CONFIG_RTTI` symbol.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
`CONFIG_EXCEPTIONS` is ambiguous in that the word "exception" may be
used to refer to many different types of exceptions, from the hardware
generated faults and interrupts (aka. exceptions) to the C++
exceptions.
This commit renames the Kconfig `CONFIG_EXCEPTIONS` symbol to
`CONFIG_CPP_EXCEPTIONS` in order to clarify that the symbol refers to
the C++ exceptions and eliminate any ambiguity, and deprecates the old
`CONFIG_EXCEPTIONS` symbol.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
This commit updates all in-tree code to use `CONFIG_CPP` instead of
`CONFIG_CPLUSPLUS`, which is now deprecated.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
There is no reason for the top-level C++ Kconfig symbol to be called
`CPLUSPLUS` when the convention used throughout the Zephyr codebase is
to use "cpp" to refer to C++ and the rest of the C++-related Kconfig
symbols are prefixed with `CPP_`.
This commit renames the Kconfig `CPLUSPLUS` symbol to `CPP` in order to
better align with the de-facto standard naming convention used throughout
the Zephyr codebase, and deprecates the old `CPLUSPLUS` symbol.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
This commit relocates the "C++ minimal library" components, that
implement a very limited subset of the standard C++ library, to a
dedicated directory, `lib/cpp/minimal`, in order to provide a clear
separation among the different C++ library components.
After this refactoring, the top `lib/cpp` directory should only contain
the sub-directories for each C++ library (i.e. `abi`, `minimal`). In
the future, a C++ library-specific shim layer implementation may be
added as sub-directories under `lib/cpp` as well (e.g. `libstdc++`
sub-directory containing the shim layer implementation for the GCC
libstdc++ library) -- this is similar to how the libc directories are
structured under `lib/libc`.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
This commit relocates the "C++ ABI library" components such as
global constructor/destructor and initialiser handlers to a dedicated
directory, `lib/cpp/abi`, in order to provide a clear separation
between the C++ ABI/runtime library and the standard C++ library
components.
Note that the Zephyr C++ ABI library currently implements the GNU/GCC
C++ ABI, which is the de-facto standard ABI used by many compilers
including Clang -- it may be necessary to sub-divide the `lib/cpp/abi`
into `lib/cpp/abi/gnu` and `lib/cpp/abi/someotherabi` in the future
when adding the support for a C++ compiler that expects an ABI vastly
different from the GNU C++ ABI.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
This commit moves the files under `subsys/cpp` directory to the
`lib/cpp` directory because the C++ ABI runtime library and the
standard C++ library components are not a "subsystem" (aka. API) in
conventional sense and is better described as a "library."
Classifying the C++ ABI runtime library and the standard C++ library as
"libraries" instead of "subsystems" also better aligns with how the
existing C standard library implementation (`lib/libc`) is handled.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
After fcntl.h moved to posix, there have a compiler note
on fdtable.c. As suggested in fcntl.h, instead with
zephyr/posix/fcntl.h.
Signed-off-by: HaiLong Yang <hailong.yang@brainco.cn>
The remaining types that needed to be harmonized between
Newlib and Zephyr's POSIX definitions are:
* `struct sched_param`
- don't re-define if using minimal libc
* `pthread_attr_t`
- convert to `struct pthread_attr`
- define type if using minimal libc
- assert acceptible object size
* `pthread_mutexattr_t`
- convert to `struct pthread_mutexattr`
- define type if using minimal libc
- assert acceptible object size
* `pthred_condattr_t`
- convert to `struct pthread_condattr`
- define type if using minimal libc
- assert acceptible object size
* `pthread_once_t`
- adopt newlib definition
- define type if using minimal libc
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Define `PTHREAD_CREATE_DETACHED` and
`PTHREAD_CREATE_JOINABLE` to be compatible with the Newlib
definitions.
This is a temporary workaround for #51211 until Newlib
headers are pulled in.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
The `fcntl.h` header has never been a part of ISO C so move it to
`include/zephyr/posix`.
To ensure a smooth migration, a header was left in
`lib/libc/minimal/include` that prints a deprecation warning.
Users should either include `<zephyr/posix/fcntl.h>` or switch to
`CONFIG_POSIX_API=y`.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
The `sys/stat.h` header has never been a part of ISO C so move it
to `zephyr/include/posix/sys/`.
To ensure a smooth migration, leave a stub header in
`lib/libc/minimal/include/sys/` that prints a deprecation warning
suggesting developers either include `<zephyr/posix/sys/stat.h>`
or use `CONFIG_POSIX_API=y`.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
The previous method used to calculate seconds in `clock_gettime()`
seemed to have an inaccuracy that grew with time causing the
seconds to be off by an order of magnitude when ticks would roll
over.
This change fixes the method used to calculate seconds.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Fixed issues which were leading to failures when producing
and consuming is preempted at various stages.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Use flag instead of word in the buffer. Using this method allows
to dedicate full buffer capacity for data.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
should be able to configure the time spent waiting
for available resources when calling timer_create()
to not cause a hiccup in applications that require
faster response times than the original hard-coded 100 ms.
Signed-off-by: Nicholas Lowell <nlowell@lexmark.com>
Currently OpenAMP is unconditionally compiled with the options to use
the vrings cache operations disabled.
Add a new CONFIG_OPENAMP_WITH_DCACHE Kconfig option to enable the
support for d-cache operations in OpenAMP when needed.
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
This commit updates the Picolibc configurations to remove any
unnecessary defaults and dependencies and conform to the de-facto
standard convention across the Zephyr repository.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
This commit relocates the newlib libc configurations under the top-
level libc Kconfig to a new Kconfig under `lib/libc/newlib` for
improved organisation of the libc configurations.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
This commit relocates the minimal libc configurations under the top-
level libc Kconfig to a new Kconfig under `lib/libc/minimal` for
improved organisation of the libc configurations.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
This commit cleans up the top `CMakeLists.txt` for the libc directory
to use `add_subdirectory_ifdef` in order to make the code more
readable.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
This commit properly writes back cached read pointer in spsc buffer
when freeing the memory.
Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
This commit updates the Newlib integration to define `_ANSI_SOURCE`
in order to prevent Newlib from defining POSIX primitives in its
headers when GNU dialect is used (`-std=gnu*`).
Newlib `features.h` defines `_DEFAULT_SOURCE` when `__STRICT_ANSI__`
is not defined by GCC (i.e. when `-std=gnu*`), which results in the
Newlib headers defining POSIX primitives that are in conflict with the
POSIX primitives defined by Zephyr.
Newlib must not define POSIX primitives unless the feature test macros
such as `_POSIX_SOURCE`, `_GNU_SOURCE` and `_DEFAULT_SOURCE` are
explicitly defined.
Note that `-std=gnu` does not imply `_GNU_SOURCE` or `_DEFAULT_SOURCE`
because it is only supposed to instruct the compiler to use the GNU C
language dialect (i.e. GNU C language extensions).
Refer to the GitHub issue #52739 for more details.
Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
Declarations for `getopt()` should be in `<unistd.h>`
according to the spec. The extended versions `getopt_long()`
and `getopt_long_only()` are declared in `<getopt.h>`.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
This seems to have caused build failures in spite of CI being
green in PR 52653.
This reverts commit fc92eb1b37.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Declarations for `getopt()` should be in `<unistd.h>`
according to the spec. The extended versions `getopt_long()`
and `getopt_long_only()` are declared in `<getopt.h>`.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
There are several Zephyr shell commands that are used for
transferring data over a possibly unreliable connection such as a
UART into either memory or flash. For example, `flash load` and
`devmem load`.
Make the CRC functions available so that they can be used to
verify the integrity of data transferred over possibly
unreliable connections.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
The original implementation of `usleep()` was not compliant
to the POSIX spec in 3 ways.
- calling thread may not be suspended (because `k_busy_wait()`
was previously used for short durations)
- if `usecs` > 1000000, previously we did not return -1 or set
`errno` to `EINVAL`
- if interrupted, previously we did not return -1 or set
`errno` to `EINTR`
This change addresses those issues to make `usleep()` more
POSIX-compliant.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
In the case that `sleep()` is interrupted, the POSIX spec requires
it to return the number of "unslept" seconds (i.e. the number of
seconds requested minus the number of seconds actually slept).
Since `k_sleep()` already returns the amount of "unslept" time
in ms, we can simply use that.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Consistent with the change of `pthread_t`, `pthread_mutex_t`,
and `pthread_cond_t` to `uint32_t`, we can now also abstract
`pthread_key_t` as `uint32_t` and separate the implementation
detail, hidden from POSIX API consumers.
This change introduces `CONFIG_MAX_PTHREAD_KEY_COUNT`.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
None of the operations that `pthread_key_sem` protected were
blocking, so simply make it a spinlock.
Also made the lock static.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Add CONFIG_CRC for building CRC related routines.
CRC routines are now being built for each application, whether used or
not and are add in the build system unconditionally.
Keep CONFIG_CRC enabled by default for now and until all users have
converted to use the new option.
Partial fix for #50654
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Consistent with the change of `pthread_t` from
`struct posix_thread` to `uint32_t`, we can now also abstract
`pthread_cond_t` as `uint32_t` and separate `struct posix_cond`
as an implementation detail, hidden from POSIX API consumers.
This change deprecates `PTHREAD_COND_DEFINE()` in favour of the
(standardized) `PTHREAD_COND_INITIALIZER`.
This change introduces `CONFIG_MAX_PTHREAD_COND_COUNT`.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Previously, `pthread_cond_init()` could not actually fail, and
destroying condition variables was a no-op, and it was missing
in `pthread_exit()`.
However, with the change of `pthread_cond_t` to `uint32_t`, and
since those are embedded inside of `struct posix_thread` for the
time being, the pthread code needs to keep track that it is
relinquishes used condition variables when a thread completes.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Previously `PTHREAD_MUTEX_MASK_INIT` was used to mark a
`pthread_mutex_t` as initialized.
The same needs to be done for `pthread_cond_t` and likely others.
Rather than copy-pasting that and a number of inlines that
duplicate the same functionality, simply make it more generic.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Consistent with the change of `pthread_t` from
`struct posix_thread` to `uint32_t`, we can now also abstract
`pthread_mutex_t` as `uint32_t` and separate `struct posix_mutex`
as an implementation detail, hidden from POSIX API consumers.
This change deprecates `PTHREAD_MUTEX_DEFINE()` in favour of the
(standardized) `PTHREAD_MUTEX_INITIALIZER`.
This change introduces `CONFIG_MAX_PTHREAD_MUTEX_COUNT`.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Previously, `pthread_mutex_init()` could not actually fail, and
destroying mutexes was a no-op, so it was missing in a couple of
places.
However, with the change of `pthread_mutex_t` to `uint32_t`, and
since those are embedded inside of `struct posix_thread` for the
time being, the pthread code needs to keep track that it is
relinquishes used mutex resources when a thread completes.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
The `pthread_create()` function is not a cancellation point and
iterating over / mutating `posix_thread_pool` is not a blocking
operation, so use a spinlock for the internal `pthread_pool_lock`.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
The `struct pthread` and `enum pthread_state` are actually
implementation details specific to Zephyr.
Let's limit the scope where that level of detail is visible.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
In the interest of reducing any layering concerns,
avoid using POSIX locking primitives where necessary.
Note: it is not safe to use a spinlock here, as the
callback function to `pthread_once()` may itself be
a cancellation point.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
While reviewing the dependency between Picolibc POSIX APIs and Zephyr, I
found that the picolibc libc-hooks code copied a bunch of functions from
the newlib version which weren't needed. This required replacing a few
calls to the (now removed) '_write' hook with printk instead.
Signed-off-by: Keith Packard <keithp@keithp.com>
Several other widely-used pthread implementations
abstract `pthread_t` as `uint32_t`. The benefit
there is that we avoid passing around a pointer to
an internal structure (implementation detail).
Additionally, this removes the alias from `k_tid_t`
to `pthread_t` inside of `struct pthread_mutex`.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Move runtime checks to use arch_num_cpus(). This is to allow
runtime determination of the number of CPUs in the future.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>