Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(options)
# zephyr-keep-sorted-start
add_subdirectory_ifdef(CONFIG_EVENTFD eventfd)
add_subdirectory_ifdef(CONFIG_POSIX_C_LANG_SUPPORT_R c_lang_support_r)
add_subdirectory_ifdef(CONFIG_POSIX_C_LIB_EXT c_lib_ext)
add_subdirectory_ifdef(CONFIG_POSIX_SHELL shell)
add_subdirectory_ifdef(CONFIG_POSIX_SYSTEM_INTERFACES options)
# zephyr-keep-sorted-stop
36 changes: 35 additions & 1 deletion lib/posix/Kconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
# Copyright (c) 2024 Meta
# Copyright (c) 2025 Tenstorrent AI ULC
#
# SPDX-License-Identifier: Apache-2.0

menu "POSIX API Support"

# POSIX Subprofile Definitions
rsource "Kconfig.profile"

# Toolchain hooks for external implementations
rsource "Kconfig.toolchain"

# POSIX C Library Extensions
# This menu is for POSIX Option Groups that do not require OS support.
menu "POSIX C Library Extensions"
rsource "c_lang_support_r/Kconfig"
rsource "c_lib_ext/Kconfig"
endmenu

# POSIX System Interfaces
menuconfig POSIX_SYSTEM_INTERFACES
bool "POSIX System Interfaces"
select NATIVE_LIBC_INCOMPATIBLE
help
Select 'y' here to support POSIX System Interfaces within Zephyr.

Options in this menu are organized by POSIX subprofiling Option Group.

For more information, see
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html


if POSIX_SYSTEM_INTERFACES
rsource "options/Kconfig"

# POSIX Shell utilities
rsource "shell/Kconfig"
endif

endmenu

endmenu # "POSIX API Support"
# Eventfd Support (not officially POSIX)
rsource "eventfd/Kconfig"
50 changes: 37 additions & 13 deletions lib/posix/options/Kconfig.profile → lib/posix/Kconfig.profile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
#
# SPDX-License-Identifier: Apache-2.0

config POSIX_SYSTEM_HEADERS
config POSIX_SYSTEM_INTERFACES
bool
select NATIVE_LIBC_INCOMPATIBLE
help
Make POSIX headers available to the system without the "zephyr/posix" prefix.

config POSIX_API
bool "POSIX APIs"
select NATIVE_LIBC_INCOMPATIBLE
select POSIX_SYSTEM_HEADERS
select POSIX_SYSTEM_INTERFACES
select POSIX_BASE_DEFINITIONS # clock_gettime(), pthread_create(), sem_get(), etc
select POSIX_AEP_REALTIME_MINIMAL # CLOCK_MONOTONIC, pthread_attr_setstack(), etc
select POSIX_NETWORKING if NETWORKING # inet_ntoa(), socket(), etc
Expand All @@ -27,7 +26,7 @@ config POSIX_API

choice POSIX_AEP_CHOICE
prompt "POSIX Subprofile"
default POSIX_AEP_CHOICE_NONE
default POSIX_AEP_CHOICE_ZEPHYR
help
This choice is intended to help users select the correct POSIX profile for their
application. Choices are based on IEEE 1003.13-2003 (now inactive / reserved) and
Expand All @@ -38,13 +37,35 @@ choice POSIX_AEP_CHOICE
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html

config POSIX_AEP_CHOICE_NONE
bool "No pre-defined POSIX subprofile"
bool "No POSIX subprofile"
help
No POSIX subprofile is selected.

config POSIX_AEP_CHOICE_ZEPHYR
bool "Minimal Zephyr System Profile"
select POSIX_C_LIB_EXT
select POSIX_C_LANG_SUPPORT_R
help
No pre-defined POSIX profile is selected.
Zephyr expects certain POSIX functions to be available throughout the build environment,
such as gmtime_r(), strnlen(), strtok_r(), and possibly others.

