It is undefined behaviour to shift / add offsets to a null pointer.
Move to direct offset tracking to satisfy UBSAN.
Simple translation of code:
buf0 -> buf
buf +=/++ -> offset +=/++
buf = -> buf+offset =
Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
Up until now, the `__thread` keyword has been used for declaring
variables as Thread local storage. However, `__thread` is a GNU
specific keyword which thus limits compatibility with other
toolchains (for instance IAR).
This PR intoduces a new macro `Z_THREAD_LOCAL` which expands to the
corresponding C11, C23 or C++11 standard keyword based on the standard
that is specified during compilation, else it uses the old `__thread`
keyword.
Signed-off-by: Daniel Flodin <daniel.flodin@iar.com>
Add missing braces to comply with MISRA C:2012 Rule 15.6 and
also following Zephyr's style guideline.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
The buffer flags MPSC_PBUF_FULL is a shared resource to determine
whether the buffer is available. When processing drop messages,
the flag will be cleared first and then set, add spin lock protection.
Signed-off-by: Xiaolu Sun <xiaolu.sun@intel.com>
Not sure why this was returning a void * but it seems to make sense to
return the correct type instead.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Add a zephyr/printk.h header for the __printk_hook functions, these are
currently manually declared by all console drivers for no good reason.
Move the documentation into the header and also unify the way that
console drivers call the function.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Looks like this was really meant to be static, there are explicit
getters and setters for it anyway.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
When multithreading is off packet buffer should not use feature which
allows waiting for available buffer.
mpsc_pbuf is used by logging which can work in deferred mode in
no multithreading build.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This reverts commit a9a909c558.
PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.
For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This reverts commit 86b92934cc.
PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.
For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This reverts commit 2d72966516.
PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.
For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This reverts commit 93973e2ead.
PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.
For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This reverts commit 49ac1912b2.
PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.
For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This reverts commit 305ec62a6b.
PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.
For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This reverts commit 581a0f56e6.
PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.
For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This reverts commit 48dff5562c.
PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.
For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This reverts commit b18cad15b9.
PR #73978 introduced a regression.
Unfortunately this PR cannot be reverted without reverting also
Let's revert both PRs to stabilize main again towards the 3.7 release.
For more details on the issue see
https://github.com/zephyrproject-rtos/zephyr/issues/75205
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Packet buffer can be used for sharing data between cores. In that
case when any core has data cache then data cache handling must
be enabled in the module. However, it shall never be enabled when
the packet buffer is used on a single core. Adding that information
to the documentation.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
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>
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>
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>
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>
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>
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>
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>
Use `do { ... } while (false)' instead of `do { ... } while (0)'.
Use comparisons with zero instead of implicitly testing integers.
Use comparisons with NULL instead of implicitly testing pointers.
Use comparisons with NUL instead of implicitly testing plain chars.
Use `bool' instead of `int' to represent Boolean values.
Use `while (true)' instead of `while (1)' to express infinite loops.
Signed-off-by: frei tycho <tfrei@baumer.com>
Until recently, the posix api was purely a consumer of the
network subsystem. However, a dependency cycle was added as
a stop-gap solution for challenges with the native platform.
Specifically,
1. eventfd symbols conflict with those of the host
2. eventfd was excluded from native libc builds via cmake
If any part of the posix were then to select the network
subsystem (which is a legitimate use case, given that networking
is a part of the posix api), we would get a build error due to
the Kconfig dependency cycle.
As usual, with dependency cycles, the cycle can be broken
via a third, mutual dependency.
What is the third mutual dependency? Naturally, it is ZVFS
which was planned some time ago. ZVFS will be where we
collect file-descriptor and FILE-pointer APIs so that we can
ensure consistency for Zephyr users.
This change deprecates EVENTFD_MAX in favour of
ZVFS_EVENTFD_MAX.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This change deprecates CONFIG_POSIX_FS in favour of
CONFIG_POSIX_FILE_SYSTEM, which maps directly to the name of the
standard POSIX Option Group.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
The POSIX_MAX_FDS option does not correspond to any standard
POSIX option. It was used to define the size of the file
descriptor table, which is by no means exclusively used by
POSIX (also net, fs, ...).
POSIX_MAX_FDS is being deprecated in order to ensure that
Zephyr's POSIX Kconfig variables correspond to those defined in
the specification, as of IEEE 1003.1-2017. Namely,
POSIX_OPEN_MAX. CONFIG_POSIX_MAX_OPEN_FILES is being deprecated
for the same reason.
To mitigate any possible layering violations, that option is
not user selectable. It tracks the newly added
CONFIG_ZVFS_OPEN_MAX option, which is native to Zephyr.
With this deprecation, we introduce the following Kconfig
options that map directly to standard POSIX Option Groups by
simply removing "CONFIG_":
* CONFIG_POSIX_DEVICE_IO
Similarly, with this deprecation, we introduce the following
Kconfig options that map directly to standard POSIX Options by
simply removing "CONFIG":
* CONFIG_POSIX_OPEN_MAX
In order to maintain parity with the current feature set, we
introduce the following Kconfig options.
* CONFIG_POSIX_DEVICE_IO_ALIAS_CLOSE
* CONFIG_POSIX_DEVICE_IO_ALIAS_OPEN
* CONFIG_POSIX_DEVICE_IO_ALIAS_READ
* CONFIG_POSIX_DEVICE_IO_ALIAS_WRITE
Gate open(), close(), read(), and write() via the
CONFIG_POSIX_DEVICE_IO Kconfig option and move
implementations into device_io.c, to be conformant with the
spec.
Lastly, stage function names for upcoming ZVFS work, to be
completed as part of the LTSv3 Roadmap (e.g. zvfs_open(), ..).
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
With this change, we collect implementations of functions that are
part of the POSIX_FD_MGMT Option Group into one compilation unit
(fd_mgmt.c) and provide a matching Kconfig symbol that is
reflective of the standard.
Additionally, provide Kconfig options for aliases of those functions
since Newlib-based toolchains internally use an underscore-prefixed
alias for many POSIX functions (in this case _lseek).
Prefix Zephyr-native implementations with zvfs_ to prepare for the
up-coming changes in that area.
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.
Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.
Updated the includes path of in-tree sources accordingly.
Most of the changes here are scripted, check the PR for more
info.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>