The Pedigree Project  0.1
glue-sysconf.c
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #define _PEDIGREE_COMPILING_SUBSYS
21 
22 #include "pedigree/kernel/processor/types.h"
23 
24 #define _COMPILING_NEWLIB
25 #include <newlib.h>
26 
27 #include <errno.h>
28 #include <limits.h>
29 #include <sys/config.h>
30 #include <syslog.h>
31 #include <time.h>
32 #include <unistd.h>
33 
34 // Ensure errno is usable
35 #define errno (*__errno())
36 extern int *__errno(void);
37 
38 long sysconf(int name)
39 {
40  syslog(LOG_NOTICE, "[%d] sysconf(%d)", getpid(), name);
41 
42  switch (name)
43  {
44  case _SC_AIO_LISTIO_MAX:
45 #ifdef AIO_LISTIO_MAX
46  return AIO_LISTIO_MAX;
47 #else
48  return -1;
49 #endif
50 
51  case _SC_AIO_MAX:
52 #ifdef AIO_MAX
53  return AIO_MAX;
54 #else
55  return -1;
56 #endif
57 
58  case _SC_AIO_PRIO_DELTA_MAX:
59 #ifdef AIO_PRIO_DELTA_MAX
60  return AIO_PRIO_DELTA_MAX;
61 #else
62  return -1;
63 #endif
64 
65  case _SC_ARG_MAX:
66 #ifdef ARG_MAX
67  return ARG_MAX;
68 #else
69  return -1;
70 #endif
71 
72  case _SC_CHILD_MAX:
73 #ifdef CHILD_MAX
74  return CHILD_MAX;
75 #else
76  return -1;
77 #endif
78 
79  case _SC_CLK_TCK:
80  //#ifdef CLK_TCK
81  return CLK_TCK;
82  //#else
83  // return -1;
84  //#endif
85 
86  case _SC_DELAYTIMER_MAX:
87 #ifdef DELAYTIMER_MAX
88  return DELAYTIMER_MAX;
89 #else
90  return -1;
91 #endif
92 
93  case _SC_GETGR_R_SIZE_MAX:
94 #ifdef _GETGR_R_SIZE_MAX
95  return _GETGR_R_SIZE_MAX;
96 #else
97  return -1;
98 #endif
99 
100  case _SC_GETPW_R_SIZE_MAX:
101 #ifdef _GETPW_R_SIZE_MAX
102  return _GETPW_R_SIZE_MAX;
103 #else
104  return -1;
105 #endif
106 
107  case _SC_LOGIN_NAME_MAX:
108 #ifdef LOGIN_NAME_MAX
109  return LOGIN_NAME_MAX;
110 #else
111  return -1;
112 #endif
113 
114  case _SC_MQ_OPEN_MAX:
115 #ifdef MQ_OPEN_MAX
116  return MQ_OPEN_MAX;
117 #else
118  return -1;
119 #endif
120 
121  case _SC_MQ_PRIO_MAX:
122 #ifdef MQ_PRIO_MAX
123  return MQ_PRIO_MAX;
124 #else
125  return -1;
126 #endif
127 
128  case _SC_NGROUPS_MAX:
129 #ifdef NGROUPS_MAX
130  return NGROUPS_MAX;
131 #else
132  return -1;
133 #endif
134 
135  case _SC_OPEN_MAX:
136 #ifdef OPEN_MAX
137  return OPEN_MAX;
138 #else
139  return 0xffff;
142 #endif
143 
144  case _SC_PAGESIZE:
145 #ifdef PAGESIZE
146  return PAGESIZE;
147 #else
148 #ifdef PAGE_SIZE
149  return PAGE_SIZE;
150 #else
151  return -1;
152 #endif
153 #endif
154 
155  case _SC_RTSIG_MAX:
156 #ifdef RTSIG_MAX
157  return RTSIG_MAX;
158 #else
159  return -1;
160 #endif
161 
162  case _SC_SEM_NSEMS_MAX:
163 #ifdef SEM_NSEMS_MAX
164  return SEM_NSEMS_MAX;
165 #else
166  return -1;
167 #endif
168 
169  case _SC_SEM_VALUE_MAX:
170 #ifdef SEM_VALUE_MAX
171  return SEM_VALUE_MAX;
172 #else
173  return -1;
174 #endif
175 
176  case _SC_SIGQUEUE_MAX:
177 #ifdef SIGQUEUE_MAX
178  return SIGQUEUE_MAX;
179 #else
180  return -1;
181 #endif
182 
183  case _SC_STREAM_MAX:
184 #ifdef STREAM_MAX
185  return STREAM_MAX;
186 #else
187  return -1;
188 #endif
189 
190  case _SC_THREAD_DESTRUCTOR_ITERATIONS:
191 #ifdef PTHREAD_DESTRUCTOR_ITERATIONS
192  return PTHREAD_DESTRUCTOR_ITERATIONS;
193 #else
194  return -1;
195 #endif
196 
197  case _SC_THREAD_KEYS_MAX:
198 #ifdef PTHREAD_KEYS_MAX
199  return PTHREAD_KEYS_MAX;
200 #else
201  return -1;
202 #endif
203 
204  case _SC_THREAD_STACK_MIN:
205 #ifdef PTHREAD_STACK_MIN
206  return PTHREAD_STACK_MIN;
207 #else
208  return -1;
209 #endif
210 
211  case _SC_THREAD_THREADS_MAX:
212 #ifdef PTHREAD_THREADS_MAX
213  return PTHREAD_THREADS_MAX;
214 #else
215  return -1;
216 #endif
217 
218  case _SC_TIMER_MAX:
219 #ifdef TIMER_MAX
220  return TIMER_MAX;
221 #else
222  return -1;
223 #endif
224 
225  case _SC_TTY_NAME_MAX:
226 #ifdef TTY_NAME_MAX
227  return TTY_NAME_MAX;
228 #else
229  return -1;
230 #endif
231 
232  case _SC_TZNAME_MAX:
233 #ifdef TZNAME_MAX
234  return TZNAME_MAX;
235 #else
236  return -1;
237 #endif
238 
239  case _SC_ASYNCHRONOUS_IO:
240 #ifdef _POSIX_ASYNCHRONOUS_IO
241  return 1;
242 #else
243  return -1;
244 #endif
245 
246  case _SC_FSYNC:
247 #ifdef _POSIX_FSYNC
248  return 1;
249 #else
250  return -1;
251 #endif
252 
253  case _SC_JOB_CONTROL:
254 #ifdef _POSIX_JOB_CONTROL
255  return 1;
256 #else
257  return -1;
258 #endif
259 
260  case _SC_MAPPED_FILES:
261 #ifdef _POSIX_MAPPED_FILES
262  return 1;
263 #else
264  return -1;
265 #endif
266 
267  case _SC_MEMLOCK:
268 #ifdef _POSIX_MEMLOCK
269  return 1;
270 #else
271  return -1;
272 #endif
273 
274  case _SC_MEMLOCK_RANGE:
275 #ifdef _POSIX_MEMLOCK_RANGE
276  return _POSIX_MEMLOCK_RANGE;
277 #else
278  return -1;
279 #endif
280 
281  case _SC_MEMORY_PROTECTION:
282 #ifdef _POSIX_MEMORY_PROTECTION
283  return 1;
284 #else
285  return -1;
286 #endif
287 
288  case _SC_MESSAGE_PASSING:
289 #ifdef _POSIX_MESSAGE_PASSING
290  return 1;
291 #else
292  return -1;
293 #endif
294 
295  case _SC_PRIORITIZED_IO:
296 #ifdef _POSIX_PRIORITIZED_IO
297  return 1;
298 #else
299  return -1;
300 #endif
301 
302  case _SC_PRIORITY_SCHEDULING:
303 #ifdef _POSIX_PRIORITY_SCHEDULING
304  return 1;
305 #else
306  return -1;
307 #endif
308 
309  case _SC_REALTIME_SIGNALS:
310 #ifdef _POSIX_REALTIME_SIGNALS
311  return 1;
312 #else
313  return -1;
314 #endif
315 
316  case _SC_SAVED_IDS:
317 #ifdef _POSIX_SAVED_IDS
318  return 1;
319 #else
320  return -1;
321 #endif
322 
323  case _SC_SEMAPHORES:
324 #ifdef _POSIX_SEMAPHORES
325  return 1;
326 #else
327  return -1;
328 #endif
329 
330  case _SC_SHARED_MEMORY_OBJECTS:
331 #ifdef _POSIX_SHARED_MEMORY_OBJECTS
332  return 1;
333 #else
334  return -1;
335 #endif
336 
337  case _SC_SYNCHRONIZED_IO:
338 #ifdef _POSIX_SYNCHRONIZED_IO
339  return 1;
340 #else
341  return -1;
342 #endif
343 
344  case _SC_TIMERS:
345 #ifdef _POSIX_TIMERS
346  return 1;
347 #else
348  return -1;
349 #endif
350 
351  case _SC_THREADS:
352 #ifdef _POSIX_THREADS
353  return 1;
354 #else
355  return -1;
356 #endif
357 
358  case _SC_THREAD_ATTR_STACKADDR:
359 #ifdef _POSIX_THREAD_ATTR_STACKADDR
360  return 1;
361 #else
362  return -1;
363 #endif
364 
365  case _SC_THREAD_ATTR_STACKSIZE:
366 #ifdef _POSIX_THREAD_ATTR_STACKSIZE
367  return 1;
368 #else
369  return -1;
370 #endif
371 
372  case _SC_THREAD_PRIORITY_SCHEDULING:
373 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
374  return 1;
375 #else
376  return -1;
377 #endif
378 
379  case _SC_THREAD_PRIO_INHERIT:
380 #ifdef _POSIX_THREAD_PRIO_INHERIT
381  return 1;
382 #else
383  return -1;
384 #endif
385 
386  case _SC_THREAD_PRIO_PROTECT:
387 #ifdef _POSIX_THREAD_PRIO_PROTECT
388  return 1;
389 #else
390  return -1;
391 #endif
392 
393  case _SC_THREAD_PROCESS_SHARED:
394 #ifdef _POSIX_THREAD_PROCESS_SHARED
395  return 1;
396 #else
397  return -1;
398 #endif
399 
400  case _SC_THREAD_SAFE_FUNCTIONS:
401 #ifdef _POSIX_THREAD_SAFE_FUNCTIONS
402  return 1;
403 #else
404  return -1;
405 #endif
406 
407  case _SC_VERSION:
408 #ifdef _POSIX_VERSION
409  return _POSIX_VERSION;
410 #else
411  return -1;
412 #endif
413 
414  default:
415  errno = EINVAL;
416  return -1;
417  }
418 
419  return -1; /* can't get here */
420 }