Commit Graph

1945 Commits

Author SHA1 Message Date
Chris Friedt
05305e2647 lib: libc: common: time: do not set errno in time()
The ISO C function time() is not specified to set the global
errno variable, so remove that in case there are side-effects.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-07-23 09:34:36 +02:00
Sanjay Vallimanalan
ce4eba52d5 lib: utils: json: add support for mixed array types
Added support for mixed array types in JSON by introducing a new type -
json_mixed_arr_descr. Added APIs for mixed array type parsing and
encoding.

Signed-off-by: Sanjay Vallimanalan <sanjay@linumiz.com>
2025-07-21 21:31:21 -04:00
Luis Ubieda
7a90d9d34d crc: Add CRC24Q for RTCM3 checksum calculations
Used in GNSS RTK correction frames.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2025-07-21 09:19:14 -04:00
Jukka Rissanen
45a0a4949d lib: net_buf: Add a way to create pool with aligned data
Add a new macro NET_BUF_POOL_VAR_ALIGN_DEFINE() which can be
used to create a pool with aligned data where both the start
of the data and the length of the data is aligned.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-07-19 15:37:01 -04:00
Mohamed Moawad
4b90816982 posix: Map CLOCK_REALTIME and CLOCK_MONOTONIC to Zephyr clock IDs
Some toolchains may define CLOCK_REALTIME and
CLOCK_MONOTONIC in their libc headers
with values that differ from Zephyr's internal
SYS_CLOCK_REALTIME and SYS_CLOCK_MONOTONIC.

To ensure consistent behavior across all boards and
toolchains, Introduce a helper function to map
CLOCK_REALTIME and CLOCK_MONOTONIC to Zephyr's internal
clock IDs (SYS_CLOCK_REALTIME and SYS_CLOCK_MONOTONIC).

This prevents mismatched clock IDs being passed to
the kernel, avoiding invalid clockid errors when using
functions like clock_gettime().

Signed-off-by: Mohamed Moawad <moawad@synopsys.com>
2025-07-19 13:43:21 -04:00
Alberto Escolar Piedras
471706ec9a lib/libc/Kconfig: Simply C library choice dependencies
After removing NATIVE_APPLICATION, only NATIVE_LIBRARY is
possible with NATIVE_BUILD.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-07-19 09:38:15 +02:00
Alberto Escolar Piedras
e5db1f7f4a Kconfig: Remove NATIVE_APPLICATION option
CONFIG_NATIVE_APPLICATION, which represents the way in which
native_posix and its kin were built, was deprecated in 4.1 after the
introduction of native_sim and CONFIG_NATIVE_LIBRARY.

We remove support for it now for 4.3.

Let's remove the kconfig option and all dependencies in the kconfig
tree.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-07-19 09:38:15 +02:00
Chris Friedt
9e5e294ea4 lib: os: clock: fix for CID 529870
Fix for CID 529870, where Coverity found an issue where `timespec.tv_sec`
is never greater than `UINT64_MAX / NSEC_PER_SEC` (18446744073).

This is naturally true when `time_t` is only 32-bit, which is actually
never the case for any Zephyr platform aside from `native_sim/native/32`.

When `time_t` is a signed 64-bit value, at some point in the future, but
maybe not in our lifetimes, `timespec.tv_sec` could exceed 18446744073,
since `INT64_MAX > UINT64_MAX / NSEC_PER_SEC`.

We should not see coverity issues errors like this in the future, once we
have a consistent `time_t` representation across all Zephyr platforms.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-07-11 08:21:46 -10:00
Christoph Winklhofer
d5354449be json: fix encoding of string null pointer
A segmentation fault occurs when a zero initialized struct with a string
field (JSON_TOK_STRING) is encoded. Encode a string null pointer as an
empty JSON string "".

Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
2025-07-11 08:15:36 -10:00
Ilya Tagunov
e22ca6b132 libc: arcmwdt: grant all threads access to stdio locks
Some of the locks are created in supervisor mode (i.e. stdout one),
but should be accessed from user mode too. Unfortunately, there is
no way to distinguish these locks, so grant the access to all of them
as the actual reads and writes should end up as syscalls anyway.

Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
2025-07-10 19:54:27 -05:00
Ilya Tagunov
bba649156c libc: arcmwdt: require static initializers
The ARC MWDT C library puts some constructors into .ctors section
to initialize its internal stdio locks. Enable the initializers
to make sure these constructors are actually executed.

Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
2025-07-10 19:54:22 -05:00
Mai Shimozato
0f8b7b7443 stdlib : strtoll : fix strtoll overflow handling with unsigned accumulator
ensure correct assignment of overflow values to unsigned accumulator

