Added ifdef guard (CONFIG_GETOPT_LONG) around the functions in
getopt_shim.c that requires getopt_long implementation.
Signed-off-by: Magne Værnes <magne.varnes@nordicsemi.no>
Do not add this folder to the include path when this component is not
enabled. As that creates noise and slows down builds.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
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 <chris@fr4.co>
Fixes this define leaking into all application source files when
the feature is not even enabled
Co-authored-by: Chris Friedt <cfriedt@tenstorrent.com>
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
k_condvar_broadcast does not error. It returns the number of
woken threads on success. We should not assert any value.
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
When eventfd is used through read(2) and write(2), the mutex is
already locked from the fdtable implementation. So we remove the
usage of the mutex from the zvfs_eventfd_*_op functions, as it is
already managed by fdtable.
However, when zvfs_eventfd_{read,write} are used, no fdtable layer
is used and we shuld call the _op function with the mutex locked
(the same behavior as with fdtable), so these functions should
manage the mutex. We add it there.
Fixes#99234
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
C99 § 7.19.6.5 defines `snprintf`. According to ¶ 2:
> If `n` is zero, nothing is written, and `s` may be a null pointer.
And according to § 7.19.6.12 ¶ 2:
> The `vsnprintf` function is equivalent to `snprintf` (...)
However, prior to this change, `vsnprintfcb` (and indirectly, `snprintfcb`)
unconditionally null-terminates the output buffer.
This fixes#48394, which was auto-closed without actually being fixed.
Co-authored-by: Adrien Lessard <adrien.lessard@rbr-global.com>
Signed-off-by: Samuel Coleman <samuel.coleman@rbr-global.com>
Previously, eventfd file descriptors were not being counted against the
required size for the global file descriptor table, which would result
in the function `eventfd()` (and `zvfs_eventfd()`) failing due to
insufficient resources.
Signed-off-by: Chris Friedt <chris@fr4.co>
The tolower() function takes an int parameter. LLVM compilers generate a
warning if a char is passed instead.
Signed-off-by: Keith Short <keithshort@google.com>
A couple of tests were inconsistent with glibc and picolibc.
Significant rework done to the `fnmatch()` implementation which included
refreshing that and the `rangematch()` implementations from commit
0a3b2e376d150258c8294c12a85bec99546ab84b
in https://github.com/lattera/freebsd
Removed `match_posix_class()` and implemented that functionality as
`rangematch_cc()`, which uses 64-bit integer comparison for matching
`[:alnum:]` et al instead of string comparison. That likely only works
for the "C" locale.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Signed-off-by: Harun Spago <harun.spago.code@gmail.com>
A regression in 936d0278bd introduced a
subtle bug in the way that escaped expressions were handled.
The regression originated with the assumption that test data (originally
adapted from a 3rd-party testsuite) was correct when it was in fact
flawed.
Specifically, `fnmatch("[[?*\\]", "\\", 0)` should fail (`FNM_NOMATCH`),
since the "\\" sequence (a single backslash after compilation) escapes
the following ']' character, thus leaving the bracket expression
incomplete.
As @keith-packard has pointed out,
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/\
V3_chap02.html#tag_18_13_01 says that a bracket expression is only
interpreted as a bracket expression, when a proper bracket expression
is formed.
Therefore, the pattern is interpreted as the sequence
`'['`, `'['`, `'?'`, `*` (wildcard), `']'` and the call should return
`FNM_NOMATCH` to indicate failure rather than 0 to indicate success.
Added new test cases from #98827 and some commentary for subsequent
reviewers.
This change does not completely fix#55186 but is related to it.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
According to the hashmap interface specification sys_hashmap_remove will
"Erase the entry associated with key `key`, if one exists"
If a rehash is performed OA/LP will return 1 and no old_value for
sys_hashmap_insert.
If a rehash is NOT performed OA/LP will return 0 and a stale old_value for
sys_hashmap_insert even though the user requested the entry for that key to
be removed.
This patch makes OA/LP not return the value of tombstoned entries.
Signed-off-by: Emil Hammarstrom <emil.hammarstrom1@assaabloy.com>
Accurately applying clock skew correction in
`timeutil_sync_ref_from_local` and `timeutil_sync_local_from_ref`
requires double-precision floating point operations. If this is the only
usage of double precision logic in the build, but clocks skews are not
used, this can be a significant ROM overhead. Disabling this option can
save ~2.4 kB of ROM.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Remove duplicated #include directives within the same
preprocessor scope across the Zephyr tree.
Duplicates inside different #ifdef branches are preserved
as they may be intentional.
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
We currently only disable "normal" IRQs with irq_lock(). This is not
sufficient if ZLIs are enabled, as even though they are supposed to
be "above" the kernel, they must not interrupt the poweroff procedure.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
We currently only disable "normal" IRQs with irq_lock(). This is not
sufficient if ZLIs are enabled, as even though they are supposed to
be "above" the kernel, they must not interrupt the reboot procedure.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
As per our naming conventions for public symbols, these utility functions
and macros should be prefixed with "sys_".
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Sibling transitions are now detected in smf_set_state() when source and
destination share the same parent, removing the need for states to flag
the sibling transition explicitly.
Restore include/zephyr/smf.h and lib/smf/Kconfig to match main so this
change only carries the functional update in lib/smf/smf.c, and add a
micro-benchmark test. For accurate statistics, run the test on a board.
Micro-benchmark setup
- Board: NUCLEO-F746ZG (STM32F746, ~192 MHz)
- 200000 iterations per state transition
- Simple HSM (letters are nodes; R is root):
=== SMF transition micro-benchmark ===
R
/ \
A B
/ \ / \
C D E F
/ \ \
G H J
Current smf_set_state:
======================
Sibling Transitions
(A->B) : 459 cycles/transition (2390 ns)
(C->D) : 482 cycles/transition (2510 ns)
(G->H) : 522 cycles/transition (2718 ns)
Other Transitions
(G<->G) : 237 cycles/transition (1234 ns)
(C->G) : 343 cycles/transition (1786 ns)
(A->H) : 452 cycles/transition (2354 ns)
(G->D) : 651 cycles/transition (3390 ns)
(D->E) : 752 cycles/transition (3916 ns)
(J->D) : 893 cycles/transition (4651 ns)
(J->G) : 1077 cycles/transition (5609 ns)
New smf_set_state:
==================
Sibling Transitions
(A->B) : 356 cycles/transition (1854 ns)(22% faster)
(C->D) : 356 cycles/transition (1854 ns)(26% faster)
(G->H) : 356 cycles/transition (1854 ns)(32% faster)
Other Transitions
(G<->G) : 258 cycles/transition (1343 ns)(9% slower)
(C->G) : 356 cycles/transition (1854 ns)(4% slower)
(A->H) : 464 cycles/transition (2416 ns)(3% slower)
(G->D) : 707 cycles/transition (3682 ns)(9% slower)
(D->E) : 797 cycles/transition (4151 ns)(6% slower)
(J->D) : 970 cycles/transition (5052 ns)(9% slower)
(J->G) : 1157 cycles/transition (6026 ns)(8% slower)
This change makes sibling transitions
deterministic and cheaper (356 cycles on nsim),
at the cost of a small increase for deeper/LCA
transitions (~7–9%). This is a net win for state machines
that mostly hop between siblings.
Signed-off-by: Vladislav Kulikov <vlad_kulikov_c@pm.me>
This is available in util.h since 646f255373 and the existing one
creates a collision and build breakage. Just drop it.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Add the functions below to the minimal libc ctype.h since they are
missing, and are required as of C89 (C99 for `isblank()`)
* `isblank()`
* `islower()`
* `ispunct()`
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
A review comment in the PR below requested that unnecessary casts were
removed from ctype.h in the PR below.
https://github.com/zephyrproject-rtos/zephyr/pull/99451
Tested with manual compilation in C and C++ mode with the arguments
```shell
gcc -Wconversion -Werror -Wall -Wextra -Wint-conversion
clang -Wconversion -Werror -Wall -Wextra -Wint-conversion
gcc -Wconversion -Werror -Wall -Wimplicit--Wextra
clang++ -Wconversion -Werror -Wall -Wextra
```
and also with `-- -DCONFIG_COMPILER_WARNINGS_AS_ERRORS=y`
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Based on review feedback, it was suggested to express ctype
character checks in a more direct fashion, rather than using
arithmetic, and allow the compiler to optimize as it sees fit.
https://github.com/zephyrproject-rtos/zephyr/pull/99451#\
discussion_r2530339430
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The "check warns" workflow in CI warned over the use of `unsigned` as a
shorthand for `unsigned int` in several locations in
`lib/libc/minimal/include/ctype.h`.
```
UNSPECIFIED_INT: Prefer 'unsigned int' to bare use of 'unsigned'
File:lib/libc/minimal/include/ctype.h
```
Adjust `unsigned` to `unsigned int` to avoid linter warnings.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add DWARF hint to handle z_thread_entry correctly
in debuggers. This function starts a new thread and never returns.
Use `.cfi_undefined` so DWARF-based unwinding does not rely on return.
Without this, unwinding may follow a bogus return address, leading to
invalid memory reads and potential bus faults during backtrace.
Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
One thread calls mpsc_pbuf_alloc to produce data, which invokes
add_skip_item and steps into k_sem_take.
Another thread calls mpsc_pbuf_claim to consume data. In this condition,
mpsc_pbuf_claim has only small remaining space and needs to call rd_idx_inc
to reserve space, but there is still no data available.
The consumer should call k_sem_give to wake mpsc_pbuf_alloc again,
so the producer can allocate space and continue producing data.
Without this wake-up, the producer thread may wait forever in
k_sem_take, leading to a deadlock situation.
Signed-off-by: Fei Wang <fei.wang@jaguarmicro.com>
Fix uncontroversional issues detected by SonarCloud, whose fixes are
trivial, and improve code readability.
This commit fixes multiple sonar cloud detected issues like:
"Give names to the parameters of this function prototype."
"Declare the variable "i"/"j" inside the loop"
"Remove this empty statement"
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Allow user to use the new sys_getopt API via the old non-Posix
compliant getopt API. This is a temporary solution and the shim
will be deprecated and eventually removed at some point.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
Summary:
As Zephyr getopt is not really compatible with Posix getopt, rename
Zephyr getopt to sys_getopt.
Background:
Zephyr getopt module was introduced in #31356 to be used by the shell.
Zephyr's getopt is not the standard one. It has multiple APIs which make
it more suited for a system like Zephyr where different components may
want to use it for different purposes. Including APIs to init it,
get and set its internal state etc.
Several Zephyr modules (shell, net, wifi, ztest) use this getopt with
these special APIs. The getopt module is bundled in the POSIX
compatibility API subsystem (CONFIG_POSIX_C_LIB_EXT).
Problem description:
As it is not the standard getopt(), no C library can possibly provide
a Zephyr compatible version (even if such C library were to provide a
standard getopt()). As it is bundled in Zephyr's POSIX API in
CONFIG_POSIX_C_LIB_EXT), multiple components that depend on it are
selecting CONFIG_POSIX_C_LIB_EXT. Zephyr core components should not
depend on the POSIX API in this way.
Changes done in this commit:
Rename the getopt*() APIs to sys_getopt*() and move them into a module
under lib/utils with its own Kconfig option to enable it.
Zephyr's users are changed to use this new component.
The POSIX subsystem can continue providing getopt() by calling the new
sys_getopt() and in that way retain backwards compatibility for external
users.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This removes a function that created a new mutex and conditional variable
and used memcpy() to compare them with ones in a given fdtable entry.
Since those struct members are initialized statically, this test doesn't
serve much of a purpose anymore. Moreover, padding bytes inside structs
are technically not required to be zero, so these memcpy() calls caused
SonarQube to complain.
Signed-off-by: Jakub Klimczak <jklimczak@internships.antmicro.com>
The file descriptor table is used in every area that expects to work on
files through descriptor indices. It can only be operated on through
functions whose names indicate a relationship with ZVFS (`zvfs_*fd*`).
The integer file descriptor mechanism shouldn't be separate from ZVFS.
This will make cooperation between different file access APIs much
simpler. This commit also makes preparations for the fdtable becoming
optional.
Signed-off-by: Jakub Klimczak <jklimczak@internships.antmicro.com>
This commit moves all operations on single files into ZVFS and makes the
POSIX subsystem call into ZVFS to perform them. It was necessary to define
a `struct zvfs_stat` to avoid a dependency cycle. Functions used
internally for file i/o operations are publicised since they won't require
any changes between various subsystems. This allows ZVFS to actually
fulfill its purpose of facilitating cooperation of different file APIs.
Signed-off-by: Jakub Klimczak <jklimczak@internships.antmicro.com>
Fix the JSON library to properly unescape sequences during decoding.
Previously, escape sequences like \n, \t, \" etc were validated but
not converted back to their actual character representations during
decoding, causing backslash duplication with each encode/decode cycle.
This fix modifies decode_string_buf() to properly handle escape
sequence unescaping and ensures strings maintain their original
content across multiple encode/decode cycles.
Signed-off-by: BUDKE Gerson Fernando <gerson.budke@leica-geosystems.com>
We have two places defining cpu_load_get() and trying to the same thing,
one is a core kernel feature supported on all architecture, the other is
part of debug, requires tracing and supported only on a subset of
architectures. Both deliver different results and accuracy.
While we figure our how to merge those into one API and with the
advanatges of both, rename the API so there is no confusion about what
is being used.
Fixes#97845
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Replace the open-ended while(true) with a null-terminated parent walk.
Improves readability, behavior is unchanged.
Signed-off-by: Vlad Kulikov <vlad_kulikov_c@pm.me>
Add bounds check to prevent accessing heaps array with index=-1
when the address parameter is NULL or too small.
Return NULL in such cases to match the API specification.
Signed-off-by: Nulliu Z <zophaisina@outlook.com>
Replace all in-function instances of MIN/MAX/CLAMP with the single
evaluation version min/max/clamp.
There's probably no race conditions in these files, but the single
evaluation ones save a couple of instructions each so they should save
few code bytes and potentially perform better, so they should be
preferred in general.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
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>
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>
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>
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>
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>