Commit Graph

1733 Commits

Author SHA1 Message Date
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
Yong Cong Sin 0c4870a0f0 lib: posix: mutex: implement pthread_mutexattr_setprotocol
Implement and test `pthread_mutexattr_setprotocol()`.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-08-05 11:32:43 +02:00
Yong Cong Sin 50f47a44b7 lib: posix: mutex: check args of pthread_mutexattr_getprotocol
Perform arguments checking in the
`pthread_mutexattr_getprotocol()` function.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-08-05 11:32:43 +02:00
Yong Cong Sin 2ccfe8202d lib: posix: add stubs for thread-safe grp & pwd functions
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>
2024-08-05 10:17:27 +02:00
Yong Cong Sin b7ad4c53b0 posix: fs: implement readdir_r
Add implementation for `readdir_r()`.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-08-05 10:17:27 +02:00
Yong Cong Sin 91abf0e329 posix: fs: implement `fdatasync()`
`fdatasync()` is basically equivalent to `fsync()` according
to the standards.

Added test for it.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-07-29 14:14:33 +02:00
Pieter De Gendt ad63ca284e kconfig: replace known integer constants with variables
Make the intent of the value clear and avoid invalid ranges with typos.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-07-27 20:49:15 +03: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
Chris Friedt ac52bd629d posix: deprecated: remove new options without deprecation
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>
2024-07-18 16:28:02 -04:00
Gerard Marull-Paretas 28a515982c lib: libc: errno: remove non-existing c_std_lib doxygen group
Some groups were being added to a non-existing group: c_std_lib

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2024-07-18 09:23:33 -04:00
Yong Cong Sin 0155c6f87f lib/libc: minimal: remove deprecated headers
This headers have been deprecated for > 2 releases,
remove them.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-07-12 20:38:20 -04:00
Evgeniy Paltsev 89f3d220d4 tests: posix: headers: fix build error when minimal libc is used
The `tests/posix/headers/portability.posix.headers.without_posix_api`
test fails to build in case of toolchain which uses minimal libc by
default (for example ARC MWDT toolchain).

It can be easily fixed by providing sighal.h handler in minimal libc

Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
2024-07-12 05:49:28 -04:00
Evgeniy Paltsev d8929b5dc6 posix: shm: fix build error with minimal libc
In `lib/posix/options/shm.c` we don't include stdio.h
header but use standard SEEK_xxx definitions (i.e. `SEEK_SET`)
which cause build issues (if the minimal libc is used).

Fix that.

Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
2024-07-10 14:40:48 +02:00
Yong Cong Sin f87539081d lib/libc: picolibc: select its source with Kconfig choice
Implement the selection of the picolibc source in a Kconfig
choice as they are mutually exclusive.

The following table represents the possible choices, where 'X'
means that `PICOLIBC_SUPPORTED=n` and is guarded in the parent
level as `PICOLIBC=n`, so we do not need to care.

Module  Toolchain    C++   |       Choice
  0         0         0    |          X
  0         0         1    |          X
  0         1         0    |    Toolchain only
  0         1         1    |    Toolchain only
  1         0         0    |      Module only
  1         0         1    |          X
  1         1         0    |   Toolchain/Module
  1         1         1    |    Toolchain only

The current implementation favors `PICOLIBC_USE_TOOLCHAIN` over
`PICOLIBC_USE_MODULE` whenever possible, that preference is
maintained in this implementation as well - the TOOLCHAIN
source will be the default choice when the toolchain supports
it or when the C++ is enabled. Otherwise, fallback to MODULE.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-07-09 17:29:12 -04:00
Mykyta Poturai 3afd9429c0 json: Fix alignment calculation for nested objects
Currently, json array macros are passing the outer "container" struct
to the Z_JSON_ELEMENT_DESCR macro, causing the alignment to be calculated
from the outer struct which may be incorrect. Fix this by using the
biggest shift from the nested objects to calculate the alignment as the
struct size is calculated based on the biggest alignment of it's members.

Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
2024-07-09 19:02:25 +02: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
Yong Cong Sin 89bf4b2ad9 lib/libc: select PICOLIBC_SUPPORTED if toolchain has it or module exists
Currently, `PICOLIBC_SUPPORTED` could be enabled even when
neither the toolchain has picolibc nor the picolibc module is
present, this can be the case when Zephyr is built with
external toolchain (non-Zephyr SDK) + external build system
where PICOLIBC module doesn't exist.

Fix this by having `PICOLIBC_SUPPORTED` depends on either
toolchain OR module, while taking the libc++ into
consideration.

Here's the full logic table of when the PICOLIBC should
be marked as supported.

libc++  TOOLCHAIN       MODULE          PICOLIBC_SUPPORTED
  0         0             0                     0
  0         0             1                     1
  0         1             0                     1
  0         1             1                     1
  1         0             0                     0
  1         0             1                     0
  1         1             0                     1
  1         1             1                     1

Co-authored-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-07-05 12:30:42 +02:00
Yong Cong Sin 7950638e53 lib/libc: picolibc: cleanup PICOLIBC_USE_TOOLCHAIN dependencies
Since `PICOLIBC_USE_TOOLCHAIN` is available only if
`PICOLIBC` is enabled, it doesn't need to depend on the latter
again.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-07-05 12:30:42 +02: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 97e925e57d Revert "posix: device_io: require a full libc for c89 functions"
This reverts commit 6f62292d42.

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