Commit graph

1698 commits

Author SHA1 Message Date
Yong Cong Sin
9a8d1360cb posix: signal: use the provided argument in the macros
The `SIGNO_WORD_IDX` & `SIGNO_WORD_BIT` macros should have
used its own argument `_signo` instead of `signo`. It didn't
cause and error because the function's argument has `signo`.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-25 19:13:30 -04:00
Glenn Andrews
87db81e5cd Lib: SMF: fix stuck handled bit when transitioning
If both `smf_set_state()` and `smf_set_handled()` are called in
a run action, the `internal->handled` bit would not be reset.

This could cause an issue on the next run action by not
propagating events to parents.

Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
2024-06-24 14:50:00 -04:00
Jordan Yates
07870934e3 everywhere: replace double words
Treewide search and replace on a range of double word combinations:
    * `the the`
    * `to to`
    * `if if`
    * `that that`
    * `on on`
    * `is is`
    * `from from`

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-22 05:40:22 -04: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
Yong Cong Sin
3ecef55179 posix: shm: offset should compare with the shm size
The read/write offset should have compared with the size of
the shm object, not the size of the buffer.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 19:56:13 -04:00
Yong Cong Sin
19e4cb8f89 libc: cleanup deprecated heap-related Kconfigs
The following heap-related Kconfigs shared by the picolibc &
minimal libc have been deprecated for more than 2 releases,
remove them and update the Kconfigs accordingly:

- `CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE`
- `CONFIG_MINIMAL_LIBC_REALLOCARRAY`

Cleanup the handling to support the deprecated malloc arena
size configuration values.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 14:33:58 -04:00
Yong Cong Sin
c22c98e510 libc: minimal: remove deprecated Kconfigs
The following Kconfigs have been deprecated for more than 2
releases, remove them:

- `CONFIG_SUPPORT_MINIMAL_LIBC`
- `CONFIG_MINIMAL_LIBC_MALLOC`
- `CONFIG_MINIMAL_LIBC_CALLOC`
- `CONFIG_MINIMAL_LIBC_REALLOCARRAY`

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 14:33:58 -04:00
Yong Cong Sin
67578faefe lib: cpp: remove deprecated Kconfigs
These Kconfigs should have been deprecated for more than 2
releases, remove them:

- `CONFIG_CPP_MAIN`
- `CONFIG_CPLUSPLUS`
- `CONFIG_LIB_CPLUSPLUS`
- `CONFIG_EXCEPTIONS`
- `CONFIG_RTTI`

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 14:33:58 -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
Jonathon Penix
d6041d62b3 cmake: kconfig: Add new abstraction for -Oz optimization level
Both Clang [1] and (recently) GCC [2] support this flag to enable
additional codesize optimizations beyond -Os, possibly at the expense of
performance.

