Commit Graph

1758 Commits

Author SHA1 Message Date
Krzysztof Chruściński 0a54922ba7 lib: cbprintf: fix ubsan errors in cbvprintf_package (take 2)
First approach had to be reverted because it did not pass tests.
Take 2 attempts to use uintptr_t instead of a pointer and cast it
to the expected pointer when necessary.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-10-22 20:40:49 +02:00
Alexandru Lastur ec2dd19d45 samples: openamp_rsc_table: Add the option to use predefined vring ID
Currently, Zephyr is always sending back notifications to
AP (e.g Linux in our case) on channel 0.

But this currently doesn't work if Linux uses other channel
id for communication. So, add option to use predefined
vring ID that can accomodate Linux used ID.

Signed-off-by: Alexandru Lastur <alexandru.lastur@nxp.com>
2024-10-15 13:53:42 +02:00
Robert Lubos c4803752a8 net: Deprecate CONFIG_NET_SOCKETS_POLL_MAX
CONFIG_ZVFS_POLL_MAX is now used to control the maximum number of poll()
entires. Thereby, CONFIG_NET_SOCKETS_POLL_MAX is redundant and shall
be deprecated.

Modify the defaults for NET_SOCKETS_POLL_MAX and ZVS_POLL_MAX so that
the deprecation actually makes sense instead of symbol removal. In case
the application still sets the old config, it will modify the
ZVS_POLL_MAX default.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt c152fb90f8 posix: kconfig: remove select y from non-user-selectable help
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>
2024-10-14 13:01:51 +02:00
Chris Friedt 748252aa76 posix: device_io: use mode argument correctly in open()
Previously, we had only used the flags field and ignored mode
with the open() function.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt ab8b28ed7b 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-10-14 13:01:51 +02:00
Chris Friedt 399458e3b4 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-10-14 13:01:51 +02:00
Chris Friedt 1715196cff posix: device_io: implement pselect()
Implement pselect() as it's required by POSIX_DEVICE_IO

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt b3d3d4fff7 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-10-14 13:01:51 +02:00
Chris Friedt 881dc1fa7a 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-10-14 13:01:51 +02:00
Chris Friedt 5ccbaeff39 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-10-14 13:01:51 +02:00
Chris Friedt fe26de9606 posix: device_io: require a full libc for c89 functions
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().

Additionally, symbols stdin, stdout, and stderr should be
provided.

These should be provided by any conformant C library
(not by the POSIX API).

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-14 13:01:51 +02:00
Chris Friedt 6f766a0058 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-10-14 13:01:51 +02:00
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
Jordan Yates 88ee2bee39 net: buf: increase log level of timeout ignore
Notifying users that the supplied timeout is being ignored is worthy of
a higher log level than debug. Any such usage should be changed at the
application level.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-10-10 14:59:16 -04:00
Pisit Sawangvonganan ec5354cd80 lib: crc: add `crc8_rohc` for CRC-8/ROHC variant calculation
This commit introduces the `crc8_rohc` function to the CRC library,
implementing the CRC-8/ROHC (RObust Header Compression) variant.
This algorithm is widely used in networking protocols, which is commonly
found in modem subsystems.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-10-09 09:48:00 +02:00
Mykhailo Lohvynenko 03029e7bd7 json: support parsing and serializing 'uint64_t'
Introduce support for 'uint64_t' type, so that unsigned numbers
can be serialized into JSON payloads.

Signed-off-by: Mykhailo Lohvynenko <Mykhailo_Lohvynenko@epam.com>
2024-10-05 14:04:48 -04:00
Torsten Rasmussen 9d835fe464 cmake: move specs compiler and linker flags to toolchain properties
Moving specs argument to compiler and linker properties so that the
compiler and linker in use can decide how the flags are mapped / handled
for the compiler and linker in use.

This avoids specifying `--specs=spec.picolibc` for clang which prints a
warning about an unused argument.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-04 16:34:35 +01:00
Torsten Rasmussen 2e3873adde cmake: improve Zephyr link phase
Zephyr is a bare metal build where standard libs are disabled.

This means that c and runtime libraries must manually be linked in.

This has generally been handled by using CMake's link libraries handling
but the issue with that is both de-duplication but also library link
order.

Standard libraries must be linked at last location to ensure symbols
are always available, however this is not optimal with
target_link_libraries() because this would ultimately require every
library to know the c library to link with, which is not desired.

Therefore, setup standard C and runtime library linking in linker
CMake files for toolchains where this is required.

