From cdb1193f3e633f4f3c305b2dd58789a99143319d Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Mon, 15 Apr 2024 10:11:07 -0400 Subject: [PATCH] posix: add stubs for asynchronous io Add stubs for POSIX asynchronous io that return -1 and set errno to ENOTSUP. The functions and structures in aio.h are required by the _POSIX_ASYNCHRONOUS_IO Option as detailed in Section E.1 of IEEE-1003.1-2017. The _POSIX_ASYNCHRONOUS_IO interface is required for PSE51, PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory for any POSIX conforming system as per Section A.2.1.3 of IEEE-1003-1.2017. Signed-off-by: Chris Friedt --- include/zephyr/posix/aio.h | 46 ++++++++++++++++++ include/zephyr/posix/unistd.h | 2 +- lib/posix/options/CMakeLists.txt | 1 + lib/posix/options/Kconfig | 1 + lib/posix/options/Kconfig.aio | 10 ++++ lib/posix/options/aio.c | 82 ++++++++++++++++++++++++++++++++ 6 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 include/zephyr/posix/aio.h create mode 100644 lib/posix/options/Kconfig.aio create mode 100644 lib/posix/options/aio.c diff --git a/include/zephyr/posix/aio.h b/include/zephyr/posix/aio.h new file mode 100644 index 0000000000..8645ff801c --- /dev/null +++ b/include/zephyr/posix/aio.h @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Tenstorrent AI ULC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_ZEPHYR_POSIX_AIO_H_ +#define ZEPHYR_INCLUDE_ZEPHYR_POSIX_AIO_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct aiocb { + int aio_fildes; + off_t aio_offset; + volatile void *aio_buf; + size_t aio_nbytes; + int aio_reqprio; + struct sigevent aio_sigevent; + int aio_lio_opcode; +}; + +#if _POSIX_C_SOURCE >= 200112L + +int aio_cancel(int fildes, struct aiocb *aiocbp); +int aio_error(const struct aiocb *aiocbp); +int aio_fsync(int filedes, struct aiocb *aiocbp); +int aio_read(struct aiocb *aiocbp); +ssize_t aio_return(struct aiocb *aiocbp); +int aio_suspend(const struct aiocb *const list[], int nent, const struct timespec *timeout); +int aio_write(struct aiocb *aiocbp); +int lio_listio(int mode, struct aiocb *const ZRESTRICT list[], int nent, + struct sigevent *ZRESTRICT sig); + +#endif /* _POSIX_C_SOURCE >= 200112L */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_ZEPHYR_POSIX_AIO_H_ */ diff --git a/include/zephyr/posix/unistd.h b/include/zephyr/posix/unistd.h index 990211730e..89fc159f27 100644 --- a/include/zephyr/posix/unistd.h +++ b/include/zephyr/posix/unistd.h @@ -37,7 +37,7 @@ extern "C" { /* Constants for Options and Option Groups */ #define _POSIX_ADVISORY_INFO (-1L) -#define _POSIX_ASYNCHRONOUS_IO (-1L) +#define _POSIX_ASYNCHRONOUS_IO Z_SC_VAL_IFDEF(CONFIG_POSIX_ASYNCHRONOUS_IO, _POSIX_VERSION) #define _POSIX_BARRIERS Z_SC_VAL_IFDEF(CONFIG_PTHREAD_IPC, _POSIX_VERSION) #define _POSIX_CHOWN_RESTRICTED (-1L) #define _POSIX_CLOCK_SELECTION Z_SC_VAL_IFDEF(CONFIG_POSIX_CLOCK, _POSIX_VERSION) diff --git a/lib/posix/options/CMakeLists.txt b/lib/posix/options/CMakeLists.txt index d7f3ef94e5..68794e442e 100644 --- a/lib/posix/options/CMakeLists.txt +++ b/lib/posix/options/CMakeLists.txt @@ -37,6 +37,7 @@ 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_ASYNCHRONOUS_IO aio.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) diff --git a/lib/posix/options/Kconfig b/lib/posix/options/Kconfig index ee9bd0f662..1f0da85318 100644 --- a/lib/posix/options/Kconfig +++ b/lib/posix/options/Kconfig @@ -25,6 +25,7 @@ config PTHREAD_IPC endif # POSIX_CLOCK +rsource "Kconfig.aio" rsource "Kconfig.barrier" rsource "Kconfig.clock" rsource "Kconfig.cond" diff --git a/lib/posix/options/Kconfig.aio b/lib/posix/options/Kconfig.aio new file mode 100644 index 0000000000..6fc3534973 --- /dev/null +++ b/lib/posix/options/Kconfig.aio @@ -0,0 +1,10 @@ +# Copyright (c) 2024 Tenstorrent AI ULC +# +# SPDX-License-Identifier: Apache-2.0 + +config POSIX_ASYNCHRONOUS_IO + bool "Asynchronous IO" + default y if POSIX_API + help + Enable this option for asynchronous I/O. This option is present for conformance purposes + only. All functions listed in return -1 and set errno to ENOSYS. diff --git a/lib/posix/options/aio.c b/lib/posix/options/aio.c new file mode 100644 index 0000000000..538333345d --- /dev/null +++ b/lib/posix/options/aio.c @@ -0,0 +1,82 @@ +/* + * Copyright 2024 Tenstorrent AI ULC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include + +int aio_cancel(int fildes, struct aiocb *aiocbp) +{ + ARG_UNUSED(fildes); + ARG_UNUSED(aiocbp); + + errno = ENOSYS; + return -1; +} + +int aio_error(const struct aiocb *aiocbp) +{ + ARG_UNUSED(aiocbp); + + errno = ENOSYS; + return -1; +} + +int aio_fsync(int fildes, struct aiocb *aiocbp) +{ + ARG_UNUSED(fildes); + ARG_UNUSED(aiocbp); + + errno = ENOSYS; + return -1; +} + +int aio_read(struct aiocb *aiocbp) +{ + ARG_UNUSED(aiocbp); + + errno = ENOSYS; + return -1; +} + +ssize_t aio_return(struct aiocb *aiocbp) +{ + ARG_UNUSED(aiocbp); + + errno = ENOSYS; + return -1; +} + +int aio_suspend(const struct aiocb *const list[], int nent, const struct timespec *timeout) +{ + ARG_UNUSED(list); + ARG_UNUSED(nent); + ARG_UNUSED(timeout); + + errno = ENOSYS; + return -1; +} + +int aio_write(struct aiocb *aiocbp) +{ + ARG_UNUSED(aiocbp); + + errno = ENOSYS; + return -1; +} + +int lio_listio(int mode, struct aiocb *const ZRESTRICT list[], int nent, + struct sigevent *ZRESTRICT sig) +{ + ARG_UNUSED(mode); + ARG_UNUSED(list); + ARG_UNUSED(nent); + ARG_UNUSED(sig); + + errno = ENOSYS; + return -1; +}