Replace all in-function instances of MIN/MAX/CLAMP with the single
evaluation version min/max/clamp.
There's probably no race conditions in these files, but the single
evaluation ones save a couple of instructions each so they should save
few code bytes and potentially perform better, so they should be
preferred in general.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Make sure we always allocate space for stdin, stdout and stderr file
descriptors if Posix device io option is enabled.
Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
CONFIG_XOPEN_STREAMS does not follow the pattern of other XSI Option
Groups, where the Option Group name is not the same as the feature
test macro that indicates it is supported by the implementation.
Deprecate CONFIG_XOPEN_STREAMS and rename it to CONFIG_XSI_STREAMS.
For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/\
V1_chap02.html#tag_02_01_05_09
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The `sched_yield()` function was originally included to facilitate the of
POSIX_REALTIME and POSIX_THREADS_EXT Option Groups in Issue 5.
It was then marked as part of the _POSIX_PROCESS_SCHEDULING Option in
Issue 6, but then was not clearly marked as part of the
POSIX_THREADS(_BASE) Option Group until Issue 7.
Moving it to `pthread.c` (and making it a function with regular
linkage rather than inline) ensures that it will be available with the
`POSIX_THREADS` Option Group.
For more information, please see `POSIX_THREADS_BASE` in
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/\
V4_subprofiles.html and
https://pubs.opengroup.org/onlinepubs/9799919799/xrat/\
V4_subprofiles.html
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add a custom Zephyr POSIX subprofile specifically for enabling the
default features that Zephyr requires as per the coding guidelines.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The getopt sources were not formatted according to our codying style
conventions, so apply formatting rules as a separate commit.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Separate the POSIX implementation into two categories:
- Extensions to ISO C
- System Interfaces
The first category include standalone functions that generally do not
require OS support or depend on any other features within the POSIX
specification. The Option Groups that comprise this category include
- POSIX_C_LIB_EXT: e.g. strnlen(), fnmatch()
- POSIX_C_LANG_SUPPORT_R: e.g. gmtime_r(), strtok_r()
The second category includes the majority of other POSIX Option Groups
that do require OS support. The latter group may also be categorized
generally as being NATIVE_LIBC_INCOMPATIBLE, although that might
eventually become more granular.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The eventfd configuration does not need to be so deeply nested within
POSIX since it does not depend on POSIX completely.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add support for the `times()` function, which can be used to get the
number of ticks spent in "system" and "user" mode, and which returns
the "real time" that has expired, since an arbitrary point in the past.
The following invariant should always hold:
rtime <= stime + utime
The `times()` function measures time for the calling process and all
of it's child processes. In Zephyr, we don't support separate processes
(yet), so the time spent in child processes is zero.
Additionally, in Zephyr we do not differentiate between "system" time
(i.e. time spent executing kernel code) and "user" time (time spent
executing application code). We only have information on "total time"
(time spent executing code) and "execution time" (time spent executing
code plus idle time).
For now, only report utime, since it is not clear how to obtain other
values.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
1. Fix an off-by-one error in `signo_fits()` (a utility function inside
signal.c
2. Adjust expectations for C libraries that do not provide a sigset_t
large enough to support `SIGRTMIN` or `SIGRAMAX`.
This fixes an issue in CI that appeared when run under ARC.
```shell
west build -p auto -b qemu_arc/qemu_arc_hs -t run tests/posix/signals
```
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
To avoid conflicts between the C library's `time.h` and signal.h use an
"override" header (when necessary) for C libraries that do not themselves
provide POSIX definitions in `time.h` or `signal.h`.
V2
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
To avoid conflicts between the C library's `time.h` and signal.h use an
"override" header (when necessary) for C libraries that do not themselves
provide POSIX definitions in `time.h` or `signal.h`.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Convert `gethostname()` from a static inline wrapper to a normal function
with regular linkage.
This change was prompted mainly as housekeeping for #95811, but a
secondary reason was to make this a linkable symbol so that the API works
at a binary level as well (which could be provided by the toolchain as
well).
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
pwd.c and grp.c both had incorrect preprocessor guards around the stubs
that they were implementing. Functions were surrounded by
```cpp
ifdef CONFIG_POSIX_THREAD_SAFE_FUNCTIONS
..
endif /* CONFIG_POSIX_THREAD_SAFE_FUNCTIONS */
```
Which is not at all accurate, since that subprofiling option group is
`(CONFIG_)POSIX_SYSTEM_DATABASE_R` (which is a PR that is in-draft).
Remove the guards, since they are invalid anyway, and at most an
application will link properly. We don't really need the guards anyway,
since conditional compilation will be used to link the files into the
build.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Rather than keeping limits defined in a common way, controllable with one
Kconfig, move posix definitions out of the standard common libc header
`<limits.h>` into `<zephyr/posix/posix_limits.h>`, not controlled with
Kconfig. Additionally, include `<zephyr/posix/posix_limits.h>` wherever
an in-tree C library includes a custom `<limits.h>`.
Note: the only reason any of the `<limits.h>` files exist, is to define
the POSIX limit PATH_MAX without declaring `_POSIX_C_SOURCE`, which would
be necessary according to the standard, and each of the custom `<limits.h>`
files is nearly identical in this regard.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
In order to reduce conflicts with limits defined in external C libraries,
move Zephyr's POSIX limits from posix_features.h to limits.h in the
common C library sources.
In order to give the implementation better control over where POSIX
limit definitions originate, use `#include_next <limits.h>` to pull in
the corresponding header of the C library, and provide a non-user
configurable option `CONFIG_TC_PROVIDES_POSIX_LIMIT_DEFS` that may be set
in order to ensure that the C library version of POSIX limits are used.
Note: this may mean that runtime invariant values are inconsistent with
parts that are actually in use within Zephyr, so applications are
encouraged to use `sysconf()` with external C libraries that implement
parts of the POSIX standard to query system configuration values at
runtime.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Since an implementation may omit definitions of runtime invariant values
in limits.h if the corresponding value is equal to or greater than the
minimum, is unspecified, and must be queried at runtime [1], do not rely
on PAGE_SIZE being declared in limits.h .
[1]
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/limits.h.html
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Some toolchains may define CLOCK_REALTIME and
CLOCK_MONOTONIC in their libc headers
with values that differ from Zephyr's internal
SYS_CLOCK_REALTIME and SYS_CLOCK_MONOTONIC.
To ensure consistent behavior across all boards and
toolchains, Introduce a helper function to map
CLOCK_REALTIME and CLOCK_MONOTONIC to Zephyr's internal
clock IDs (SYS_CLOCK_REALTIME and SYS_CLOCK_MONOTONIC).
This prevents mismatched clock IDs being passed to
the kernel, avoiding invalid clockid errors when using
functions like clock_gettime().
Signed-off-by: Mohamed Moawad <moawad@synopsys.com>
CONFIG_NATIVE_APPLICATION, which represents the way in which
native_posix and its kin were built, was deprecated in 4.1 after the
introduction of native_sim and CONFIG_NATIVE_LIBRARY.
We remove support for it now for 4.3.
Let's remove the kconfig option and all dependencies in the kconfig
tree.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
When built with the minimal libc while using POSIX clocks, Zephyr
compilation breaks with "error: unknown type name 'clockid_t'." Use
int instead of clockid_t to eliminate the dependency.
Suggested-by: Chris Friedt <cfriedt@tenstorrent.com>
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Coverity regularly raised a CID with every release that it found
`sizeof(char **)` confusing and somehow nonportable.
With every release, it needed to be marked as a false positive.
Change `sizeof(char **)` to `sizeof(void *)` to silence the
CID warnings.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Use the newly added sys_clock API in lib/os for
* clock_gettime()
* clock_settime()
* clock_nanosleep() and nanosleep()
* gettimeofday()
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Previously, log messages would generate warnings (escalated to errors
in CI) when CONFIG_TIMEOUT_64BIT=n.
For example,
```
west build -p auto -b qemu_cortex_m0 -t run tests/posix/timers/ \
-- -DCONFIG_TIMEOUT_64BIT=n
..
warning: format '%llx' expects argument of type \
'long long unsigned int', but argument 3 has type 'k_ticks_t' \
{aka 'unsigned int'}
```
Use portable print specifiers and cast the argument to int64_t.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add a dedicated symbol for including the POSIX system headers path
directly into the include path, enabling (for example)
`#include <time.h>` instead of `#include <zephyr/posix/time.h>`.
Signed-off-by: Jordan Yates <jordan@embeint.com>
It's possible for newlib/picolib libc libraries to
internally call sysconf() which would execute zephyr's
implementation. However, if the _SC* defines do not have
matching values, then the incorrect switch case executes.
This issue arises when using newlib/picolib libc that includes
sysconf implementation for ARM. With current defaults, the
zephyr sysconf() overrides the original libc sysconf() so
we must ensure proper operation.
We will switch to the #define list just like newlib/picolib.
We can't currently use their unistd.h directly due to a domino
of declaration conflicts.
For the "small" macro implementation, we have to drop using
CONCAT to prevent pre-expansion of the new #defines
Signed-off-by: Nicholas Lowell <Nicholas.Lowell@lexmark.com>
match standard by having input void *buf parameter
for pwrite() marked as const, and avoid any potential
declaration conflicts
Signed-off-by: Nicholas Lowell <Nicholas.Lowell@lexmark.com>
static inline gethostname() in unistd.h can cause declaration collisions.
we should just move it to a normal function definition like the
rest of the network functions.
Signed-off-by: Nicholas Lowell <Nicholas.Lowell@lexmark.com>
Use the newly added timespec util functions to manipulate and
compare timespec structures with overflow detection.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Compiler gets confused and thinks base may be used uninitialized. This
shouldn't be possible, but to make the warning go away, initialize it.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Implement the POSIX_CLOCK_SELECTION Option Group.
This was mostly already done, but compiled / linked in the wrong places.
E.g. pthread_condattr_getclock() and pthread_condattr_setclock() were
in pthread.c and part of POSIX_THREADS_BASE. clock_nanosleep() was in
clock.c and part of POSIX_TIMERS.
This change builds them as part of clock_selection.c with
CONFIG_POSIX_CLOCK_SELECTION.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
gettimeofday() was already implemented, but incorrectly lumped into
POSIX_TIMERS.
putenv() is really just a wrapper around setenv().
The only one left to implement was gethostid() which was relatively
trivial.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Move most implementations to clock_common.c in preparation for
moving gettimeofday() and clock_nanosleep() to different compilation
units.
We also take this as an opportunity to switch from using k_spinlock
to sys_sem.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
To facilitate moving gettimeofday() and clock_nanosleep() to separate
compilation units, make z_clock_nanosleep(), z_clock_gettime(),
and z_clock_settime() convenience functions.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Move most implementations to env-common.c in preparation for adding
putenv.c .
We also take this as an opportunity to switch from using k_spinlock
to sys_sem.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>