The function writes random data to the provided buffer. Maximum
permitted buffer size is 256 bytes. On success the function returns 0,
otherwise it returns -1 and sets errno to appropriate value.
Signed-off-by: Patryk Duda <patrykd@google.com>
Add stubs for POSIX asynchronous io that return -1 and set
errno to ENOTSUP.
The functions and structures in aio.h are required by the
_POSIX_ASYNCHRONOUS_IO Option as detailed in Section E.1 of
IEEE-1003.1-2017.
The _POSIX_ASYNCHRONOUS_IO interface is required for PSE51,
PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory
for any POSIX conforming system as per Section A.2.1.3 of
IEEE-1003-1.2017.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Let's introduce a new option so components which cannot
be used with the native libC can select it.
And at this point let's already have POSIX_API select it
instead of being used in the libC choice default.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
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>
ftruncate should return -1 on errors and it needs to
set appropriate error values in errno
Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
Commit e6eb0a705b ("posix: eventfd: revise locking, signaling, and
allocation") introduced a regression where the internal flags of an
event file descriptor would be erased when calling the F_SETFL ioctl
operation.
This includes the flag EFD_IN_USE_INTERNAL which determines whether
this file descriptor has been opened, thus effectively closing the
eventfd whenever one tries to change a flag.
Signed-off-by: Celina Sophie Kalus <hello@celinakalus.de>
The `BUILD_VERSION` can be defined but empty when built
without git, causing version to be missing from the uname
version string:
```
*** Booting Zephyr OS build 3.5.0 ***
Printing everything in utsname...
sysname[7]: Zephyr
nodename[7]: zephyr
release[13]: 3.5.0
version[61]: Apr 1 2024 23:48:30
machine[8]: riscv64
uart:~$
```
Let's check if it is empty before using it, so that
`KERNEL_VERSION_STRING`, which is generated independently
with cmake can be used as a fallback:
```
*** Booting Zephyr OS build 3.5.0 ***
Printing everything in utsname...
sysname[7]: Zephyr
nodename[7]: zephyr
release[13]: 3.5.0
version[61]: 3.5.0 Apr 1 2024 23:53:48
machine[8]: riscv64
uart:~$
```
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
With CONFIG_NET_POSIX_NAMES being deprecated, convert static
inlines in headers to prototypes, and move implementations
to lib/posix/options/net.c .
Since select and poll should technically also operate on
non-socket file descriptors, these may be relocated in the
future.
Below are some reasons for this change.
1. So posix calls are regular symbols and not directly inlined
as syscalls. This is also the most portable linkage type.
2. Many posix calls are cancellation points and additional
checks are necessary within the implementation.
3. The more we add to an inline call, the less sense it makes
for that call to be inline.
4. When the implementation of a posix function changes, the
interface for it should still remain consistent.
Note: the same principles have been applied in Zephyr's
posix implementation already, e.g. clock_gettime(), so this
is nothing new.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Implement `pthread_attr_setinheritsched()` and
`pthread_attr_getinheritsched()`are required
as part of _POSIX_THREAD_PRIORITY_SCHEDULING Option Group.
signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
Implement if_indextoname(), if_freenameindex(), if_nameindex(),
and if_nametoindex() by wrapping around networking subystem
calls.
Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Implement pthread_rwlockattr_setpshared() and
pthread_rwlockattr_getpshared().
Both functions are required by the _POSIX_READER_WRITER_LOCKS
Option as detailed in Section E.1 of IEEE-1003.1-2017.
The _POSIX_READER_WRITER_LOCKS Option is required for PSE51,
PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory
for any POSIX conforming system as per Section A.2.1.3 of
IEEE-1003-1.2017.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Move the implementation of the following functions into
the posix library rather than having themn as static
inline functions.
* pthread_rwlockattr_init()
* pthread_rwlockattr_destroy()
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
clock_getres() is required by the POSIX_TIMERS Option Group
as detailed in Section E.1 of IEEE-1003.1-2017.
The POSIX_TIMERS Option Group is required for PSE51, PSE52,
PSE53, and PSE54 conformance, and is otherwise mandatory for
any POSIX conforming system as per Section A.2.1.3 of
IEEE-1003-1.2017.
With this, we have complete support for the POSIX_TIMERS
Option Group.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Support querying POSIX string configuration values (similar to
sysconf()).
confstr() is required by the POSIX_SINGLE_PROCESS Option
Group as detailed in Section E.1 of IEEE-1003.1-2017 and has
been part of the specification since POSIX-2.
The POSIX_SINGLE_PROCESS Option Group is required for PSE51,
PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory
for any POSIX conforming system as per Section A.2.1.3 of
IEEE-1003-1.2017.
With this, we have complete support for the POSIX_SINGLE_PROCESS
Option Group.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Implement `pthread_attr_setscope()` and `pthread_attr_getscope()`
are required as part of _POSIX_THREAD_PRIORITY_SCHEDULING Option Group.
signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
This PR fixes the following compiler warning:
No SOURCES given to Zephyr library: lib__posix__shell
Signed-off-by: Matthias Alleman <matthias.alleman@basalte.be>
Previously, sysconf() was only available as a macro (i.e. the
"extra-small" option).
This has the advantage of being compile-time constant, and
optimized for both space and speed. One disadvantage is that
querying an `_SC_` value that was invalid or unsupported
would result in a compile error.
Provide a "small" implementation of sysconf() (via Kconfig
choice) as a normal addressable function.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Seen this in compiler
lib/posix/options/syslog.c: In function 'setlogmask':
lib/posix/options/syslog.c:66:16: error: 'oldpri' may be used uninitialized
66 | return oldpri;
| ^~~~~~
lib/posix/options/syslog.c:59:13: note: 'oldpri' was declared here
59 | int oldpri;
| ^~~~~~
lib/posix/options/syslog.c: In function 'vsyslog':
lib/posix/options/syslog.c:83:33: error: 'mask' may be used uninitialized
83 | if ((BIT(level) & mask) == 0) {
| ~~~~~~~~~~~~~~~~~~~~^~~~
lib/posix/options/syslog.c:71:17: note: 'mask' was declared here
71 | uint8_t mask;
| ^~~~
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This PR adds declarations for the application conformance
feature test macro _POSIX_C_SOURCE.
It needs to be defined to value greater than or equal to 200112L
by the appplication.
However, Zephyr currently does not have a simple and consistent
means of specifying this value for POSIX samples, tests,
applications, and other libraries.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This service is used to get, set, and unset system
environment variables.
Note: shell parameter expansion is not supported
at this time.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Support getting and setting POSIX environment variables.
Additionally, the thread-safe BSD variant getenv_r() is
provided.
environ, getenv(), setenv(), and unsetenv() are required by
the POSIX_SINGLE_PROCESS Option Group as detailed in
Section E.1 of IEEE-1003.1-2017.
The POSIX_SINGLE_PROCESS Option Group is required for PSE51,
PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory
for any POSIX conforming system as per Section A.2.1.3 of
IEEE-1003-1.2017.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This is just a simple wrapper around Zephyr's native log api.
Note: the standard LOG_ERR syslog priority does conflict with
Zephyr's LOG_ERR() macro. This will need to be worked-around on
a case-by-case basis.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Previously, pthread_mutexattr_gettype() and
pthread_mutexattr_settype() were non-conformant and also
less safe, as they would not check whether a pthread_mutexattr_t
had been initialized prior to manipulating them. Furthermore,
they would potentially dereference NULL pointers.
Additionally, move the pthread_mutexattr_init() and
pthread_mutexattr_destroy() functions to the library, and add
some level of checking to them so that they are more than simply
static inline / no-op calls.
Lastly, reduce the size of struct pthread_mutexattr to only
what is necessary (one byte should suffice).
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
pthread_exit() does not return and therefore it does not make
sense to return NULL after it in mq_notify_thread(), and that
would constitute dead code.
Rather than explicitly exiting the thread, simply return
gracefully from the thread function, and allow the pthread to
terminate in the usual way.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
In Zephyr, things are often optimized for size first. That's how
we fit into such tight parking spaces.
This change gives more control to the user about whether the
POSIX API does any logging at all, simultaneously shrinking binary
size while improving speed.
No bytes / cycles left behind!
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This fixes CID 340851.
This should never fail, but it's also something that can be
easily verified.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This change mitigates the following cmake warning
No SOURCES given to Zephyr library: lib__posix__options
without needing to have a separate interface library
(as we do not need private headers exposed).
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Implement `sched_rr_get_interval()` POSIX APIs
as a part of PSE53 `_POSIX_PRIORITY_SCHEDULING` option group.
Functions is actually placeholders and just return `ENOSYS`
since Zephyr does not yet support processes or process scheduling.
signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
The CONFIG_APP_LINK_WITH_POSIX_SUBSYS option was originally
present so that internal POSIX implementation headers would be
on the include path.
There is no implicit need for any app or library to include
private POSIX headers. Instead, the standard POSIX API should
be used.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Previously, the POSIX shell utilities were intermixed with the
POSIX API implementation.
The POSIX shell utilities only depend on the public POSIX API,
so it makes sense to keep them in a separate subdirectory.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Implement `sched_setparam()` and `sched_setscheduler()` POSIX APIs
as a part of PSE53 `_POSIX_PRIORITY_SCHEDULING` option group.
Both functions are actually placeholders and just return `ENOSYS`
since Zephyr does not yet support processes or process scheduling.
signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
The patch introduces basic implementation of sysconf() function.
It's based on macro - that means that every function call is resolved
at compile time - and is not fully complient with POSIX standard
(the errno value is not handled and passing invalid name argument
results in compilation error). Treat this commit as a starting point
for proper sysconf() implementation. The one introduced in the patch
could stay as a defult implementation.
sysconf() documentation:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.htmlhttps://man7.org/linux/man-pages/man3/sysconf.3.htmlFixes#56670
Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
Previously timer.c was only built with CONFIG_POSIX_CLOCK=y even
though it has had its own Kconfig symbol (CONFIG_TIMER) for a
very long time.
Make POSIX_CLOCK imply TIMER rather than control whether it is
built, and adjust Kconfig / CMake as necessary.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Two functions can be used with relative ease to convert between
Zephyr and POSIX priorities and policies. Namely,
uint32_t zephyr_to_posix_priority(int32_t z_prio, int *policy)
int32_t posix_to_zephyr_priority(uint32_t priority, int policy)
These are not necessarily public API, but they helped with the
POSIX Philosophers Sample, which is in a subsequent commit.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
* initialize posix_thread and __pthread_cleanup ptrs to NULL
* check ret is zero before finalizing a thread in pthread_cancel()
Signed-off-by: Christopher Friedt <cfriedt@meta.com>