Skip to content

Commit 6a76659

Browse files
Nicholas LowellNicholas Lowell
Nicholas Lowell
authored and
Nicholas Lowell
committed
posix: sysconf: match _SC* defines with newlib/picolib
It's possible for newlib/picolib libc libraries to internally call sysconf() which would execute zephyr's implementation. However, if the _SC* defines do not have matching values, then the incorrect switch case executes. This issue arises when using newlib/picolib libc that includes sysconf implementation for ARM. With current defaults, the zephyr sysconf() overrides the original libc sysconf() so we must ensure proper operation. For Full Sysconf implementation, we will switch to the #define list just like newlib/picolib, but furthermore, we will try to reference their unistd.h and use their values when available. Signed-off-by: Nicholas Lowell <[email protected]>
1 parent 59b6224 commit 6a76659

File tree

3 files changed

+295
-260
lines changed

3 files changed

+295
-260
lines changed

include/zephyr/posix/sys/sysconf.h

+165-127
Original file line numberDiff line numberDiff line change
@@ -7,139 +7,177 @@
77
#ifndef ZEPHYR_INCLUDE_POSIX_SYS_SYSCONF_H_
88
#define ZEPHYR_INCLUDE_POSIX_SYS_SYSCONF_H_
99

10+
#include <zephyr/posix/pthread.h>
1011
#include <zephyr/sys/util_macro.h>
1112

