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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
`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>
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>
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>