Commit graph

449 commits

Author SHA1 Message Date
Chris Friedt b1e2e4ac2c posix: fs: create a separate Kconfig option for fsync
Create CONFIG_POSIX_FSYNC to match the spec.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-05-07 21:22:56 -04:00
frei tycho 32ba549536 lib: os: coding guidelines: add explicit cast to void
- added explicit cast to void when returned value is expectedly ignored

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-05-03 07:52:42 -04:00
Karthikeyan Krishnasamy 65ad32b3ca lib: os: fdtable: add support for fsync
Add support for fsync in existing posix ioctl call

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
2024-04-15 13:23:37 -04:00
Florian La Roche 0d5a670f4f lib/os/printk.c: use ARG_UNUSED() for char_out()
Use ARG_UNUSED() within the function char_out()
to handel unused param.

Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com>
2024-03-06 12:11:26 +01:00
Daniel Leung 627d3b2cb6 lib: cbprintf: do not blindly skip tags
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>
2024-02-06 09:53:15 +01:00
Patrick Wildt f61bbad625 spsc_pbuf: fix cache invalidation in spsc_pbuf_free
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>
2024-02-01 13:10:28 -06:00
Luca Burelli 5f2c6e58b0 ztest: export ztest_test_* symbols to llexts
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>
2024-01-26 12:36:23 +01:00
Krzysztof Chruściński c48d61a4b4 lib: os: cbprintf: Fix size miscalculation in cbprintf_convert
When package contained RO string positions and flag indicates that
they shall not be kept, length was miscalculated which could lead
to failures (e.g. memory corruption).

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-12-28 12:18:50 +00:00
Anas Nashif 0b999c0943 lib: move utilities into own folder
Move various utilities out of lib into own folder for better assignement
and management in the maintainer file. lib/os has become another dumping
ground for everything and it the Kconfig and contents in that folder
became difficult to manage, configure and test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-12-22 09:54:12 +01:00
Anas Nashif d4c881da04 lib: mem_block: move to own folder
Move mem_block into own folder and seperate from lib/os and heap
configuration.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-12-13 17:27:54 -05:00
Anas Nashif 6cb588820f lib: os: move heap to own folder
consolidate all heap related files and implementation into one folder.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-12-13 17:27:54 -05:00
Guennadi Liakhovetski 69cdc32892 llext: export some symbols
Export some symbols for loadable modules. Also add an
EXPORT_SYSCALL() helper macro for exporting system calls by their
official names.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2023-12-01 10:08:12 -05:00
Flavio Ceolin 8679c58644 kernel: Option to not use tls to get current thread
Add a Kconfig option to tell whether or not using thread
local storage to store current thread.

The function using it can be called from ISR and using
TLS variables in this context may (should ???) not be
allowed

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-11-21 15:49:48 +01:00
Keith Packard 7a5fcb8c60 libc/picolibc: Support 'long long' and 'minimal' printf variants
Picolibc's 'minimal' printf mode reduces functionality and size even more
than the 'integer' mode. Use this where memory is at a premium and where
the application knows that it does not require exact printf semantics.

1.8.5 adds two more printf variants, 'long long' and 'minimal'. The 'long
long' variant is the same as the 'integer' variant but with long long
support enabled. The 'minimal' variant reduces functionality and size even
more than the 'integer' mode. Applications can use this where memory is at
a premium and where the application does not require exact printf
semantics.

With these two added variants, the SDK has enough options so that all of
the cbprintf modes can be supported with the pre-compiled bits:

 1. CBPRINTF_NANO - picolibc's 'minimal' variant
 2. CBPRINTF_REDUCED_INTEGRAL - picolibc's 'integer' variant
 3. CBPRINTF_FULL_INTEGRAL - picolibc's 'long long' variant
 4. CBPRINTF_FB_SUPPORT - picolibc's 'double' variant

This patch makes the cbprintf Kconfig values drive the default picolibc
variant, disables picolibc variants not capable of supporting the required
cbprintf level, but allows applications to select more functionality in
picolibc than cbprintf requires.

Note that this depends on the SDK including picolibc 1.8.5. Without that,
selecting the 'minimal' or 'long long' variant in Zephyr will end up with
the default variant from picolibc, which is the full version with floating
point support. When using the module things will work as specified.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-11-20 06:07:58 -05:00
Keith Packard 47e09806c8 lib/os: With CBPRINTF_NANO, picolibc long-long printf isn't required
CBPRINTF_FULL_INTEGRAL doesn't happen to explicitly conflict with
CBPRINTF_NANO, but when CBPRINTF_NANO is enabled, there's no long long I/O
support provided.