These functions are divided into two standalone Option Groups that may be enabled
independently of the remainder of the POSIX API implementation; namely POSIX_C_LIB_EXT and
POSIX_C_LANG_SUPPORT_R. If not referenced by the Zephyr kernel or application, there are no
resource implications for enabling these option groups.

Unlike pre-defined, standard POSIX subprofiles, this subprofile is custom to Zephyr and
therefore does not need to include the base definitions or system interfaces that would
otherwise be required for a conformant POSIX system or subprofile. This system profile
does not itself meet the requirements for POSIX implementation conformance.

For more information, see
https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html

config POSIX_AEP_CHOICE_BASE
bool "Base definitions (system interfaces)"
select NATIVE_LIBC_INCOMPATIBLE
bool "Minimal POSIX System Profile"
select POSIX_SYSTEM_INTERFACES
select POSIX_BASE_DEFINITIONS
help
Only enable the base definitions required for all POSIX systems.
Expand All @@ -54,7 +75,7 @@ config POSIX_AEP_CHOICE_BASE

config POSIX_AEP_CHOICE_PSE51
bool "Minimal Realtime System Profile (PSE51)"
select NATIVE_LIBC_INCOMPATIBLE
select POSIX_SYSTEM_INTERFACES
select POSIX_BASE_DEFINITIONS
select POSIX_AEP_REALTIME_MINIMAL
help
Expand All @@ -67,7 +88,7 @@ config POSIX_AEP_CHOICE_PSE51

config POSIX_AEP_CHOICE_PSE52
bool "Realtime Controller System Profile (PSE52)"
select NATIVE_LIBC_INCOMPATIBLE
select POSIX_SYSTEM_INTERFACES
select POSIX_BASE_DEFINITIONS
select POSIX_AEP_REALTIME_MINIMAL
select POSIX_AEP_REALTIME_CONTROLLER
Expand All @@ -81,7 +102,7 @@ config POSIX_AEP_CHOICE_PSE52

config POSIX_AEP_CHOICE_PSE53
bool "Dedicated Realtime System Profile (PSE53)"
select NATIVE_LIBC_INCOMPATIBLE
select POSIX_SYSTEM_INTERFACES
select POSIX_BASE_DEFINITIONS
select POSIX_AEP_REALTIME_MINIMAL
select POSIX_AEP_REALTIME_CONTROLLER
Expand All @@ -98,10 +119,11 @@ config POSIX_AEP_CHOICE_PSE53

endchoice # POSIX_AEP_CHOICE

# Base Definitions (System Interfaces)
if POSIX_SYSTEM_INTERFACES

# Mandatory POSIX System Interfaces (base profile)
config POSIX_BASE_DEFINITIONS
bool
select POSIX_SYSTEM_HEADERS
select POSIX_ASYNCHRONOUS_IO
select POSIX_BARRIERS
select POSIX_CLOCK_SELECTION
Expand Down Expand Up @@ -187,3 +209,5 @@ config POSIX_AEP_REALTIME_DEDICATED

For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html

endif # POSIX_SYSTEM_INTERFACE
File renamed without changes.
8 changes: 8 additions & 0 deletions lib/posix/c_lang_support_r/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright The Zephyr Project Contributors
# SPDX-License-Identifier: Apache-2.0

set(POSIX_VERSION 200809L)

if (CONFIG_POSIX_C_LANG_SUPPORT_R)
zephyr_compile_definitions(-D_POSIX_THREAD_SAFE_FUNCTIONS=${POSIX_VERSION})
endif()
File renamed without changes.
17 changes: 17 additions & 0 deletions lib/posix/c_lib_ext/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_include_directories(getopt)

if (CONFIG_TC_PROVIDES_POSIX_C_LIB_EXT)
return()
endif()

zephyr_library()
zephyr_library_sources(
fnmatch.c
getentropy.c
getopt/getopt.c
getopt/getopt_common.c
)

zephyr_library_sources_ifdef(CONFIG_GETOPT_LONG getopt/getopt_long.c)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: getopt.c,v 1.26 2003/08/07 16:43:40 agc Exp $ */

Check warning on line 1 in lib/posix/c_lib_ext/getopt/getopt.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License may not be allowed