This tradeoff is worthwhile for some (and, Clang's -Oz seems to be
closer to GCC's -Os currently), so add a new abstraction for this flag
so users can select it as appropriate.

[1] https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-O0
[2] https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-Oz

Signed-off-by: Jonathon Penix <jpenix@quicinc.com>
2024-06-14 19:05:50 -04:00
Chris Friedt
2d4346ba53 posix: implement mprotect()
Provide a stub for mprotect() to satisfy the requirement for the
base definitions / system interfaces and subsequently PSE51,
PSE52, PSE52, etc.

Currently, Zephyr's virtual memory-management API does not seem
to support modifying memory protection bits after pages have
already been mapped.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-14 14:01:05 -04:00
Chris Friedt
64f336c251 posix: tie page size to mmu page size
Make POSIX_PAGE_SIZE_BITS not user-configurable and tie it to
CONFIG_MMU_PAGE_SIZE if there is an MMU. Otherwise, simply
default it to something small.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-14 14:01:05 -04:00
Chris Friedt
5346306261 posix: add support for shared memory objects
Implement shm_open() and shm_unlink() to complete support for
the _POSIX_SHARED_MEMORY_OBJECTS Option.

Since mmap() support is not yet implemented in Zephyr, I/O is
limited to read(), write(), ftruncate(), lseek(), close(), for now.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-14 14:01:05 -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
5e99e13b4c posix: add support for mlockall() and munlockall()
Add support for mlockall() and munlockall(). These two functions
comprise the _POSIX_MEMLOCK Option which is required by PSE51,
PSE52, PSE53, and PSE54.

Zephyr's on-demand paging API does not yet support pinning and
unpinning *all* virtual memory regions, so these functions are
expected to fail, setting errno to ENOSYS. Any other usage is
currently categorized as undefined behaviour.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-14 14:01:05 -04:00
Chris Friedt
d949c9c8b8 posix: add support for mlock() and munlock()
Add support for mlock() and munlock(). These two functions
comprise the _POSIX_MEMLOCK_RANGE Option which is
required by PSE51, PSE52, PSE53, and PSE54.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-14 14:01:05 -04:00
Chris Friedt
73394a8390 posix: add implementation of mmap(), msync(), and munmap()
Add stubs for mmap(), msync(), and munmap() as required by the
_POSIX_MAPPED_FILES Option and POSIX_MAPPED_FILES and
Option Group of IEEE 1003.1-2017.

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
TaiJu Wu
a2e97405d0 lib: check null pointer before taking lock for bitarray
In some function in bitarray.c, we should check the pointer
of bitarry before taking bitarray lock.

In this patch, we move the null-check assert before the use of
the struct to provide better validation than a crash.

Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>
2024-06-14 19:18:28 +02:00
Hess Nathan
5120744c8d lib: added blanks between operators
To adhere to general code style, I added some
blanks around operators

Signed-off-by: Hess Nathan <nhess@baumer.com>
2024-06-13 20:28:23 -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
Chris Friedt
8b61b71818 posix: streams: add stub for missing putpmsg() function
The putpmsg() function was left unimplemented when other
functions in the _XOPEN_STREAMS Option.

Add a stub to complete the Option.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-13 05:35:31 -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
Fin Maaß
01c40dda1f json: add JSON_TOK_ENCODED_OBJ
add support to include a already encoded object
to a object

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-06-12 21:15:27 -04:00
Hou Zhiqiang
209568eabe driver: ram_console: leave one byte from the defined buffer size
Leave one byte from the CONFIG_RAM_CONSOLE_BUFFER_SIZE to ensure
the NULL-termination.

Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
2024-06-12 17:09:24 -05:00
Chun-Chieh Li
55a988ef44 lib: smf: fix ctx->executing in smf_execute_all_entry_actions
Fix ctx->executing is not updated in smf_execute_all_entry_actions()

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2024-06-12 12:52:46 -04:00
Chun-Chieh Li
eae0900122 lib: smf: add NULL check in smf_execute_all_exit_actions
Like in smf_execute_all_entry_actions(), add NULL check
in smf_execute_all_exit_actions().

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2024-06-12 12:52:46 -04:00
Chris Friedt
598b2e11b2 posix: conditionally generate posix_clock syscall header
If POSIX_TIMERS is not configured, there is no reason to
generate syscall headers from posix_clock.h .

Make header generation conditional on POSIX_TIMERS in
this case.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-11 20:27:32 -05:00
frei tycho
139f16702a lib: utils: avoid Boolean-to-integer type casts
Avoid casting expression to an inappropriate essential type.

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-06-11 20:05:37 +03: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
Fabio Baltieri
c250c330c6 posix: re-introduce PTHREAD_RWLOCK_INITIALIZER
Rename the POSIX_RWLOCK_INITIALIZER back to PTHREAD_RWLOCK_INITIALIZER.
This was changed in 70e2b02c8e, but PTHREAD_RWLOCK_INITIALIZER is the
standard name used by external libraries.

Change it back to restore compatibility.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-06-05 19:31:59 -04:00
Chris Friedt
fe1e7f8d37 doc: release: posix: deprecate non-normative POSIX Kconfig
Add release notes for the deprecation of a number of POSIX
Kconfig options. These have been deprecated so that we can
use more normative Kconfig variable identifiers, based on
the Options and Option Groups of IEEE 1003.1-2017.

To simplify migration, use

python $ZEPHYR_BASE/scripts/utils/migrate_posix_kconfigs.py \
    -r root_path

Additionally, document the removal of PTHREAD_BARRIER_DEFINE(),
EFD_IN_USE, EFD_FLAGS_SET, which were previously deprecated
>= 2 release cycles before.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
0fa97326c7 posix: create kconfig options for pse51, pse52, pse53
Create Kconfig "shortcuts" for PSE51, PSE52, and PSE53.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05: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
b3e36ad6e8 posix: eventfd: remove deprecated eventfd macros
Remove the EFD_IN_USE and EFD_FLAGS_SET macros as they were not
part of the public API.

Rename the internal versions, accordingly.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
3949e89330 posix: net: update for POSIX_NETWORKING
Add a link to the Kconfig option CONFIG_POSIX_NETWORKING in
the documentation.

Additionally, add Kconfig options for other Network
dependencies in an effort to make POSIX Kconfig options
consistent with the specification.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
b051bcee25 posix: move getpid() to Kconfig.procN and doc MULTI_PROCESS
Create a Kconfig option for POSIX_MULTI_PROCESS Option Group
and mark it as experimental.

Currently, Zephyr has two functions that belong to this
Option Group:
- sleep()
- getpid()

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
2e429f1b9d posix: reword aio and sched options. add experimental
The asynchronous I/O and (process) scheduling options needed
minor rewording.

Additionally, add the experimental flag to each of them since
they are not yet supported.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
3f29b17bd1 posix: deprecate POSIX_SIGNAL in favour of POSIX_SIGNALS
This change deprecates CONFIG_POSIX_SIGNAL in favour of
the plural CONFIG_POSIX_SIGNALS, which maps directly to the
name of the standard POSIX Option Group POSIX_SIGNALS.

Additionally, mark signals as experimental.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
2642eaa4e9 posix: relocate Kconfig.eventfd to Kconfig.compat
While event file descriptors (eventfd) are extremely useful, the
API has still not been formalized as part of the POSIX
specification.

Therefore, move this to a separate Kconfig menu for "compat"
(compatibility) features.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
fcebe60090 posix: deprecate PTHREAD_IPC _MUTEX _COND and _KEY
Zephyr's POSIX API is moving toward using the standard
nomenclature from IEEE 1003.1-2017 for as much as possible. In
particular, we want to have consistent naming between Zephyr's
POSIX API Kconfig options and the naming for POSIX Options and
Option Groups.

The Kconfig option CONFIG_PTHREAD_IPC has been (ab)used for a
very long time for a variety of different purposes. However,
the standard Option / feature test macro for POSIX Threads is,
intuitively _POSIX_THREADS. There is a corresponding sysconf()
key named _SC_POSIX_THREADS.

Annoyingly, the POSIX Option Group that corresponds to the
Option is POSIX_THREADS_BASE, which is a minor inconsistency
in the standard.

The _POSIX_THREADS Option already includes mutexes, condition
variables, and thread-specific storage (keys). So with this
change, we also deprecate the redundant Kconfig variables that
do not have a corresponding match in the standard.

- CONFIG_PTHREAD_IPC
- CONFIG_PTHREAD
- CONFIG_PTHREAD_COND
- CONFIG_PTHREAD_MUTEX
- CONFIG_PTHREAD_KEY

Additionally, create Kconfig variables for those configurables
which we are lacking:

- CONFIG_POSIX_THREADS_EXT
- CONFIG_POSIX_THREAD_ATTR_STACKSIZE
- CONFIG_POSIX_THREAD_ATTR_STACKADDR
- CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING
- CONFIG_POSIX_THREAD_PRIO_INHERIT
- CONFIG_POSIX_THREAD_PRIO_PROTECT
- CONFIG_POSIX_THREAD_SAFE_FUNCTIONS

Some Kconfig variables were renamed to more properly match the spec:

- CONFIG_MAX_PTHREAD_COUNT -> CONFIG_POSIX_THREAD_THREADS_MAX
- CONFIG_MAX_PTHREAD_KEY_COUNT -> CONFIG_POSIX_THREAD_KEYS_MAX

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
2f2cad742e posix: deprecate POSIX_PUTMSG for XOPEN_STREAMS
This change deprecates CONFIG_POSIX_PUTMSG and introduces a new
Kconfig option CONFIG_XOPEN_STREAMS which maps directly to the
standard POSIX Option, _XOPEN_STREAMS.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
0711d603f7 posix: deprecate POSIX_SYSLOG for XSI_SYSTEM_LOGGING
This change deprecates the CONFIG_POSIX_SYSLOG Kconfig
variable for CONFIG_XSI_SYSTEM_LOGGING, which has a
direct mapping to the POSIX Option Group XSI_SYSTEM_LOGGING.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
842a7b7ba1 posix: deprecate SEM_VALUE_MAX and SEM_NAMELEN_MAX
This change deprecates CONFIG_SEM_VALUE_MAX in favour of
CONFIG_POSIX_SEM_VALUE_MAX which maps directly to
_POSIX_SEM_VALUE_MAX.

Additionally, we add the Kconfig option
CONFIG_POSIX_SEMAPHORES which maps directly to the
POSIX Option _POSIX_SEMAPHORES.

For consistence, deprecate CONFIG_SEM_NAMELEN_MAX
in favour of CONFIG_POSIX_SEM_NAMELEN_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
2bc722a97e posix: deprecate POSIX_FNMATCH GETOPT GETENTROPY
The functions fnmatch(), getopt(), getentropy()
and others are grouped into the standard Option Group
POSIX_C_LIB_EXT.

The getentropy() function is currently in-draft for
Issue 8 as of 2021.

https://www.opengroup.org/austin/docs/austin_1110.pdf

Not surprisingly, the POSIX_C_LIB_EXT Option Group
also includes the highly debated strnlen() function.

Moving that function will be deferred until later.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
70e2b02c8e posix: deprecate PTHREAD_RWLOCK for POSIX_READER_WRITER_LOCKS
This change deprecates CONFIG_PTHREAD_RWLOCK in favour of
CONFIG_POSIX_READER_WRITER_LOCKS, which maps directly to the
name of the standard POSIX Option.

Annoyingly, the POSIX_RW_LOCKS Option Group is inconsistently
named. However, it is more convenient for us to use the Option
name since it is also the format used by the sysconf() variable
(_SC_READER_WRITER_LOCKS).

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
f270de7362 posix: deprecate POSIX_MQUEUE in favour of POSIX_MESSAGE_PASSING
This change deprecates CONFIG_POSIX_MQUEUE in favour of
CONFIG_POSIX_MESSAGE_PASSING, which maps directly to the name of the
standard POSIX Option.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
4e181f7031 posix: deprecate PTHREAD_SPINLOCK for POSIX_SPIN_LOCKS
This change deprecates CONFIG_PTHREAD_SPINLOCK in favour of
CONFIG_POSIX_SPIN_LOCKS, 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
2fe9d6cd68 posix: deprecate POSIX_ENV _CONFSTR _SYSCONF and _UNAME
This change deprecates the following Kconfig options
* CONFIG_POSIX_ENV
* CONFIG_POSIX_CONFSTR
* CONFIG_POSIX_SYSCONF
* CONFIG_POSIX_UNAME

and instead groups them into a single Kconfig option that maps
directly to the standard. Namely, CONFIG_POSIX_SINGLE_PROCESS.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
b639604833 posix: deprecate PTHREAD_BARRIER for POSIX_BARRIERS
The standard specifies _POSIX_BARRIERS as an Option so let's
use CONFIG_POSIX_BARRIERS for consistence.

This change deprecates CONFIG_PTHREAD_BARRIER. Users should
instead choose CONFIG_POSIX_BARRIERS.

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
Chris Friedt
4a5c4e5f73 posix: timers: deprecate CONFIG_POSIX_CLOCK and TIMER
The POSIX_CLOCK option does not correspond to any standard
option. It was used to active features of several distinct
POSIX Options and Option Groups, which complicated API and
application configuration as a result.

POSIX_CLOCK 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.

Additionally, CONFIG_TIMER is being deprecated because it does
not match the corresponding POSIX Option (_POSIX_TIMERS).

With this deprecation, we introduce the following Kconfig
options that map directly to standard POSIX Option Groups by
simply removing "CONFIG_":

* CONFIG_POSIX_TIMERS

Similarly, we introduce the following Kconfig options that
map directly to standard POSIX Options by simply removing
"CONFIG":

* CONFIG_POSIX_CLOCK_SELECTION
* CONFIG_POSIX_CPUTIME
* CONFIG_POSIX_DELAYTIMER_MAX
* CONFIG_POSIX_MONOTONIC_CLOCK
* CONFIG_POSIX_TIMEOUTS
* CONFIG_POSIX_TIMER_MAX

In order to maintain parity with the current feature set, we
introduce the following Kconfig options that map directly to
standard POSIX Option Groups by simply removing "CONFIG_":

* CONFIG_POSIX_MULTI_PROCESS - sleep()

Similarly, in order to maintain parity with the current feature
set, we introduce the following additional Kconfig options that
map directly to standard POSIX Options by simply removing
"CONFIG":

* CONFIG_XSI_SINGLE_PROCESS - gettimeofday()

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
e2fc78af23 posix: signals: deprecate CONFIG_POSIX_LIMITS_RTSIG_MAX
There were two Kconfig constants defined for (effectively) the
same thing in Zephyr. Namely, RTSIG_MAX - the highest valued
real-time signal.

Deprecate CONFIG_POSIX_LIMITS_RTSIG_MAX in favour of
CONFIG_POSIX_RTSIG_MAX since the latter more closely matches
convention.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
feb841a0f7 posix: add Kconfig.deprecated
There will be some POSIX Kconfig symbols that will be deprecated
in favour of Kconfig symbols that are exact matches for those in
the POSIX specification (1003.1-2017).

Create the empty Kconfig file now, and then incrementally add to
it as non-standard POSIX Kconfig options are replaced with
standard-like POSIX Kconfig options.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chris Friedt
aa6a472355 posix: sysconf: define z sysconf macros with COND_CODE_1
It's sort of more conventient to do the opposite of what was
done with the __z_sysconf_ macros, and use them for both the
full implementation and the macro implementation.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-06-04 16:27:12 -05:00
Chaitanya Tata
40de2cbc0d lib: heap: Add dependency for asserts
There is no point in having heap validation enabled but without asserts,
as nothing is reported to the user.

Add this dependency to make sure this option is useful.

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
2024-05-31 09:55:28 -05:00
Adrien Ricciardi
863f6affef lib: crc: Add OpenPGP CRC-24
Implementation is based on the section 6.1 of the RFC 4880.

Signed-off-by: Adrien Ricciardi <aricciardi@baylibre.com>
2024-05-29 10:51:21 -07: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
Andrew Davis
39863b66bd lib: open-amp: Use struct fw_resource_table type instead of void
The type of the resource table is known, casting to and from void* only
hides this type which can prevent the compiler from giving helpful
warnings. One warning would have been the accidental use of
"st_resource_table" in a cast, a struct which does not exist.

Use the fw_resource_table type when dealing with resource tables.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-05-24 07:51:42 -04:00
Andrew Davis
4c5eb92650 lib: open-amp: Use fixed width types for resource table
This structure is shared between cores which may have different type
widths. Use fixed width types when defining the structure. We can
also use struct resource_table to help as it is already defined with
fixed width types and removes the need to redefine these elements.

Signed-off-by: Andrew Davis <afd@ti.com>
2024-05-24 07:51:42 -04:00
Glenn Andrews
531c457550 Lib: SMF Modify HSM operation for UML-Style transitions
Modify the SMF such that state transitions from parent states choose the
correct Least Common Ancestor based on the transition source rather than
the current state.

SMF set as experimental.

Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
2024-05-22 21:41:06 -04:00
Lucas Romero
3f50197a90 lib: bitarray: add method to find nth bit set in region
This is part one of several changes to add more methods to the bitarray api
so that it can be used for broader usecases, specifically LoRaWAN forward
error correction.

Signed-off-by: Lucas Romero <luqasn@gmail.com>
2024-05-21 16:44:38 -04:00
Lucas Romero
752d3c529e lib: bitarray: add method to xor two bitarrays
This is part one of several changes to add more methods to the bitarray api
so that it can be used for broader usecases, specifically LoRaWAN forward
error correction.

Signed-off-by: Lucas Romero <luqasn@gmail.com>
2024-05-21 16:44:38 -04:00
Lucas Romero
c5e5686805 lib: bitarray: add method to count bits set in region
This is part one of several changes to add more methods to the bitarray api
so that it can be used for broader usecases, specifically LoRaWAN forward
error correction.

Signed-off-by: Lucas Romero <luqasn@gmail.com>
2024-05-21 16:44:38 -04:00
Patryk Duda
759dcfe18f llvm: stdint: Don't define integer constant macros in llvm.h
Zephyr minimal libc implements integer constant macros using internal
headers provided by GCC, for example INT64_C(x) is just a __INT64_C(x)
which is implemented by the GCC.

Clang compiler doesn't provide these definitions, so we define them
(__INT64_C() and INT64_C()) in zephyr/toolchain/llvm.h, but it looks
like INT64_C() definition doesn't come from llvm.h, but from stdlib.h
despite of checking if __GNUC__ is defined.

This is because Clang sometimes pretends to be GNU compiler:
$ x86_64-pc-linux-gnu-clang -dM -E - < /dev/null | grep "GNU"
 #define __GNUC_MINOR__ 2
 #define __GNUC_PATCHLEVEL__ 1
 #define __GNUC_STDC_INLINE__ 1
 #define __GNUC__ 4

Let's keep the integer constant macros in stdlib.h and their
actual implementation in llvm.h. Also define these macros if __clang__
is defined, just in case.

Signed-off-by: Patryk Duda <patrykd@google.com>
2024-05-20 18:04:54 +02:00
Pisit Sawangvonganan
557ad8e45c shell: devmem: address cmd_dump multiple call problem
Call `getopt_init()` to reset `state->optind` instead of directly setting
`optind = 1`. The `getopt()` function uses `getopt_state` from
`getopt_state_get` for state handling, so `getopt_init()` should be called
to correctly run the command again.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-05-15 10:13:23 +02:00
Alberto Escolar Piedras
7c8d538982 posix: env: Fix 2 build warnings
Fix 2 build warnings in posix/options/env:
The maximum length given to strncpy() matches the input
string length, which makes the call equivalent to strcpy().
As the destination buffer size has been ensured sufficient
(in the first case by chechking just before,
in the second case by allocating it big enough),
let's just use strcpy() instead.

lib/posix/options/env.c: In function 'getenv_r':
lib/posix/options/env.c:109:17: error: 'strncpy' specified bound
depends on the length of the source argument
[-Werror=stringop-truncation]
  109 |                 strncpy(buf, val, vsize);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~
lib/posix/options/env.c:104:25: note: length computed here
  104 |                 vsize = strlen(val) + 1;
      |                         ^~~~~~~~~~~
lib/posix/options/env.c: In function 'setenv':
lib/posix/options/env.c:191:17: error: 'strncpy' output truncated
before terminating nul copying as many bytes from a string as its
length [-Werror=stringop-truncation]
  191 |                 strncpy(environ[ret], name, nsize);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/posix/options/env.c:128:51: note: length computed here
  128 |         const size_t nsize = (name == NULL) ? 0 : strlen(name);
      |                                                   ^~~~~~~~~~~~

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-05-14 13:25:33 +02:00
David Schneider
012c9a2847 libc/picolibc: Support Picolibc for toolchains without bundled Picolibc
Allow Picolibc to get build from module, if the toolchain does not
include a bundled picolibc.
This should always be possible, except for native applications and
if libcpp is required.

Signed-off-by: David Schneider <david.schneider@chargepoint.com>
2024-05-09 10:28:35 +02:00
Chris Friedt
b1e2e4ac2c posix: fs: create a separate Kconfig option for fsync
Create CONFIG_POSIX_FSYNC to match the spec.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-05-07 21:22:56 -04:00
Patryk Duda
60d03c53e1 libc: minimal: Add 'noreturn' attribute to abort() and exit()
This aligns abort() and exit() definitions with other libc.

Without 'noreturn' attribute, compilers have to assume that we will
return from these functions which can lead to surprising errors like
'error: non-void function does not return a value'.

Signed-off-by: Patryk Duda <patrykd@google.com>
2024-05-06 17:32:17 +01:00
frei tycho
32ba549536 lib: os: coding guidelines: add explicit cast to void
- added explicit cast to void when returned value is expectedly ignored

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-05-03 07:52:42 -04:00
Yong Cong Sin
4363a787b1 posix: uname: increase version name length
to 70 to prevent overflowing the char array.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2024-04-29 17:40:16 +01:00
Patryk Duda
ef258166ba posix: Introduce getentropy() function
The function writes random data to the provided buffer. Maximum
permitted buffer size is 256 bytes. On success the function returns 0,
otherwise it returns -1 and sets errno to appropriate value.

Signed-off-by: Patryk Duda <patrykd@google.com>
2024-04-29 11:46:06 +01:00
Chris Friedt
cdb1193f3e posix: add stubs for asynchronous io
Add stubs for POSIX asynchronous io that return -1 and set
errno to ENOTSUP.

The functions and structures in aio.h are required by the
_POSIX_ASYNCHRONOUS_IO Option as detailed in Section E.1 of
IEEE-1003.1-2017.

The _POSIX_ASYNCHRONOUS_IO interface is required for PSE51,
PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory
for any POSIX conforming system as per Section A.2.1.3 of
IEEE-1003-1.2017.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-04-29 11:02:11 +02:00
Alberto Escolar Piedras
60d5ce452e libC kconfig: Introduce a new option to avoid the native libC
Let's introduce a new option so components which cannot
be used with the native libC can select it.
And at this point let's already have POSIX_API select it
instead of being used in the libC choice default.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-04-24 09:53:36 +02:00
Alberto Escolar Piedras
84e7107b32 Revert "posix: use sys_sem instead of k_spinlock for pool synch"
This reverts commit 6e66aa1f7c.

And fixes an indentation issue in the original code,
which triggers checkpatch.

This PR:
https://github.com/zephyrproject-rtos/zephyr/pull/71718
introduced a regression breaking CI:
https://github.com/zephyrproject-rtos/zephyr/issues/71814
Let's just revert it until a better fix is done.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-04-23 11:51:44 -04:00
Chris Friedt
6e66aa1f7c 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-04-23 07:01:25 -04:00
Karthikeyan Krishnasamy
cc06c2b21f lib: posix: fs: fix errno handling
ftruncate should return -1 on errors and it needs to
set appropriate error values in errno

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
2024-04-22 04:33:16 -07:00
Karthikeyan Krishnasamy
cd1ed1cdbf lib: posix: fs: add ftruncate support
Add support for ftruncate in posix implementation

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
2024-04-15 13:23:37 -04:00
Karthikeyan Krishnasamy
65ad32b3ca lib: os: fdtable: add support for fsync
Add support for fsync in existing posix ioctl call

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
2024-04-15 13:23:37 -04:00
Gaetan Perrot
51439f012a posix: Implement isastream
`isastream()` is required as part of _XOPEN_STREAMS Option Group.

signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
2024-04-13 20:23:34 -04:00
Celina Sophie Kalus
5bd86eaddb posix: eventfd: Fix unsetting internal flags in ioctl
Commit e6eb0a705b ("posix: eventfd: revise locking, signaling, and
allocation") introduced a regression where the internal flags of an
event file descriptor would be erased when calling the F_SETFL ioctl
operation.

This includes the flag EFD_IN_USE_INTERNAL which determines whether
this file descriptor has been opened, thus effectively closing the
eventfd whenever one tries to change a flag.

Signed-off-by: Celina Sophie Kalus <hello@celinakalus.de>
2024-04-13 06:00:08 -04:00
Fin Maaß
1ab6f82c7e lib: smf: check for NULL
don't execute share_paren() if the target is NULL
in smf_execute_ancestor_exit_actions()

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2024-04-10 07:40:21 -04:00
Yong Cong Sin
cd2c7874b9 posix: uname: use BUILD_VERSION only if not empty
The `BUILD_VERSION` can be defined but empty when built
without git, causing version to be missing from the uname
version string:

```
*** Booting Zephyr OS build 3.5.0 ***

Printing everything in utsname...
sysname[7]: Zephyr
nodename[7]: zephyr
release[13]: 3.5.0
version[61]:  Apr  1 2024 23:48:30
machine[8]: riscv64

uart:~$
```

Let's check if it is empty before using it, so that
`KERNEL_VERSION_STRING`, which is generated independently
with cmake can be used as a fallback:

```
*** Booting Zephyr OS build 3.5.0 ***

Printing everything in utsname...
sysname[7]: Zephyr
nodename[7]: zephyr
release[13]: 3.5.0
version[61]: 3.5.0 Apr  1 2024 23:53:48
machine[8]: riscv64

uart:~$
```

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-04-04 23:47:33 +02:00
Gaetan Perrot
228d932967 posix: implement pthread_setschedprio
Implement posix pthread_setschedprio()

Signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
2024-04-04 10:25:53 -04:00
Chris Friedt
5ab984a834 posix: convert static inline functions to library functions
With CONFIG_NET_POSIX_NAMES being deprecated, convert static
inlines in headers to prototypes, and move implementations
to lib/posix/options/net.c .

Since select and poll should technically also operate on
non-socket file descriptors, these may be relocated in the
future.

Below are some reasons for this change.
1. So posix calls are regular symbols and not directly inlined
   as syscalls. This is also the most portable linkage type.
2. Many posix calls are cancellation points and additional
   checks are necessary within the implementation.
3. The more we add to an inline call, the less sense it makes
   for that call to be inline.
4. When the implementation of a posix function changes, the
   interface for it should still remain consistent.

Note: the same principles have been applied in Zephyr's
posix implementation already, e.g. clock_gettime(), so this
is nothing new.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2024-04-02 21:01:33 -04:00
Gaetan Perrot
d61a7b2777 posix: Implement set and get inheritsched APIs for pthread attr
Implement `pthread_attr_setinheritsched()` and
`pthread_attr_getinheritsched()`are required
as part of _POSIX_THREAD_PRIORITY_SCHEDULING Option Group.

signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
2024-04-01 11:04:35 +01:00
Chris Friedt
494493a3b8 posix: net: add a trivial implementation of sockatmark()
Add a trivial implementation of sockatmark().

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
2024-03-27 07:36:18 -04:00
Chris Friedt
62031f5daa posix: net: add trivial netdb function implementations
Add trivial function implementations for those declared in
netdb.h .

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
2024-03-27 07:36:18 -04:00
Chris Friedt
a00eeb638a posix: net: implement if_nameindex() et al
Implement if_indextoname(), if_freenameindex(), if_nameindex(),
and if_nametoindex() by wrapping around networking subystem
calls.

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
2024-03-27 07:36:18 -04:00
Chris Friedt
7a397a08b7 posix: net: implement inet_ntoa()
Add an implementation of inet_ntoa().

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
2024-03-27 07:36:18 -04:00