Allow picolibc long-long I/O support to also be elided when CBPRINTF_NANO
is enabled to save similar amounts of space.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-11-20 06:07:58 -05:00
Keith Packard 7d9c0b9db5 lib/os/cbprintf: Picolibc doesn't support several cbprintf options
* Picolibc doesn't provide the %a-only mode.

 * On advice from security experts, who report numerous vulnerabilities
   caused by %n in printf specifiers, picolibc never supports this
   feature.

 * Picolibc doesn't use cbprintf for C-library compatible functions,
   instead it provides aliases for the *printfcb functions using stdio
   names.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-11-20 09:22:32 +01:00
Anas Nashif a08bfeb49c syscall: rename Z_OOPS -> K_OOPS
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 9c4d881183 syscall: rename Z_SYSCALL_ to K_SYSCALL_
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif c25d0804f0 syscall: rename z_object_find -> k_object_find
Rename internal API to not use z_/Z_.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 43a7402baf syscall: rename z_object_recycle -> k_object_recycle
Rename z_object_recycle and do not use z_ for internal APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif 4e396174ce kernel: move syscall_handler.h to internal include directory
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Anas Nashif a6b490073e kernel: object: rename z_object -> k_object
Do not use z_ for internal structures and rename to k_object instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +01:00
Krzysztof Chruściński 0ca5fdc6e8 lib: os: cbprintf: Add option to enable pointer checking
Add CONFIG_CBPRINTF_CONVERT_CHECK_PTR which enables support for
checking if string candidate pointer is not %p. It is by default
disabled when logging strings are removed from the binary. Option
is added to save code.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2023-10-31 09:01:38 +01:00
Christopher Friedt 12ea06cac2 posix: fdtable: ensure stdin, stdout, and stderr are initialized
Ensure that stdin, stdout, and stderr are initialized statically.

Previously, the mutex and condition variable were uninitialized.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-10-13 04:48:47 -04:00
Flavio Ceolin e7bd10ae71 random: Rename random header
rand32.h does not make much sense, since the random subsystem
provides more APIs than just getting a random 32 bits value.

Rename it to random.h and get consistently with other
subsystems.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-10 14:23:50 +03:00
Flavio Ceolin 15aa3acaf6 kconfig: Remove MP_NUM_CPUS usage
Zephyr's code base uses MP_MAX_NUM_CPUS to
know how many cores exists in the target. It is
also expected that both symbols MP_MAX_NUM_CPUS
and MP_NUM_CPUS have the same value, so lets
just use MP_MAX_NUM_CPUS and simplify it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-03 17:45:53 +01:00
Peter Mitsis e6f1090553 kernel: Integrate object core statistics
Integrates object core statistics framework into the following
kernel objects:
  sys_mem_blocks, k_mem_slab
  threads, _cpu, z_kernel

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-09-30 08:04:14 +03:00
Peter Mitsis 6df8efe354 kernel: Integrate object cores into kernel
Integrates object cores into the following kernel structures
   sys_mem_blocks, k_mem_slab
   _cpu, z_kernel
   k_thread, k_timer
   k_condvar, k_event, k_mutex, k_sem
   k_mbox, k_msgq, k_pipe, k_fifo, k_lifo, k_stack

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-09-30 08:04:14 +03:00
Peter Mitsis baea37aeb4 kernel: Re-factor sys_mem_blocks definition
Rearranges the sys_mem_blocks fields so that information that describes
how much of the memory block is used is co-located. This will allow
easier of its statistics into the object core statistics reporting
framework.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-09-30 08:04:14 +03:00
Tom Burdick 41e0a4a371 llext: Linkable loadable extensions
Adds the linkable loadable extensions (llext) subsystem which provides
functionality for reading, parsing, and linking ELF encoded executable
code into a managed extension to the running elf base image.

A loader interface, and default buffer loader implementation,
make available to the llext subsystem the elf data. A simple management
API provide the ability to load and unload extensions as needed. A shell
interface for extension loading and unloading makes it easy to try.

Adds initial support for armv7 thumb built elfs with very specific
compiler flags.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
Co-authored-by: Chen Peng1 <peng1.chen@intel.com>
Co-authored-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2023-09-29 20:50:38 -04:00
Daniel Leung 0a50ff366e kernel: rename z_current_get() to k_sched_current_thread_query()
The original idea of z_current_get() was to be the counterpart
of k_current_get() when thread local variable for current has
not been initialized if TLS is enabled, otherwise they are
the same function. Now since z_current_get() is being used
outside of core kernel, rename it under kernel namespace so
other subsystem can conceptually use them too.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-09-28 16:15:46 +02:00
Keith Packard 8f5d0791bf sys/time_units.h: Convert time conversion to macros
The intent of this patch is to leave all of the semantics of the macros
unchanged, only replacing the easy-to-read static inline conversion
function with a pile of ?: operators.

