Commit graph

542 commits

Author SHA1 Message Date
Chris Friedt
82d564a354 posix: timers: correct pointer passed to k_mem_slab_free()
If it is not possible to create a timer in timer_create(),
then the timer_obj associated with the timer must be freed.

However, the address of the pointer was mistakenly being
passed to k_mem_slab_free() rather than simply the
the pointer.

This caused a crash in tests which can easily be avoided
by passing the pointer rather than the address of the
pointer.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-16 08:04:36 +02:00
Chris Friedt
7623a18c2e posix: remove deprecated kconfig options
Remove deprecated Kconfig options. These were given an extra
release cycle of soak time, but generally were OK to remove
after Zephyr v4.0.0 was released.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-03-12 19:03:52 +01:00
Chris Friedt
4c28582224 posix: threads: use non-deprecated kconfig
MAX_PTHREAD_COUNT was deprecated in favour of
POSIX_THREAD_THREADS_MAX prior to v3.7.0.

Use CONFIG_POSIX_THREAD_THREADS_MAX going forward.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-03-12 19:03:52 +01:00
Chris Friedt
33fb827603 posix: key: do not use deprecated kconfig
Use CONFIG_POSIX_THREAD_KEYS_MAX instead of
CONFIG_MAX_PTHREAD_KEY_COUNT.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-03-12 19:03:52 +01:00
Jari Tervonen
3b1e60da90 lib: posix: Fix NULL pointer to strcmp in posix mqueue.
When a queue has been unlinked but not removed the name pointer is set to
NULL. The queue is still in the list when adding new queues and the name
pointer is passed to strcmp.

Signed-off-by: Jari Tervonen <jari.tervonen@nordicsemi.no>
2025-03-08 03:37:48 +01:00
Chris Friedt
bca2ef672e posix: mem: remove imply MMU from POSIX options
With MMU being converted to a non-user-configurable option, we can
rely on that exclusively to know whether arch_mem_map() and
arch_mem_unmap() are available and we can remove the workarounds
in POSIX at the Kconfig level.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-02-19 04:59:33 +01:00
Chris Friedt
f4259c384f posix: options: add xsi realtime option group
Add a POSIX Option Group called XSI_REALTIME (with Kconfig
option CONFIG_XSI_REALTIME).

When XSI_REALTIME is selected (or when required POSIX Options
are enabled), define _XOPEN_REALTIME to be something other
than -1 (_XOPEN_VERSION seemed appropriate).

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-02-03 09:05:09 +01:00
Chris Friedt
d08d63676b posix: options: split kconfig.xsi into separate option groups
Since XSI is composed of several distinct POSIX Option Groups
split Kconfig.xsi into separate files - one for each Option
Group.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-02-03 09:05:09 +01:00
Chris Friedt
0ac931b386 posix: options: profiles: uncomment options that should be selected
For the REALTIME_MINIMAL Application Environment Profile, uncomment
the POSIX_MEMLOCK, POSIX_MEMLOCK_RANGE, POSIX_MEMORY_PROTECTION,
POSIX_MAPPED_FILES, and POSIX_SHARED_MEMORY_OBJECTS options.

These should have been uncommented back when Kconfig options for
those features were added, so this can probably be called a
Kconfig bug.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-02-03 09:05:09 +01:00
Chris Friedt
8ab6e29cf1 posix: shm: ensure addend is less than INTPTR_MAX
Although it's quite unlikely that we will see shared memory
objects in practice that are greater than 2GiB, there is a
possibility of integer overflow when comparing intptr_t and
size_t, since the former is signed and the latter is unsigned.

Explicitly check to ensure that the addend is less than
INTPTR_MAX before subtraction.

This fixes CID 487734

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-01-30 20:27:59 +01:00
Chris Friedt
f81293d0dc posix: semaphore: explicitly ignore return of k_mutex_unlock()
The nsem_list_unlock() static inline function looks as though it
was designed to always ignore the return value of
k_mutex_unlock(), presumably for performance reasons.

A quick audit of the code looks as though the call should
always succeed.

Prepend (void) to the call to avoid the coverity defect in the
future.

