Commit Graph

499 Commits

Author SHA1 Message Date
Carles Cufi b0f6f1d33a Revert "lib: fix ubsan errors in cbvprintf_package"
This reverts commit 6f95a50553.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2024-10-11 13:13:49 -04:00
Curtis Malainey 6f95a50553 lib: fix ubsan errors in cbvprintf_package
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>
2024-10-11 09:28:21 +02:00
Daniel Flodin 746c59c82a arch: kernel: lib: toolchain: Standardize TLS keyword
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>
2024-09-23 10:01:48 +02:00
Pisit Sawangvonganan 6a64490c34 style: lib: comply with MISRA C:2012 Rule 15.6
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>
2024-09-11 07:40:35 -04:00
Xiaolu Sun 45705a84ab logging: fix log buffer pending while it is definitely full
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>
2024-08-23 08:04:18 -04:00
Fabio Baltieri a7c8ce52f5 lib: os: change __printk_get_hook return type to printk_hook_fn_t
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>
2024-07-27 10:41:01 +03:00
Fabio Baltieri 36768aa7ff lib: os: use a typedef for __printk_hook_install argument
Use a typedef for the printk hook function argument.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-07-27 10:41:01 +03:00
Fabio Baltieri ef14c9b867 lib: os: add a header for printk hook functions
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>
2024-07-27 10:41:01 +03:00
Fabio Baltieri 84cddc6ab3 lib: os: make _char_out static
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>
2024-07-27 10:41:01 +03:00
Krzysztof Chruściński 47df73e51b lib: os: mpsc_pbuf: Do not use sem when CONFIG_MULTITHREADING=n
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>
2024-07-08 14:58:32 -04:00
Alberto Escolar Piedras 846556fa09 Revert "fdtable: read, write, close: only execute methods if non-NULL"
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>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 61e81a7ba8 Revert "posix: device_io: provide stdin, stdout, stderr variables"
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>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras c69ff543ed Revert "posix: device_io: implement pread() and pwrite()"
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>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 1df86af309 Revert "net: sockets: move poll implementation to zvfs"
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>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 14e4de6415 Revert "net: sockets: move select() implementation to zvfs"
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>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 1a2d508e68 Revert "posix: device_io: implement pselect()"
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>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras a111cec63d Revert "posix: device_io: implement fdopen()"
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>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 9f38377a66 Revert "posix: device_io: implement fileno()"
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>
2024-07-03 15:03:05 -04:00
Alberto Escolar Piedras 72e2787e70 Revert "posix: fd_mgmt: implement dup(), dup2(), fseeko(), and ftello()"
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>
2024-07-03 15:03:05 -04:00
Krzysztof Chruściński 0bb25d2e17 lib: os: spsc_pbuf: Clarify using cache management in the module
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>
2024-07-01 16:07:30 -04:00
Nikolay Agishev 5d92abeaec ARCMWDT: Fix cbprintf issue with omitted function prototype
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>
2024-06-28 07:21:11 -04:00
Chris Friedt b18cad15b9 posix: fd_mgmt: implement dup(), dup2(), fseeko(), and ftello()
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>
2024-06-27 15:17:56 -04:00
Chris Friedt 48dff5562c posix: device_io: implement fileno()
Implement fileno() as required by the POSIX_DEVICE_IO Option
Group.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-27 09:01:23 -04:00
Chris Friedt 581a0f56e6 posix: device_io: implement fdopen()
Implement fdopen(), as required by the POSIX_DEVICE_IO Option
Group.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-27 09:01:23 -04:00
Chris Friedt 305ec62a6b posix: device_io: implement pselect()
Implement pselect() as it's required by POSIX_DEVICE_IO

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-27 09:01:23 -04:00
Chris Friedt 49ac1912b2 net: sockets: move select() implementation to zvfs
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>
2024-06-27 09:01:23 -04:00
Chris Friedt 93973e2ead net: sockets: move poll implementation to zvfs
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>
2024-06-27 09:01:23 -04:00
Chris Friedt 2d72966516 posix: device_io: implement pread() and pwrite()
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>
2024-06-27 09:01:23 -04:00
Chris Friedt 86b92934cc posix: device_io: provide stdin, stdout, stderr variables
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>
2024-06-27 09:01:23 -04:00
Chris Friedt a9a909c558 fdtable: read, write, close: only execute methods if non-NULL
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>
2024-06-27 09:01:23 -04:00
Chris Friedt 9ada52f060 fdtable: replace z_ prefix with zvfs_ for fdtable.h functions
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>
2024-06-26 12:33:02 +02:00
frei tycho f17a67fee4 lib: avoided increments/decrements with side effects
- moved ++/-- before or after the value use

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-06-21 08:48:15 -04:00
Yong Cong Sin 02a47cecb9 fdtable: lseek's returned offset should start from 0
An offset of `>= 0` is valid from a `lseek` call, fix it.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 19:56:13 -04:00
Hess Nathan fe06ffb37f coding guidelines: comply with MISRA Rule 13.4
- avoid to use assignment expression value

