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>
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>
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>
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>
Update CMakeLists.txt to conditionally include address translation
support based on Kconfig options.
Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Add NXP-specific address translation table to support memory-mapped
translations between driver and device.
Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
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>
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>
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>
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>
Modify the build system to conditionally compile
vendor-specific resource table support based on configuration.
Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
It's possible for newlib/picolib libc libraries to
internally call sysconf() which would execute zephyr's
implementation. However, if the _SC* defines do not have
matching values, then the incorrect switch case executes.
This issue arises when using newlib/picolib libc that includes
sysconf implementation for ARM. With current defaults, the
zephyr sysconf() overrides the original libc sysconf() so
we must ensure proper operation.
We will switch to the #define list just like newlib/picolib.
We can't currently use their unistd.h directly due to a domino
of declaration conflicts.
For the "small" macro implementation, we have to drop using
CONCAT to prevent pre-expansion of the new #defines
Signed-off-by: Nicholas Lowell <Nicholas.Lowell@lexmark.com>
match standard by having input void *buf parameter
for pwrite() marked as const, and avoid any potential
declaration conflicts
Signed-off-by: Nicholas Lowell <Nicholas.Lowell@lexmark.com>
static inline gethostname() in unistd.h can cause declaration collisions.
we should just move it to a normal function definition like the
rest of the network functions.
Signed-off-by: Nicholas Lowell <Nicholas.Lowell@lexmark.com>
When TF-M is enabled, Mbed TLS's MD module (which is used to generate
v5 UUIDs) will dispacth hash operations to TF-M. Unfortunately TF-M
does not support SHA-1 (because it's a weak algorithm) so the
computation will fail.
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
This file is explicitly included by the espressif hal module. It's an
internal file provided by picolibc and newlib. Provide a stub to let
code designed for those to work with the minimal C library.
Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Use the newly added timespec util functions to manipulate and
compare timespec structures with overflow detection.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Compiler gets confused and thinks base may be used uninitialized. This
shouldn't be possible, but to make the warning go away, initialize it.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Implement the POSIX_CLOCK_SELECTION Option Group.
This was mostly already done, but compiled / linked in the wrong places.
E.g. pthread_condattr_getclock() and pthread_condattr_setclock() were
in pthread.c and part of POSIX_THREADS_BASE. clock_nanosleep() was in
clock.c and part of POSIX_TIMERS.
This change builds them as part of clock_selection.c with
CONFIG_POSIX_CLOCK_SELECTION.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
gettimeofday() was already implemented, but incorrectly lumped into
POSIX_TIMERS.
putenv() is really just a wrapper around setenv().
The only one left to implement was gethostid() which was relatively
trivial.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Move most implementations to clock_common.c in preparation for
moving gettimeofday() and clock_nanosleep() to different compilation
units.
We also take this as an opportunity to switch from using k_spinlock
to sys_sem.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
To facilitate moving gettimeofday() and clock_nanosleep() to separate
compilation units, make z_clock_nanosleep(), z_clock_gettime(),
and z_clock_settime() convenience functions.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>