Signed-off-by: Mai Shimozato <mshimozato@tenstorrent.com>
2025-07-09 09:44:48 -05:00
Guennadi Liakhovetski
05616c51b6 posix: fix posix clock undefined type
When built with the minimal libc while using POSIX clocks, Zephyr
compilation breaks with "error: unknown type name 'clockid_t'." Use
int instead of clockid_t to eliminate the dependency.

Suggested-by: Chris Friedt <cfriedt@tenstorrent.com>
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2025-07-09 09:43:52 -05:00
Conor Paxton
404c43af6e lib: smf: fix function name typo "share_paren"
looks like a typo and should be share_parent. quick fix

Signed-off-by: Conor Paxton <conor.paxton@microchip.com>
2025-07-08 13:41:59 -05:00
Fin Maaß
c3e4ed7e91 libc: remove POSIX_TIMERS dep from COMMON_LIBC_TIME
remove POSIX_TIMERS dependency from
COMMON_LIBC_TIME, as it is no longer
needed.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-07-08 13:38:11 -05:00
Krzysztof Sychla
a51d3c0f74 kernel: heap: Add allocation metadata to allocated_bytes
The allocated_bytes were missing the allocation metadata. Because of that
the sum of free_bytes and allocated_bytes doesn't remain constant after
each allocation. This convention doesn't match glibc's behavior. This
commit changes the chunksz_to_bytes function to include the metadata in the
calculation. The analysis of the mallinfo2 function from glibc has been
done in #92392 Pull Request.

Signed-off-by: Krzysztof Sychla <ksychla@antmicro.com>
2025-07-07 10:08:58 -05:00
Robert Lubos
c7757b982c lib: os: zvfs: select: Fix warning about bitshifting signed value
This was caught by UBSAN:

  zvfs_select.c:70:2: runtime error: left shift of 1 by 31 places
  cannot be represented in type 'int'

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2025-07-04 13:16:32 -05:00
Yishai Jaffe
6231972dd4 lib: libc: fixed Kconfig typo
Fixed typo streror -> strerror

Signed-off-by: Yishai Jaffe <yishai1999@gmail.com>
2025-06-30 17:38:17 -05:00
Pisit Sawangvonganan
a3d37e3f49 lib: smf: correct redundant ctx->executing assignment
Removed duplicate assignment of ctx->executing under
CONFIG_SMF_ANCESTOR_SUPPORT.
Also replaced #ifndef with #ifdef to align with the positive logic
used elsewhere in this file.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-06-30 15:20:48 -05:00
Matthias Plöger
4a0539af36 libc: minimal: Add "prohibit_lto" flag to avoid problems with LTO
The compiler requires that much of the C library be built without using LTO
so that various symbols are available for use by generated code, including
things like memset and memcpy.

Add the "prohibit_lto" CMake target compiler property to avoid LTO when
activated.

Signed-off-by: Matthias Plöger <matthias.ploeger@phoenixcontact.com>
2025-06-27 21:17:43 +02:00
Iuliana Prodan
75d887605c openamp: enable address translation in CMake
Update CMakeLists.txt to conditionally include address translation
support based on Kconfig options.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-27 08:44:56 -10:00
Iuliana Prodan
78511a97fd openamp: add NXP address translation table
Add NXP-specific address translation table to support memory-mapped
translations between driver and device.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-27 08:44:56 -10:00
Iuliana Prodan
bd5e38c6de openamp: add core address translation support
There are SoCs that have different memory maps for device and driver.
Therefore the shared memory between them has different values and we
need to convert the addresses.

