Skip to content
Merged
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
2 changes: 1 addition & 1 deletion doc/services/portability/posix/aep/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The *Minimal Realtime System Profile* (PSE51) includes all of the

:ref:`POSIX_C_LANG_JUMP <posix_option_group_c_lang_jump>`, yes,
:ref:`POSIX_C_LANG_SUPPORT <posix_option_group_c_lang_support>`, yes,
:ref:`POSIX_DEVICE_IO <posix_option_group_device_io>`,, :kconfig:option:`CONFIG_POSIX_DEVICE_IO`
:ref:`POSIX_DEVICE_IO <posix_option_group_device_io>`, yes, :kconfig:option:`CONFIG_POSIX_DEVICE_IO`
:ref:`POSIX_SIGNALS <posix_option_group_signals>`,, :kconfig:option:`CONFIG_POSIX_SIGNALS`
:ref:`POSIX_SINGLE_PROCESS <posix_option_group_single_process>`, yes, :kconfig:option:`CONFIG_POSIX_SINGLE_PROCESS`
:ref:`XSI_THREADS_EXT <posix_option_group_xsi_threads_ext>`, yes, :kconfig:option:`CONFIG_XSI_THREADS_EXT`
Expand Down
58 changes: 31 additions & 27 deletions doc/services/portability/posix/option_groups/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ required for error and event handling.
POSIX_DEVICE_IO
===============

.. note::
When using Newlib, Picolibc, or other C libraries conforming to the ISO C Standard, the
C89 components of the ``POSIX_DEVICE_IO`` Option Group are considered supported.

.. csv-table:: POSIX_DEVICE_IO
:header: API, Supported
:widths: 50,10
Expand All @@ -281,48 +285,48 @@ POSIX_DEVICE_IO
FD_ZERO(),yes
clearerr(),yes
close(),yes
fclose(),
fdopen(),
feof(),
ferror(),
fflush(),
fgetc(),
fgets(),
fileno(),
fopen(),
fclose(),yes
fdopen(), yes
feof(),yes
ferror(),yes
fflush(),yes
fgetc(),yes
fgets(),yes
fileno(), yes
fopen(),yes
fprintf(),yes
fputc(),yes
fputs(),yes
fread(),
freopen(),
fscanf(),
fread(),yes
freopen(),yes
fscanf(),yes
fwrite(),yes
getc(),
getchar(),
gets(),
getc(),yes
getchar(),yes
gets(),yes
open(),yes
perror(),yes
poll(),yes
printf(),yes
pread(),
pselect(),
pread(),yes
pselect(),yes
putc(),yes
putchar(),yes
puts(),yes
pwrite(),
pwrite(),yes
read(),yes
scanf(),
scanf(),yes
select(),yes
setbuf(),
setvbuf(),
stderr,
stdin,
stdout,
ungetc(),
setbuf(),yes
setvbuf(),yes
stderr,yes
stdin,yes
stdout,yes
ungetc(),yes
vfprintf(),yes
vfscanf(),
vfscanf(),yes
vprintf(),yes
vscanf(),
vscanf(),yes
write(),yes

.. _posix_option_group_barriers:
Expand Down
5 changes: 4 additions & 1 deletion include/zephyr/net/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,10 @@ static inline int zsock_ioctl_wrapper(int sock, unsigned long request, ...)
* it may conflict with generic POSIX ``poll()`` function).
* @endrst
*/
__syscall int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout);
static inline int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout)
{
return zvfs_poll(fds, nfds, timeout);
}

/**
* @brief Get various socket options
Expand Down
8 changes: 3 additions & 5 deletions include/zephyr/net/socket_poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef ZEPHYR_INCLUDE_NET_SOCKET_POLL_H_
#define ZEPHYR_INCLUDE_NET_SOCKET_POLL_H_

#include <zephyr/sys/fdtable.h>

/* Setting for pollfd to avoid circular inclusion */

/**
Expand All @@ -25,11 +27,7 @@ extern "C" {
*
* An array of these descriptors is passed as an argument to poll().
*/
struct zsock_pollfd {
int fd; /**< Socket descriptor */
short events; /**< Requested events */
short revents; /**< Returned events */
};
#define zsock_pollfd zvfs_pollfd