Ick. This is not a cleanup. However, what it does enable is using constant
results while initializing global variables, which cannot be done with
either static inline functions or even statement expressions, even when
those generate constant results.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-09-28 16:15:27 +02:00
Anas Nashif 6d23a960db lib: os: build fdtable conditionally
Stop building fdtable by default, make it conditional and build it only
when needed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-09-28 06:25:16 -04:00
Anas Nashif 8634c3b444 kernel: move wait_q.h header to be internal
This header does not expose any public APIs, so move it under
kernel/include and change files including it.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-09-12 12:55:36 -04:00
ferar alashkar 11e2c58928 lib: os: hex: clarify controlling expression
add explicit boolean type to 'if' statement controlling expression, thus
improving code readability and maintainability, complying with required
[misra-c2012-14.4] rule which states; The controlling expression of an
if statement and the controlling expression of an iteration-statement
shall have essentially boolean type.

Found as a coding guideline violation (Rule 14.4) by static code
scanning tool.

Note: Tested on STM32L5 Nucleo-144 board (stm32l552xx).

Signed-off-by: ferar alashkar <ferar.alashkar@gmail.com>
2023-08-23 16:06:05 +01:00
Anas Nashif e6885a4515 lib: crc: move from lib/os to lib/crc
Move crc implementation to own directory and reduce clutter in lib/os.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-08-18 08:52:16 +03:00
Anas Nashif 234032cac7 os: disable CRC by default
Users of CRC shall enable the the kconfig and not rely on it being
enabled by default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-08-18 08:52:16 +03:00
Flavio Ceolin d16c5b9048 kernel: canaries: Allow using TLS to store it
Add new option to use thread local storage for stack
canaries. This makes harder to find the canaries location
and value. This is made optional because there is
a performance and size penalty when using it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-08-08 19:08:04 -04:00
Nicolas Pitre 4755ebee6a lib/cbprintf: CONFIG_CBPRINTF_LIBC_SUBSTS should be optional
When aiming for the smallest build result, it is desirable to
use CONFIG_CBPRINTF_NANO together with CONFIG_MINIMAL_LIBC. However
that doesn't mean we need all the functions enabled by having
CONFIG_CBPRINTF_LIBC_SUBSTS=y which increases the binary size even if
those functions are not used and not linked in.

When CONFIG_CBPRINTF_LIBC_SUBSTS=n such functions are not defined
anyway so z_cbvprintf_impl() won't be invoked with missing
functionalities.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-08-07 11:26:40 +02:00
Gerard Marull-Paretas 90b247b90b lib: os: add support for system power off
Add a new API to perform an immediate system power off:
`sys_poweroff()`.

Until now, this functionality has been implemented via the system power
management module, but in a clunky fashion. The way system PM works is
by defining some idle states in devicetree, that, given some properties
(e.g. minimal residency, exit latency, etc.) are automatically selected
when system goes to idle based on the expected next wake-up. However,
system off is a power state that one typically wants to control manually
from the application because it implies state loss, and in most cases,
configuring some sort of wake-up source. So in general, it is not
desired to let the system enter this state automatically. This led to
the following stuff in-tree:

from `boards/arm/mimxrt595_evk/mimxrt595_evk_cm33.dts`:

```c
/*
 * Deep power-down mode is supported in this SoC through
 *  'PM_STATE_SOFT_OFF' state. There is no entry for this in device tree,
 *  user can call pm_state_force to enter this state.
 */
```

That is, state not being defined in devicetree so that PM subsystem
doesn't pick it automatically, but still implemented in in the PM hooks:

from `soc/arm/nxp_imx/rt5xx/power.c`, `pm_state_set()`:
```c
case PM_STATE_SOFT_OFF:
	set_deepsleep_pin_config();
	POWER_EnterDeepPowerDown(EXCLUDE_FROM_DEEP_POWERDOWN);
	break;
```

And to actually make use of this state, users had to do this kind of
abominations:

```c
pm_state_force(0u, &(struct pm_state_info){ PM_STATE_SOFT_OFF, 0, 0 });

/* Now we need to go sleep. This will let the idle thread runs and
 * the pm subsystem will use the forced state. To confirm that the
 * forced state is used, lets set the same timeout used previously.
 */
k_sleep(K_SECONDS(SLEEP_S));

printk("ERROR: System off failed\n");
while (true) {
	/* spin to avoid fall-off behavior */
}
```

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-08-04 16:59:36 +02:00
ferar alashkar 595bcda87c lib: os: dec: add misra-c2012 compliance changes
1. change explicit type cast of essential character type, complying with
required [misra-c2012-10.2] rule which states; Expressions of
essentially character type shall not be used inappropriately in addition
and subtraction operations, and

