Skip to content

Commit e6330e3

Browse files
committed
posix: move limit definitions to common libc limits.h
In order to reduce conflicts with limits defined in external C libraries, move Zephyr's POSIX limits from posix_features.h to limits.h in the common C library sources. In order to give the implementation better control over where POSIX limit definitions originate, use `#include_next <limits.h>` to pull in the corresponding header of the C library, and provide a non-user configurable option `CONFIG_TC_PROVIDES_POSIX_LIMIT_DEFS` that may be set in order to ensure that the C library version of POSIX limits are used. Note: this may mean that runtime invariant values are inconsistent with parts that are actually in use within Zephyr, so applications are encouraged to use `sysconf()` with external C libraries that implement parts of the POSIX standard to query system configuration values at runtime. Signed-off-by: Chris Friedt <[email protected]>
1 parent db15de5 commit e6330e3

File tree

4 files changed

+140
-2
lines changed

4 files changed

+140
-2
lines changed

include/zephyr/posix/sys/dirent.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
#include <limits.h>
1111

12-
#include <zephyr/posix/posix_features.h>
13-
1412
#if !defined(NAME_MAX) && defined(_XOPEN_SOURCE)
1513
#define NAME_MAX _XOPEN_NAME_MAX
1614
#endif

lib/libc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ config PICOLIBC
103103
imply THREAD_LOCAL_STORAGE if ARCH_HAS_THREAD_LOCAL_STORAGE && TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE
104104
select LIBC_ERRNO if THREAD_LOCAL_STORAGE
105105
select NEED_LIBC_MEM_PARTITION
106+
select TC_PROVIDES_POSIX_LIMIT_DEFS
106107
select TC_PROVIDES_POSIX_C_LANG_SUPPORT_R
107108
imply COMMON_LIBC_MALLOC
108109
imply COMMON_LIBC_ABORT

