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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
`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>
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>
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>
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>
Create stubs for getpwnam_r, getpwuid_r, getgrgid_r
& getgrnam_r.
These functions are in the _POSIX_THREAD_SAFE_FUNCTIONS
option group.
Signed-off-by: Yong Cong Sin <ycsin@meta.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>
A few previously deprecated Kconfig options have not yet been
present for 1 release cycle and can (theoretically) just be
removed, without deprecation (see next commit).
* GETENTROPY
* POSIX_CONFSTR
* POSIX_ENV
* POSIX_SYSLOG
For dependency information, please see
https://docs.zephyrproject.org/3.6.0/kconfig.html#kconfig-search
Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>