CID 444386

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-01-30 20:27:48 +01:00
Pisit Sawangvonganan
e3a4a16594 lib: fix typo in multiple directories
Utilize a code spell-checking tool to scan for and correct spelling errors
in various files within the `lib` directory.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-01-28 00:06:18 +01:00
Chris Friedt
dba7598517 posix: options: shm: use truncation flag that has been added
Originally, when the POSIX_SHARED_MEMORY_OBJECTS option was
added, the O_TRUNC flag was not consistently available.

Now that it is consistently available, ensure it is used
within the shm_open() function.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-01-23 00:12:58 +01:00
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
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
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
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ß
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
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
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
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
Chris Friedt
c152fb90f8 posix: kconfig: remove select y from non-user-selectable help
Several help prompts for non-user-selectable Kconfig options
included the phrase "select 'y' here", which does not make
any sense in this situation.

Adjust the help sections to use more appropriate language.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt
748252aa76 posix: device_io: use mode argument correctly in open()
Previously, we had only used the flags field and ignored mode
with the open() function.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt
ab8b28ed7b posix: device_io: implement fileno()
Implement fileno() as required by the POSIX_DEVICE_IO Option
Group.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt
399458e3b4 posix: device_io: implement fdopen()
Implement fdopen(), as required by the POSIX_DEVICE_IO Option
Group.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt
1715196cff posix: device_io: implement pselect()
Implement pselect() as it's required by POSIX_DEVICE_IO

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt
b3d3d4fff7 net: sockets: move select() implementation to zvfs
Move the implementation of zsock_select() to zvfs_select(). This
allows other types of file descriptors to also make use of
select() functionality even when the network subsystem is not
enabled.

Additionally, it partially removes a dependency cycle between
posix and networking by moving functionality into a mutual
dependency.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt
881dc1fa7a net: sockets: move poll implementation to zvfs
Move the implementation of zsock_poll to zvfs_poll. This allows
other types of file descriptors to also make use of poll()
functionality even when the network subsystem is not enabled.

Additionally, it partially removes a dependency cycle between
posix and networking by moving functionality into a mutual
dependency.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt
5ccbaeff39 posix: device_io: implement pread() and pwrite()
Add pread() and pwrite() implementations, which are nearly
identical to read() and write() but differ in that they do not
update the file-descriptor offset and instead read from a
specific file offset.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt
fe26de9606 posix: device_io: require a full libc for c89 functions
The POSIX_DEVICE_IO Option Group requires a number of c89
functions mainly from stdio.h .

Namely,

clearerr(), fclose(), feof(), ferror(), fflush(), fetc(),
fgets(), fprintf(), fputc(), fputs(), fread(), freopen(),
fscanf(), fwrite(), getc(), getchar(), gets(), perror(),
printf(), putc(), putchar(), puts(), scanf(), setbuf(),
setvbuf(), ungetc(), vfprintf(), vfscanf(), vfprintf(), and
vscanf().

Additionally, symbols stdin, stdout, and stderr should be
provided.

These should be provided by any conformant C library
(not by the POSIX API).

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt
7506274ef2 posix: use sys_sem instead of k_spinlock for pool synch
Based on Andy's talk at eoss 2024, use the sys/sem.h api instead
of the spinlock.h api to synchronize pooled elements since it
has minimal overhead like semaphores but also works from
userspace.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-03 17:07:05 +01:00
Keith Packard
dc7c20adf9 posix: sysconf.c uses POSIX values
We need to add _POSIX_C_SOURCE to this file as it uses POSIX values from
limits.h including IOV_MAX, CHILD_MAX and ARG_MAX.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Keith Packard
5973a71e1f posix: options/shm.c needs _POSIX_C_SOURCE
This file uses PATH_MAX, which is defined in limits.h when _POSIX_C_SOURCE
is set.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Keith Packard
3eedb20d7a lib/posix: Only enable Zephyr _r APIs when toolchain doesn't
Check TC_PROVIDES_POSIX_C_LANG_SUPPORT_R before selecting
the COMMON_LIBC_*_R APIs.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Keith Packard
98debeea78 posix: Define _POSIX_C_SOURCE to gain access to POSIX functions
options/fs.c and options/timer.c both use POSIX-only functions. To ensure
those symbols are visible from the underlying C library, define
_POSIX_C_SOURCE.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Karthikeyan Krishnasamy
063d938aa5 lib: posix:fs: handle O_TRUNC in open()
handling of O_TRUNC flag from posix open()
to zephyr filesystem flag

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
2024-09-12 10:02:57 +02:00