xref: /netbsd-src/external/gpl3/gcc/dist/libphobos/libdruntime/core/sys/posix/sys/resource.d (revision 0a3071956a3a9fdebdbf7f338cf2d439b45fc728)
1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Copyright (c) 2013 Lars Tandle Kyllingstad.
5  * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6  * Authors:   Lars Tandle Kyllingstad
7  * Standards: The Open Group Base Specifications Issue 7, IEEE Std 1003.1-2008
8  */
9 module core.sys.posix.sys.resource;
10 version (Posix):
11 
12 public import core.sys.posix.sys.time;
13 public import core.sys.posix.sys.types: id_t;
14 import core.sys.posix.config;
15 
16 version (OSX)
17     version = Darwin;
18 else version (iOS)
19     version = Darwin;
20 else version (TVOS)
21     version = Darwin;
22 else version (WatchOS)
23     version = Darwin;
24 
nogc(C)25 nothrow @nogc extern(C):
26 @system:
27 
28 //
29 // XOpen (XSI)
30 //
31 // http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_resource.h.html
32 /*
33 enum
34 {
35     PRIO_PROCESS,
36     PRIO_PGRP,
37     PRIO_USER,
38 }
39 
40 alias ulong rlim_t;
41 
42 enum
43 {
44     RLIM_INFINITY,
45     RLIM_SAVED_MAX,
46     RLIM_SAVED_CUR,
47 }
48 
49 enum
50 {
51     RUSAGE_SELF,
52     RUSAGE_CHILDREN,
53 }
54 
55 struct rusage
56 {
57     timeval ru_utime;
58     timeval ru_stime;
59 }
60 
61 enum
62 {
63     RLIMIT_CORE,
64     RLIMIT_CPU,
65     RLIMIT_DATA,
66     RLIMIT_FSIZE,
67     RLIMIT_NOFILE,
68     RLIMIT_STACK,
69     RLIMIT_AS,
70 }
71 */
72 
73 version (linux)
74 {
75     enum
76     {
77         PRIO_PROCESS = 0,
78         PRIO_PGRP    = 1,
79         PRIO_USER    = 2,
80     }
81 
82     static if (__USE_FILE_OFFSET64)
83          alias ulong rlim_t;
84     else
85          alias c_ulong rlim_t;
86 
87     static if (__USE_FILE_OFFSET64)
88         enum RLIM_INFINITY = 0xffffffffffffffffUL;
89     else
90         enum RLIM_INFINITY = cast(c_ulong)(~0UL);
91 
92     enum RLIM_SAVED_MAX = RLIM_INFINITY;
93     enum RLIM_SAVED_CUR = RLIM_INFINITY;
94 
95     enum
96     {
97         RUSAGE_SELF     =  0,
98         RUSAGE_CHILDREN = -1,
99         RUSAGE_THREAD = 1
100     }
101 
102     struct rusage
103     {
104         timeval ru_utime;
105         timeval ru_stime;
106         c_long ru_maxrss;
107         c_long ru_ixrss;
108         c_long ru_idrss;
109         c_long ru_isrss;
110         c_long ru_minflt;
111         c_long ru_majflt;
112         c_long ru_nswap;
113         c_long ru_inblock;
114         c_long ru_oublock;
115         c_long ru_msgsnd;
116         c_long ru_msgrcv;
117         c_long ru_nsignals;
118         c_long ru_nvcsw;
119         c_long ru_nivcsw;
120         version (CRuntime_Musl)
121             c_long[16] __reserved;
122     }
123 
124     enum
125     {
126         RLIMIT_CORE   = 4,
127         RLIMIT_CPU    = 0,
128         RLIMIT_DATA   = 2,
129         RLIMIT_FSIZE  = 1,
130         RLIMIT_NOFILE = 7,
131         RLIMIT_STACK  = 3,
132         RLIMIT_AS     = 9,
133     }
134 }
135 else version (Darwin)
136 {
137     enum
138     {
139         PRIO_PROCESS = 0,
140         PRIO_PGRP    = 1,
141         PRIO_USER    = 2,
142     }
143 
144     alias ulong rlim_t;
145 
146     enum
147     {
148         RLIM_INFINITY  = ((cast(ulong) 1 << 63) - 1),
149         RLIM_SAVED_MAX = RLIM_INFINITY,
150         RLIM_SAVED_CUR = RLIM_INFINITY,
151     }
152 
153     enum
154     {
155         RUSAGE_SELF     =  0,
156         RUSAGE_CHILDREN = -1,
157     }
158 
159     struct rusage
160     {
161         timeval ru_utime;
162         timeval ru_stime;
163         c_long[14] ru_opaque;
164     }
165 
166     enum
167     {
168         RLIMIT_CORE   = 4,
169         RLIMIT_CPU    = 0,
170         RLIMIT_DATA   = 2,
171         RLIMIT_FSIZE  = 1,
172         RLIMIT_NOFILE = 8,
173         RLIMIT_STACK  = 3,
174         RLIMIT_AS     = 5,
175     }
176 }
177 else version (FreeBSD)
178 {
179     enum
180     {
181         PRIO_PROCESS = 0,
182         PRIO_PGRP    = 1,
183         PRIO_USER    = 2,
184     }
185 
186     alias long rlim_t;
187 
188     enum
189     {
190         RLIM_INFINITY   = (cast(rlim_t)((cast(ulong) 1 << 63) - 1)),
191         RLIM_SAVED_MAX  = RLIM_INFINITY,
192         RLIM_SAVED_CUR  = RLIM_INFINITY,
193     }
194 
195     enum
196     {
197         RUSAGE_SELF     =  0,
198         RUSAGE_CHILDREN = -1,
199     }
200 
201     struct rusage
202     {
203         timeval ru_utime;
204         timeval ru_stime;
205         c_long ru_maxrss;
206         alias ru_ixrss ru_first;
207         c_long ru_ixrss;
208         c_long ru_idrss;
209         c_long ru_isrss;
210         c_long ru_minflt;
211         c_long ru_majflt;
212         c_long ru_nswap;
213         c_long ru_inblock;
214         c_long ru_oublock;
215         c_long ru_msgsnd;
216         c_long ru_msgrcv;
217         c_long ru_nsignals;
218         c_long ru_nvcsw;
219         c_long ru_nivcsw;
220         alias ru_nivcsw ru_last;
221     }
222 
223     enum
224     {
225         RLIMIT_CORE   =  4,
226         RLIMIT_CPU    =  0,
227         RLIMIT_DATA   =  2,
228         RLIMIT_FSIZE  =  1,
229         RLIMIT_NOFILE =  8,
230         RLIMIT_STACK  =  3,
231         RLIMIT_AS     = 10,
232     }
233 }
234 else version (NetBSD)
235 {
236     enum
237     {
238         PRIO_PROCESS = 0,
239         PRIO_PGRP    = 1,
240         PRIO_USER    = 2,
241     }
242 
243     alias long rlim_t;
244 
245     enum
246     {
247         RLIM_INFINITY   = (cast(rlim_t)((cast(ulong) 1 << 63) - 1)),
248         RLIM_SAVED_MAX = RLIM_INFINITY,
249         RLIM_SAVED_CUR = RLIM_INFINITY,
250     }
251 
252     enum
253     {
254         RUSAGE_SELF     =  0,
255         RUSAGE_CHILDREN = -1,
256     }
257 
258     struct rusage
259     {
260         timeval ru_utime;
261         timeval ru_stime;
262         c_long ru_maxrss;
263         alias ru_ixrss ru_first;
264         c_long ru_ixrss;
265         c_long ru_idrss;
266         c_long ru_isrss;
267         c_long ru_minflt;
268         c_long ru_majflt;
269         c_long ru_nswap;
270         c_long ru_inblock;
271         c_long ru_oublock;
272         c_long ru_msgsnd;
273         c_long ru_msgrcv;
274         c_long ru_nsignals;
275         c_long ru_nvcsw;
276         c_long ru_nivcsw;
277         alias ru_nivcsw ru_last;
278     }
279 
280     enum
281     {
282         RLIMIT_CORE   =  4,
283         RLIMIT_CPU    =  0,
284         RLIMIT_DATA   =  2,
285         RLIMIT_FSIZE  =  1,
286         RLIMIT_NOFILE =  8,
287         RLIMIT_STACK  =  3,
288         RLIMIT_AS     = 10,
289     }
290 }
291 else version (OpenBSD)
292 {
293     enum
294     {
295         PRIO_PROCESS = 0,
296         PRIO_PGRP    = 1,
297         PRIO_USER    = 2,
298     }
299 
300     alias ulong rlim_t;
301 
302     enum
303     {
304         RLIM_INFINITY  = (cast(rlim_t)((cast(ulong) 1 << 63) - 1)),
305         RLIM_SAVED_MAX = RLIM_INFINITY,
306         RLIM_SAVED_CUR = RLIM_INFINITY,
307     }
308 
309     enum
310     {
311         RUSAGE_SELF     =  0,
312         RUSAGE_CHILDREN = -1,
313         RUSAGE_THREAD   =  1,
314     }
315 
316     struct rusage
317     {
318         timeval ru_utime;
319         timeval ru_stime;
320         c_long ru_maxrss;
321         alias ru_ixrss ru_first;
322         c_long ru_ixrss;
323         c_long ru_idrss;
324         c_long ru_isrss;
325         c_long ru_minflt;
326         c_long ru_majflt;
327         c_long ru_nswap;
328         c_long ru_inblock;
329         c_long ru_oublock;
330         c_long ru_msgsnd;
331         c_long ru_msgrcv;
332         c_long ru_nsignals;
333         c_long ru_nvcsw;
334         c_long ru_nivcsw;
335         alias ru_nivcsw ru_last;
336     }
337 
338     enum
339     {
340         RLIMIT_CORE   =  4,
341         RLIMIT_CPU    =  0,
342         RLIMIT_DATA   =  2,
343         RLIMIT_FSIZE  =  1,
344         RLIMIT_NOFILE =  8,
345         RLIMIT_STACK  =  3,
346         // OpenBSD does not define the following:
347         //RLIMIT_AS,
348     }
349 }
350 else version (DragonFlyBSD)
351 {
352     enum
353     {
354         PRIO_PROCESS = 0,
355         PRIO_PGRP    = 1,
356         PRIO_USER    = 2,
357     }
358 
359     alias long rlim_t;
360 
361     enum
362     {
363         RLIM_INFINITY   = (cast(rlim_t)((cast(ulong) 1 << 63) - 1)),
364         RLIM_SAVED_MAX  = RLIM_INFINITY,
365         RLIM_SAVED_CUR  = RLIM_INFINITY,
366     }
367 
368     enum
369     {
370         RUSAGE_SELF     =  0,
371         RUSAGE_CHILDREN = -1,
372     }
373 
374     struct rusage
375     {
376         timeval ru_utime;
377         timeval ru_stime;
378         c_long ru_maxrss;
379         alias ru_ixrss ru_first;
380         c_long ru_ixrss;
381         c_long ru_idrss;
382         c_long ru_isrss;
383         c_long ru_minflt;
384         c_long ru_majflt;
385         c_long ru_nswap;
386         c_long ru_inblock;
387         c_long ru_oublock;
388         c_long ru_msgsnd;
389         c_long ru_msgrcv;
390         c_long ru_nsignals;
391         c_long ru_nvcsw;
392         c_long ru_nivcsw;
393         alias ru_nivcsw ru_last;
394     }
395 
396     enum
397     {
398         RLIMIT_CORE   =  4,
399         RLIMIT_CPU    =  0,
400         RLIMIT_DATA   =  2,
401         RLIMIT_FSIZE  =  1,
402         RLIMIT_NOFILE =  8,
403         RLIMIT_STACK  =  3,
404         RLIMIT_AS     = 10,
405     }
406 }
407 else version (Solaris)
408 {
409     enum
410     {
411         PRIO_PROCESS = 0,
412         PRIO_PGRP    = 1,
413         PRIO_USER    = 2,
414     }
415 
416     alias c_ulong rlim_t;
417 
418     enum : c_long
419     {
420         RLIM_INFINITY   = -3,
421         RLIM_SAVED_MAX  = -2,
422         RLIM_SAVED_CUR  = -1,
423     }
424 
425     enum
426     {
427         RUSAGE_SELF     =  0,
428         RUSAGE_CHILDREN = -1,
429     }
430 
431     struct rusage
432     {
433         timeval ru_utime;
434         timeval ru_stime;
435         c_long ru_maxrss;
436         c_long ru_ixrss;
437         c_long ru_idrss;
438         c_long ru_isrss;
439         c_long ru_minflt;
440         c_long ru_majflt;
441         c_long ru_nswap;
442         c_long ru_inblock;
443         c_long ru_oublock;
444         c_long ru_msgsnd;
445         c_long ru_msgrcv;
446         c_long ru_nsignals;
447         c_long ru_nvcsw;
448         c_long ru_nivcsw;
449     }
450 
451     enum
452     {
453         RLIMIT_CORE   = 4,
454         RLIMIT_CPU    = 0,
455         RLIMIT_DATA   = 2,
456         RLIMIT_FSIZE  = 1,
457         RLIMIT_NOFILE = 5,
458         RLIMIT_STACK  = 3,
459         RLIMIT_AS     = 6,
460     }
461 }
462 else
463     static assert (false, "Unsupported platform");
464 
465 /*
466 struct rlimit
467 {
468     rlim_t rlim_cur;
469     rlim_t rlim_max;
470 }
471 
472 int getpriority(int, id_t);
473 int getrlimit(int, rlimit*);
474 int getrusage(int, rusage*);
475 int setpriority(int, id_t, int);
476 int setrlimit(int, const rlimit*);
477 */
478 
479 struct rlimit
480 {
481     rlim_t rlim_cur;
482     rlim_t rlim_max;
483 }
484 
485 version (CRuntime_Glibc)
486 {
487     int getpriority(int, id_t);
488     int setpriority(int, id_t, int);
489     static if (__USE_FILE_OFFSET64)
490     {
491         int getrlimit64(int, rlimit*);
492         int setrlimit64(int, const scope rlimit*);
493         alias getrlimit = getrlimit64;
494         alias setrlimit = setrlimit64;
495     }
496     else
497     {
498         int getrlimit(int, rlimit*);
499         int setrlimit(int, const scope rlimit*);
500     }
501     int getrusage(int, rusage*);
502 }
503 else version (FreeBSD)
504 {
505     int getpriority(int, int);
506     int getrlimit(int, rlimit*);
507     int getrusage(int, rusage*);
508     int setpriority(int, int, int);
509     int setrlimit(int, const scope rlimit*);
510 }
511 else version (NetBSD)
512 {
513     int getpriority(int, int);
514     int getrlimit(int, rlimit*);
515     int getrusage(int, rusage*);
516     int setpriority(int, int, int);
517     int setrlimit(int, const scope rlimit*);
518 }
519 else version (OpenBSD)
520 {
521     int getpriority(int, int);
522     int getrlimit(int, rlimit*);
523     int getrusage(int, rusage*);
524     int setpriority(int, int, int);
525     int setrlimit(int, const scope rlimit*);
526 }
527 else version (DragonFlyBSD)
528 {
529     int getpriority(int, int);
530     int getrlimit(int, rlimit*);
531     int getrusage(int, rusage*);
532     int setpriority(int, int, int);
533     int setrlimit(int, const scope rlimit*);
534 }
535 else version (CRuntime_Bionic)
536 {
537     int getpriority(int, int);
538     int getrlimit(int, rlimit*);
539     int getrusage(int, rusage*);
540     int setpriority(int, int, int);
541     int setrlimit(int, const scope rlimit*);
542 }
543 else version (CRuntime_Musl)
544 {
545     int getpriority(int, id_t);
546     int setpriority(int, id_t, int);
547     int getrlimit(int, rlimit*);
548     int setrlimit(int, const scope rlimit*);
549     alias getrlimit getrlimit64;
550     alias setrlimit setrlimit64;
551     int getrusage(int, rusage*);
552 }
553 else version (Solaris)
554 {
555     int getpriority(int, int);
556     int getrlimit(int, rlimit*);
557     int getrusage(int, rusage*);
558     int setpriority(int, int, int);
559     int setrlimit(int, const scope rlimit*);
560 }
561 else version (Darwin)
562 {
563     int getpriority(int, id_t);
564     int getrlimit(int, rlimit*);
565     int getrusage(int, rusage*);
566     int setpriority(int, id_t, int);
567     int setrlimit(int, const scope rlimit*);
568 }
569 else version (CRuntime_UClibc)
570 {
571     int getpriority(int, id_t);
572     int setpriority(int, id_t, int);
573     static if (__USE_FILE_OFFSET64)
574     {
575         int getrlimit64(int, rlimit*);
576         int setrlimit64(int, const scope rlimit*);
577         alias getrlimit = getrlimit64;
578         alias setrlimit = setrlimit64;
579     }
580     else
581     {
582         int getrlimit(int, rlimit*);
583         int setrlimit(int, const scope rlimit*);
584     }
585     int getrusage(int, rusage*);
586 }
587 else
588     static assert (false, "Unsupported platform");
589