Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posix: header fixups #51771

Merged
merged 20 commits into from
Jan 23, 2023
Merged

Commits on Jan 13, 2023

  1. lib: posix: standard include paths with CONFIG_POSIX_API

    With the `<zephyr/posix/...> prefix, it became
    exponentially more difficult to integrate 3rd-party
    libraries that depend on the POSIX API.
    
    Standard POSIX headers should be available in standard
    include paths - and that should most certainly the case
    when `CONFIG_POSIX_API=y`.
    
    With this change:
    
    * When `CONFIG_POSIX_API=y`
      - applications have explicitly chosen to use
        POSIX APIs.
      - all standard POSIX includes are in the default
        include path.
    * When `CONFIG_POSIX_API=n`
      - applications *may* include POSIX headers
        explicitly with the namespaced prefix
      - e.g. `#include <zephyr/posix/unistd.h>`
      - individual Kconfig options can be used to
        enable POSIX features selectively, such as
        `getopt` or `eventfd`.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    90b1950 View commit details
    Browse the repository at this point in the history
  2. posix: rename posix_sched.h to sched.h

    Rename the `posix_sched.h` to conform to the spec.
    
    IEEE Std 1003.1
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    17a871b View commit details
    Browse the repository at this point in the history
  3. posix: treat pthread_key.h as an implementation detail

    The `pthread_key.h` header is nonstandard and is an
    implementation detail of `pthread.h`.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    bea5b9a View commit details
    Browse the repository at this point in the history
  4. posix: getopt: select getopt by default with CONFIG_POSIX_API

    The `getopt()` function is part of POSIX and should be
    available when applications choose to enable general POSIX
    API support.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    45242f6 View commit details
    Browse the repository at this point in the history
  5. posix: eventfd: select eventfd by default with CONFIG_POSIX_API

    Although the eventfd API is not (yet) a part of POSIX,
    it's pretty well ubiquitous on POSIX systems now.
    
    Enable it by default when `CONFIG_POSIX_API=y`.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    202f260 View commit details
    Browse the repository at this point in the history
  6. posix: fs: avoid adding open() alias with newlib and picolibc

    Newlib and PicoLibc both already alias `open` to `_open`.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    a540ae7 View commit details
    Browse the repository at this point in the history
  7. posix: unistd.h: add declaration for _exit()

    The `_exit()` function should be declared in `<unistd.h>`.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    5dbbad3 View commit details
    Browse the repository at this point in the history
  8. posix: avoid redefinition errors in network and posix headers

    The networking subsystem defines a rather large amount of POSIX
    prototypes. However, it's done in a somewhat subversive way via
    
    ```
    CONFIG_NET_SOCKETS_POSIX_NAMES
    ```
    
    This option should be removed (or moved to POSIX) and the
    networking implementations should be properly namespaced.
    
    With that, the POSIX interface for network-related functions
    can simply be a thin wrapper around the z-namespaced variants,
    where applicable, or proper POSIX functions should actually
    be moved to `lib/posix`.
    
    This will also require a better solution to testing network
    functionality on `native_posix` though. The ability to run
    those tests and the supposed incompatibility between
    `CONFIG_ARCH_POSIX` and `CONFIG_POSIX_API` was the main
    motivation for adding `CONFIG_NET_SOCKETS_POSIX_NAMES`.
    
    Eventually, with proper namespacing, these preprocessor
    guards against redefining the same symbols can be
    removed.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    b47f435 View commit details
    Browse the repository at this point in the history
  9. posix: mqueue: do not typedef mq_attr

    The specification actually requires this to be a plain
    `struct mq_attr`, without the typedef.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    39a6128 View commit details
    Browse the repository at this point in the history
  10. posix: ioctl: actually declare a function prototype

    The `<sys/ioctl.h>` header never actually declared
    the `ioctl(2)` function prototype, so this fixes that.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    f089cb8 View commit details
    Browse the repository at this point in the history
  11. posix: define in_port_t and in_addr_t in netinet/in.h

    The spec requires that these two types be defined in
    `<netinet/in.h>`.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    6dbd9cd View commit details
    Browse the repository at this point in the history
  12. posix: ensure in_addr_t and in_port_t defined via arpa/inet.h

    The spec requires that `in_addr_t` and `in_port_t` are both
    defined when `<arpa/inet.h>` is included.
    
    They were added to `<netinet/in.h>` in the previous commit.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    7fb8b99 View commit details
    Browse the repository at this point in the history
  13. posix: netdb: ensure that EAI constants are defined

    Constants like `EAI_SYSTEM` should be defined in `<netdb.h>`
    according to the spec.
    
    In Zephyr, they should be defined via appropriately
    namespaced z-variants (currently `DNS_EAI_SYSTEM` and so on).
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    81de964 View commit details
    Browse the repository at this point in the history
  14. posix: ioctl: define FIONREAD as some applications require it

    The `FIONREAD` ioctl is usually used to query how many bytes
    are available to read immediately from a specific file
    descriptor. It's quite useful.
    
    Define it here so that it can be used by applications.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    9a1c149 View commit details
    Browse the repository at this point in the history
  15. posix: define struct linger in sys/socket.h

    The spec requires `<sys/socket.h>` to declare
    struct linger. Define it so that applications
    and libraries do not get compile errors when
    building against Zephyr.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    e2103ab View commit details
    Browse the repository at this point in the history
  16. posix: netdb: provide NI_MAXSERV for reasonable app defaults

    The `<netdb.h>` header typically defines `NI_MAXSERV` as a
    reasonable default buffer size to use in applications that
    use `getnameinfo()` to query a service name.
    
    Most GNU and BSD systems define it by default so provide
    it as a convenience so applications and 3rd-party libraries
    do not encounter a compile error.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 13, 2023
    Configuration menu
    Copy the full SHA
    97b51cc View commit details
    Browse the repository at this point in the history