Signed-off-by: Hess Nathan <nhess@baumer.com>
2024-06-15 05:17:26 -04:00
Jordan Yates cc328a7fbf lib: os: reboot: dump coverage info on `sys_reboot`
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>
2024-06-15 04:39:53 -04:00
Chris Friedt 58c1c48df0 fdtable: per-fd offset support, add read/write_offs() methods
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>
2024-06-14 14:01:05 -04:00
Chris Friedt 2710903014 os: fdtable: add mode field for fd_entry
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>
2024-06-14 14:01:05 -04:00
Chris Friedt 156eaab70e posix: move ioctl() from fdtable to posix
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>
2024-06-14 14:01:05 -04:00
Chris Friedt 50fc010f0f posix + fdtable: move zvfs_ftruncate() to fdtable.c
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>
2024-06-14 14:01:05 -04:00
Chris Friedt 1f9ca63b93 posix: fs: implement fstat() via zvfs_fstat()
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>
2024-06-14 14:01:05 -04:00
Hess Nathan 974bad6242 coding guidelines: comply with MISRA Rule 12.1.
-added parentheses verifying lack of ambiguities

Signed-off-by: Hess Nathan <nhess@baumer.com>
2024-06-13 20:28:23 -04:00
Hess Nathan 7fb4a748b5 coding guidelines: comply with MISRA Rule 21.15
- made explicit the copied data type

Signed-off-by: Hess Nathan <nhess@baumer.com>
2024-06-13 20:27:19 -04:00
frei tycho 77a3aec34e lib: added missing parenthesis
- added missing parenthesis around macro argument expansion

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-06-13 20:21:08 -04:00
Hess Nathan 96fdbcab70 coding guidelines: comply with MISRA Rule 15.2
- moved switch clause to avoid backward jump

Signed-off-by: Hess Nathan <nhess@baumer.com>
2024-06-13 09:23:19 +02:00
frei tycho 44782fd8af lib: change controlling expressions in if/while to Boolean
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>
2024-06-11 20:03:34 +03:00
Chris Friedt 487a8756c3 posix: eventfd: fix dependency cycle between net and posix
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>
2024-06-04 16:27:12 -05:00
Chris Friedt 9f6590c7b7 posix: deprecate POSIX_FS for POSIX_FILE_SYSTEM
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>
2024-06-04 16:27:12 -05:00
Chris Friedt bc4374b5fe posix: deprecate POSIX_MAX_FDS and add POSIX_DEVICE_IO
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>
2024-06-04 16:27:12 -05:00
Chris Friedt 3f469665f4 posix: fd_mgmt: add fd_mgmt option group
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>
2024-06-04 16:27:12 -05:00
Yong Cong Sin bbe5e1e6eb build: namespace the generated headers with `zephyr/`
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>
2024-05-28 22:03:55 +02:00