Commit graph

1973 commits

Author SHA1 Message Date
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
Flavio Ceolin
69fb9d62f1 lib: heap: Use proper flexible array
0 length array is a GNU extension. Use proper C99 flexible
array.

Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
2025-09-03 13:49:31 +03:00
Daniel Hajjar
a47f304bdf lib: libc: minimal: Refactor stdbool.h for C23
Updated minimal libc to use the type "bool" which was introduced in C23
instead of defining it as a macro.

Link: https://en.cppreference.com/w/c/header/stdbool
Signed-off-by: Daniel Hajjar <daniel.hajjar16@gmail.com>
2025-09-03 01:28:42 +02:00
Chris Friedt
4ff059395b sys: timeutil: compute the remainder in timespec to timeout conversion
Since it's possible that rounding up might not always be the right thing
to do in every situation, in order to allow the application to make more
informed decisions, we created a modified timespec_to_timeout() that also
returns the remainder (or difference) between the requested time to
convert and resulting k_timeout_t. The difference is expressed as a
timespec object.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-09-02 15:53:54 +02:00
Iliar Rabet
4a4a46c26f util: adds the utf8_count_chars function
The function utf8_count_chars counts the number of UTF-encoded characters

Signed-off-by: Iliar Rabet <iliar.rabet@gmail.com>
2025-09-01 23:27:44 +02:00
Clay Wynn
40e91b4242 os: add __weak to to assert_print to allow customization
System designers may want to change the behavior of assert_print, such as
storing the message off into retained RAM and instantly rebooting. Adding
__weak allows customatization

Signed-off-by: Clay Wynn <cwynn@meta.com>
2025-08-29 22:57:52 -04:00
Chris Friedt
ab8b55ac99 posix: move posix limit definitions to posix_limits.h
Rather than keeping limits defined in a common way, controllable with one
Kconfig, move posix definitions out of the standard common libc header
`<limits.h>` into `<zephyr/posix/posix_limits.h>`, not controlled with
Kconfig. Additionally, include `<zephyr/posix/posix_limits.h>` wherever
an in-tree C library includes a custom `<limits.h>`.

Note: the only reason any of the `<limits.h>` files exist, is to define
the POSIX limit PATH_MAX without declaring `_POSIX_C_SOURCE`, which would
be necessary according to the standard, and each of the custom `<limits.h>`
files is nearly identical in this regard.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-08-29 18:21:10 +02:00
Chris Friedt
c4533d1b69 posix: move limit definitions to common libc limits.h
In order to reduce conflicts with limits defined in external C libraries,
move Zephyr's POSIX limits from posix_features.h to limits.h in the
common C library sources.

In order to give the implementation better control over where POSIX
limit definitions originate, use `#include_next <limits.h>` to pull in
the corresponding header of the C library, and provide a non-user
configurable option `CONFIG_TC_PROVIDES_POSIX_LIMIT_DEFS` that may be set
in order to ensure that the C library version of POSIX limits are used.

Note: this may mean that runtime invariant values are inconsistent with
parts that are actually in use within Zephyr, so applications are
encouraged to use `sysconf()` with external C libraries that implement
parts of the POSIX standard to query system configuration values at
runtime.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-08-29 18:21:10 +02:00
Maksymilian Goryszewski
ba30c7b4e8 lib: posix: fs: Basic fstat() using seek and tell
Implement limited posix fstat()

Signed-off-by: Maksymilian Goryszewski <mgoryszewski@internships.antmicro.com>
2025-08-27 08:27:14 +02:00
Mohamed Moawad
ed9fa3aa83 lib: libc: default LIBC_ALLOW_LESS_THAN_64BIT_TIME for ARCMWDT
Set CONFIG_LIBC_ALLOW_LESS_THAN_64BIT_TIME to default 'y' for
ARCMWDT_LIBC toolchain.
The ARCMWDT_LIBC uses a 32-bit time_t
which fails the 64-bit time_t validation introduced to prevent Y2038
issues. This change eliminates the need to manually configure this
option for every ARCMWDT test while maintaining the validation
for other toolchains that support 64-bit time_t.

Signed-off-by: Mohamed Moawad <moawad@synopsys.com>
2025-08-20 16:31:26 +02:00
Jamie McCrae
db8f991c77 kconfig: Use $(...) instead of ${...} for getting variables
Updates this to comply with the Zephyr Kconfig recommendations

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-08-20 12:05:41 +02:00
Ilya Tagunov
c8c894b83e lib: libc: arcmwdt: add a declaration for the strnlen function
ARC MWDT C library does not have an implementation of the strnlen
function, so we have a wrapper over standard-compliant strnlen_s.
However, there is no declaration of the wrapper, so add one.

Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
2025-08-13 11:09:01 +01:00
Jordan Yates
9d0d3ef076 net_buf: buf: return on double free
If assertions are disabled, return on double free instead of wrapping
around the reference count.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-08-12 20:39:06 -04:00
Jordan Yates
5184e3f86a net_buf: buf: assert on double free
Unreferencing a buffer that has already been freed should trigger an
assertion as it indicates a critical logic error and potential security
concern.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-08-12 20:39:06 -04:00
Jordan Yates
97b9a0c1c5 net_buf: buf: remove custom assertion logic
There is no need for a custom assert macro that is only used once, or
conditional compilation of the assert macro based on `__ASSERT_ON`. If
assertions are disabled the compiler should simply discard the code.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-08-12 20:39:06 -04:00
Keith Packard
4c2ac61a82 lib/libc: Provide optional check for time_t size
The LIBC_ALLOW_LESS_THAN_64BIT_TIME option disables a compile-time check
ensuring that time_t can hold 64-bit values. This check can prevent
accidental builds on targets with 32-bit time_t and the consequent 2038
issues.

This option is enabled when using the native C library as i386 glibc
uses 32-bit time_t.

A new file, validate_libc.c, is added to lib/libc to contain this and any
future libc tests. The check for CONFIG_EXTERNAL_LIBC is moved to
libc/CMakeLists.txt to ensure that this new file is always compiled.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-08-06 17:10:15 +03:00
Chris Friedt
82460c8a1d posix: signals: use Kconfig options instead of _NSIG
Use CONFIG_POSIX_RTSIG_MAX instead of _NSIG, since RTSIG_MAX isn't always
going to be defined.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-08-06 12:13:53 +03:00
Chris Friedt
a6f2bb0c4c posix: do not rely on PAGE_SIZE being defined in limits.h
Since an implementation may omit definitions of runtime invariant values
in limits.h if the corresponding value is equal to or greater than the
minimum, is unspecified, and must be queried at runtime [1], do not rely
on PAGE_SIZE being declared in limits.h .

[1]
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/limits.h.html

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-08-06 12:13:42 +03:00
Adrian Bieri
5d42408efa cpp: add kconfig option STD_CPP23 for STD_CPP
to be able to choose c++23 dialect
deprecates c++2b, but we should keep the option c++2b for legacy

Signed-off-by: Adrian Bieri <adrian.bieri@loepfe.com>
2025-07-30 07:27:53 -04:00
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