Commit graph

1905 commits

Author SHA1 Message Date
Chris Friedt
8609a05236 posix: options: mlock: refine imply for MMU and DEMAND_PAGING
POSIX mlock() and munlock() require an MMU as well as
DEMAND_PAGING.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-01-11 18:31:02 +01:00
Daniel Leung
f81add2f65 posix: pin init functions and data for demand paging
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>
2025-01-11 04:36:38 +01:00
Nicolas Pitre
46aa6717ff Revert "arch: deprecate _current"
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>
2025-01-10 07:49:08 +01:00
Chris Friedt
d58a5ce580 posix: options: mmap: disable xtensa support due to linker issue
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>
2025-01-09 15:50:26 +01:00
Chris Friedt
cee9166dee posix: options: mlockall: include toolchain header
Include the toolchain header because ARG_UNUSED() is
not defined.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-01-09 15:49:57 +01:00
Chris Friedt
0acea8d5e6 posix: options: mprotect: include toolchain header
Include zephyr/toolchain.h to get access to ARG_UNUSED().

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-01-09 15:49:42 +01:00
Chris Friedt
587490d6db posix: options: mlock: include demand paging header
Fix a compile error because `k_mem_pin()` and `k_mem_unpin()`
are not defined.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-01-09 15:49:32 +01:00
Chris Friedt
2423219ea1 posix: include: dirent: rework the dirent.h header
Declare standard functions and split type definitions into
sys/dirent.h .

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-01-08 01:29:06 +01:00
Chris Friedt
fa841fe7bd posix: fs: declare _POSIX_C_SOURCE in a consistent way
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>
2025-01-08 01:29:06 +01:00
Yong Cong Sin
1a578eb72c lib: os: mpsc_pbuf: do not wait when spinlock is held
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>
2025-01-06 06:53:52 +01:00
Chris Friedt
68c0ff4e85 posix: fcntl.h: define constants in terms of zvfs constants
Define fcntl.h constants in terms of zvfs constants.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-01-05 09:58:54 +01:00
Chris Friedt
e08cc508e1 os: fdtable: set offset to zero with newly reserved fd's
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>
2025-01-05 09:58:19 +01:00
Chris Friedt
2a2806bb40 os: fdtable: restore errno if optional locking ioctl fails
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>
2025-01-05 09:57:49 +01:00
Chris Friedt
ba8025fcd4 newlib: correct signature of _open() for xtensa
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>
2025-01-05 09:56:54 +01:00
Chris Friedt
60928a55fc posix: options: remove default setting of toolchain option
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>
2025-01-04 00:49:03 +01:00
Chris Friedt
6b103837a5 posix: options: file_system_r: include sys/util.h header for MIN
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>
2025-01-02 19:53:29 +01:00
Chris Friedt
60ef84a48e posix: options: kconfig: fix typo informnation -> information
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>
2025-01-02 19:47:36 +01:00
Chris Friedt
bc5aff3582 posix: options: fs: separate file_system_r to its own file
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>
2025-01-02 09:18:57 +01:00
Chris Friedt
00a8818a71 posix: options: fs: move posix_fs_desc to fs_priv.h
Move struct posix_fs_desc to fs_priv.h

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-01-02 09:18:57 +01:00
Keith Packard
7962dcb288 picolibc: Disable LTO while building picolibc bits
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>
2024-12-20 00:49:56 +01:00
Robert Lubos
982402a99d posix: Move POSIX configs out of experimental
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>
2024-12-19 17:37:40 +01:00
Cla Galliard
a71e0f2a29 posix: pthread: implement non-standard try-join and timed-join
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>
2024-12-15 19:24:33 +01:00
Fin Maaß
a9a475e525 lib: libc: newlib: Don't replace newlib libc time _r functions
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>
2024-12-10 08:06:25 +01:00
Fin Maaß
c221496f14 lib: libc: select POSIX_C_LANG_SUPPORT_R
also select POSIX_C_LANG_SUPPORT_R, so we can check
that, to see if gmtime_r() is available.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-12-10 08:06:25 +01:00
Fin Maaß
0418771902 lib: posix: set default of POSIX_C_LANG_SUPPORT_R
enable POSIX_C_LANG_SUPPORT_R by default if
the functions are already provided by the toolchain.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-12-10 08:06:25 +01:00
Kai Vehmanen
4b49d7cb23 lib: os: p4wq: fix K_P4WQ_DELAYED_START mode
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>
2024-12-04 22:26:38 -05:00
James Roy
c875582443 lib: posix: Fix unchecked return value in rwlock
Fix 'sys_sem_xxx' functions unchecked return value
scanned by Coverity.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2024-12-04 02:03:20 +01:00
Ilya Tagunov
bedfa5788d libc: arcmwdt: increase the number of preallocated locks
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>
2024-12-03 02:37:16 +01:00
Ilya Tagunov
0afae55b4f libc: arcmwdt: replace _write if not provided by the POSIX subsystem
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>
2024-12-03 02:37:16 +01:00
Ilya Tagunov
07b4d3a297 posix: clock: partially reformat __z_clock_nanosleep
Apply clang-format to the offending lines to make it happy.