This commit expands the principle introduced with toolchain abstraction,
see PR#24851.

This means that a toolchain implementation may specify standard C,
runtime, C++, etc libraries, as well as their link order.
Because a property approach is used, then Zephyr modules, such as the
Picolibc module can adjust such properties.

An optional `zephyr_linker_finalize()` macro is called at the end of
Zephyr's CMakeList process and can be used by the toolchain
implementation to define the final linker invocation.

This aligns the linker handling flow to the principle introduced in
PR#24851 and improves the flexibility and robustness of Zephyr build
system.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-04 16:34:35 +01:00
Chris Friedt 7506274ef2 posix: use sys_sem instead of k_spinlock for pool synch
Based on Andy's talk at eoss 2024, use the sys/sem.h api instead
of the spinlock.h api to synchronize pooled elements since it
has minimal overhead like semaphores but also works from
userspace.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-10-03 17:07:05 +01:00
Lars-Ove Karlsson 8fceb6421f libc: minimal: math: Removed undefined behavior in sqrt routines
Fixed a clang config warning.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2024-09-30 17:12:43 +01:00
Lars-Ove Karlsson 0a8e1ad972 libc: minimal: math: Removed undefined behavior in sqrt routines
The previous code used casts of address of int to float pointer.
This is undefined behavior in C and may cause a compiler to
optimize code incorrectly.

I have replaced it with a union of int and float types,
eliminating the cast problem.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2024-09-30 17:12:43 +01:00
Jamie McCrae 3a15e37b5a lib: libc: common: time: Add toolchain include
This file uses something that is defined in the toolchain files,
fix a build error by including that header

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2024-09-26 13:31:03 -05: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
Keith Packard dc7c20adf9 posix: sysconf.c uses POSIX values
We need to add _POSIX_C_SOURCE to this file as it uses POSIX values from
limits.h including IOV_MAX, CHILD_MAX and ARG_MAX.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Keith Packard 5973a71e1f posix: options/shm.c needs _POSIX_C_SOURCE
This file uses PATH_MAX, which is defined in limits.h when _POSIX_C_SOURCE
is set.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Keith Packard 8d176ea97d libc/picolibc: Don't replace picolibc time _r functions
Select TC_PROVIDES_POSIX_C_LANG_SUPPORT_R to keep Zephyr from
including the common libc implementation of the various _r APIs.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Keith Packard 3eedb20d7a lib/posix: Only enable Zephyr _r APIs when toolchain doesn't
Check TC_PROVIDES_POSIX_C_LANG_SUPPORT_R before selecting
the COMMON_LIBC_*_R APIs.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Keith Packard ac3df26f0a libc/common: Remove redundant Kconfig POSIX_THREAD_SAFE_FUNCTIONS uses
POSIX_THREAD_SAFE_FUNCTIONS already selects POSIX_C_LANG_SUPPORT_R and
POSIX_C_LANG_SUPPORT_R alread selects all of the COMMON_LIBC_*_R values.
That makes the 'default y if POSIX_THREAD_SAFE_FUNCTIONS' clauses in these
symbols redundant.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Keith Packard 98debeea78 posix: Define _POSIX_C_SOURCE to gain access to POSIX functions
options/fs.c and options/timer.c both use POSIX-only functions. To ensure
those symbols are visible from the underlying C library, define
_POSIX_C_SOURCE.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Keith Packard 7f412924d3 libc/common: Define _POSIX_C_SOURCE to gain access to POSIX functions
ctime.c and localtime_r_utc.c may use POSIX-only functions; to ensure those
are visible from a POSIX-conforming C library, define _POSIX_C_SOURCE in
these source files.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00
Alberto Escolar Piedras 6ce257cc76 lib/libc/Kconfig: Fix libC depends with NATIVE_APPlICATION
NATIVE_APPlICATION (old native_posix) does not support bulding with the
any other library than the host libC (EXTERNAL_LIBC).

MINIMAL_LIBC_SUPPORTED defaulted to y always, and instead the depends
was set in the MINIMAL_LIBC choice.
This lead to the right library selected, but an incorrectly set
MINIMAL_LIBC_SUPPORTED.
Many tests filter based on MINIMAL_LIBC_SUPPORTED, so they were
not filtered out appropriately.

