Commit graph

529 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
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
Pisit Sawangvonganan
6a64490c34 style: lib: comply with MISRA C:2012 Rule 15.6
Add missing braces to comply with MISRA C:2012 Rule 15.6 and
also following Zephyr's style guideline.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-09-11 07:40:35 -04:00
Chris Friedt
1593954083 posix: add stubs for signal.h functions that need process support
Since Zephyr itself does not currently support processes, but
conformant applications should still be able to link, add stubs
for the remaining POSIX functions in the POSIX_SIGNALS Option
Group.

The POSIX_SIGNALS Option Group is required for PSE51, PSE52,
PSE53, PSE54, and likely many other POSIX Subprofiles.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-08-23 10:35:11 -04:00
Chris Friedt
b71062e9f8 posix: procN: add missing alias for getpid()
Newlib requires an alias for the getpid() function. There was
a Kconfig already present for doing so, but the actual alias
was missing.

So this is technically a bugfix.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-08-23 10:35:11 -04:00
Karthikeyan Krishnasamy
f616c43c9e lib: posix: fs: add rmdir support
Implementation of rmdir, Posix style file
system API to remove directory

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
2024-08-22 14:26:00 -04:00
Yong Cong Sin
fe94d4354a libc: common: implement multiple time functions
Implemented the following:
- `asctime_r()`
- `asctime()`
- `localtime()`
- `localtime_r()`
- `ctime()`
- `ctime_r()`

Specifically:
- the implementation of `localtime()` & `localtime_r()` simply
  wraps around the gmtime() & gmtime_r() functions, the
  results are always expressed as UTC.
- `ctime()` is equivalent to `asctime(localtime(clock))`, it
  inherits the limitation of `localtime()` as well, which only
  supports UTC results currently.

Added tests for these newly implemented functions.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-21 16:59:15 -04:00
Yong Cong Sin
5978e5231e lib: posix: update option group of readdir_r()
`readdir_r()` belongs to the following option group

POSIX_FILE_SYSTEM_R: Thread-Safe File System

Create a new Kconfig `CONFIG_POSIX_FILE_SYSTEM_R` to compile
it.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-21 16:59:15 -04:00
Yong Cong Sin
8e1ac56847 lib: posix: mutex: stubs remaining of _POSIX_THREAD_PRIO_PROTECT
Create stub functions for the remaining of
`_POSIX_THREAD_PRIO_PROTECT` option group.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-08-05 11:32:43 +02:00
Yong Cong Sin
0c4870a0f0 lib: posix: mutex: implement pthread_mutexattr_setprotocol
Implement and test `pthread_mutexattr_setprotocol()`.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-08-05 11:32:43 +02:00
Yong Cong Sin
50f47a44b7 lib: posix: mutex: check args of pthread_mutexattr_getprotocol
Perform arguments checking in the
`pthread_mutexattr_getprotocol()` function.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-08-05 11:32:43 +02:00
Yong Cong Sin
2ccfe8202d lib: posix: add stubs for thread-safe grp & pwd functions
Create stubs for getpwnam_r, getpwuid_r, getgrgid_r
& getgrnam_r.

These functions are in the _POSIX_THREAD_SAFE_FUNCTIONS
option group.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-08-05 10:17:27 +02:00
Yong Cong Sin
b7ad4c53b0 posix: fs: implement readdir_r
Add implementation for `readdir_r()`.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-08-05 10:17:27 +02:00
Yong Cong Sin
91abf0e329 posix: fs: implement fdatasync()
`fdatasync()` is basically equivalent to `fsync()` according
to the standards.

Added test for it.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-07-29 14:14:33 +02:00
Pieter De Gendt
ad63ca284e kconfig: replace known integer constants with variables
Make the intent of the value clear and avoid invalid ranges with typos.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-27 20:49:15 +03:00