Signed-off-by: Ilya Tagunov <Ilya.Tagunov@synopsys.com>
2024-11-28 15:41:32 +00:00
Ilya Tagunov
4c56eb6f65 posix: clock: fix potential int32_t overflow in __z_clock_nanosleep
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>
2024-11-28 15:41:32 +00:00
Ilya Tagunov
bf525851e8 posix: clock: fix 32-bit time_t overflow in __z_clock_nanosleep
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>
2024-11-28 15:41:32 +00:00
Jakub Michalski
044b702b90 posix: fix pthread thread specific data cleanup
It was never deallocationg pthread_key_data nor it was removing the node
with it from list

Signed-off-by: Jakub Michalski <jmichalski@antmicro.com>
2024-11-25 08:31:08 +01:00
Yong Cong Sin
b1def7145f arch: deprecate _current
`_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>
2024-11-23 20:12:24 -05:00
Ilya Tagunov
9f2a7a7ca2 lib: libc: arcmwdt: avoid double definition of clock_t and clockid_t
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>
2024-11-23 20:12:02 -05:00
Ilya Tagunov
390a7f8950 lib: libc: arcmwdt: move ssize_t definition from the toolchain header
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>
2024-11-23 20:12:02 -05:00
Ilya Tagunov
c8511c1ea0 lib: libc: arcmwdt: add declarations for reentrant time functions
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>
2024-11-23 20:12:02 -05:00
Ilya Tagunov
de18565e2a lib: libc: arcmwdt: replace the fileno macro
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>
2024-11-23 20:12:02 -05:00
Torsten Rasmussen
d2896df821 cmake: set minimal C++ linker properties in minimal C++ CMake impl
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>
2024-11-16 15:28:20 -05:00
Noemie Gillet
a214ddb2c9 posix: fix one-time timer for SIGEV_SIGNAL
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>
2024-11-16 15:26:42 -05:00
Meir Komet
5595f66851 multi_heap: introduce support for realloc()
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>
2024-11-16 14:02:07 -05:00
Keith Packard
c759b8ac3d libc/picolibc: Split hooks into separate files
This splits the picolibc helper functions into separate files instead of
smashing them all together.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-11-16 13:50:16 -05:00
Alberto Escolar Piedras
84dc9a1721 lib/cpp: Remove deprecated CONFIG_CPP_STATIC_INIT_GNU
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>
2024-11-16 13:36:37 -05:00
Jukka Rissanen
04d8b7c595 net: sockets: Cleanup socket properly if POSIX API is enabled
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>
2024-11-08 15:56:39 -06:00
Simon Maurer
18818c15cd openamp: resource table: fixes resource table for ram_console section
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>
2024-11-08 15:55:11 -06:00
Krzysztof Chruściński
3bf54a9e85 lib: os: cbprintf_packaged: Fix cbprintf_package_convert
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>
2024-11-01 09:56:03 -05:00
Jonathon Penix
e020f31fdb cmake: libc: minimal: Avoid linking against other libc implementations
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>
2024-10-30 14:29:37 -05:00
Krzysztof Chruściński
0a54922ba7 lib: cbprintf: fix ubsan errors in cbvprintf_package (take 2)
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>
2024-10-22 20:40:49 +02:00
Alexandru Lastur
ec2dd19d45 samples: openamp_rsc_table: Add the option to use predefined vring ID
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>
2024-10-15 13:53:42 +02:00
Robert Lubos
c4803752a8 net: Deprecate CONFIG_NET_SOCKETS_POLL_MAX
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>
2024-10-14 13:01:51 +02:00