Commit graph

2,113 commits

Author SHA1 Message Date
Valerio Setti
fc422beb68 lib: uuid: replace legacy crypto support with PSA API
Legacy crypto support is going to be removed in the next Mbed TLS release
(which will be named TF-PSA-Crypto for the crypto support) so this
commit transitions UUID library from legacy crypto to PSA API.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-10-23 11:42:11 +03:00
Anas Nashif
24e094ef5e lib: move cpu_load into lib/os
Move cpu_load to lib/os, as this functionality on its own does not
justify being a subsystem on its own.

Fixes #95498

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-22 09:02:38 +02:00
Jukka Rissanen
5d4e4e5018 lib: posix: device_io: Add standard file descriptor sizes
Make sure we always allocate space for stdin, stdout and stderr file
descriptors if Posix device io option is enabled.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-10-21 17:22:03 +03:00
Jukka Rissanen
1cfdf7c8d1 lib: Introduce a way to set minimum file descriptors count
Instead of user trying to figure out what is the amount of file /
socket descriptors in the system, let the various subsystems etc.
specify their need using a Kconfig option. The build system will
then add these smaller values together and set a suitable file
descriptor count in the system.

This works the same way as the heap size calculation introduced
in commit 3fbf12487c

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-10-21 17:22:03 +03:00
Benjamin Cabé
312688d7ea Revert "posix: xsi: streams: deprecate CONFIG_XOPEN_STREAMS"
This reverts commit b762a43738
which was merged without enough time in review.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-10-20 11:28:54 -04:00
Chris Friedt
b762a43738 posix: xsi: streams: deprecate CONFIG_XOPEN_STREAMS
CONFIG_XOPEN_STREAMS does not follow the pattern of other XSI Option
Groups, where the Option Group name is not the same as the feature
test macro that indicates it is supported by the implementation.

Deprecate CONFIG_XOPEN_STREAMS and rename it to CONFIG_XSI_STREAMS.

For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/\
V1_chap02.html#tag_02_01_05_09

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-19 20:53:48 -04:00
Chris Friedt
9f13274c00 libc: indicate timeval is defined
In order to avoid multiple definition errors, indicate that struct
timeval is declared.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-18 20:33:57 -04:00
Chris Friedt
192b721732 libc: indicate timespec is defined
In order to avoid multiple definition errors, indicate that struct
timespec is declared.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-18 20:33:57 -04:00
Chris Friedt
8017e17ff6 libc: newlib + picolibc: indicate sigevent and sigval are declared
Indicate that C library headers have declared `struct sigevent` and
`struct sigval` to avoid redefinition warnings / errors.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-18 20:33:57 -04:00
Chris Friedt
8f899db04d posix: sched: move sched_yield() to pthread.c
The `sched_yield()` function was originally included to facilitate the of
POSIX_REALTIME and POSIX_THREADS_EXT Option Groups in Issue 5.

It was then marked as part of the _POSIX_PROCESS_SCHEDULING Option in
Issue 6, but then was not clearly marked as part of the
POSIX_THREADS(_BASE) Option Group until Issue 7.

Moving it to `pthread.c` (and making it a function with regular
linkage rather than inline) ensures that it will be available with the
`POSIX_THREADS` Option Group.

For more information, please see `POSIX_THREADS_BASE` in
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/\
V4_subprofiles.html and
https://pubs.opengroup.org/onlinepubs/9799919799/xrat/\
V4_subprofiles.html

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-15 11:46:00 -04:00
Chris Friedt
c617ede1bd libc: minimal: sys/types.h: move mem_word_t to string.c
The `sys/types.h` header is part of POSIX, which is optional in Zephyr and
is mostly unimplemented by Zephyr's minimal C library.

Additionally, the only reason `sys/types.h` is included in `string.c` (in
the minimal libc) is because of the non-standard `mem_word_t` type.

`mem_word_t` is not used anywhere else in-tree or in modules hosted by the
Zephyr project. It is only used in `string.c` in the minimal c library.

It's definitely not specified here
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
and so does not really belong in `sys/types.h`.

Move `mem_word_t` into the minimal libc's `string.c`. If needed, it can be
removed at a later date and switched for `uintptr_t`.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-15 15:38:03 +03:00
Chris Friedt
aaf391405c posix: options: add keep-sorted-start and -stop
Add zephyr-keep-sorted-start and zephyr-keep-sorted-stop
comments.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-15 12:08:00 +03:00
Chris Friedt
8a48177130 posix: profiles: make POSIX_AEP_CHOICE_ZEPHYR the default
Default POSIX_AEP_CHOICE to POSIX_AEP_CHOICE_ZEPHYR

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-15 12:08:00 +03:00
Chris Friedt
27bc1fed47 posix: profiles: add custom Zephyr POSIX subprofile
Add a custom Zephyr POSIX subprofile specifically for enabling the
default features that Zephyr requires as per the coding guidelines.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-15 12:08:00 +03:00
Chris Friedt
c64974cc75 posix: c_lib_ext: apply clang-format to getopt sources
The getopt sources were not formatted according to our codying style
conventions, so apply formatting rules as a separate commit.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-15 12:08:00 +03:00
Chris Friedt
12fd61d6c7 posix: separate option groups into c library ext and system interfaces
Separate the POSIX implementation into two categories:

