Support querying POSIX string configuration values (similar to
sysconf()).
confstr() is required by the POSIX_SINGLE_PROCESS Option
Group as detailed in Section E.1 of IEEE-1003.1-2017 and has
been part of the specification since POSIX-2.
The POSIX_SINGLE_PROCESS Option Group is required for PSE51,
PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory
for any POSIX conforming system as per Section A.2.1.3 of
IEEE-1003-1.2017.
With this, we have complete support for the POSIX_SINGLE_PROCESS
Option Group.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Implement `pthread_attr_setscope()` and `pthread_attr_getscope()`
are required as part of _POSIX_THREAD_PRIORITY_SCHEDULING Option Group.
signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
This PR fixes the following compiler warning:
No SOURCES given to Zephyr library: lib__posix__shell
Signed-off-by: Matthias Alleman <matthias.alleman@basalte.be>
Previously, sysconf() was only available as a macro (i.e. the
"extra-small" option).
This has the advantage of being compile-time constant, and
optimized for both space and speed. One disadvantage is that
querying an `_SC_` value that was invalid or unsupported
would result in a compile error.
Provide a "small" implementation of sysconf() (via Kconfig
choice) as a normal addressable function.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Seen this in compiler
lib/posix/options/syslog.c: In function 'setlogmask':
lib/posix/options/syslog.c:66:16: error: 'oldpri' may be used uninitialized
66 | return oldpri;
| ^~~~~~
lib/posix/options/syslog.c:59:13: note: 'oldpri' was declared here
59 | int oldpri;
| ^~~~~~
lib/posix/options/syslog.c: In function 'vsyslog':
lib/posix/options/syslog.c:83:33: error: 'mask' may be used uninitialized
83 | if ((BIT(level) & mask) == 0) {
| ~~~~~~~~~~~~~~~~~~~~^~~~
lib/posix/options/syslog.c:71:17: note: 'mask' was declared here
71 | uint8_t mask;
| ^~~~
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This PR adds declarations for the application conformance
feature test macro _POSIX_C_SOURCE.
It needs to be defined to value greater than or equal to 200112L
by the appplication.
However, Zephyr currently does not have a simple and consistent
means of specifying this value for POSIX samples, tests,
applications, and other libraries.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This service is used to get, set, and unset system
environment variables.
Note: shell parameter expansion is not supported
at this time.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Support getting and setting POSIX environment variables.
Additionally, the thread-safe BSD variant getenv_r() is
provided.
environ, getenv(), setenv(), and unsetenv() are required by
the POSIX_SINGLE_PROCESS Option Group as detailed in
Section E.1 of IEEE-1003.1-2017.
The POSIX_SINGLE_PROCESS Option Group is required for PSE51,
PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory
for any POSIX conforming system as per Section A.2.1.3 of
IEEE-1003-1.2017.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Brings SMF framework closer into alignment with accepted Hierarchical State
Machine operation by:
1. Allowing 'programming by difference' by having some child states handle
events and prevent propagation up to the parent run actions while others
propagate events up to a common handler in a parent state.
2. Optionally allow initial transitions within a parent state to determine
the most nested child state to transition to.
3. Adding a test case for `CONFIG_SMF_INITIAL_TRANSITION` and
`smf_set_handled()`
4. Updating documentation for the new API (and fixing some references)
There was discussion in https://github.com/zephyrproject-rtos/zephyr/issues/55344
about not making the initial transition a Kconfig option, but I'm not sure
of any way else of doing it without permanently adding a pointer to each
`smf_state` entry, which is a problem for resource-constrained devices.
This does not fix https://github.com/zephyrproject-rtos/zephyr/issues/66341
but documentation has been updated to warn users of the issue.
Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
It turns out that currently LTO is enabled only for the kernel.
This commit updates it to enable it for the whole application
and adds additional LTO exclusions required for the standard
C libraries to build and link properly.
Signed-off-by: Radosław Koppel <radoslaw.koppel@nordicsemi.no>
This is just a simple wrapper around Zephyr's native log api.
Note: the standard LOG_ERR syslog priority does conflict with
Zephyr's LOG_ERR() macro. This will need to be worked-around on
a case-by-case basis.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
gmtime_r() has been in the minimal libc for years, however it was not
added to expcetions due to an overlook. In order to do this however, it
has to be moved first to the common libc area, so that it's available
to any libc that may not implement it.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Previously, pthread_mutexattr_gettype() and
pthread_mutexattr_settype() were non-conformant and also
less safe, as they would not check whether a pthread_mutexattr_t
had been initialized prior to manipulating them. Furthermore,
they would potentially dereference NULL pointers.
Additionally, move the pthread_mutexattr_init() and
pthread_mutexattr_destroy() functions to the library, and add
some level of checking to them so that they are more than simply
static inline / no-op calls.
Lastly, reduce the size of struct pthread_mutexattr to only
what is necessary (one byte should suffice).
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
pthread_exit() does not return and therefore it does not make
sense to return NULL after it in mq_notify_thread(), and that
would constitute dead code.
Rather than explicitly exiting the thread, simply return
gracefully from the thread function, and allow the pthread to
terminate in the usual way.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
In Zephyr, things are often optimized for size first. That's how
we fit into such tight parking spaces.
This change gives more control to the user about whether the
POSIX API does any logging at all, simultaneously shrinking binary
size while improving speed.
No bytes / cycles left behind!
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
update shell and test app with the modifed resource struct such as
acpi_irq_resource and acpi_mmio_resource
Signed-off-by: Najumon B.A <najumon.ba@intel.com>
This fixes CID 340851.
This should never fail, but it's also something that can be
easily verified.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
When CONFIG_LOG_USE_TAGGED_ARGUMENTS is enabled, and
CONFIG_CBPRINTF_COMPLETE is also enabled, we should not be
blindly skipping tags when processing the tagged package
for output. The issue is that if there is a "%%" in
the format string, the specifier is considered invalid but
the code blindly skips ahead in the argument list as if
it is a valid specifier (think "%s"), which resulting in
the next valid specifier using incorrect argument in
the list. So fix it by skipping ahead if and only if
the specifier is not invalid.
Fixes#68271
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This change mitigates the following cmake warning
No SOURCES given to Zephyr library: lib__posix__options
without needing to have a separate interface library
(as we do not need private headers exposed).
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Newlib doesn't have Zephyr support, so we need to define these functions
when the application doesn't ask for the right level of POSIX support.
Signed-off-by: Keith Packard <keithp@keithp.com>
Implement `sched_rr_get_interval()` POSIX APIs
as a part of PSE53 `_POSIX_PRIORITY_SCHEDULING` option group.
Functions is actually placeholders and just return `ENOSYS`
since Zephyr does not yet support processes or process scheduling.
signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
In case the read index points to the end of the packet buffer and thus
wraps around, we must not invalidate the cache, otherwise we draw
outside of the lines and purge data outside of our responsibility.
Signed-off-by: Patrick Wildt <pwildt@google.com>
The CONFIG_APP_LINK_WITH_POSIX_SUBSYS option was originally
present so that internal POSIX implementation headers would be
on the include path.
There is no implicit need for any app or library to include
private POSIX headers. Instead, the standard POSIX API should
be used.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Previously, the POSIX shell utilities were intermixed with the
POSIX API implementation.
The POSIX shell utilities only depend on the public POSIX API,
so it makes sense to keep them in a separate subdirectory.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
add resource enumeration and acpi method shell commands such as
retrieve mmio and interrupt resources.
Signed-off-by: Najumon B.A <najumon.ba@intel.com>
Implement `sched_setparam()` and `sched_setscheduler()` POSIX APIs
as a part of PSE53 `_POSIX_PRIORITY_SCHEDULING` option group.
Both functions are actually placeholders and just return `ENOSYS`
since Zephyr does not yet support processes or process scheduling.
signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
The patch introduces basic implementation of sysconf() function.
It's based on macro - that means that every function call is resolved
at compile time - and is not fully complient with POSIX standard
(the errno value is not handled and passing invalid name argument
results in compilation error). Treat this commit as a starting point
for proper sysconf() implementation. The one introduced in the patch
could stay as a defult implementation.
sysconf() documentation:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.htmlhttps://man7.org/linux/man-pages/man3/sysconf.3.htmlFixes#56670
Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
Previously timer.c was only built with CONFIG_POSIX_CLOCK=y even
though it has had its own Kconfig symbol (CONFIG_TIMER) for a
very long time.
Make POSIX_CLOCK imply TIMER rather than control whether it is
built, and adjust Kconfig / CMake as necessary.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Two functions can be used with relative ease to convert between
Zephyr and POSIX priorities and policies. Namely,
uint32_t zephyr_to_posix_priority(int32_t z_prio, int *policy)
int32_t posix_to_zephyr_priority(uint32_t priority, int policy)
These are not necessarily public API, but they helped with the
POSIX Philosophers Sample, which is in a subsequent commit.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
* initialize posix_thread and __pthread_cleanup ptrs to NULL
* check ret is zero before finalizing a thread in pthread_cancel()
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This was necessary to get Picolibc to expose the whole Zephyr C library
API, but current versions of the SDK use a version of Picolibc with
built-in Zephyr support.
Signed-off-by: Keith Packard <keithp@keithp.com>
Create getter and setter functions for setting internal pthread
states to READY, RUN, or DONE queues.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
There may be race conditions when calling to_posix_thread()
from multiple threads.
Ensuing that the pthread pool lock is held when
to_posix_thread() is called will prevent those races.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Rather than shadowing most of the fields from pthread_attr_t
(struct posix_thread_attr) inside of struct posix_thread, just
embed the structure itself.
Additionally, use pthread_attr_init() to allocate a thread
stack and pthread_attr_destroy() to destroy a thread stack,
dramatically simplifying pthread_create().
A fair bit of rework was needed already to mitigate bitrot
issues in the testsuite. More should probably be done later.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The default pthread cancellation type is deferred.
Check that the canceltype is asynchronous (with
respect to cancellation points) before cancelling
a thread.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Add a small wrapper to check if a pthread_attr_t has been
properly initialized (i.e. ready to pass to
pthread_create()).
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Export the minimal set of ztest_test_* symbols to llexts so that the
zassert_* macros can be used by the extension code to affect test
execution. Calling these also requires vprintk() to be exported.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
The function was the last missing piece of the `_POSIX_MESSAGE_PASSING`
option group. Due to lack of signal subsystem in the Zephyr RTOS
the `sigev_notify` member of the `sigevent` structure that describes
the notification cannot be set to `SIGEV_SIGNAL` - this notification
type is not implemented, the function will return -1 and set `errno`
to `ENOSYS`.
`mq_notify` documentation:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_notify.htmlFixes#66958
Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
Add a top-level menu to prevent POSIX API options from
cluttering the menuconfig view under
"Additional libraries".
Signed-off-by: Christopher Friedt <cfriedt@meta.com>