| 1 | #ifndef _WASI_EMULATED_PROCESS_CLOCKS |
| 2 | #error WASI lacks process-associated clocks; to enable emulation of the `getrusage` function using \ |
| 3 | the wall clock, which isn't sensitive to whether the program is running or suspended, \ |
| 4 | compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks |
| 5 | #else |
| 6 | #ifndef	_SYS_RESOURCE_H |
| 7 | #define	_SYS_RESOURCE_H |
| 8 | |
| 9 | #ifdef __cplusplus |
| 10 | extern "C" { |
| 11 | #endif |
| 12 | |
| 13 | #include <features.h> |
| 14 | #include <sys/time.h> |
| 15 | |
| 16 | #define __NEED_id_t |
| 17 | |
| 18 | #ifdef _GNU_SOURCE |
| 19 | #define __NEED_pid_t |
| 20 | #endif |
| 21 | |
| 22 | #include <bits/alltypes.h> |
| 23 | #include <bits/resource.h> |
| 24 | |
| 25 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ |
| 26 | typedef unsigned long long rlim_t; |
| 27 | |
| 28 | struct rlimit { |
| 29 | 	rlim_t rlim_cur; |
| 30 | 	rlim_t rlim_max; |
| 31 | }; |
| 32 | |
| 33 | struct rusage { |
| 34 | 	struct timeval ru_utime; |
| 35 | 	struct timeval ru_stime; |
| 36 | 	/* linux extentions, but useful */ |
| 37 | 	long	ru_maxrss; |
| 38 | 	long	ru_ixrss; |
| 39 | 	long	ru_idrss; |
| 40 | 	long	ru_isrss; |
| 41 | 	long	ru_minflt; |
| 42 | 	long	ru_majflt; |
| 43 | 	long	ru_nswap; |
| 44 | 	long	ru_inblock; |
| 45 | 	long	ru_oublock; |
| 46 | 	long	ru_msgsnd; |
| 47 | 	long	ru_msgrcv; |
| 48 | 	long	ru_nsignals; |
| 49 | 	long	ru_nvcsw; |
| 50 | 	long	ru_nivcsw; |
| 51 | 	/* room for more... */ |
| 52 | 	long __reserved[16]; |
| 53 | }; |
| 54 | |
| 55 | int getrlimit (int, struct rlimit *); |
| 56 | int setrlimit (int, const struct rlimit *); |
| 57 | int getrusage (int, struct rusage *); |
| 58 | |
| 59 | int getpriority (int, id_t); |
| 60 | int setpriority (int, id_t, int); |
| 61 | |
| 62 | #ifdef _GNU_SOURCE |
| 63 | int prlimit(pid_t, int, const struct rlimit *, struct rlimit *); |
| 64 | #define prlimit64 prlimit |
| 65 | #endif |
| 66 | |
| 67 | #define PRIO_MIN (-20) |
| 68 | #define PRIO_MAX 20 |
| 69 | |
| 70 | #define PRIO_PROCESS 0 |
| 71 | #define PRIO_PGRP 1 |
| 72 | #define PRIO_USER 2 |
| 73 | |
| 74 | #define RUSAGE_SELF 0 |
| 75 | #define RUSAGE_CHILDREN (-1) |
| 76 | #define RUSAGE_THREAD 1 |
| 77 | |
| 78 | #define RLIM_INFINITY (~0ULL) |
| 79 | #define RLIM_SAVED_CUR RLIM_INFINITY |
| 80 | #define RLIM_SAVED_MAX RLIM_INFINITY |
| 81 | |
| 82 | #define RLIMIT_CPU 0 |
| 83 | #define RLIMIT_FSIZE 1 |
| 84 | #define RLIMIT_DATA 2 |
| 85 | #define RLIMIT_STACK 3 |
| 86 | #define RLIMIT_CORE 4 |
| 87 | #ifndef RLIMIT_RSS |
| 88 | #define RLIMIT_RSS 5 |
| 89 | #define RLIMIT_NPROC 6 |
| 90 | #define RLIMIT_NOFILE 7 |
| 91 | #define RLIMIT_MEMLOCK 8 |
| 92 | #define RLIMIT_AS 9 |
| 93 | #endif |
| 94 | #define RLIMIT_LOCKS 10 |
| 95 | #define RLIMIT_SIGPENDING 11 |
| 96 | #define RLIMIT_MSGQUEUE 12 |
| 97 | #define RLIMIT_NICE 13 |
| 98 | #define RLIMIT_RTPRIO 14 |
| 99 | #define RLIMIT_RTTIME 15 |
| 100 | #define RLIMIT_NLIMITS 16 |
| 101 | |
| 102 | #define RLIM_NLIMITS RLIMIT_NLIMITS |
| 103 | |
| 104 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) |
| 105 | #define RLIM64_INFINITY RLIM_INFINITY |
| 106 | #define RLIM64_SAVED_CUR RLIM_SAVED_CUR |
| 107 | #define RLIM64_SAVED_MAX RLIM_SAVED_MAX |
| 108 | #define getrlimit64 getrlimit |
| 109 | #define setrlimit64 setrlimit |
| 110 | #define rlimit64 rlimit |
| 111 | #define rlim64_t rlim_t |
| 112 | #endif |
| 113 | #else |
| 114 | #include <__header_sys_resource.h> |
| 115 | #endif |
| 116 | |
| 117 | #if _REDIR_TIME64 |
| 118 | __REDIR(getrusage, __getrusage_time64); |
| 119 | #endif |
| 120 | |
| 121 | #ifdef __cplusplus |
| 122 | } |
| 123 | #endif |
| 124 | |
| 125 | #endif |
| 126 | #endif |