Skip to content

Allow CONFIG_POSIX_API on CONFIG_ARCH_POSIX #45100

@cfriedt

Description

@cfriedt

Is your enhancement proposal related to a problem? Please describe.
Problem:

  1. CONFIG_ARCH_POSIX and CONFIG_POSIX_API should not be mutually exclusive
  2. 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

  1. efficiently test Zephyr code paths in CI
  2. 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:

  1. 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
  2. The Zephyr application should interface with the Zephyr-provided implementation (with suitable platform-level abstractions)
  3. 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

  1. Provide a formal definition of abstractions required today to support native_posix
    i. for now this can be limited to C function & symbol definitions
  2. 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)
  3. An (optional) secure method for loading host libc symbols
    i. leverage Kconfig to (optionally) provide the name or path of the host libc
    ii. leverage Kconfig 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 and CONFIG_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

Metadata

Metadata

Assignees

Labels

EnhancementChanges/Updates/Additions to existing featuresarea: POSIXPOSIX API Libraryarea: native portHost native arch port (native_sim)

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions