__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>
MWDT requires function to be declared with argument types.
This PR provides explisitly type cast for out routine
inside z_cbvprintf_impl().
This PR also actual to LLVM-based compilers with strict
rules of compilation. It covers warnings generated with
additional flag -Wincompatible-function-pointer-types-strict.
This fixes https://github.com/zephyrproject-rtos/zephyr/issues/74562
Signed-off-by: Nikolay Agishev <agishev@synopsys.com>
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>
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>
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>
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>
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>
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>
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>
Create a compatibility Kconfig option for libc's that provide
their own stdin, stdout, stderr variables.
These are POSIX variables, so eventually we may want to
consider defaulting this option to 'y' and maybe providing
some zvfs abstraction for them.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
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().
These should be provided by any conformant C library
(not by the POSIX API).
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Only invoke vtable methods read, write, and close if they are
non-NULL.
The close() vtable method is optional, so that should not return
an error if zvfs_close() is called and that method is
unimplemented.
Otherwise, if zvfs_read() or zvfs_write() are called and the
corresponding vtable method is unimplemented, fail setting
errno to EIO.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The function did not check if the provided string had a zero
length before starting to truncate, which meant that last_byte_p
could possible have pointed to the value before the string.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Make it easier for external C libraries, toolchains, and
integrators to override Zephyr's implementation of functions and
sybmols on a per-Option-Group basis.
This change adds a number of non-user-configurable Kconfig
options that block internal Cmake rules from building Zephyr's
C sources corresponding to the particular option.
This is useful, for example, if a specific C library has a smaller,
or faster, or more secure version of some symbols belonging to a
a particular option group.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
In device init phase, it will call _mbedtls_init before malloc_prepare
as mbedtls has higher priority defined in SYS_INIT..
_mbedtls_init() will call psa_crypto_init() and malloc buffer,
but z_malloc_heap is not initialized, which will cause device hang.
Should call malloc_prepare() before _mbedtls_init to fix this issue,
so add new Kconfig to increase the priority of libc to deafult 30.
Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
When a new stack is allocated successfully in pthread_attr_setstacksize,
the new address should be printed not the original one.
Signed-off-by: Paul He <pawpawhe@gmail.com>
Remove two casts since the type was already the same.
Otherwise, the casts caused a warning with IAR tools.
Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
For each of the fdtable.h functions listed below, convert the
z_ prefixed semi-private functions to use the zvfs_ prefix.
ZVFS stands for Zephyr Virtual File System and
is intended to be a common library used by the C library,
POSIX API, Networking, Filesystem, and other areas.
There are already a few functions in fdtable.h that use the
zvfs_ prefix, so this change is mostly about unifying them in
a way that uses a suitable prefix ("namespace") so that it can
be considered a public API.
- z_alloc_fd
- z_fdtable_call_ioctl
- z_finalize_fd
- z_finalize_typed_fd
- z_free_fd
- z_get_fd_obj
- z_get_fd_obj_and_vtable
- z_get_obj_lock_and_cond
- z_reserve_fd
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
* Move ctors and init_array from the CPP library
to the kernel library, as this is common for both C
and C++ and it is the kernel who is running it.
* Rename the hidden kconfig option CPP_STATIC_INIT_GNU
STATIC_INIT_GNU instead.
* If STATIC_INIT_GNU is not selected verify there is
constructors left behind.
* Rename common-rom-cpp.ld to common-rom-init.ld
* Rename z_cpp_init_static to z_init_static,
and have the kernel always call it.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Signed-off-by: Keith Packard <keithp@keithp.com>
The `SIGNO_WORD_IDX` & `SIGNO_WORD_BIT` macros should have
used its own argument `_signo` instead of `signo`. It didn't
cause and error because the function's argument has `signo`.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
If both `smf_set_state()` and `smf_set_handled()` are called in
a run action, the `internal->handled` bit would not be reset.
This could cause an issue on the next run action by not
propagating events to parents.
Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
The following heap-related Kconfigs shared by the picolibc &
minimal libc have been deprecated for more than 2 releases,
remove them and update the Kconfigs accordingly:
- `CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE`
- `CONFIG_MINIMAL_LIBC_REALLOCARRAY`
Cleanup the handling to support the deprecated malloc arena
size configuration values.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
The following Kconfigs have been deprecated for more than 2
releases, remove them:
- `CONFIG_SUPPORT_MINIMAL_LIBC`
- `CONFIG_MINIMAL_LIBC_MALLOC`
- `CONFIG_MINIMAL_LIBC_CALLOC`
- `CONFIG_MINIMAL_LIBC_REALLOCARRAY`
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
These Kconfigs should have been deprecated for more than 2
releases, remove them:
- `CONFIG_CPP_MAIN`
- `CONFIG_CPLUSPLUS`
- `CONFIG_LIB_CPLUSPLUS`
- `CONFIG_EXCEPTIONS`
- `CONFIG_RTTI`
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
If `sys_reboot` is called during testing, the standard dump when `main`
returns will never be executed. Failing to dump at this point means any
coverage information gathered will be lost upon reboot.
Signed-off-by: Jordan Yates <jordan@embeint.com>
Both Clang [1] and (recently) GCC [2] support this flag to enable
additional codesize optimizations beyond -Os, possibly at the expense of
performance.
This tradeoff is worthwhile for some (and, Clang's -Oz seems to be
closer to GCC's -Os currently), so add a new abstraction for this flag
so users can select it as appropriate.
[1] https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-O0
[2] https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-Oz
Signed-off-by: Jonathon Penix <jpenix@quicinc.com>
Provide a stub for mprotect() to satisfy the requirement for the
base definitions / system interfaces and subsequently PSE51,
PSE52, PSE52, etc.
Currently, Zephyr's virtual memory-management API does not seem
to support modifying memory protection bits after pages have
already been mapped.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Make POSIX_PAGE_SIZE_BITS not user-configurable and tie it to
CONFIG_MMU_PAGE_SIZE if there is an MMU. Otherwise, simply
default it to something small.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Implement shm_open() and shm_unlink() to complete support for
the _POSIX_SHARED_MEMORY_OBJECTS Option.
Since mmap() support is not yet implemented in Zephyr, I/O is
limited to read(), write(), ftruncate(), lseek(), close(), for now.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
File offset actually varies on a per-file-descriptor basis,
and not with the resource that is abstracted behind the file
descriptor.
This is consistent with both the POSIX model and also the
ISO C/C++ model, so Zephyr should follow suit.
This is very work-around-y, but it's necessary to ensure
that shared memory objects, block devices, files and
directories all behave consistently.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add a mode field for struct fd_entry, as well as a new
initializer, z_finalize_typed_fd().
The constants ZVFS_MODE_* may be used to differentiate
between fifo, character device, message queues, directories,
semaphores, block devices, shared memory objects, regular files,
symbolic links, and sockets.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add support for mlockall() and munlockall(). These two functions
comprise the _POSIX_MEMLOCK Option which is required by PSE51,
PSE52, PSE53, and PSE54.
Zephyr's on-demand paging API does not yet support pinning and
unpinning *all* virtual memory regions, so these functions are
expected to fail, setting errno to ENOSYS. Any other usage is
currently categorized as undefined behaviour.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add support for mlock() and munlock(). These two functions
comprise the _POSIX_MEMLOCK_RANGE Option which is
required by PSE51, PSE52, PSE53, and PSE54.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add stubs for mmap(), msync(), and munmap() as required by the
_POSIX_MAPPED_FILES Option and POSIX_MAPPED_FILES and
Option Group of IEEE 1003.1-2017.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The ioctl() call should be a part of the _XOPEN_STREAMS
Option in posix, so move it there.
Create a zephyr-native zvfs_ioctl() in the layer below.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Move the zvfs_ftruncate() call from fs.c to fdtable.c, as file
types other than regular files can also be truncated.
Instead of hard-wiring zvfs_ftruncate() to fs_truncate(),
add a new ZVFS_IOCTL_TRUNCATE so that the operation can be
handled with other ioctl() operations.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Route the fstat() call (part of POSIX_FILE_SYSTEM) to
zvfs_fstat() so that other types of file descriptors can also
supply file status information.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
In some function in bitarray.c, we should check the pointer
of bitarry before taking bitarray lock.
In this patch, we move the null-check assert before the use of
the struct to provide better validation than a crash.
Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>