lib/posix/c_lib_ext/getopt/getopt.c:1 License file for 'BSD-3-Clause' not found in /LICENSES. Please check https://docs.zephyrproject.org/latest/contribute/guidelines.html#components-using-other-licenses.
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright (c) 1987, 1993, 1994
Expand Down Expand Up @@ -41,9 +41,9 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(getopt);

#define BADCH ((int)'?')
#define BADARG ((int)':')
#define EMSG ""
#define BADCH ((int)'?')
#define BADARG ((int)':')
#define EMSG ""

void getopt_init(void)
{
Expand All @@ -61,7 +61,7 @@

#if CONFIG_GETOPT_LONG
state->nonopt_start = -1; /* first non option argument (for permute) */
state->nonopt_end = -1; /* first option after non options (for permute) */
state->nonopt_end = -1; /* first option after non options (for permute) */
#endif

opterr = 1;
Expand Down Expand Up @@ -151,8 +151,7 @@
return BADARG;
}
if (state->opterr) {
LOG_DBG("option requires an argument -- %c",
state->optopt);
LOG_DBG("option requires an argument -- %c", state->optopt);
}
z_getopt_global_state_update(state);
return BADCH;
Expand All @@ -161,5 +160,5 @@
++state->optind;
}
z_getopt_global_state_update(state);
return state->optopt; /* return option letter */
return state->optopt; /* return option letter */
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ extern "C" {
#include <zephyr/kernel.h>

struct getopt_state {
int opterr; /* if error message should be printed */
int optind; /* index into parent argv vector */
int optopt; /* character checked for validity */
int optreset; /* reset getopt */
char *optarg; /* argument associated with option */
int opterr; /* if error message should be printed */
int optind; /* index into parent argv vector */
int optopt; /* character checked for validity */
int optreset; /* reset getopt */
char *optarg; /* argument associated with option */

char *place; /* option letter processing */
char *place; /* option letter processing */

#if CONFIG_GETOPT_LONG
int nonopt_start;
int nonopt_end;
#endif
};

extern int optreset; /* reset getopt */
extern int optreset; /* reset getopt */
extern char *optarg;
extern int opterr;
extern int optind;
extern int optopt;

#define no_argument 0
#define required_argument 1
#define optional_argument 2
#define no_argument 0
#define required_argument 1
#define optional_argument 2

struct option {
/* name of long option */
Expand Down Expand Up @@ -79,9 +79,8 @@ struct getopt_state *getopt_state_get(void);
* @return If an option was successfully found, function returns
* the option character.
*/
int getopt_long(int nargc, char *const *nargv,
const char *options, const struct option *long_options,
int *idx);
int getopt_long(int nargc, char *const *nargv, const char *options,
const struct option *long_options, int *idx);

/**
* @brief Parses the command-line arguments.
Expand All @@ -106,9 +105,8 @@ int getopt_long(int nargc, char *const *nargv,
* @return If an option was successfully found, function returns
* the option character.
*/
int getopt_long_only(int nargc, char *const *nargv,
const char *options, const struct option *long_options,
int *idx);
int getopt_long_only(int nargc, char *const *nargv, const char *options,
const struct option *long_options, int *idx);

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* When more threads are using getopt please call getopt_state_get to know
* getopt state for the current thread.
*/
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int optopt; /* character checked for validity */
int optreset; /* reset getopt */
char *optarg; /* argument associated with option */
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int optopt; /* character checked for validity */
int optreset; /* reset getopt */
char *optarg; /* argument associated with option */

/* Common state for all threads that did not have own getopt state. */
static struct getopt_state m_getopt_common_state = {
Expand All @@ -34,7 +34,7 @@ static struct getopt_state m_getopt_common_state = {

#if CONFIG_GETOPT_LONG
.nonopt_start = -1, /* first non option argument (for permute) */
.nonopt_end = -1, /* first option after non options (for permute) */
.nonopt_end = -1, /* first option after non options (for permute) */
#endif
};

Expand Down
Loading
Loading