Boot time initialization functions and data used there must be
available at boot. With demand paging, these may not exist in
memory when they are being used, resulting in page faults.
So pin these functions and data in linker sections to make
sure they are in memory at boot time.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Mostly a revert of commit b1def7145f ("arch: deprecate `_current`").
This commit was part of PR #80716 whose initial purpose was about providing
an architecture specific optimization for _current. The actual deprecation
was sneaked in later on without proper discussion.
The Zephyr core always used _current before and that was fine. It is quite
prevalent as well and the alternative is proving rather verbose.
Furthermore, as a concept, the "current thread" is not something that is
necessarily architecture specific. Therefore the primary abstraction
should not carry the arch_ prefix.
Hence this revert.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The Xtensa linker scripts seem to be injecting syntax errors when
MMU is enabled. Disable the implication in Kconfig.mem for Xtensa
until linker issues are resolved.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Declare _POSIX_C_SOURCE in a consistent way for both the
posix/options library as well as the tests/posix/fs
testsuite.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Check if the spinlock is held before attempting to wait by
taking the semaphore, as that would cause a context switch which
isn't allowed and will trigger an assertion error when
`CONFIG_SPIN_VALIDATE` is enabled.
Logging in spinlock-held context when the log buffer is full can lead
to an infinite assertion error loop, as the logging subsys attempts to
allocate buffer when there's none available, it will try to wait for
one and thus triggers the assertion error, the error message will be
printed through the logging sybsys but there's no buffer available,
so it will try to wait for one and triggers another assertion error..
This loop just goes on and on forever, and nothing gets printed to
the terminal.
Added a test to validate the fix.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
Signed-off-by: Maxim Adelman <imax@meta.com>
Previously, if a file object is was re-used, it could
inherit the offset field of the previously closed file object,
making reading from the beginning of the file impossible
until the offset was manually zero'ed.
The offset should *always* be zero when a file is ready to be
used.
The issue really only presents itself when implementing a
vtable backend.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The `zvfs_finalize_typed_fd()` function notifies some backends
via `ioctl()` with `ZFD_IOCTL_SET_LOCK`. However, support for
this method and functionality is optional.
In backends that do not support locking, this benign failure can
set `errno` to 95 (`EOPNOTSUPP`) in many circumstances where a
change in `errno` (indicating some kind of failure) is not
appropriate.
Prevent errno poisoning by backing-up and restoring `errno`.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Previously, in libc-hooks.c, the signature of `_open()` was as
shown below.
```cpp
int _open(const char *name, int mode);
```
This conflicted with the signature of `_open()` from newlib,
which is
```cpp
int _open(const char *name, int flags, ...);
```
Moreover, the mode and flags field were reversed, but only for
the Xtensa architecture due to the `_open_r()` hook that is
present in `libc-hooks.c`.
This manifested itself via a call to `fopen(file, "w+")`, where
the expected flags should include `O_CREAT | O_TRUNC`, or
`0x200 | 0x400`. Instead, the unexpected flags passed to the
underlying `zvfs_open()` call were `0x1b6`.
This change corrects the function signature and order of the
arguments.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Do not set TC_PROVIDES_POSIX_C_LANG_SUPPORT_R as the default in
lib/posix/options/Kconfig.c_lang_r . TC_PROVIDES options are
only intended to be set by C libraries that implement parts of
the POSIX standard.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Oddly, even though CI passed when the file_system_r change was
merged, now CI has encountered a build error because MIN() was
not defined.
Include `<zephyr/sys/util.h>` to pull in the definition.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
A copy-paste error propogated this typo to a few different
Kconfig files.
Correct 'informnation' to 'information'.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Move the functionality of POSIX_FILE_SYSTEM_R to its own
compilation unit and remove the unnecessary dependency on
POSIX_FILE_SYSTEM.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.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 -fno-lto when building both picolibc itself as well as the Zephyr
interface bits.
Closes: #81674
Signed-off-by: Keith Packard <keithp@keithp.com>
Many out of the POSIX subsystem configs are enabled automatically
when merely CONFIG_POSIX_API is enabled, which is a prerequisite for
many networking samples. This causes a massive experimental warning
printout when building with warnings enabled.
Since the new POSIX Kconfig configuration options are already present
in Zephyr for 2 release cycles and seem settled, I suggest we move
them out of experimental phase.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
These functions can be used to join pthreads in a non-standard way.
The function pthread_tryjoin will not block and simply test whether the
thread has exited already. The function pthread_timed_join will only block
until the specified time. The functions are wrappers for calling the
k_thread_join with timeout K_NO_WAIT and with a specific timeout as opposed
to calling it with K_FOREVER.
Signed-off-by: Cla Galliard <clamattia@gmail.com>
Select TC_PROVIDES_POSIX_C_LANG_SUPPORT_R to keep Zephyr from
including the common libc implementation of the various _r APIs.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
When the PRESTART thread state was removed, this changed the semantics
of k_thread_start() when thread was created with a K_FOREVER timeout,
suspended and then started with k_thread_start().
This sequence is used in p4wq to implement K_P4WQ_DELAYED_START
(which again is needed by K_P4WQ_USER_CPU_MASK).
With PRESTART removed, the following sequence:
z_mark_thread_as_not_suspended(thread);
k_thread_start(thread);
.. no longer starts the thread. As a result, p4wq users like SOF
multicore configurations, hit errors as p4wq threads never start.
Fix the implementation by removing the calls to change thread
suspended state explicitly, but rather rely on the new
k_thread_create() and k_thread_start() semantics.
Fixes: 7cdf40541b ("kernel/sched: Eliminate PRESTART thread state")
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Increase the number of locks to match what the ARC MWDT libc requires
now. The library wants to have 2 locks per each available FILE entry,
and then some more. Also do not include an internal libc header, as
all that is needed from that header is a simple typedef.
Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
If CONFIG_POSIX_API is enabled, but CONFIG_POSIX_DEVICE_IO_ALIAS_WRITE
is not, the _write replacement should be provided to make stdio work.
Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
As k_sleep returns int32_t, there is a possibility for integer overflow
during conversion from milliseconds to nanoseconds.
Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
Nanosecond time calculation overflows if the libc has 32-bit time_t.
One such libc is the classic ARC MWDT one, but there might be others.
Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
`_current` is now functionally equals to `arch_curr_thread()`, remove
its usage in-tree and deprecate it instead of removing it outright,
as it has been with us since forever.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
The clock_t and clockid_t types are already defined in ARC MWDT headers,
so they should not be defined again in Zephyr headers.
Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
Until POSIX layer decoupling is done, we still need the size_t type
definition across the codebase, but it should come through sys/types.h
and not through toolchain-specific headers.
Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
ARC MWDT library does not contain implementations for the reentrant
POSIX time functions, so common Zephyr implementations end up being
used instead. However, there are no declarations, so we just add them
here, unguarded, until a better place is found.
Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
The fileno macro defined in ARC MWDT headers conflicts with the fileno()
function defined in lib/posix/options/device_io.c. We should undefine it
and replace with a POSIX-compliant declaration and a weak definition.
Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
The property based toolchain integration allows a cleaner design by
letting the toolchain define its properties and values and let CMake
implementation of Zephyr provided C and C++ libraries adjust those
properties when minimal C or C++ libraries are used.
This commit moves handling of C++ linker library properties into
the minimal C++ CMake implementation.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
For SIGEV_SIGNAL, the function zephyr_timer_wrapper() is the handler
between kernel and posix layer.
Here, for one-time timer, reload is equal to 0 and function returns.
As a consequence, handler function was never called.
Signed-off-by: Noemie Gillet <ngillet@sequans.com>
Add support for realloc (and realloc_aligned) into the multi heap lib,
where the buffer sent in will either be reused (maybe shrinked),
or enlarged by allocating on any of the matching heaps of the multi heap.
Signed-off-by: Meir Komet <mskomet1@gmail.com>
This option was replaced with CONFIG_STATIC_INIT_GNU
2 releases ago in 6e977ae2d5
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
The sock_obj_core_dealloc() was not called if close() is called
instead of zsock_close(). This happens if POSIX API is enabled.
Fix this by calling zvfs_close() from zsock_close() and then
pass the socket number to zsock_close_ctx() so that the cleanup
can be done properly.
Reported-by: Andreas Ålgård <aal@ixys.no>
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
in commit 1cd37f21f3 the global ram console buffer was replaced
with a pointer. This didn't work with the OpenAMP resource table
anymore (#75656).
Signed-off-by: Simon Maurer <mail@maurer.systems>
When conversion is done in two steps (output length calculation
followed by the actual conversion), it was failing when helper
array for holding calculated string length from the first
conversion run was shorter than number of strings that were
supposed to be appended to the package. Fix by taking into
account strl_len to determine if length can be taken from the
array or need to be calculated again.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
The minimal libc is currently built as a zephyr_library and will be
included in the final link line as such. However, the c_library property
will still be set as "-lc" (for most linkers) and will be added to the
link line. This effectively requires that a separate libc implementation
be available in the toolchain and makes it possible to accidentally pull
from the non-minimal libc.
This doesn't seem desirable, so try to prevent this by clearing the
c_library property if we are using the minimal libc.
Signed-off-by: Jonathon Penix <jpenix@quicinc.com>
First approach had to be reverted because it did not pass tests.
Take 2 attempts to use uintptr_t instead of a pointer and cast it
to the expected pointer when necessary.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Currently, Zephyr is always sending back notifications to
AP (e.g Linux in our case) on channel 0.
But this currently doesn't work if Linux uses other channel
id for communication. So, add option to use predefined
vring ID that can accomodate Linux used ID.
Signed-off-by: Alexandru Lastur <alexandru.lastur@nxp.com>
CONFIG_ZVFS_POLL_MAX is now used to control the maximum number of poll()
entires. Thereby, CONFIG_NET_SOCKETS_POLL_MAX is redundant and shall
be deprecated.
Modify the defaults for NET_SOCKETS_POLL_MAX and ZVS_POLL_MAX so that
the deprecation actually makes sense instead of symbol removal. In case
the application still sets the old config, it will modify the
ZVS_POLL_MAX default.
Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>