This commit introduces address translation support for OpenAMP:
- implements the address translation functions;
- returns the I/O operations used for address translation.
The ops can be used in Libmetal (see metal_io_init()).

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-27 08:44:56 -10:00
Iuliana Prodan
71f3f7006a openamp: add Kconfig entries for address translation
Add configuration options to enable address translation in OpenAMP
and specify vendor header files for translation tables.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-27 08:44:56 -10:00
Jukka Rissanen
410afbaf19 lib: zvfs: Add default eventfd count for hostap
hostap needs more eventfd to function so set a proper default value.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-06-27 10:56:49 +02:00
Chris Friedt
c3368f6491 posix: env: use sizeof void ptr instead of char ptr ptr
Coverity regularly raised a CID with every release that it found
`sizeof(char **)` confusing and somehow nonportable.

With every release, it needed to be marked as a false positive.

Change `sizeof(char **)` to `sizeof(void *)` to silence the
CID warnings.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-26 10:50:56 -10:00
Sayooj K Karun
964a832702 lib: min_heap: Refactor heapify_up/down functions
Remove using `swap()` which was using VLA and replace it
with `byteswp()`.
Reduce the scope of local variables in `heapify_up/down` to
the smallest necessary block.
Replace `while(true)` loop in `heapify_down()` with a bounded `for`
loop.

Signed-off-by: Sayooj K Karun <sayooj@aerlync.com>
2025-06-26 11:58:05 -04:00
Minh Tang
8ce9e11242 lib: posix: Update attribute packed for posix_thread_attr
Add attributed packed for struct posix_thread_attr when arch is RX

Signed-off-by: Minh Tang <minh.tang.ue@bp.renesas.com>
2025-06-26 14:07:03 +02:00
Iuliana Prodan
b3e4809554 lib: open-amp: Add NXP-specific resource table implementation
Implement NXP-specific support for the remote processor
resource table, including custom definitions and initialization
logic to meet NXP's communication requirements.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Iuliana Prodan
7c82d6c2ab lib: open-amp: Update CMakeLists.txt for vendor resource table
Modify the build system to conditionally compile
vendor-specific resource table support based on configuration.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Iuliana Prodan
9db96e8a04 lib: open-amp: Add vendor-specific config options
Add config options for vendor-specific resource tables.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Iuliana Prodan
222297ee07 lib: open-amp: Add base support for resource table
Introduce macros to define initialization
routines for OpenAMP resource table entries.

This will allow to extend the default OpenAMP
resource table with vendor-specific data structures.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Iuliana Prodan
e8a702026a lib: open-amp: Allow vendor specific resource table definition
Enhance flexibility by allowing vendors to define their own
resource tables. This is achieved by moving the vdev and vring
functions into the source file, requiring each vendor to
implement these functions within their specific resource
table definitions.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Iuliana Prodan
a50ddace58 lib: open-amp: Replace struct fw_resource_table with void
Switching to void allows greater flexibility in supporting
vendor-specific resource tables.

This change reverts commit 39863b66bd, and adds some fixes.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2025-06-25 14:05:38 +02:00
Chris Friedt
8743da2f32 posix: use sys_clock implementation
Use the newly added sys_clock API in lib/os for

* clock_gettime()
* clock_settime()
* clock_nanosleep() and nanosleep()
* gettimeofday()

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
49cc01d4b5 libc: common: thrd: use sys_clock_nanosleep() instead of nanosleep()
Reduce the dependency on POSIX by taking advantage of the newly added
sys_clock_nanosleep().

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
ff7825b9aa libc: use the common libc time() implementation for most libcs
Use the implementation of time() from the common libc, since there
it no longer pulls in POSIX.

Use is implied for minimal, newlib, and picolibc, and selected
for IAR.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
17964083d3 libc: common: time: use sys_clock api rather than posix
Remove POSIX clock_gettime() from the common libc time implementation,
since POSIX should not be a dependency for ISO C.

Instead, use the newly added lib/os sys_clock API.

Specifically, sys_clock_gettime().

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
a3e934f12c sys: clock: additional sys_clock api calls
Additional entries for the sys_clock API, comprised of:

* sys_clock_gettime()
* sys_clock_settime()
* sys_clock_nanosleep()

along with the constants

