Commit graph

561 commits

Author SHA1 Message Date
Chris Friedt
4137c489d8 posix: env: create z_getenv()..z_setenv() convenience functions
To facilitate adding putenv in a separate compilation unit,
make z_getenv(), z_getenv_r(), z_setenv(), and z_unsetenv()
convenience functions.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-13 22:23:21 -04:00
Chris Friedt
76e1fc7713 tests: posix: move tv_to_ts to posix_clock.h
Move the private static inline function tv_to_ts() to posix_clock.h .

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-04 19:56:02 +02:00
Benjamin Cabé
f412cc643d posix: fix typo in pthread_cond_init
Update the casting of the 'attr' parameter in pthread_cond_init to use
the correct variable name 'att'. Thanks clang for spotting the typo.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-04-25 19:03:28 +02:00
Chris Friedt
e71c12c68f posix: refactor timespec_to_timeoutms() to use tp_diff()
Use the tp_diff() macro as a means of converting an absolute timeout
with respect to a specific clock to a relative timeout, in ms.

Clamp the result between 0 and UINT32_MAX.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
89c1f15a6e posix: move timespec functions to posix_clock.h
Move somewhat useful (but private and internal functions) that deal
with struct timespec to posix_clock.h until there is a better API
available for dealing with operations on struct timespec.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
d40be58093 posix: doc: hide internal posix_clock.h functions from doxygen
Prevent doxygen from parsing internal functions declared in
posix_clock.h .

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
615ae7e1b5 posix: always require clockid_t argument to timespec_to_timeoutms()
Always require the clockid_t argument to timespec_to_timeoutms() and
remove the unused variant that accepts no clockid_t parameter.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
a10f96e153 posix + tests: use CLOCK_REALTIME where specified by POSIX
Use CLOCK_REALTIME for the default clock source throughout
the POSIX implementation and tests so that we are
consistent with the specification.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
e75f285bd1 posix: add timespec_is_valid() private internal function
Add a common private function timespec_is_valid() that
can be used to check if a timespec object is valid, and
use that consistently in lib/posix/options.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
bb9ec32cf6 posix: cond: use clock specified via pthread_condattr_t
Use the clock specified via pthread_condattr_t in
pthread_cond_timedwait().

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
8b60aa75fa posix: cond: check whether condattr is initialized in attr fns
Check whenther a pthread_condattr_t has been initialized in
pthread_condattr_*() functions.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
ce7ae220a2 posix: cond: use struct posix_cond and struct posix_condattr internally
Use struct posix_cond and struct posix_condattr internally.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
f208e3b02a posix: posix_internal: add definitions for posix_condattr, posix_cond
Add definitions for struct posix_condattr and struct posix_cond, which
are internal variants of the external pthread_condattr_t and
pthread_cond_t types.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
241469af9a posix: provide timespec_to_clock_timeoutms
Provide a private internal function timespec_to_clock_timeoutms() to
complement timespec_to_timeoutms(). This new variant accepts a clock_t
parameter that allows the caller to specify which clock to use.

The original timespec_to_timeoutms() then just becomes a static inline
wrapper around the original.

Note: timespec_to_clock_timeoutms() and timespec_to_timeoutms() might
have a limited lifespan, since it might make sense to create a
common timespec manipulation library.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
fffbd76683 posix: declare timespec_to_timeoutms() in posix_clock.h
Provide a single declaration of timespec_to_timeoutms() (which is
a private function), in the private header file posix_clock.h .

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Chris Friedt
0449324257 posix: semaphores: use a default minimal heap-add for semaphores
The implementation of POSIX_SEMAPHORES historically used heap allocation
and has not yet been transitioned to a pool allocator.

However, since 590258b381, the default heap-add with CONFIG_POSIX_API
has been reduced from 1 kiB which causes tests/posix/semaphores to fail
due to NULL being returned from a call to k_calloc().

Create a minimal heap-add for the POSIX_SEMAPHORES Option Group.

This can be removed at a future date if semaphores are changed to use
a pooled allocator and fixed-size name, rather than heap allocation.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-22 14:03:10 +02:00
Jordan Yates
590258b381 posix: options: POSIX_THREADS require a stack
`pthread_setspecific` requires a stack in order to allocate the
`struct pthread_key_data` data structure. On 64 bit systems this data
structure is 32 bytes, resulting in 160 bytes usage for the default 5
supported threads.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-18 12:36:58 +02:00
Jordan Yates
3da69a809c posix: options: don't imply POSIX_MESSAGE_PASSING
Don't `imply POSIX_MESSAGE_PASSING` when `POSIX_API=y` as this option
has a non-trivial RAM implication in `HEAP_MEM_POOL_ADD_SIZE_MQUEUE`.

The `mq_*` API is minimally used in-tree, with all users already
enabling the symbol directly.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-04-18 12:36:58 +02:00
Daniel Hajjar
69713f4e6a posix: net: Fix undefined behavior
The signedness of the variable caused undefined behavior because the
sign bit is modified when it gets left-shifted.

This fixes that by changing it to an unsigned variable.

Signed-off-by: Daniel Hajjar <daniel.hajjar16@gmail.com>
2025-04-17 09:05:56 +02:00
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