#ifdef __cplusplus
}
Expand Down
45 changes: 31 additions & 14 deletions include/zephyr/net/socket_select.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
* @{
*/

#include <time.h>

#include <zephyr/toolchain.h>
#include <zephyr/net/socket_types.h>
#include <zephyr/sys/fdtable.h>

#ifdef __cplusplus
extern "C" {
#endif

/** Socket file descriptor set. */
typedef struct zsock_fd_set {
uint32_t bitset[(CONFIG_ZVFS_OPEN_MAX + 31) / 32];
} zsock_fd_set;
typedef struct zvfs_fd_set zsock_fd_set;

/**
* @brief Legacy function to poll multiple sockets for events
Expand All @@ -47,13 +48,19 @@ typedef struct zsock_fd_set {
* it may conflict with generic POSIX ``select()`` function).
* @endrst
*/
__syscall int zsock_select(int nfds, zsock_fd_set *readfds,
zsock_fd_set *writefds,
zsock_fd_set *exceptfds,
struct zsock_timeval *timeout);
static inline int zsock_select(int nfds, zsock_fd_set *readfds, zsock_fd_set *writefds,
zsock_fd_set *exceptfds, struct zsock_timeval *timeout)
{
struct timespec to = {
.tv_sec = (timeout == NULL) ? 0 : timeout->tv_sec,
.tv_nsec = (long)((timeout == NULL) ? 0 : timeout->tv_usec * NSEC_PER_USEC)};

return zvfs_select(nfds, (struct zvfs_fd_set *)readfds, (struct zvfs_fd_set *)writefds,
(struct zvfs_fd_set *)exceptfds, (timeout == NULL) ? NULL : &to, NULL);
}

/** Number of file descriptors which can be added to zsock_fd_set */
#define ZSOCK_FD_SETSIZE (sizeof(((zsock_fd_set *)0)->bitset) * 8)
#define ZSOCK_FD_SETSIZE ZVFS_FD_SETSIZE

/**
* @brief Initialize (clear) fd_set
Expand All @@ -67,7 +74,10 @@ __syscall int zsock_select(int nfds, zsock_fd_set *readfds,
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* @endrst
*/
void ZSOCK_FD_ZERO(zsock_fd_set *set);
static inline void ZSOCK_FD_ZERO(zsock_fd_set *set)
{
ZVFS_FD_ZERO(set);
}

/**
* @brief Check whether socket is a member of fd_set
Expand All @@ -81,7 +91,10 @@ void ZSOCK_FD_ZERO(zsock_fd_set *set);
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* @endrst
*/
int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set);
static inline int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set)
{
return ZVFS_FD_ISSET(fd, set);
}

/**
* @brief Remove socket from fd_set
Expand All @@ -95,7 +108,10 @@ int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set);
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* @endrst
*/
void ZSOCK_FD_CLR(int fd, zsock_fd_set *set);
static inline void ZSOCK_FD_CLR(int fd, zsock_fd_set *set)
{
ZVFS_FD_CLR(fd, set);
}

/**
* @brief Add socket to fd_set
Expand All @@ -109,7 +125,10 @@ void ZSOCK_FD_CLR(int fd, zsock_fd_set *set);
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* @endrst
*/
void ZSOCK_FD_SET(int fd, zsock_fd_set *set);
static inline void ZSOCK_FD_SET(int fd, zsock_fd_set *set)
{
ZVFS_FD_SET(fd, set);
}

/** @cond INTERNAL_HIDDEN */

Expand Down Expand Up @@ -153,8 +172,6 @@ static inline void FD_SET(int fd, zsock_fd_set *set)
}
#endif

#include <zephyr/syscalls/socket_select.h>

/**
* @}
*/
Expand Down
9 changes: 6 additions & 3 deletions include/zephyr/posix/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
#define ZEPHYR_POSIX_FCNTL_H_

#ifdef CONFIG_PICOLIBC
#define O_CREAT 0x0040
#define O_CREAT 0x0040
#define O_TRUNC 0x0200
#define O_APPEND 0x0400
#else
#define O_CREAT 0x0200
#define O_APPEND 0x0008
#define O_CREAT 0x0200
#define O_TRUNC 0x0400
#endif