lib/libc/common/include/limits.h

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright The Zephyr Project Contributors
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_LIB_LIBC_COMMON_INCLUDE_LIMITS_H_
8+
#define ZEPHYR_LIB_LIBC_COMMON_INCLUDE_LIMITS_H_
9+
10+
#include_next <limits.h>
11+
12+
#if !defined(CONFIG_TC_PROVIDES_POSIX_LIMIT_DEFS)
13+
14+
#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
15+
16+
/*
17+
* clang-format and checkpatch disagree on formatting here, so use rely and checkpatch and disable
18+
* clang-format since the checkpatch cannot be selectively disabled.
19+
*/
20+
21+
/* clang-format off */
22+
23+
/* Maximum values */
24+
#define _POSIX_CLOCKRES_MIN (20000000L)
25+
26+
/* Minimum values */
27+
#define _POSIX_AIO_LISTIO_MAX (2)
28+
#define _POSIX_AIO_MAX (1)
29+
#define _POSIX_ARG_MAX (4096)
30+
#define _POSIX_CHILD_MAX (25)
31+
#define _POSIX_DELAYTIMER_MAX (32)
32+
#define _POSIX_HOST_NAME_MAX (255)
33+
#define _POSIX_LINK_MAX (8)
34+
#define _POSIX_LOGIN_NAME_MAX (9)
35+
#define _POSIX_MAX_CANON (255)
36+
#define _POSIX_MAX_INPUT (255)
37+
#define _POSIX_MQ_OPEN_MAX (8)
38+
#define _POSIX_MQ_PRIO_MAX (32)
39+
#define _POSIX_NAME_MAX (14)
40+
#define _POSIX_NGROUPS_MAX (8)
41+
#define _POSIX_OPEN_MAX (20)
42+
#define _POSIX_PATH_MAX (256)
43+
#define _POSIX_PIPE_BUF (512)
44+
#define _POSIX_RE_DUP_MAX (255)
45+
#define _POSIX_RTSIG_MAX (8)
46+
#define _POSIX_SEM_NSEMS_MAX (256)
47+
#define _POSIX_SEM_VALUE_MAX (32767)
48+
#define _POSIX_SIGQUEUE_MAX (32)
49+
#define _POSIX_SSIZE_MAX (32767)
50+
#define _POSIX_SS_REPL_MAX (4)
51+
#define _POSIX_STREAM_MAX (8)
52+
#define _POSIX_SYMLINK_MAX (255)
53+
#define _POSIX_SYMLOOP_MAX (8)
54+
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS (4)
55+
#define _POSIX_THREAD_KEYS_MAX (128)
56+
#define _POSIX_THREAD_THREADS_MAX (64)
57+
#define _POSIX_TIMER_MAX (32)
58+
#define _POSIX_TRACE_EVENT_NAME_MAX (30)
59+
#define _POSIX_TRACE_NAME_MAX (8)
60+
#define _POSIX_TRACE_SYS_MAX (8)
61+
#define _POSIX_TRACE_USER_EVENT_MAX (32)
62+
#define _POSIX_TTY_NAME_MAX (9)
63+
#define _POSIX_TZNAME_MAX (6)
64+
#define _POSIX2_BC_BASE_MAX (99)
65+
#define _POSIX2_BC_DIM_MAX (2048)
66+
#define _POSIX2_BC_SCALE_MAX (99)
67+
#define _POSIX2_BC_STRING_MAX (1000)
68+
#define _POSIX2_CHARCLASS_NAME_MAX (14)
69+
#define _POSIX2_COLL_WEIGHTS_MAX (2)
70+
#define _POSIX2_EXPR_NEST_MAX (32)
71+
#define _POSIX2_LINE_MAX (2048)
72+
#define _XOPEN_IOV_MAX (16)
73+
#define _XOPEN_NAME_MAX (255)
74+
#define _XOPEN_PATH_MAX (1024)
75+
76+
/* Other invariant values */
77+
#define NL_LANGMAX (14)
78+
#define NL_MSGMAX (32767)
79+
#define NL_SETMAX (255)
80+
#define NL_TEXTMAX (_POSIX2_LINE_MAX)
81+
#define NZERO (20)
82+
83+
/* Runtime invariant values */
84+
#define AIO_LISTIO_MAX _POSIX_AIO_LISTIO_MAX
85+
#define AIO_MAX _POSIX_AIO_MAX
86+
#define AIO_PRIO_DELTA_MAX (0)
87+
#define ARG_MAX _POSIX_ARG_MAX
88+
#define ATEXIT_MAX (32)
89+
#define DELAYTIMER_MAX \
90+
COND_CODE_1(CONFIG_POSIX_TIMERS, (CONFIG_POSIX_DELAYTIMER_MAX), (0))
91+
#define HOST_NAME_MAX \
92+
COND_CODE_1(CONFIG_POSIX_NETWORKING, (CONFIG_POSIX_HOST_NAME_MAX), (0))
93+
#define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX
94+
#define MQ_OPEN_MAX \
95+
COND_CODE_1(CONFIG_POSIX_MESSAGE_PASSING, (CONFIG_POSIX_MQ_OPEN_MAX), (0))
96+
#define MQ_PRIO_MAX _POSIX_MQ_PRIO_MAX
97+
#define OPEN_MAX CONFIG_POSIX_OPEN_MAX
98+
#define PAGE_SIZE CONFIG_POSIX_PAGE_SIZE
99+
#define PAGESIZE CONFIG_POSIX_PAGE_SIZE
100+
#undef PATH_MAX
101+
#define PATH_MAX _POSIX_PATH_MAX
102+
#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
103+
#define PTHREAD_KEYS_MAX \
104+
COND_CODE_1(CONFIG_POSIX_THREADS, (CONFIG_POSIX_THREAD_KEYS_MAX), (0))
105+
#define PTHREAD_THREADS_MAX \
106+
COND_CODE_1(CONFIG_POSIX_THREADS, (CONFIG_POSIX_THREAD_THREADS_MAX), (0))
107+
#define RTSIG_MAX \
108+
COND_CODE_1(CONFIG_POSIX_REALTIME_SIGNALS, (CONFIG_POSIX_RTSIG_MAX), (0))
109+
#define SEM_NSEMS_MAX \
110+
COND_CODE_1(CONFIG_POSIX_SEMAPHORES, (CONFIG_POSIX_SEM_NSEMS_MAX), (0))
111+
#define SEM_VALUE_MAX \
112+
COND_CODE_1(CONFIG_POSIX_SEMAPHORES, (CONFIG_POSIX_SEM_VALUE_MAX), (0))
113+
#define SIGQUEUE_MAX _POSIX_SIGQUEUE_MAX
114+
#define STREAM_MAX _POSIX_STREAM_MAX
115+
#define SYMLOOP_MAX _POSIX_SYMLOOP_MAX
116+
#define TIMER_MAX \
117+
COND_CODE_1(CONFIG_POSIX_TIMERS, (CONFIG_POSIX_TIMER_MAX), (0))
118+
#define TTY_NAME_MAX _POSIX_TTY_NAME_MAX
119+
#define TZNAME_MAX _POSIX_TZNAME_MAX
120+
121+
/* Pathname variable values */
122+
#define FILESIZEBITS (32)
123+
#define POSIX_ALLOC_SIZE_MIN (256)
124+
#define POSIX_REC_INCR_XFER_SIZE (1024)
125+
#define POSIX_REC_MAX_XFER_SIZE (32767)
126+
#define POSIX_REC_MIN_XFER_SIZE (1)
127+
#define POSIX_REC_XFER_ALIGN (4)
128+
#define SYMLINK_MAX _POSIX_SYMLINK_MAX
129+
130+
/* clang-format on */
131+
132+
#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */
133+
134+
#endif /* !defined(CONFIG_TC_PROVIDES_POSIX_LIMIT_DEFS) */
135+
136+
#endif /* ZEPHYR_LIB_LIBC_COMMON_INCLUDE_LIMITS_H_ */

lib/posix/options/Kconfig.toolchain

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#
1414
# https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
1515

16+
config TC_PROVIDES_POSIX_LIMIT_DEFS
17+
bool
18+
1619
config TC_PROVIDES_POSIX_ASYNCHRONOUS_IO
1720
bool
1821

0 commit comments

Comments
 (0)