Skip to content

Commit

Permalink
posix: separate shell utilities and posix api implementation
Browse files Browse the repository at this point in the history
Previously, the POSIX shell utilities were intermixed with the
POSIX API implementation.

The POSIX shell utilities only depend on the public POSIX API,
so it makes sense to keep them in a separate subdirectory.

(cherry picked from commit 855b8bc)

Original-Signed-off-by: Christopher Friedt <cfriedt@meta.com>
GitOrigin-RevId: 855b8bc
Change-Id: I76a8a18bb82bd0ab1d3030fd64bcb800c69a007d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5280059
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Commit-Queue: Al Semjonovs <asemjonovs@google.com>
Reviewed-by: Al Semjonovs <asemjonovs@google.com>
Tested-by: Al Semjonovs <asemjonovs@google.com>
  • Loading branch information
cfriedt authored and Chromeos LUCI committed Feb 8, 2024
1 parent c2c4b98 commit 0c77b0e
Show file tree
Hide file tree
Showing 65 changed files with 238 additions and 189 deletions.
69 changes: 2 additions & 67 deletions lib/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,69 +1,4 @@
# SPDX-License-Identifier: Apache-2.0

set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated)

zephyr_syscall_header(
posix_clock.h
)

zephyr_interface_library_named(posix_subsys)

if(CONFIG_POSIX_API)
zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/posix)
endif()

if(CONFIG_POSIX_SIGNAL)
set(STRSIGNAL_TABLE_H ${GEN_DIR}/posix/strsignal_table.h)

add_custom_command(
OUTPUT ${STRSIGNAL_TABLE_H}
COMMAND
${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/build/gen_strsignal_table.py
-i ${ZEPHYR_BASE}/include/zephyr/posix/signal.h
-o ${STRSIGNAL_TABLE_H}
DEPENDS ${ZEPHYR_BASE}/include/zephyr/posix/signal.h
)
endif()

if(CONFIG_POSIX_API OR CONFIG_PTHREAD_IPC OR CONFIG_POSIX_CLOCK OR
CONFIG_POSIX_MQUEUE OR CONFIG_POSIX_FS OR CONFIG_EVENTFD OR CONFIG_GETOPT)
# This is a temporary workaround so that Newlib declares the appropriate
# types for us. POSIX features to be formalized as part of #51211
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:-D_POSIX_THREADS>)
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:-D_POSIX_THREADS>)
endif()

zephyr_library()
add_subdirectory_ifdef(CONFIG_GETOPT getopt)
add_subdirectory_ifdef(CONFIG_SHELL shell)
zephyr_library_sources_ifdef(CONFIG_EVENTFD eventfd.c)
zephyr_library_sources_ifdef(CONFIG_FNMATCH fnmatch.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_API perror.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK clock.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK nanosleep.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK sleep.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_FS fs.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_MQUEUE mqueue.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_SIGNAL signal.c ${STRSIGNAL_TABLE_H})
zephyr_library_sources_ifdef(CONFIG_POSIX_UNAME uname.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC _common.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_BARRIER barrier.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_COND cond.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_KEY key.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_MUTEX mutex.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD pthread.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_RWLOCK rwlock.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC semaphore.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_SPINLOCK spinlock.c)
zephyr_library_sources_ifdef(CONFIG_TIMER timer.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_PUTMSG stropts.c)

zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include
${ARCH_DIR}/${ARCH}/include
)

zephyr_library_link_libraries(posix_subsys)
zephyr_library_property(ALLOW_EMPTY TRUE)
add_subdirectory(options)
add_subdirectory(shell)
76 changes: 2 additions & 74 deletions lib/posix/Kconfig
Original file line number Diff line number Diff line change
@@ -1,82 +1,10 @@
# Copyright (c) 2018 Intel Corporation
# Copyright (c) 2023 Meta
# Copyright (c) 2024 Meta
#
# SPDX-License-Identifier: Apache-2.0

menu "POSIX API Support"

config POSIX_MAX_FDS
int "Maximum number of open file descriptors"
default 16 if WIFI_NM_WPA_SUPPLICANT
default 16 if POSIX_API
default 4
help
Maximum number of open file descriptors, this includes
files, sockets, special devices, etc.

config POSIX_API
depends on !NATIVE_APPLICATION
bool "POSIX APIs"
help
Enable mostly-standards-compliant implementations of
various POSIX (IEEE 1003.1) APIs.

# The name of this option is mandated by zephyr_interface_library_named
# cmake directive.
config APP_LINK_WITH_POSIX_SUBSYS
bool "Make POSIX headers available to application"
default y
depends on POSIX_API
help
Add POSIX subsystem header files to the 'app' include path.