#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
Expand All @@ -19,7 +23,6 @@
#define O_WRONLY 01
#define O_RDWR 02

#define O_APPEND 0x0400
#define O_EXCL 0x0800
#define O_NONBLOCK 0x4000

Expand Down
16 changes: 10 additions & 6 deletions include/zephyr/posix/sys/select.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@
extern "C" {
#endif

#undef fd_set
#define fd_set zsock_fd_set
#define FD_SETSIZE ZSOCK_FD_SETSIZE
#define FD_ZERO ZSOCK_FD_ZERO
#define FD_SET ZSOCK_FD_SET
#define FD_CLR ZSOCK_FD_CLR
#define FD_ISSET ZSOCK_FD_ISSET

#define FD_SETSIZE ZVFS_FD_SETSIZE

struct timeval;

int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
const struct timespec *timeout, const void *sigmask);
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout);
void FD_CLR(int fd, fd_set *fdset);
int FD_ISSET(int fd, fd_set *fdset);
void FD_SET(int fd, fd_set *fdset);
void FD_ZERO(fd_set *fdset);

#ifdef __cplusplus
}
Expand Down
36 changes: 36 additions & 0 deletions include/zephyr/sys/fdtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

#include <stdarg.h>
#include <sys/types.h>

/* FIXME: For native_posix ssize_t, off_t. */
#include <zephyr/fs/fs.h>
#include <zephyr/sys/mutex.h>
#include <zephyr/sys/util.h>

/* File mode bits */
#define ZVFS_MODE_IFMT 0170000
Expand All @@ -26,6 +28,13 @@
#define ZVFS_MODE_IFLNK 0120000
#define ZVFS_MODE_IFSOCK 0140000

#define ZVFS_POLLIN BIT(0)
#define ZVFS_POLLPRI BIT(1)
#define ZVFS_POLLOUT BIT(2)
#define ZVFS_POLLERR BIT(3)
#define ZVFS_POLLHUP BIT(4)
#define ZVFS_POLLNVAL BIT(5)

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -191,6 +200,31 @@ static inline int zvfs_fdtable_call_ioctl(const struct fd_op_vtable *vtable, voi
return res;
}

struct zvfs_pollfd {
int fd;
short events;
short revents;
};

__syscall int zvfs_poll(struct zvfs_pollfd *fds, int nfds, int poll_timeout);

struct zvfs_fd_set {
uint32_t bitset[(CONFIG_ZVFS_OPEN_MAX + 31) / 32];
};

#define ZVFS_FD_SETSIZE (sizeof(((struct zvfs_fd_set *)0)->bitset) * 8)

void ZVFS_FD_CLR(int fd, struct zvfs_fd_set *fdset);
int ZVFS_FD_ISSET(int fd, struct zvfs_fd_set *fdset);
void ZVFS_FD_SET(int fd, struct zvfs_fd_set *fdset);
void ZVFS_FD_ZERO(struct zvfs_fd_set *fdset);

struct timespec;
__syscall int zvfs_select(int nfds, struct zvfs_fd_set *ZRESTRICT readfds,
struct zvfs_fd_set *ZRESTRICT writefds,
struct zvfs_fd_set *ZRESTRICT errorfds,
const struct timespec *ZRESTRICT timeout, const void *ZRESTRICT sigmask);

/**
* Request codes for fd_op_vtable.ioctl().
*
Expand Down Expand Up @@ -220,4 +254,6 @@ enum {
}
#endif

#include <zephyr/syscalls/fdtable.h>

#endif /* ZEPHYR_INCLUDE_SYS_FDTABLE_H_ */
3 changes: 3 additions & 0 deletions lib/os/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ zephyr_sources(
)

zephyr_sources_ifdef(CONFIG_FDTABLE fdtable.c)
zephyr_syscall_header_ifdef(CONFIG_FDTABLE
${ZEPHYR_BASE}/include/zephyr/sys/fdtable.h
)

zephyr_sources_ifdef(CONFIG_CBPRINTF_COMPLETE cbprintf_complete.c)
zephyr_sources_ifdef(CONFIG_CBPRINTF_NANO cbprintf_nano.c)
Expand Down
Loading