]> git.ipfire.org Git - thirdparty/gcc.git/blob - libphobos/libdruntime/core/sys/posix/sys/resource.d
libphobos: Merge upstream druntime 94686651
[thirdparty/gcc.git] / libphobos / libdruntime / core / sys / posix / sys / resource.d
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
25 nothrow @nogc extern(C):
26
27 //
28 // XOpen (XSI)
29 //
30 // http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_resource.h.html
31 /*
32 enum
33 {
34 PRIO_PROCESS,
35 PRIO_PGRP,
36 PRIO_USER,
37 }
38
39 alias ulong rlim_t;
40
41 enum
42 {
43 RLIM_INFINITY,
44 RLIM_SAVED_MAX,
45 RLIM_SAVED_CUR,
46 }
47
48 enum
49 {
50 RUSAGE_SELF,
51 RUSAGE_CHILDREN,
52 }
53
54 struct rlimit
55 {
56 rlim_t rlim_cur;
57 rlim_t rlim_max;
58 }
59
60 struct rusage
61 {
62 timeval ru_utime;
63 timeval ru_stime;
64 }
65
66 enum
67 {
68 RLIMIT_CORE,
69 RLIMIT_CPU,
70 RLIMIT_DATA,
71 RLIMIT_FSIZE,
72 RLIMIT_NOFILE,
73 RLIMIT_STACK,
74 RLIMIT_AS,
75 }
76
77 int getpriority(int, id_t);
78 int getrlimit(int, rlimit*);
79 int getrusage(int, rusage*);
80 int setpriority(int, id_t, int);
81 int setrlimit(int, const rlimit*);
82 */
83
84
85 version (CRuntime_Glibc)
86 {
87 // rusage and some other constants in the Bionic section below really
88 // come from the linux kernel headers, but they're all mixed right now.
89 enum
90 {
91 PRIO_PROCESS = 0,
92 PRIO_PGRP = 1,
93 PRIO_USER = 2,
94 }
95
96 static if (__USE_FILE_OFFSET64)
97 alias ulong rlim_t;
98 else
99 alias c_ulong rlim_t;
100
101 static if (__USE_FILE_OFFSET64)
102 enum RLIM_INFINITY = 0xffffffffffffffffUL;
103 else
104 enum RLIM_INFINITY = cast(c_ulong)(~0UL);
105
106 enum RLIM_SAVED_MAX = RLIM_INFINITY;
107 enum RLIM_SAVED_CUR = RLIM_INFINITY;
108
109 enum
110 {
111 RUSAGE_SELF = 0,
112 RUSAGE_CHILDREN = -1,
113 }
114
115 struct rusage
116 {
117 timeval ru_utime;
118 timeval ru_stime;
119 c_long ru_maxrss;
120 c_long ru_ixrss;
121 c_long ru_idrss;
122 c_long ru_isrss;
123 c_long ru_minflt;
124 c_long ru_majflt;
125 c_long ru_nswap;
126 c_long ru_inblock;
127 c_long ru_oublock;
128 c_long ru_msgsnd;
129 c_long ru_msgrcv;
130 c_long ru_nsignals;
131 c_long ru_nvcsw;
132 c_long ru_nivcsw;
133 }
134
135 enum
136 {
137 RLIMIT_CORE = 4,
138 RLIMIT_CPU = 0,
139 RLIMIT_DATA = 2,
140 RLIMIT_FSIZE = 1,
141 RLIMIT_NOFILE = 7,
142 RLIMIT_STACK = 3,
143 RLIMIT_AS = 9,
144 }
145 }
146 else version (Darwin)
147 {
148 enum
149 {
150 PRIO_PROCESS = 0,
151 PRIO_PGRP = 1,
152 PRIO_USER = 2,
153 }
154
155 alias ulong rlim_t;
156
157 enum
158 {
159 RLIM_INFINITY = ((cast(ulong) 1 << 63) - 1),
160 RLIM_SAVED_MAX = RLIM_INFINITY,
161 RLIM_SAVED_CUR = RLIM_INFINITY,
162 }
163
164 enum
165 {
166 RUSAGE_SELF = 0,
167 RUSAGE_CHILDREN = -1,
168 }
169
170 struct rusage
171 {
172 timeval ru_utime;
173 timeval ru_stime;
174 c_long[14] ru_opaque;
175 }
176
177 enum
178 {
179 RLIMIT_CORE = 4,
180 RLIMIT_CPU = 0,
181 RLIMIT_DATA = 2,
182 RLIMIT_FSIZE = 1,
183 RLIMIT_NOFILE = 8,
184 RLIMIT_STACK = 3,
185 RLIMIT_AS = 5,
186 }
187 }
188 else version (FreeBSD)
189 {
190 enum
191 {
192 PRIO_PROCESS = 0,
193 PRIO_PGRP = 1,
194 PRIO_USER = 2,
195 }
196
197 alias long rlim_t;
198
199 enum
200 {
201 RLIM_INFINITY = (cast(rlim_t)((cast(ulong) 1 << 63) - 1)),
202 // FreeBSD explicitly does not define the following:
203 //RLIM_SAVED_MAX,
204 //RLIM_SAVED_CUR,
205 }
206
207 enum
208 {
209 RUSAGE_SELF = 0,
210 RUSAGE_CHILDREN = -1,
211 }
212
213 struct rusage
214 {
215 timeval ru_utime;
216 timeval ru_stime;
217 c_long ru_maxrss;
218 alias ru_ixrss ru_first;
219 c_long ru_ixrss;
220 c_long ru_idrss;
221 c_long ru_isrss;
222 c_long ru_minflt;
223 c_long ru_majflt;
224 c_long ru_nswap;
225 c_long ru_inblock;
226 c_long ru_oublock;
227 c_long ru_msgsnd;
228 c_long ru_msgrcv;
229 c_long ru_nsignals;
230 c_long ru_nvcsw;
231 c_long ru_nivcsw;
232 alias ru_nivcsw ru_last;
233 }
234
235 enum
236 {
237 RLIMIT_CORE = 4,
238 RLIMIT_CPU = 0,
239 RLIMIT_DATA = 2,
240 RLIMIT_FSIZE = 1,
241 RLIMIT_NOFILE = 8,
242 RLIMIT_STACK = 3,
243 RLIMIT_AS = 10,
244 }
245 }
246 else version (NetBSD)
247 {
248 enum
249 {
250 PRIO_PROCESS = 0,
251 PRIO_PGRP = 1,
252 PRIO_USER = 2,
253 }
254
255 alias long rlim_t;
256
257 enum
258 {
259 RLIM_INFINITY = (cast(rlim_t)((cast(ulong) 1 << 63) - 1)),
260 // FreeBSD explicitly does not define the following:
261 //RLIM_SAVED_MAX,
262 //RLIM_SAVED_CUR,
263 }
264
265 enum
266 {
267 RUSAGE_SELF = 0,
268 RUSAGE_CHILDREN = -1,
269 }
270
271 struct rusage
272 {
273 timeval ru_utime;
274 timeval ru_stime;
275 c_long ru_maxrss;
276 alias ru_ixrss ru_first;
277 c_long ru_ixrss;
278 c_long ru_idrss;
279 c_long ru_isrss;
280 c_long ru_minflt;
281 c_long ru_majflt;
282 c_long ru_nswap;
283 c_long ru_inblock;
284 c_long ru_oublock;
285 c_long ru_msgsnd;
286 c_long ru_msgrcv;
287 c_long ru_nsignals;
288 c_long ru_nvcsw;
289 c_long ru_nivcsw;
290 alias ru_nivcsw ru_last;
291 }
292
293 enum
294 {
295 RLIMIT_CORE = 4,
296 RLIMIT_CPU = 0,
297 RLIMIT_DATA = 2,
298 RLIMIT_FSIZE = 1,
299 RLIMIT_NOFILE = 8,
300 RLIMIT_STACK = 3,
301 RLIMIT_AS = 10,
302 }
303 }
304 else version (OpenBSD)
305 {
306 enum
307 {
308 PRIO_PROCESS = 0,
309 PRIO_PGRP = 1,
310 PRIO_USER = 2,
311 }
312
313 alias ulong rlim_t;
314
315 enum
316 {
317 RLIM_INFINITY = (cast(rlim_t)((cast(ulong) 1 << 63) - 1)),
318 RLIM_SAVED_MAX = RLIM_INFINITY,
319 RLIM_SAVED_CUR = RLIM_INFINITY,
320 }
321
322 enum
323 {
324 RUSAGE_SELF = 0,
325 RUSAGE_CHILDREN = -1,
326 RUSAGE_THREAD = 1,
327 }
328
329 struct rusage
330 {
331 timeval ru_utime;
332 timeval ru_stime;
333 c_long ru_maxrss;
334 alias ru_ixrss ru_first;
335 c_long ru_ixrss;
336 c_long ru_idrss;
337 c_long ru_isrss;
338 c_long ru_minflt;
339 c_long ru_majflt;
340 c_long ru_nswap;
341 c_long ru_inblock;
342 c_long ru_oublock;
343 c_long ru_msgsnd;
344 c_long ru_msgrcv;
345 c_long ru_nsignals;
346 c_long ru_nvcsw;
347 c_long ru_nivcsw;
348 alias ru_nivcsw ru_last;
349 }
350
351 enum
352 {
353 RLIMIT_CORE = 4,
354 RLIMIT_CPU = 0,
355 RLIMIT_DATA = 2,
356 RLIMIT_FSIZE = 1,
357 RLIMIT_NOFILE = 8,
358 RLIMIT_STACK = 3,
359 // OpenBSD does not define the following:
360 //RLIMIT_AS,
361 }
362 }
363 else version (DragonFlyBSD)
364 {
365 enum
366 {
367 PRIO_PROCESS = 0,
368 PRIO_PGRP = 1,
369 PRIO_USER = 2,
370 }
371
372 alias long rlim_t;
373
374 enum
375 {
376 RLIM_INFINITY = (cast(rlim_t)((cast(ulong) 1 << 63) - 1)),
377 // DragonFlyBSD explicitly does not define the following:
378 //RLIM_SAVED_MAX,
379 //RLIM_SAVED_CUR,
380 }
381
382 enum
383 {
384 RUSAGE_SELF = 0,
385 RUSAGE_CHILDREN = -1,
386 }
387
388 struct rusage
389 {
390 timeval ru_utime;
391 timeval ru_stime;
392 c_long ru_maxrss;
393 alias ru_ixrss ru_first;
394 c_long ru_ixrss;
395 c_long ru_idrss;
396 c_long ru_isrss;
397 c_long ru_minflt;
398 c_long ru_majflt;
399 c_long ru_nswap;
400 c_long ru_inblock;
401 c_long ru_oublock;
402 c_long ru_msgsnd;
403 c_long ru_msgrcv;
404 c_long ru_nsignals;
405 c_long ru_nvcsw;
406 c_long ru_nivcsw;
407 alias ru_nivcsw ru_last;
408 }
409
410 enum
411 {
412 RLIMIT_CORE = 4,
413 RLIMIT_CPU = 0,
414 RLIMIT_DATA = 2,
415 RLIMIT_FSIZE = 1,
416 RLIMIT_NOFILE = 8,
417 RLIMIT_STACK = 3,
418 RLIMIT_AS = 10,
419 }
420 }
421 else version (Solaris)
422 {
423 enum
424 {
425 PRIO_PROCESS = 0,
426 PRIO_PGRP = 1,
427 PRIO_USER = 2,
428 }
429
430 alias c_ulong rlim_t;
431
432 enum : c_long
433 {
434 RLIM_INFINITY = -3,
435 RLIM_SAVED_MAX = -2,
436 RLIM_SAVED_CUR = -1,
437 }
438
439 enum
440 {
441 RUSAGE_SELF = 0,
442 RUSAGE_CHILDREN = -1,
443 }
444
445 struct rusage
446 {
447 timeval ru_utime;
448 timeval ru_stime;
449 c_long ru_maxrss;
450 c_long ru_ixrss;
451 c_long ru_idrss;
452 c_long ru_isrss;
453 c_long ru_minflt;
454 c_long ru_majflt;
455 c_long ru_nswap;
456 c_long ru_inblock;
457 c_long ru_oublock;
458 c_long ru_msgsnd;
459 c_long ru_msgrcv;
460 c_long ru_nsignals;
461 c_long ru_nvcsw;
462 c_long ru_nivcsw;
463 }
464
465 enum
466 {
467 RLIMIT_CORE = 4,
468 RLIMIT_CPU = 0,
469 RLIMIT_DATA = 2,
470 RLIMIT_FSIZE = 1,
471 RLIMIT_NOFILE = 5,
472 RLIMIT_STACK = 3,
473 RLIMIT_AS = 6,
474 }
475 }
476 else version (CRuntime_Bionic)
477 {
478 enum
479 {
480 PRIO_PROCESS = 0,
481 PRIO_PGRP = 1,
482 PRIO_USER = 2,
483 }
484
485 alias c_ulong rlim_t;
486 enum RLIM_INFINITY = cast(c_ulong)(~0UL);
487
488 enum
489 {
490 RUSAGE_SELF = 0,
491 RUSAGE_CHILDREN = -1,
492 }
493
494 struct rusage
495 {
496 timeval ru_utime;
497 timeval ru_stime;
498 c_long ru_maxrss;
499 c_long ru_ixrss;
500 c_long ru_idrss;
501 c_long ru_isrss;
502 c_long ru_minflt;
503 c_long ru_majflt;
504 c_long ru_nswap;
505 c_long ru_inblock;
506 c_long ru_oublock;
507 c_long ru_msgsnd;
508 c_long ru_msgrcv;
509 c_long ru_nsignals;
510 c_long ru_nvcsw;
511 c_long ru_nivcsw;
512 }
513
514 enum
515 {
516 RLIMIT_CORE = 4,
517 RLIMIT_CPU = 0,
518 RLIMIT_DATA = 2,
519 RLIMIT_FSIZE = 1,
520 RLIMIT_NOFILE = 7,
521 RLIMIT_STACK = 3,
522 RLIMIT_AS = 9,
523 }
524 }
525 else version (CRuntime_Musl)
526 {
527 alias ulong rlim_t;
528
529 int getrlimit(int, rlimit*);
530 int setrlimit(int, in rlimit*);
531 alias getrlimit getrlimit64;
532 alias setrlimit setrlimit64;
533 enum
534 {
535 RUSAGE_SELF = 0,
536 RUSAGE_CHILDREN = -1,
537 RUSAGE_THREAD = 1
538 }
539 struct rusage
540 {
541 timeval ru_utime;
542 timeval ru_stime;
543 c_long ru_maxrss;
544 c_long ru_ixrss;
545 c_long ru_idrss;
546 c_long ru_isrss;
547 c_long ru_minflt;
548 c_long ru_majflt;
549 c_long ru_nswap;
550 c_long ru_inblock;
551 c_long ru_oublock;
552 c_long ru_msgsnd;
553 c_long ru_msgrcv;
554 c_long ru_nsignals;
555 c_long ru_nvcsw;
556 c_long ru_nivcsw;
557 c_long[16] __reserved;
558 }
559
560 enum
561 {
562 RLIMIT_CPU = 0,
563 RLIMIT_FSIZE = 1,
564 RLIMIT_DATA = 2,
565 RLIMIT_STACK = 3,
566 RLIMIT_CORE = 4,
567 RLIMIT_NOFILE = 7,
568 RLIMIT_AS = 9,
569 }
570 }
571 else version (CRuntime_UClibc)
572 {
573 enum
574 {
575 PRIO_PROCESS = 0,
576 PRIO_PGRP = 1,
577 PRIO_USER = 2,
578 }
579
580 static if (__USE_FILE_OFFSET64)
581 alias ulong rlim_t;
582 else
583 alias c_ulong rlim_t;
584
585 static if (__USE_FILE_OFFSET64)
586 enum RLIM_INFINITY = 0xffffffffffffffffUL;
587 else
588 enum RLIM_INFINITY = cast(c_ulong)(~0UL);
589
590 enum RLIM_SAVED_MAX = RLIM_INFINITY;
591 enum RLIM_SAVED_CUR = RLIM_INFINITY;
592
593 enum
594 {
595 RUSAGE_SELF = 0,
596 RUSAGE_CHILDREN = -1,
597 }
598
599 struct rusage
600 {
601 timeval ru_utime;
602 timeval ru_stime;
603 c_long ru_maxrss;
604 c_long ru_ixrss;
605 c_long ru_idrss;
606 c_long ru_isrss;
607 c_long ru_minflt;
608 c_long ru_majflt;
609 c_long ru_nswap;
610 c_long ru_inblock;
611 c_long ru_oublock;
612 c_long ru_msgsnd;
613 c_long ru_msgrcv;
614 c_long ru_nsignals;
615 c_long ru_nvcsw;
616 c_long ru_nivcsw;
617 }
618
619 enum
620 {
621 RLIMIT_CORE = 4,
622 RLIMIT_CPU = 0,
623 RLIMIT_DATA = 2,
624 RLIMIT_FSIZE = 1,
625 RLIMIT_NOFILE = 7,
626 RLIMIT_STACK = 3,
627 RLIMIT_AS = 9,
628 }
629 }
630 else static assert (false, "Unsupported platform");
631
632 struct rlimit
633 {
634 rlim_t rlim_cur;
635 rlim_t rlim_max;
636 }
637
638 version (CRuntime_Glibc)
639 {
640 int getpriority(int, id_t);
641 int setpriority(int, id_t, int);
642 }
643 else version (FreeBSD)
644 {
645 int getpriority(int, int);
646 int setpriority(int, int, int);
647 }
648 else version (DragonFlyBSD)
649 {
650 int getpriority(int, int);
651 int setpriority(int, int, int);
652 }
653 else version (CRuntime_Bionic)
654 {
655 int getpriority(int, int);
656 int setpriority(int, int, int);
657 }
658 else version (Solaris)
659 {
660 int getpriority(int, id_t);
661 int setpriority(int, id_t, int);
662 }
663 else version (Darwin)
664 {
665 int getpriority(int, id_t);
666 int setpriority(int, id_t, int);
667 }
668 else version (CRuntime_UClibc)
669 {
670 int getpriority(int, id_t);
671 int setpriority(int, id_t, int);
672 }
673
674 version (CRuntime_Glibc)
675 {
676 static if (__USE_FILE_OFFSET64)
677 {
678 int getrlimit64(int, rlimit*);
679 int setrlimit64(int, in rlimit*);
680 alias getrlimit = getrlimit64;
681 alias setrlimit = setrlimit64;
682 }
683 else
684 {
685 int getrlimit(int, rlimit*);
686 int setrlimit(int, in rlimit*);
687 }
688 int getrusage(int, rusage*);
689 }
690 else version (CRuntime_Bionic)
691 {
692 int getrlimit(int, rlimit*);
693 int getrusage(int, rusage*);
694 int setrlimit(int, in rlimit*);
695 }
696 else version (Darwin)
697 {
698 int getrlimit(int, rlimit*);
699 int getrusage(int, rusage*);
700 int setrlimit(int, in rlimit*);
701 }
702 else version (FreeBSD)
703 {
704 int getrlimit(int, rlimit*);
705 int getrusage(int, rusage*);
706 int setrlimit(int, in rlimit*);
707 }
708 else version (NetBSD)
709 {
710 int getrlimit(int, rlimit*);
711 int getrusage(int, rusage*);
712 int setrlimit(int, in rlimit*);
713 }
714 else version (OpenBSD)
715 {
716 int getrlimit(int, rlimit*);
717 int getrusage(int, rusage*);
718 int setrlimit(int, in rlimit*);
719 }
720 else version (DragonFlyBSD)
721 {
722 int getrlimit(int, rlimit*);
723 int getrusage(int, rusage*);
724 int setrlimit(int, in rlimit*);
725 }
726 else version (Solaris)
727 {
728 int getrlimit(int, rlimit*);
729 int getrusage(int, rusage*);
730 int setrlimit(int, in rlimit*);
731 }
732 else version (CRuntime_UClibc)
733 {
734 static if (__USE_FILE_OFFSET64)
735 {
736 int getrlimit64(int, rlimit*);
737 int setrlimit64(int, in rlimit*);
738 alias getrlimit = getrlimit64;
739 alias setrlimit = setrlimit64;
740 }
741 else
742 {
743 int getrlimit(int, rlimit*);
744 int setrlimit(int, in rlimit*);
745 }
746 int getrusage(int, rusage*);
747 }