2. add explicit boolean type to 'if' statement controlling expression,
consolidating it with 'buflen' type, thus improving code readability and
maintainability , complying with required [misra-c2012-14.4] rule which
states; ; The controlling expression of an if statement and the
controlling expression of an iteration-statement shall have essentially
boolean type, and

3. add enclosing parentheses enforcing and clarifying precedence of
operators, improving code readability and maintainability, complying
with *advisory* [misra-c2012-12.1] rule which states; The precedence of
operators within expressions should be made explicit.

Found as a coding guideline violation (Rules 10.2, 14.4), and coding
guideline recommendation (Rule 12.1) by static code scanning tool.

Note: Tested on STM32L5 Nucleo-144 board (stm32l552xx).

Signed-off-by: ferar alashkar <ferar.alashkar@gmail.com>
2023-07-28 11:15:44 +02:00
ferar alashkar dddc034923 lib: os: hex: correct explicit cast type
change explicit type cast of essential character type, complying with
required [misra-c2012-10.2] rule which states; Expressions of
essentially character type shall not be used inappropriately in addition
and subtraction operations.

Found as a coding guideline violation (Rule 10.2) by static code
scanning tool.

Note: Tested on STM32L5 Nucleo-144 board (stm32l552xx).

Signed-off-by: ferar alashkar <ferar.alashkar@gmail.com>
2023-07-28 11:15:19 +02:00
ferar alashkar bba6a1d69e lib: os: hex: add explicit unsigned suffices
add explicit unsigned suffices to various immediate numbers, matching
them to size_t, complying with required [misra-c2012-10.4] rule which
states; Both operands of an operator in which the usual arithmetic
conversions are performed shall have the same essential type category.

Found as a coding guideline violation (Rule 10.4) by static code
scanning tool.

Note: Tested on STM32L5 Nucleo-144 board (stm32l552xx).

Signed-off-by: ferar alashkar <ferar.alashkar@gmail.com>
2023-07-28 11:15:12 +02:00
Carlo Caione 561a80d109 shared_multi_heap: Use a data struct
Embed all the helper structs in one single data struct for easy access
indexed on the memory attr.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-07-26 07:56:39 -04:00
Carlo Caione 5d6d93c3b5 shared_multi_heap: Rename heap counter
We are calling the heap counter `attr_cnt` and that is misleading.
Rename it.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-07-26 07:56:39 -04:00
Carlo Caione b7e252c2db shared_multi_heap: Use proper enum instead of int
We have an enum for the memory attr, use that instead of a generic
unsigned int.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-07-26 07:56:39 -04:00
Markus Fuchs c0d7218ef2 json: Skip unknown fields on parsing
Skip child objects and arrays that are not specified in the given object
descriptor when parsing a JSON input string.
This patch adds support for extra child arrays which previously were not
supported by the parser as opposed to additional child objects.

Fixes #47988

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2023-07-18 11:03:21 +00:00
Markus Fuchs 8757c71bd0 json: Fix 64-bit support
This patch fixes encoding arrays of objects on 64-bit targets.

Fixes #36696

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2023-06-29 21:03:48 +02:00
Markus Fuchs ae6aa6165c json: Fix multidimensional array support
This patch fixes support for encoding and decoding multidimensional arrays
as described by the JSON_OBJ_DESCR_ARRAY_ARRAY() macro.

Currently, the JSON array encoding and decoding functions, arr_encode()
and arr_parse(), expect array elements to be of object or primitive type.
However, arrays may be nested and so an array's elements may also be
arrays.

In order to support nested arrays, two special cases must be considered:

1. The array of objects/arrays sub-descriptor is described by two
`json_obj_descr` structs and so two instead of one `json_obj_descr`
structs must be skipped when iterating over the JSON descriptor to get to
an array's elements.
2. The implicit array item count field has to be considered for the
parent itself and all its child array items when calculating an element's
size.

Fixes #50801

Signed-off-by: Markus Fuchs <markus.fuchs@ch.sauter-bc.com>
2023-06-29 21:03:48 +02:00
Daniel Leung 1d4d718a9b lib: syscalls: use zephyr_syscall_header
This adds a few line use zephyr_syscall_header() to include
headers containing syscall function prototypes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00