1213
#ifdef __cplusplus
1314
extern "C" {
1415
#endif
1516

16-
enum {
17-
_SC_ADVISORY_INFO,
18-
_SC_ASYNCHRONOUS_IO,
19-
_SC_BARRIERS,
20-
_SC_CLOCK_SELECTION,
21-
_SC_CPUTIME,
22-
_SC_FSYNC,
23-
_SC_IPV6,
24-
_SC_JOB_CONTROL,
25-
_SC_MAPPED_FILES,
26-
_SC_MEMLOCK,
27-
_SC_MEMLOCK_RANGE,
28-
_SC_MEMORY_PROTECTION,
29-
_SC_MESSAGE_PASSING,
30-
_SC_MONOTONIC_CLOCK,
31-
_SC_PRIORITIZED_IO,
32-
_SC_PRIORITY_SCHEDULING,
33-
_SC_RAW_SOCKETS,
34-
_SC_RE_DUP_MAX,
35-
_SC_READER_WRITER_LOCKS,
36-
_SC_REALTIME_SIGNALS,
37-
_SC_REGEXP,
38-
_SC_SAVED_IDS,
39-
_SC_SEMAPHORES,
40-
_SC_SHARED_MEMORY_OBJECTS,
41-
_SC_SHELL,
42-
_SC_SPAWN,
43-
_SC_SPIN_LOCKS,
44-
_SC_SPORADIC_SERVER,
45-
_SC_SS_REPL_MAX,
46-
_SC_SYNCHRONIZED_IO,
47-
_SC_THREAD_ATTR_STACKADDR,
48-
_SC_THREAD_ATTR_STACKSIZE,
49-
_SC_THREAD_CPUTIME,
50-
_SC_THREAD_PRIO_INHERIT,
51-
_SC_THREAD_PRIO_PROTECT,
52-
_SC_THREAD_PRIORITY_SCHEDULING,
53-
_SC_THREAD_PROCESS_SHARED,
54-
_SC_THREAD_ROBUST_PRIO_INHERIT,
55-
_SC_THREAD_ROBUST_PRIO_PROTECT,
56-
_SC_THREAD_SAFE_FUNCTIONS,
57-
_SC_THREAD_SPORADIC_SERVER,
58-
_SC_THREADS,
59-
_SC_TIMEOUTS,
60-
_SC_TIMERS,
61-
_SC_TRACE,
62-
_SC_TRACE_EVENT_FILTER,
63-
_SC_TRACE_EVENT_NAME_MAX,
64-
_SC_TRACE_INHERIT,
65-
_SC_TRACE_LOG,
66-
_SC_TRACE_NAME_MAX,
67-
_SC_TRACE_SYS_MAX,
68-
_SC_TRACE_USER_EVENT_MAX,
69-
_SC_TYPED_MEMORY_OBJECTS,
70-
_SC_VERSION,
71-
_SC_V7_ILP32_OFF32,
72-
_SC_V7_ILP32_OFFBIG,
73-
_SC_V7_LP64_OFF64,
74-
_SC_V7_LPBIG_OFFBIG,
75-
_SC_V6_ILP32_OFF32,
76-
_SC_V6_ILP32_OFFBIG,
77-
_SC_V6_LP64_OFF64,
78-
_SC_V6_LPBIG_OFFBIG,
79-
_SC_BC_BASE_MAX,
80-
_SC_BC_DIM_MAX,
81-
_SC_BC_SCALE_MAX,
82-
_SC_BC_STRING_MAX,
83-
_SC_2_C_BIND,
84-
_SC_2_C_DEV,
85-
_SC_2_CHAR_TERM,
86-
_SC_COLL_WEIGHTS_MAX,
87-
_SC_DELAYTIMER_MAX,
88-
_SC_EXPR_NEST_MAX,
89-
_SC_2_FORT_DEV,
90-
_SC_2_FORT_RUN,
91-
_SC_LINE_MAX,
92-
_SC_2_LOCALEDEF,
93-
_SC_2_PBS,
94-
_SC_2_PBS_ACCOUNTING,
95-
_SC_2_PBS_CHECKPOINT,
96-
_SC_2_PBS_LOCATE,
97-
_SC_2_PBS_MESSAGE,
98-
_SC_2_PBS_TRACK,
99-
_SC_2_SW_DEV,
100-
_SC_2_UPE,
101-
_SC_2_VERSION,
102-
_SC_XOPEN_CRYPT,
103-
_SC_XOPEN_ENH_I18N,
104-
_SC_XOPEN_REALTIME,
105-
_SC_XOPEN_REALTIME_THREADS,
106-
_SC_XOPEN_SHM,
107-
_SC_XOPEN_STREAMS,
108-
_SC_XOPEN_UNIX,
109-
_SC_XOPEN_UUCP,
110-
_SC_XOPEN_VERSION,
111-
_SC_CLK_TCK,
112-
_SC_GETGR_R_SIZE_MAX,
113-
_SC_GETPW_R_SIZE_MAX,
114-
_SC_AIO_LISTIO_MAX,
115-
_SC_AIO_MAX,
116-
_SC_AIO_PRIO_DELTA_MAX,
117-
_SC_ARG_MAX,
118-
_SC_ATEXIT_MAX,
119-
_SC_CHILD_MAX,
120-
_SC_HOST_NAME_MAX,
121-
_SC_IOV_MAX,
122-
_SC_LOGIN_NAME_MAX,
123-
_SC_NGROUPS_MAX,
124-
_SC_MQ_OPEN_MAX,
125-
_SC_MQ_PRIO_MAX,
126-
_SC_OPEN_MAX,
127-
_SC_PAGE_SIZE,
128-
_SC_PAGESIZE,
129-
_SC_THREAD_DESTRUCTOR_ITERATIONS,
130-
_SC_THREAD_KEYS_MAX,
131-
_SC_THREAD_STACK_MIN,
132-
_SC_THREAD_THREADS_MAX,
133-
_SC_RTSIG_MAX,
134-
_SC_SEM_NSEMS_MAX,
135-
_SC_SEM_VALUE_MAX,
136-
_SC_SIGQUEUE_MAX,
137-
_SC_STREAM_MAX,
138-
_SC_SYMLOOP_MAX,
139-
_SC_TIMER_MAX,
140-
_SC_TTY_NAME_MAX,
141-
_SC_TZNAME_MAX,
142-
};
17+
#ifdef CONFIG_POSIX_SYSCONF_IMPL_FULL
18+
#ifndef _SC_ARG_MAX /* Assume if this is defined, so are the others */
19+
/* Values assigned are intended to match the values assigned in newlib and picolib
20+
* Even though the POSIX standard does not require specific values, this seems to be
21+
* required for proper sysconf() operation when called from within newlib/picolib itself.
22+
*/
23+
#define _SC_ARG_MAX 0
24+
#define _SC_CHILD_MAX 1
25+
#define _SC_CLK_TCK 2
26+
#define _SC_NGROUPS_MAX 3
27+
#define _SC_OPEN_MAX 4
28+
#define _SC_JOB_CONTROL 5
29+
#define _SC_SAVED_IDS 6
30+
#define _SC_VERSION 7
31+
#define _SC_PAGESIZE 8
32+
#define _SC_PAGE_SIZE _SC_PAGESIZE
33+
/* These are non-POSIX values we accidentally introduced in 2000 without
34+
* guarding them. Keeping them unguarded for backward compatibility.
35+
*/
36+
#define _SC_NPROCESSORS_CONF 9
37+
#define _SC_NPROCESSORS_ONLN 10
38+
#define _SC_PHYS_PAGES 11
39+
#define _SC_AVPHYS_PAGES 12
40+
/* End of non-POSIX values. */
41+
#define _SC_MQ_OPEN_MAX 13
42+
#define _SC_MQ_PRIO_MAX 14
43+
#define _SC_RTSIG_MAX 15
44+
#define _SC_SEM_NSEMS_MAX 16
45+
#define _SC_SEM_VALUE_MAX 17
46+
#define _SC_SIGQUEUE_MAX 18
47+
#define _SC_TIMER_MAX 19
48+
#define _SC_TZNAME_MAX 20
49+
#define _SC_ASYNCHRONOUS_IO 21
50+
#define _SC_FSYNC 22
51+
#define _SC_MAPPED_FILES 23
52+
#define _SC_MEMLOCK 24
53+
#define _SC_MEMLOCK_RANGE 25
54+
#define _SC_MEMORY_PROTECTION 26
55+
#define _SC_MESSAGE_PASSING 27
56+
#define _SC_PRIORITIZED_IO 28
57+
#define _SC_REALTIME_SIGNALS 29
58+
#define _SC_SEMAPHORES 30
59+
#define _SC_SHARED_MEMORY_OBJECTS 31
60+
#define _SC_SYNCHRONIZED_IO 32
61+
#define _SC_TIMERS 33
62+
#define _SC_AIO_LISTIO_MAX 34
63+
#define _SC_AIO_MAX 35
64+
#define _SC_AIO_PRIO_DELTA_MAX 36
65+
#define _SC_DELAYTIMER_MAX 37
66+
#define _SC_THREAD_KEYS_MAX 38
67+
#define _SC_THREAD_STACK_MIN 39
68+
#define _SC_THREAD_THREADS_MAX 40
69+
#define _SC_TTY_NAME_MAX 41
70+
#define _SC_THREADS 42
71+
#define _SC_THREAD_ATTR_STACKADDR 43
72+
#define _SC_THREAD_ATTR_STACKSIZE 44
73+
#define _SC_THREAD_PRIORITY_SCHEDULING 45
74+
#define _SC_THREAD_PRIO_INHERIT 46
75+
/* _SC_THREAD_PRIO_PROTECT was _SC_THREAD_PRIO_CEILING in early drafts */
76+
#define _SC_THREAD_PRIO_PROTECT 47
77+
#define _SC_THREAD_PRIO_CEILING _SC_THREAD_PRIO_PROTECT
78+
#define _SC_THREAD_PROCESS_SHARED 48
79+
#define _SC_THREAD_SAFE_FUNCTIONS 49
80+
#define _SC_GETGR_R_SIZE_MAX 50
81+
#define _SC_GETPW_R_SIZE_MAX 51
82+
#define _SC_LOGIN_NAME_MAX 52
83+
#define _SC_THREAD_DESTRUCTOR_ITERATIONS 53
84+
#define _SC_ADVISORY_INFO 54
85+
#define _SC_ATEXIT_MAX 55
86+
#define _SC_BARRIERS 56
87+
#define _SC_BC_BASE_MAX 57
88+
#define _SC_BC_DIM_MAX 58
89+
#define _SC_BC_SCALE_MAX 59
90+
#define _SC_BC_STRING_MAX 60
91+
#define _SC_CLOCK_SELECTION 61
92+
#define _SC_COLL_WEIGHTS_MAX 62
93+
#define _SC_CPUTIME 63
94+
#define _SC_EXPR_NEST_MAX 64
95+
#define _SC_HOST_NAME_MAX 65
96+
#define _SC_IOV_MAX 66
97+
#define _SC_IPV6 67
98+
#define _SC_LINE_MAX 68
99+
#define _SC_MONOTONIC_CLOCK 69
100+
#define _SC_RAW_SOCKETS 70
101+
#define _SC_READER_WRITER_LOCKS 71
102+
#define _SC_REGEXP 72
103+
#define _SC_RE_DUP_MAX 73
104+
#define _SC_SHELL 74
105+
#define _SC_SPAWN 75
106+
#define _SC_SPIN_LOCKS 76
107+
#define _SC_SPORADIC_SERVER 77
108+
#define _SC_SS_REPL_MAX 78
109+
#define _SC_SYMLOOP_MAX 79
110+
#define _SC_THREAD_CPUTIME 80
111+
#define _SC_THREAD_SPORADIC_SERVER 81
112+
#define _SC_TIMEOUTS 82
113+
#define _SC_TRACE 83
114+
#define _SC_TRACE_EVENT_FILTER 84
115+
#define _SC_TRACE_EVENT_NAME_MAX 85
116+
#define _SC_TRACE_INHERIT 86
117+
#define _SC_TRACE_LOG 87
118+
#define _SC_TRACE_NAME_MAX 88
119+
#define _SC_TRACE_SYS_MAX 89
120+
#define _SC_TRACE_USER_EVENT_MAX 90
121+
#define _SC_TYPED_MEMORY_OBJECTS 91
122+
#define _SC_V7_ILP32_OFF32 92
123+
#define _SC_V6_ILP32_OFF32 _SC_V7_ILP32_OFF32
124+
#define _SC_XBS5_ILP32_OFF32 _SC_V7_ILP32_OFF32
125+
#define _SC_V7_ILP32_OFFBIG 93
126+
#define _SC_V6_ILP32_OFFBIG _SC_V7_ILP32_OFFBIG
127+
#define _SC_XBS5_ILP32_OFFBIG _SC_V7_ILP32_OFFBIG
128+
#define _SC_V7_LP64_OFF64 94
129+
#define _SC_V6_LP64_OFF64 _SC_V7_LP64_OFF64
130+
#define _SC_XBS5_LP64_OFF64 _SC_V7_LP64_OFF64
131+
#define _SC_V7_LPBIG_OFFBIG 95
132+
#define _SC_V6_LPBIG_OFFBIG _SC_V7_LPBIG_OFFBIG
133+
#define _SC_XBS5_LPBIG_OFFBIG _SC_V7_LPBIG_OFFBIG
134+
#define _SC_XOPEN_CRYPT 96
135+
#define _SC_XOPEN_ENH_I18N 97
136+
#define _SC_XOPEN_LEGACY 98
137+
#define _SC_XOPEN_REALTIME 99
138+
#define _SC_STREAM_MAX 100
139+
#define _SC_PRIORITY_SCHEDULING 101
140+
#define _SC_XOPEN_REALTIME_THREADS 102
141+
#define _SC_XOPEN_SHM 103
142+
#define _SC_XOPEN_STREAMS 104
143+
#define _SC_XOPEN_UNIX 105
144+
#define _SC_XOPEN_VERSION 106
145+
#define _SC_2_CHAR_TERM 107
146+
#define _SC_2_C_BIND 108
147+
#define _SC_2_C_DEV 109
148+
#define _SC_2_FORT_DEV 110
149+
#define _SC_2_FORT_RUN 111
150+
#define _SC_2_LOCALEDEF 112
151+
#define _SC_2_PBS 113
152+
#define _SC_2_PBS_ACCOUNTING 114
153+
#define _SC_2_PBS_CHECKPOINT 115
154+
#define _SC_2_PBS_LOCATE 116
155+
#define _SC_2_PBS_MESSAGE 117
156+
#define _SC_2_PBS_TRACK 118
157+
#define _SC_2_SW_DEV 119
158+
#define _SC_2_UPE 120
159+
#define _SC_2_VERSION 121
160+
#define _SC_THREAD_ROBUST_PRIO_INHERIT 122
161+
#define _SC_THREAD_ROBUST_PRIO_PROTECT 123
162+
#define _SC_XOPEN_UUCP 124
163+
#define _SC_LEVEL1_ICACHE_SIZE 125
164+
#define _SC_LEVEL1_ICACHE_ASSOC 126
165+
#define _SC_LEVEL1_ICACHE_LINESIZE 127
166+
#define _SC_LEVEL1_DCACHE_SIZE 128
167+
#define _SC_LEVEL1_DCACHE_ASSOC 129
168+
#define _SC_LEVEL1_DCACHE_LINESIZE 130
169+
#define _SC_LEVEL2_CACHE_SIZE 131
170+
#define _SC_LEVEL2_CACHE_ASSOC 132
171+
#define _SC_LEVEL2_CACHE_LINESIZE 133
172+
#define _SC_LEVEL3_CACHE_SIZE 134
173+
#define _SC_LEVEL3_CACHE_ASSOC 135
174+
#define _SC_LEVEL3_CACHE_LINESIZE 136
175+
#define _SC_LEVEL4_CACHE_SIZE 137
176+
#define _SC_LEVEL4_CACHE_ASSOC 138
177+
#define _SC_LEVEL4_CACHE_LINESIZE 139
178+
#define _SC_POSIX_26_VERSION 140
179+
#endif /* ifdef _SC_ARG_MAX */
180+
#endif /* ifdef CONFIG_POSIX_SYSCONF_IMPL_FULL */
143181

144182
#define __z_posix_sysconf_SC_ADVISORY_INFO (-1L)
145183
#define __z_posix_sysconf_SC_ASYNCHRONOUS_IO \

include/zephyr/posix/unistd.h

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#ifndef ZEPHYR_INCLUDE_POSIX_UNISTD_H_
77
#define ZEPHYR_INCLUDE_POSIX_UNISTD_H_
88

9+
#ifdef CONFIG_POSIX_SYSCONF_IMPL_FULL
10+
#include_next <unistd.h>
11+
#endif
912
#include <zephyr/posix/posix_types.h>
1013

1114
#ifdef CONFIG_POSIX_API

0 commit comments

Comments
 (0)