config PTHREAD_IPC
bool "POSIX pthread IPC API"
default y if POSIX_API
depends on POSIX_CLOCK
help
This enables a mostly-standards-compliant implementation of
the pthread mutex, condition variable and barrier IPC
mechanisms.

config POSIX_SYSCONF
bool "Support for sysconf"
default y if POSIX_API
help
The sysconf() function provides a method for the application to determine
the current value of a configurable system limit or option (variable).

config POSIX_PAGE_SIZE_BITS
int "Number of bits to use for PAGE_SIZE"
range 6 16
default 12 if POSIX_API
default 6
help
Define PAGE_SIZE as BIT(n), where n is the value configured here.
PAGE_SIZE is supported in the range [64, 65536]
If CONFIG_POSIX_API=y, PAGE_SIZE defaults to 4096, otherwise, it is 64 bytes.

source "lib/posix/Kconfig.barrier"
source "lib/posix/Kconfig.clock"
source "lib/posix/Kconfig.cond"
source "lib/posix/Kconfig.eventfd"
source "lib/posix/Kconfig.fnmatch"
source "lib/posix/Kconfig.fs"
source "lib/posix/Kconfig.getopt"
source "lib/posix/Kconfig.key"
source "lib/posix/Kconfig.limits"
source "lib/posix/Kconfig.mqueue"
source "lib/posix/Kconfig.mutex"
source "lib/posix/Kconfig.pthread"
source "lib/posix/Kconfig.rwlock"
source "lib/posix/Kconfig.sched"
source "lib/posix/Kconfig.semaphore"
source "lib/posix/Kconfig.signal"
source "lib/posix/Kconfig.spinlock"
source "lib/posix/Kconfig.timer"
source "lib/posix/Kconfig.uname"
source "lib/posix/Kconfig.stropts"

rsource "options/Kconfig"
rsource "shell/Kconfig"

endmenu # "POSIX API Support"
13 changes: 0 additions & 13 deletions lib/posix/Kconfig.limits

This file was deleted.

68 changes: 68 additions & 0 deletions lib/posix/options/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# SPDX-License-Identifier: Apache-2.0

set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated)

zephyr_syscall_header(
posix_clock.h
)

zephyr_interface_library_named(posix_subsys)

if(CONFIG_POSIX_API)
zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/posix)
endif()

if(CONFIG_POSIX_SIGNAL)
set(STRSIGNAL_TABLE_H ${GEN_DIR}/posix/strsignal_table.h)

add_custom_command(
OUTPUT ${STRSIGNAL_TABLE_H}
COMMAND
${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/build/gen_strsignal_table.py
-i ${ZEPHYR_BASE}/include/zephyr/posix/signal.h
-o ${STRSIGNAL_TABLE_H}
DEPENDS ${ZEPHYR_BASE}/include/zephyr/posix/signal.h
)
endif()

if(CONFIG_POSIX_API OR CONFIG_PTHREAD_IPC OR CONFIG_POSIX_CLOCK OR
CONFIG_POSIX_MQUEUE OR CONFIG_POSIX_FS OR CONFIG_EVENTFD OR CONFIG_GETOPT)
# This is a temporary workaround so that Newlib declares the appropriate
# types for us. POSIX features to be formalized as part of #51211
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:-D_POSIX_THREADS>)
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:-D_POSIX_THREADS>)
endif()

zephyr_library()
add_subdirectory_ifdef(CONFIG_GETOPT getopt)
zephyr_library_sources_ifdef(CONFIG_EVENTFD eventfd.c)
zephyr_library_sources_ifdef(CONFIG_FNMATCH fnmatch.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_API perror.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK clock.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK nanosleep.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK sleep.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_FS fs.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_MQUEUE mqueue.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_PUTMSG stropts.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_SIGNAL signal.c ${STRSIGNAL_TABLE_H})
zephyr_library_sources_ifdef(CONFIG_POSIX_UNAME uname.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC _common.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_BARRIER barrier.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_COND cond.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_KEY key.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_MUTEX mutex.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD pthread.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_RWLOCK rwlock.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC semaphore.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_SPINLOCK spinlock.c)
zephyr_library_sources_ifdef(CONFIG_TIMER timer.c)

zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include
${ARCH_DIR}/${ARCH}/include
)

zephyr_library_link_libraries(posix_subsys)
zephyr_library_property(ALLOW_EMPTY TRUE)
58 changes: 58 additions & 0 deletions lib/posix/options/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (c) 2018 Intel Corporation
# Copyright (c) 2023 Meta
#
# SPDX-License-Identifier: Apache-2.0

menu "POSIX Options"

