Commit Graph

458 Commits

Author SHA1 Message Date
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
Chris Friedt ac52bd629d posix: deprecated: remove new options without deprecation
A few previously deprecated Kconfig options have not yet been
present for 1 release cycle and can (theoretically) just be
removed, without deprecation (see next commit).

* GETENTROPY
* POSIX_CONFSTR
* POSIX_ENV
* POSIX_SYSLOG

For dependency information, please see
https://docs.zephyrproject.org/3.6.0/kconfig.html#kconfig-search

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-07-18 16:28:02 -04:00
Evgeniy Paltsev d8929b5dc6 posix: shm: fix build error with minimal libc
In `lib/posix/options/shm.c` we don't include stdio.h
header but use standard SEEK_xxx definitions (i.e. `SEEK_SET`)
which cause build issues (if the minimal libc is used).

Fix that.

Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
2024-07-10 14:40:48 +02:00
Alberto Escolar Piedras 97e925e57d Revert "posix: device_io: require a full libc for c89 functions"
This reverts commit 6f62292d42.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 61e81a7ba8 Revert "posix: device_io: provide stdin, stdout, stderr variables"
This reverts commit 86b92934cc.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras c69ff543ed Revert "posix: device_io: implement pread() and pwrite()"
This reverts commit 2d72966516.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 1df86af309 Revert "net: sockets: move poll implementation to zvfs"
This reverts commit 93973e2ead.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 14e4de6415 Revert "net: sockets: move select() implementation to zvfs"
This reverts commit 49ac1912b2.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 1a2d508e68 Revert "posix: device_io: implement pselect()"
This reverts commit 305ec62a6b.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras a111cec63d Revert "posix: device_io: implement fdopen()"
This reverts commit 581a0f56e6.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 9f38377a66 Revert "posix: device_io: implement fileno()"
This reverts commit 48dff5562c.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras ade54b35ca Revert "posix: device_io: use mode argument correctly in open()"
This reverts commit 499a633976.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras db5266caa4 Revert "posix: kconfig: remove select y from non-user-selectable help"
This reverts commit b82b5b0734.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 9a02561406 Revert "posix: procN: add missing alias for getpid()"
This reverts commit be086f174c.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 772ba464f7 Revert "posix: add stubs for signal.h functions that need process support"
This reverts commit b2243af32d.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 72e2787e70 Revert "posix: fd_mgmt: implement dup(), dup2(), fseeko(), and ftello()"
This reverts commit b18cad15b9.

PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.

For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-07-03 15:03:05 -04:00
Ederson de Souza d83a649a67 lib/posix: Get uptime in ticks instead of cycles
__z_clock_nanosleep function was getting current time in cycles, via
k_cycle_get_32(), to perform its time calculations. However, when calling
k_sleep() to actually sleep, times are measured in ticks.

This causes a problem when there's a big skew between the uptime
measured in cycles vs uptime measured in ticks: in some platforms, the
system clock maybe up for a long time already when Zephyr starts
counting ticks, for instance, while downloading an image via PXE. In
this case, the calculations done inside __z_clock_nanosleep end up
measuring a much bigger current time than expected, thus sleeping too
much, basically all the time since system clock initialization.

This patch fixes that by avoiding the cycle trip: stick to ticks,
instead. They start counting from Zephyr initialization instead, which
is the expected uptime.

Fixes #69608

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2024-06-28 21:01:54 -04:00
Chris Friedt b18cad15b9 posix: fd_mgmt: implement dup(), dup2(), fseeko(), and ftello()
Implement the remaining functions from the POSIX_FD_MGMT Option
Group that are part of POSIX, and add the
CONFIG_REQUIRES_FULL_LIBC dependency to CONFIG_POSIX_FD_MGMT, to
pull in the remaining C89 functions.

The POSIX_FD_MGMT Option Group is required for PSE52, PSE53, and
PSE54 Subprofiling Option Groups.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-27 15:17:56 -04:00
Chris Friedt b2243af32d 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-06-27 15:16:50 -04:00
Chris Friedt be086f174c 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-06-27 15:16:50 -04:00
Chris Friedt b82b5b0734 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-06-27 09:01:23 -04:00
Chris Friedt 499a633976 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-06-27 09:01:23 -04:00