Commits on Jan 16, 2023

  1. net: socket: additional POSIX constants

    The POSIX spec requires that `SO_LINGER`, `SO_RCVLOWAT`,
    and `SO_SNDLOWAT`, and `SOMAXCONN` are defined in
    `<sys/socket.h>`. However, most of the existing socket
    options and related constants are defined in
    `<zephyr/net/socket.h>`.
    
    For now, we'll co-locate them. It would be
    good to properly namespace things.
    
    Additionally, a no-op for setsockopt for `SO_LINGER` to
    make things Just Work (TM) for now.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 16, 2023
    Configuration menu
    Copy the full SHA
    f19242a View commit details
    Browse the repository at this point in the history
  2. tests: posix: existence tests for standard POSIX includes

    Add a trivial suite that simply ensures headers exist and that
    they supply standard symbols and constants.
    
    These tests are intended to be ordered exactly as the respective
    feature appears in the respective specification at
    
    https://pubs.opengroup.org/onlinepubs/9699919799
    
    Over time, as POSIX support improves, we can enable additional
    checks.
    
    If `CONFIG_POSIX_API=n`, then we simply ensure that the header
    can be included, that constants and structures exist, including
    the existence of required fields in each structure.
    
    We check that a constant exist, by comparing its value against
    an arbitrary number. If the constant does not exist, it would
    of course be a compile error.
    
    ```
    zassert_not_equal(-1, POLLIN);
    ```
    
    We check that a structure contains required fields by
    comparing the field offset with an arbitrary number. If
    the field does not exist, of course, there would be a
    compile error.
    
    ```
    zassert_not_equal(-1, offsetof(struct pollfd, fd));
    ```
    
    For non-scalar constants, we simply attempt to assign
    a value to the specific type:
    
    ```
    struct in6_addr any6 = IN6ADDR_ANY_INIT;
    ```
    
    If `CONFIG_POSIX_API=y`, then we additionally check that required
    functions are non-NULL (limited to what is currently supported in
    Zephyr).
    
    ```
    zassert_not_null(pthread_create);
    ```
    
    Note: functional verification tests should be done outside of this
    test suite.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 16, 2023
    Configuration menu
    Copy the full SHA
    49a04c2 View commit details
    Browse the repository at this point in the history
  3. net: sockets: conditionally include zephyr/posix/fcntl.h

    Only include `<fcntl.h>` for `CONFIG_ARCH_POSIX`. Otherwise,
    include `<zephyr/posix/fcntl.h>`.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 16, 2023
    Configuration menu
    Copy the full SHA
    6fd104c View commit details
    Browse the repository at this point in the history
  4. include: posix: add c++ extern scope

    `<fcntl.h>`, `<net/if.h>`, and `<netinet/tcp.h>` were missing
    `extern "C" { .. }"` which is required to avoid C++ name
    mangling.
    
    Signed-off-by: Chris Friedt <[email protected]>
    cfriedt committed Jan 16, 2023
    Configuration menu
    Copy the full SHA
    759dc8d View commit details
    Browse the repository at this point in the history