- Extensions to ISO C
- System Interfaces

The first category include standalone functions that generally do not
require OS support or depend on any other features within the POSIX
specification. The Option Groups that comprise this category include

- POSIX_C_LIB_EXT: e.g. strnlen(), fnmatch()
- POSIX_C_LANG_SUPPORT_R: e.g. gmtime_r(), strtok_r()

The second category includes the majority of other POSIX Option Groups
that do require OS support. The latter group may also be categorized
generally as being NATIVE_LIBC_INCOMPATIBLE, although that might
eventually become more granular.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-15 12:08:00 +03:00
Chris Friedt
ed0ae68f77 eventfd: bring config to top-level of posix dir, since it is not posix
The eventfd configuration does not need to be so deeply nested within
POSIX since it does not depend on POSIX completely.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-15 12:08:00 +03:00
Anas Nashif
f22a0afc74 testsuite: coverage: Support semihosting
Use semihosting to collect coverage data instead of dumping data to
serial console.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-14 17:32:46 -04:00
Chris Friedt
20cda02d11 posix: multi process: add support for times()
Add support for the `times()` function, which can be used to get the
number of ticks spent in "system" and "user" mode, and which returns
the "real time" that has expired, since an arbitrary point in the past.

The following invariant should always hold:

rtime <= stime + utime

The `times()` function measures time for the calling process and all
of it's child processes. In Zephyr, we don't support separate processes
(yet), so the time spent in child processes is zero.

Additionally, in Zephyr we do not differentiate between "system" time
(i.e. time spent executing kernel code) and "user" time (time spent
executing application code). We only have information on "total time"
(time spent executing code) and "execution time" (time spent executing
code plus idle time).

For now, only report utime, since it is not clear how to obtain other
values.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-14 17:27:08 -04:00
Vladislav Kulikov
beb5f45a76 smf: use get_child_of() for topmost in smf_set_initial()
Replace get_last_of(init_state) with get_child_of(init_state, NULL),
and add a brief comment to avoid relying on a trivial wrapper. Also,
the wrapper name get_last_of() is not very descriptive; using
get_child_of() with an comment makes the intent more explicit.

Signed-off-by: Vladislav Kulikov <vlad_kulikov_c@pm.me>
2025-10-14 17:25:55 -04:00
Robin-Charles Guihéneuf
e4bd3cffd4 lib: utils: json: Fix encoded_obj element size
The size of the JSON_TOK_ENCODED_OBJ type was not defined, which
caused errors when generating an array.

Signed-off-by: Robin-Charles Guihéneuf <robin-charles@hotmail.fr>
2025-10-09 22:55:58 +03:00
Titouan Christophe
f7ccc6bae3 lib: midi2: fix const-incorrect ump_stream_responder_cfg
Passing a USB-MIDI device in a ump stream responder configuration,
as obtained from the device tree with DEVICE_DT_GET(), was wrongly
casting is from const struct device* to void*, hence removing the const
pointer attribute.

This incorrectness introduces some compilation issue. Let's therefore
make the device pointer constant in ump_stream_responder_cfg, and
add a macro to make the proper typecast consistently. Finally, adapt the
corresponding samples to use that new macro.

Signed-off-by: Titouan Christophe <titouan.christophe@mind.be>
2025-10-08 15:06:33 -04:00
Titouan Christophe
5e83d222b6 lib: midi2: new UMP Stream responder library
Add a new top-level, transport independent library to respond to UMP Stream
Discovery messages. This allows MIDI2.0 clients to discover UMP endpoints
hosted on Zephyr over the UMP protocol.

The endpoint specification can be gathered from the device tree, so that
the same information used to generate USB descriptors in usb-midi2.0
can be delivered over UMP Stream.

Signed-off-by: Titouan Christophe <titouan.christophe@mind.be>
2025-10-08 08:42:27 +02:00
Anisetti Avinash Krishna
69826c5a95 lib: acpi: Enable support for ACPI_RESOURCE_TYPE_ADDRESS64
Enable support for ACPI_RESOURCE_TYPE_ADDRESS64 in acpi_device_mmio_get
to fetch 64bit address from resource of an ACPI device.