Let's place the depends in the right place to avoid this problem.
Also remove a redundant depends on for PICOLIBC and NEWLIB_LIBC
which already have the dependency in their respective _SUPPORTED
option.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-09-16 13:51:50 +02:00
Karthikeyan Krishnasamy 063d938aa5 lib: posix:fs: handle O_TRUNC in open()
handling of O_TRUNC flag from posix open()
to zephyr filesystem flag

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
2024-09-12 10:02:57 +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
Henrik Brix Andersen 159f7dbbb1 lib: net_buf: rename header file from zephyr/net/buf.h to zephyr/net_buf.h
Move the network buffer header file from zephyr/net/buf.h to
zephyr/net_buf.h as the implementation now lives outside of the networking
subsystem.

Add (deprecated) zephyr/net/buf.h header to maintain compatibility with old
file path.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2024-09-07 11:19:05 -05:00
Henrik Brix Andersen ced80b13bf lib: net_buf: move the network buffer implementation to lib
Move the net_buf implementation from the networking subsystem to a library
as they have no dependency on the networking subsystem.

Network buffers are used in subsystems outside of networking
(e.g. Bluetooth, USB).

Fixes: #36374

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2024-09-07 11:19:05 -05:00
Torsten Rasmussen ce0ab067e6 cmake: cleanup newlib CMakeLists.txt file
Commit 282f77e732 removed the only place
defining LIBC_INCLUDE_DIR. Remove the corresponding use of
LIBC_INCLUDE_DIR from newlib/CMakeLists.txt as this setting is no longer
being defined anywhere.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-09-04 21:26:59 +02:00
Anuj Pathak 836514c9dd sys: timeutil: expose and use macro for base year
timeutil internally uses 1900 as base year for calculation,
that is hidden from caller context. Thus declared a macro in
the public header file, and uses that macro will let caller adjust the
calulations accordingly.

Signed-off-by: Anuj Pathak <anuj@croxel.com>
2024-08-29 11:38:28 +02:00
Chris Friedt 1593954083 posix: add stubs for signal.h functions that need process support
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>
2024-08-23 10:35:11 -04:00
Chris Friedt b71062e9f8 posix: procN: add missing alias for getpid()
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>
2024-08-23 10:35:11 -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
Karthikeyan Krishnasamy abf62699cb lib: libc: stdio: add support remove api
Implement remove api to zephyr's native c library

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
2024-08-22 14:26:00 -04:00
Karthikeyan Krishnasamy f616c43c9e lib: posix: fs: add rmdir support
Implementation of rmdir, Posix style file
system API to remove directory

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
2024-08-22 14:26:00 -04:00
Yong Cong Sin fe94d4354a libc: common: implement multiple time functions
Implemented the following:
- `asctime_r()`
- `asctime()`
- `localtime()`
- `localtime_r()`
- `ctime()`
- `ctime_r()`

Specifically:
- the implementation of `localtime()` & `localtime_r()` simply
  wraps around the gmtime() & gmtime_r() functions, the
  results are always expressed as UTC.
- `ctime()` is equivalent to `asctime(localtime(clock))`, it
  inherits the limitation of `localtime()` as well, which only
  supports UTC results currently.

Added tests for these newly implemented functions.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-21 16:59:15 -04:00
Yong Cong Sin 5978e5231e lib: posix: update option group of `readdir_r()`
`readdir_r()` belongs to the following option group

POSIX_FILE_SYSTEM_R: Thread-Safe File System

Create a new Kconfig `CONFIG_POSIX_FILE_SYSTEM_R` to compile
it.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-08-21 16:59:15 -04:00
Pisit Sawangvonganan 57b5f7193b style: lib: crc: 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-08-20 10:33:51 +02:00
Marcin Niestroj 878640fa08 json: support parsing and serializing 'int64_t'
Up to now there was only support for parsing/encoding 32-bit integer
numbers, with no support for larger ones.

Introduce support for 'int64_t' type, so that large numbers can be
serialized into JSON payloads.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2024-08-13 14:58:06 +02:00
Dawid Niedzwiecki ff668a6bed libc: newlib: add config to use custom sbrk
Add a config to use the custom _sbrk function, defined by a user.

It is possible that an application doesn't want to use the entire
remaining RAM for the heap.

Signed-off-by: Dawid Niedzwiecki <dawidn@google.com>
2024-08-07 07:25:46 -04:00
Yong Cong Sin 8e1ac56847 lib: posix: mutex: stubs remaining of _POSIX_THREAD_PRIO_PROTECT
Create stub functions for the remaining of
`_POSIX_THREAD_PRIO_PROTECT` option group.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-08-05 11:32:43 +02:00