* SYS_CLOCK_REALTIME
* SYS_CLOCK_MONOTONIC
* SYS_TIMER_ABSTIME

The primary motivation for this API is so that libc and other
libraries have a familiar-enough API to reach to when POSIX
is not available, since POSIX is optional in Zephyr.

By adding this API to lib/os, we also eliminate dependency cycles
between libc and posix, as lib/os is a mutual dependency.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
282b47cf37 posix: cond + mutex: log messages generate warnings for 32-bit timeouts
Previously, log messages would generate warnings (escalated to errors
in CI) when CONFIG_TIMEOUT_64BIT=n.

For example,

```
west build -p auto -b qemu_cortex_m0 -t run tests/posix/timers/ \
  -- -DCONFIG_TIMEOUT_64BIT=n
..
warning: format '%llx' expects argument of type \
  'long long unsigned int', but argument 3 has type 'k_ticks_t' \
  {aka 'unsigned int'}
```

Use portable print specifiers and cast the argument to int64_t.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Anas Nashif
d4a2b7dc57 lib: os: cbprintf_complete: add missing break statement
Add missing break in switch statement.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-06-18 17:48:03 -04:00
Tim Pambor
3b90ed6122 lib: os: Fix function signature of str_out
Update the str_out function signature to match the expected
cbprintf_cb_local type:
typedef int (*cbprintf_cb_local)(int c, void *ctx);

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-06-18 17:45:06 -04:00
Keith Packard
34a03fb436 posix: Use 'char' for posix_condattr bitfields
Ensure that posix_condattr is smaller than pthread_condattr by keeping it
under one byte.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-06-17 16:06:21 +02:00
Glenn Andrews
94084e5aba Lib: SMF: Add return code to signal event propagation
See Discussion https://github.com/zephyrproject-rtos/zephyr/discussions/83659
for information about the purpose of this change.

Modifies run actions of hierarchical state machines
to return a value indicating if the event was handled
by the run action or should be propagated up to the
parent run action. Flat state machines are not affected,
and their run action returns void.

smf_set_handled() has been removed and replaced by
this return value. smf_set_state() will not propagate
events regardless of the return value as the transition
is considered to have occurred.

Documentation, tests, samples, has been updated.
USB-C and hawkBit use SMF and have been updated to use
the new return codes.

Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
2025-06-17 16:04:04 +02:00
Benjamin Cabé
455280e5aa lib: hex: remove unnecessary defensive programming
The hex2char() calls in bin2hex() can never fail since buf[i] >> 4
and buf[i] & 0xf always produce values in range 0-15.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-11 10:25:14 -07:00
Jordan Yates
b64fb93d93 lib: posix: dedicated symbol for POSIX system headers
Add a dedicated symbol for including the POSIX system headers path
directly into the include path, enabling (for example)
`#include <time.h>` instead of `#include <zephyr/posix/time.h>`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-06-11 08:19:54 +02:00
Nimish Tambe
936d0278bd posix: fnmatch: fix bugs in fnmatch(), see issue #55186
all tests in tests/posix/c_lib_ext/src/fnmatch.c seem to pass
except one (which is still commented)

Signed-off-by: Nimish Tambe <nimisht@gmail.com>
2025-06-09 17:05:40 -05:00
Sayooj K Karun
cd7c78e92e lib: min_heap: Add min-heap data structure
Introduce a binary min-heap implementation as a generic data structure
for use in kernel and application code. A min-heap always maintains
the smallest element at the root, making insertion and removal of the
minimum element efficient (O(log n)).

The API allows both static and dynamic initialization, supports custom
comparators.

Signed-off-by: Sayooj K Karun <sayooj@aerlync.com>
2025-06-07 13:29:24 +01:00
Peter Mitsis
811302e6d2 kernel: sys_heap: Fix chunk size request validation
Updates the heap code to ensure that when converting the requested
number of bytes to chunks, we do not return a value that exceeds
the number of chunks in the heap.

Fixes #90306

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-06-06 10:12:19 +02:00
Anas Nashif
7bbb834deb Revert "posix: rwlock: Refactor locking using k_timepoint_t"
This reverts commit 833eaccfd1.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-30 08:27:19 -04:00