config POSIX_API
depends on !NATIVE_APPLICATION
bool "POSIX APIs"
help
Enable mostly-standards-compliant implementations of
various POSIX (IEEE 1003.1) APIs.

# The name of this option is mandated by zephyr_interface_library_named
# cmake directive.
config APP_LINK_WITH_POSIX_SUBSYS
bool "Make POSIX headers available to application"
default y
depends on POSIX_API
help
Add POSIX subsystem header files to the 'app' include path.

if POSIX_CLOCK

config PTHREAD_IPC
bool "POSIX pthread IPC API"
default y if POSIX_API
help
This enables a mostly-standards-compliant implementation of
the pthread mutex, condition variable and barrier IPC
mechanisms.

endif # POSIX_CLOCK

rsource "Kconfig.barrier"
rsource "Kconfig.clock"
rsource "Kconfig.cond"
rsource "Kconfig.eventfd"
rsource "Kconfig.fdtable"
rsource "Kconfig.fnmatch"
rsource "Kconfig.fs"
rsource "Kconfig.getopt"
rsource "Kconfig.key"
rsource "Kconfig.mqueue"
rsource "Kconfig.mutex"
rsource "Kconfig.pthread"
rsource "Kconfig.rwlock"
rsource "Kconfig.sched"
rsource "Kconfig.semaphore"
rsource "Kconfig.signal"
rsource "Kconfig.spinlock"
rsource "Kconfig.stropts"
rsource "Kconfig.sysconf"
rsource "Kconfig.timer"
rsource "Kconfig.uname"

endmenu # "POSIX Options"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TYPE = PTHREAD_BARRIER
type = pthread_barrier_t
type-function = pthread_barrier_wait
source "lib/posix/Kconfig.template.pooled_ipc_type"
rsource "Kconfig.template.pooled_ipc_type"

if PTHREAD_BARRIER

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

config POSIX_CLOCK
bool "POSIX clock and sleep APIs"
bool "clock and sleep APIs"
default y if POSIX_API
imply TIMER
depends on !NATIVE_LIBC
Expand Down
2 changes: 1 addition & 1 deletion lib/posix/Kconfig.cond → lib/posix/options/Kconfig.cond
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
TYPE = PTHREAD_COND
type = pthread_cond_t
type-function = pthread_cond_wait
source "lib/posix/Kconfig.template.pooled_ipc_type"
rsource "Kconfig.template.pooled_ipc_type"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# SPDX-License-Identifier: Apache-2.0

config EVENTFD
menuconfig EVENTFD
bool "Support for eventfd"
depends on !NATIVE_APPLICATION
select POLL
Expand Down
16 changes: 16 additions & 0 deletions lib/posix/options/Kconfig.fdtable
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2018 Linaro
#
# SPDX-License-Identifier: Apache-2.0

menu "File descriptor table options"

config POSIX_MAX_FDS
int "Maximum number of open file descriptors"
default 16 if WIFI_NM_WPA_SUPPLICANT
default 16 if POSIX_API
default 4
help
Maximum number of open file descriptors, this includes
files, sockets, special devices, etc.

endmenu # "File descriptor table options"
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/posix/Kconfig.fs → lib/posix/options/Kconfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0

config POSIX_FS
menuconfig POSIX_FS
bool "POSIX file system API support"
default y if POSIX_API
depends on FILE_SYSTEM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# SPDX-License-Identifier: Apache-2.0

source "lib/posix/getopt/Kconfig"
rsource "getopt/Kconfig"
2 changes: 1 addition & 1 deletion lib/posix/Kconfig.key → lib/posix/options/Kconfig.key
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
TYPE = PTHREAD_KEY
type = pthread_key_t
type-function = pthread_setspecific
source "lib/posix/Kconfig.template.pooled_ipc_type"
rsource "Kconfig.template.pooled_ipc_type"
4 changes: 2 additions & 2 deletions lib/posix/Kconfig.mqueue → lib/posix/options/Kconfig.mqueue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# SPDX-License-Identifier: Apache-2.0

config POSIX_MQUEUE
bool "POSIX message queue"
menuconfig POSIX_MQUEUE
bool "Message queue support"
default y if POSIX_API
help
This enabled POSIX message queue related APIs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
TYPE = PTHREAD_MUTEX
type = pthread_mutex_t
type-function = pthread_mutex_lock
source "lib/posix/Kconfig.template.pooled_ipc_type"
rsource "Kconfig.template.pooled_ipc_type"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TYPE = PTHREAD
type = pthread_t
type-function = pthread_create
source "lib/posix/Kconfig.template.pooled_ipc_type"
rsource "Kconfig.template.pooled_ipc_type"

if PTHREAD

Expand Down
Loading

0 comments on commit 0c77b0e

Please sign in to comment.