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>
If it is not possible to create a timer in timer_create(),
then the timer_obj associated with the timer must be freed.
However, the address of the pointer was mistakenly being
passed to k_mem_slab_free() rather than simply the
the pointer.
This caused a crash in tests which can easily be avoided
by passing the pointer rather than the address of the
pointer.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Remove deprecated Kconfig options. These were given an extra
release cycle of soak time, but generally were OK to remove
after Zephyr v4.0.0 was released.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
MAX_PTHREAD_COUNT was deprecated in favour of
POSIX_THREAD_THREADS_MAX prior to v3.7.0.
Use CONFIG_POSIX_THREAD_THREADS_MAX going forward.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
When a queue has been unlinked but not removed the name pointer is set to
NULL. The queue is still in the list when adding new queues and the name
pointer is passed to strcmp.
Signed-off-by: Jari Tervonen <jari.tervonen@nordicsemi.no>
With MMU being converted to a non-user-configurable option, we can
rely on that exclusively to know whether arch_mem_map() and
arch_mem_unmap() are available and we can remove the workarounds
in POSIX at the Kconfig level.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add a POSIX Option Group called XSI_REALTIME (with Kconfig
option CONFIG_XSI_REALTIME).
When XSI_REALTIME is selected (or when required POSIX Options
are enabled), define _XOPEN_REALTIME to be something other
than -1 (_XOPEN_VERSION seemed appropriate).
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Since XSI is composed of several distinct POSIX Option Groups
split Kconfig.xsi into separate files - one for each Option
Group.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
For the REALTIME_MINIMAL Application Environment Profile, uncomment
the POSIX_MEMLOCK, POSIX_MEMLOCK_RANGE, POSIX_MEMORY_PROTECTION,
POSIX_MAPPED_FILES, and POSIX_SHARED_MEMORY_OBJECTS options.
These should have been uncommented back when Kconfig options for
those features were added, so this can probably be called a
Kconfig bug.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Although it's quite unlikely that we will see shared memory
objects in practice that are greater than 2GiB, there is a
possibility of integer overflow when comparing intptr_t and
size_t, since the former is signed and the latter is unsigned.
Explicitly check to ensure that the addend is less than
INTPTR_MAX before subtraction.
This fixes CID 487734
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The nsem_list_unlock() static inline function looks as though it
was designed to always ignore the return value of
k_mutex_unlock(), presumably for performance reasons.
A quick audit of the code looks as though the call should
always succeed.
Prepend (void) to the call to avoid the coverity defect in the
future.
CID 444386
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Utilize a code spell-checking tool to scan for and correct spelling errors
in various files within the `lib` directory.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
Originally, when the POSIX_SHARED_MEMORY_OBJECTS option was
added, the O_TRUNC flag was not consistently available.
Now that it is consistently available, ensure it is used
within the shm_open() function.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>