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