Signed-off-by: Anisetti Avinash Krishna <anisetti.avinash.krishna@intel.com>
2025-10-07 22:59:32 -04:00
Siwei Yang
4b71cf9822 lib: smf: add API to get the current leaf and executing state
Retrieve the current leaf state by calling `smf_get_current_leaf_state`
and the state which is currently-executing by calling
`smf_get_current_executing_state`.

Signed-off-by: Siwei Yang <yswysc@gmail.com>
2025-10-07 22:58:58 -04:00
Siwei Yang
af6f88b205 lib: smf: add const qualifier to ctx arg
Add const qualifier to ctx arguments
for immutability and consistency with other functions.

Signed-off-by: Siwei Yang <yswysc@gmail.com>
2025-10-07 22:58:58 -04:00
Chris Friedt
c8e22ec596 tests: posix: signals: adjust expectations for real-time signals
1. Fix an off-by-one error in `signo_fits()` (a utility function inside
   signal.c

2. Adjust expectations for C libraries that do not provide a sigset_t
  large enough to support `SIGRTMIN` or `SIGRAMAX`.

This fixes an issue in CI that appeared when run under ARC.

```shell
west build -p auto -b qemu_arc/qemu_arc_hs -t run tests/posix/signals
```

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-06 20:15:10 -04:00
Johann Fischer
f289613c4c net_buf: do not assert on buffer reset when flags are set
There is only one flag, NET_BUF_EXTERNAL_DATA, used when net_buf was
allocated with external data. The flag is checked in net_buf_clone() and
net_buf_destroy(). net_buf with external buffer can be used for
receiving and transmitting. net_buf_reset() is convenient way
to reset net_buf with external data before it is re-enqueued again.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-10-06 20:01:51 +03:00
Vlad Kulikov
2d151b22c1 lib: smf: remove unreachable case in get_lca_of()
smf_set_state() excludes ancestor/descendant relations before calling
get_lca_of(). The function now walks from source->parent and returns
the first ancestor that contains dest. The 'ancestor == dest' case
was unreachable and is removed.

No functional change intended.

Ref: RFC #95952
Signed-off-by: Vlad Kulikov <vlad_kulikov_c@pm.me>
2025-10-01 17:12:38 -04:00
Chris Friedt
5cbb2a421d posix: switch to using posix_time.h and posix_signal.h
To avoid conflicts between the C library's `time.h` and signal.h use an
"override" header (when necessary) for C libraries that do not themselves
provide POSIX definitions in `time.h` or `signal.h`.

V2

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-10-01 14:36:55 +03:00
Chris Friedt
584b73a8d4 timeutil: make timespec_normalize() a regular function
Since the timespec_normalize() function is not branchless, and since it
can also generate a fair bit of code, make the function non-inline and
place it in timeutil.c instead.

This should save some code space on most systems.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-09-26 09:35:33 -04:00
Iuliana Prodan
a795046143 ipc: move Open AMP from lib/ to subsys/ipc/
Moved the Open AMP code from lib/ to subsys/ipc/ to better
organize IPC-related components.

Updated build and config files to reflect the new location.

Adjusted path in MAINTAINERS.yml.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-09-26 13:22:55 +02:00
Fabio Baltieri
9384cc5b96 Revert "posix: switch to using posix_time.h and posix_signal.h"
This reverts commit 1eb5c97bd6.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2025-09-25 14:15:57 -04:00
Chris Friedt
1eb5c97bd6 posix: switch to using posix_time.h and posix_signal.h
To avoid conflicts between the C library's `time.h` and signal.h use an
"override" header (when necessary) for C libraries that do not themselves
provide POSIX definitions in `time.h` or `signal.h`.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-09-25 12:01:23 +01:00
Chris Friedt
f071df29a7 posix: net: move gethostname() from static inline to normal function
Convert `gethostname()` from a static inline wrapper to a normal function
with regular linkage.

This change was prompted mainly as housekeeping for #95811, but a
secondary reason was to make this a linkable symbol so that the API works
at a binary level as well (which could be provided by the toolchain as
well).

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-09-23 09:39:24 +01:00
Aditya Chopra
58a444c6c3 libc : implement signal()
Creates implementation stub for signal() using sigaction.

Signed-off-by: Aditya Chopra <adityachopra2912@gmail.com>
2025-09-23 09:38:56 +01:00
Al Semjonovs
3fd186e71f newlib: allow limits to be defined externally
Downstream toolchains may already define these macros, add guard to
prevent macro redefined errors.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2025-09-22 17:50:11 -04:00
Chaitanya Tata
19449e4396 wifi: treewide: Adjust defaults for dual mode usage
In case STA + AP mode is enabled, then adjust the defaults to accomodate
the second interface.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2025-09-19 08:27:55 -04:00
Romain Pelletant
732823e0c6 posix: options: replace kconfig for rw lock
- Update Kconfig from CONFIG_POSIX_READER_WRITER_LOCKS to POSIX_RW_LOCKS

Signed-off-by: Romain Pelletant <romainp@kickmaker.net>
2025-09-19 08:27:49 -04:00
Anisetti Avinash Krishna
5bdd670e2c lib: acpi: Enable poweroff feature
Enable system poweroff feature using ACPI.

Signed-off-by: Anisetti Avinash Krishna <anisetti.avinash.krishna@intel.com>
2025-09-16 17:20:41 -04:00
Alberto Escolar Piedras
1d6da40624 lib: os: clock: Fix possibly unitialized variable warning
When building with high optimization level, the compiler thinks
duration may be used initialized and warns as much.

Let's initialize this variable always to ensure it does not happen
and with it pacify the compiler.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-09-13 09:37:19 +02:00
Yuval Peress
24ca0fbb76 cpp: Support C mocked __atomic_compare_exchange_*
The builtin functions __atomic_compare_exchange_* are missing when
CONFIG_ATOMIC_OPERATIONS_C is set. Add them and verify they build/work
as expected.

Signed-off-by: Yuval Peress <peress@google.com>
2025-09-11 18:10:15 +01:00
Chris Friedt
6529c847fe libc: newlib: limits.h: include posix limits from zephyr
Newlib does not seem to define a number of mandatory POSIX limits
(e.g. minimum values).

Include Zephyr's POSIX definitions in an override of Newlib's limits.h
(when the appropriate application conformance macro is provided).

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-09-10 08:27:38 +02:00
Chris Friedt
25e36f01f3 posix: limits: de-duplicate limit logic
Rather than duplicating limit logic in several places, de-duplicate it
and centralize preprocessor checks in posix_limits.h .

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-09-10 08:27:38 +02:00
Duy Vo
0c5af6f25f crc: initial support for CRC subsystem
Migrate support from crc library to new crc subsystem
Add hardware acclerator backend for crc subsystem

Signed-off-by: Duy Vo <duy.vo.xc@bp.renesas.com>
2025-09-10 08:26:32 +02:00
Chris Friedt
86eca47529 posix: system_database_r: remove invalid compilation filters
pwd.c and grp.c both had incorrect preprocessor guards around the stubs
that they were implementing. Functions were surrounded by

```cpp
ifdef CONFIG_POSIX_THREAD_SAFE_FUNCTIONS
..
endif /* CONFIG_POSIX_THREAD_SAFE_FUNCTIONS */
```

Which is not at all accurate, since that subprofiling option group is
`(CONFIG_)POSIX_SYSTEM_DATABASE_R` (which is a PR that is in-draft).

Remove the guards, since they are invalid anyway, and at most an
application will link properly. We don't really need the guards anyway,
since conditional compilation will be used to link the files into the
build.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-09-09 17:27:28 +02:00
Fabio Baltieri
fbe0c9feb9 utils: utf8: change utf8_count_chars return to int
Change utf8_count_chars return type to int and drop thesys/types.h, this
way the function does not depend on posix types.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2025-09-08 11:11:40 -04:00
Fabio Baltieri
8366365c03 util: move utf8 utils to a separate header
This moves the declaration of the utf8 utils defined in lib/utils/utf8.c
in their own header. Main reason to do this is that the current setup
requried adding an include for sys/types.h in util.h, which can result
in a build falure due to a circular header depdenecy when using:

CONFIG_POSIX_API=y
CONFIG_NEWLIB_LIBC=y
_GNU_SOURCE

the loop and error are:

- include/sys/types.h:50: <- this is a NEWLIB one
- include/zephyr/posix/sys/select.h:9:
- include/zephyr/posix/posix_types.h:30:
- include/zephyr/kernel.h:17:
- include/zephyr/kernel_includes.h:25:
- include/zephyr/sys/atomic.h:18:

include/zephyr/sys/util.h:705:1:
error: unknown type name 'ssize_t'

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2025-09-08 11:11:40 -04:00
Krzysztof Chruściński
a6c04cf7d8 lib: utils: bitarray: Use optimized version for 32 bit array
When bitarray is limited to a single 32 bit word then bitmask_find_gap
can be used which is much faster than bit by bit search which is
used in bitarray spanning across multiple 32 bit words. Tests shows
that allocation and freeing is 2-3 times faster.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-09-06 10:38:18 +02:00
Krzysztof Chruściński
53c2d58ff8 lib: utils: Add function for finding group of cleared bits in a bit mask
Add function which finds contiguous number of bits which are not set
in the 32 bit mask.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-09-06 10:38:18 +02:00