-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Is your enhancement proposal related to a problem? Please describe.
Problem:
CONFIG_ARCH_POSIX
andCONFIG_POSIX_API
should not be mutually exclusive- the POSIX arch should provide a scalable, portable, and maintainable abstraction layer
Intent:
With the POSIX arch, we want to abstract away the host OS system calls (and parts of the system C library) in order to
- efficiently test Zephyr code paths in CI
- provide devs with a native environment for prototyping and debugging new features that use Zephyr code paths
For further details on intent see the docs
Clarification on CONFIG_POSIX_API
:
- This is the implementation of a subset of the POSIX API to support Zephyr's needs
i. not strictly adhering the the embedded POSIX profile - The Zephyr application should interface with the Zephyr-provided implementation (with suitable platform-level abstractions)
- In the case of
CONFIG_ARCH_POSIX
, The Zephyr application should not interface directly to the host OS system calls / or libc implementations
The native_posix
port used to rely on posix_cheats.h
to perform some questionable preprocessor redefinitions of standard function names in order to avoid conflicts in the C global symbol namespace. This was obviously not portable and somewhat fragile.
After some time, it was decided that CONFIG_ARCH_POSIX
and CONFIG_POSIX_API
were mutually exclusive options (see #13054, #13540).
This proposal is intended to show that CONFIG_ARCH_POSIX
and CONFIG_POSIX_API
do not need to be (and really should not be) mutually exclusive, and that functionality can be achieved with conventional OOP methods and very mature, standard APIs.
Moreover, the proposed solution is completely scalable, maintainable, and portable to any OS (likely even including non-POSIX operating systems).
Describe the solution you'd like
- Provide a formal definition of abstractions required today to support
native_posix
i. for now this can be limited to C function & symbol definitions - An abstraction that works for Linux (and most any other OS) that uses
i. portable and standard C
i. standard POSIX APIs (e.g.dlopen()
,dlsym()
, can be extended to e.g. Windows API)
i. conventional OOP methods (encapsulation / abstraction) - An (optional) secure method for loading host libc symbols
i. leverageKconfig
to (optionally) provide the name or path of the host libc
ii. leverageKconfig
to (optionally) require a strong checksum for the host libc
W.r.t. host libc name, on GNU systems, the default fault is obtainable programmatically with #include <gnu/lib-names.h>
and LIBC_SO
. However, it should be possible to link to other libc's as well.
It would probably make sense to encapsulate this abstraction on a per-OS bases by having separate compilation units (e.g. posix-arch-if-linux.c, posix-arch-macos.c).
Describe alternatives you've considered
Proposal in #24685
- both dynamic and static proposals rely on visibility attribute (ELF-specific)
- requiring a non-standardized feature increases technical debt
- immediately precludes macOS support for native_posix
- AMP is thrown into the mix (somewhat conflates intent)
There may be other RFCs on this subject
Additional context
This enhancement is a requirement / blocks #43987 which
- drastically simplifies using POSIX calls within Zephyr
- already demonstrates that
CONFIG_POSIX_API
andCONFIG_ARCH_POSIX
are not mutually exclusive - makes Zephyr more compatible for 3rd-party library code
- already has support from HAL / modules / networking
- provides a clear path forward for zephyr-namespaced implementations / POSIX wrappers
PR on its way