1 #ifndef _SYS_RESOURCE_H
2 #include <resource/sys/resource.h>
3 
4 #ifndef _ISOMAC
5 # include <time.h>
6 # include <string.h>
7 
8 /* Internal version of rusage with a 64-bit time_t. */
9 #if __TIMESIZE == 64
10 # define __rusage64 rusage
11 #else
12 struct __rusage64
13   {
14     struct __timeval64 ru_utime;
15     struct __timeval64 ru_stime;
16     __extension__ union
17       {
18 	long int ru_maxrss;
19 	__syscall_slong_t __ru_maxrss_word;
20       };
21     __extension__ union
22       {
23 	long int ru_ixrss;
24 	__syscall_slong_t __ru_ixrss_word;
25       };
26     __extension__ union
27       {
28 	long int ru_idrss;
29 	__syscall_slong_t __ru_idrss_word;
30       };
31     __extension__ union
32       {
33 	long int ru_isrss;
34 	 __syscall_slong_t __ru_isrss_word;
35       };
36     __extension__ union
37       {
38 	long int ru_minflt;
39 	__syscall_slong_t __ru_minflt_word;
40       };
41     __extension__ union
42       {
43 	long int ru_majflt;
44 	__syscall_slong_t __ru_majflt_word;
45       };
46     __extension__ union
47       {
48 	long int ru_nswap;
49 	__syscall_slong_t __ru_nswap_word;
50       };
51     __extension__ union
52       {
53 	long int ru_inblock;
54 	__syscall_slong_t __ru_inblock_word;
55       };
56     __extension__ union
57       {
58 	long int ru_oublock;
59 	__syscall_slong_t __ru_oublock_word;
60       };
61     __extension__ union
62       {
63 	long int ru_msgsnd;
64 	__syscall_slong_t __ru_msgsnd_word;
65       };
66     __extension__ union
67       {
68 	long int ru_msgrcv;
69 	__syscall_slong_t __ru_msgrcv_word;
70       };
71     __extension__ union
72       {
73 	long int ru_nsignals;
74 	__syscall_slong_t __ru_nsignals_word;
75       };
76     __extension__ union
77       {
78 	long int ru_nvcsw;
79 	__syscall_slong_t __ru_nvcsw_word;
80       };
81     __extension__ union
82       {
83 	long int ru_nivcsw;
84 	__syscall_slong_t __ru_nivcsw_word;
85       };
86   };
87 #endif
88 
89 static inline void
rusage64_to_rusage(const struct __rusage64 * restrict r64,struct rusage * restrict r)90 rusage64_to_rusage (const struct __rusage64 *restrict r64,
91                     struct rusage *restrict r)
92 {
93   /* Make sure the entire output structure is cleared, including
94      padding and reserved fields.  */
95   memset (r, 0, sizeof *r);
96 
97   r->ru_utime    = valid_timeval64_to_timeval (r64->ru_utime);
98   r->ru_stime    = valid_timeval64_to_timeval (r64->ru_stime);
99   r->ru_maxrss   = r64->ru_maxrss;
100   r->ru_ixrss    = r64->ru_ixrss;
101   r->ru_idrss    = r64->ru_idrss;
102   r->ru_isrss    = r64->ru_isrss;
103   r->ru_minflt   = r64->ru_minflt;
104   r->ru_majflt   = r64->ru_majflt;
105   r->ru_nswap    = r64->ru_nswap;
106   r->ru_inblock  = r64->ru_inblock;
107   r->ru_oublock  = r64->ru_oublock;
108   r->ru_msgsnd   = r64->ru_msgsnd;
109   r->ru_msgrcv   = r64->ru_msgrcv;
110   r->ru_nsignals = r64->ru_nsignals;
111   r->ru_nvcsw    = r64->ru_nvcsw;
112   r->ru_nivcsw   = r64->ru_nivcsw;
113 }
114 
115 /* Prototypes repeated instead of using __typeof because
116    sys/resource.h is included in C++ tests, and declaring functions
117    with __typeof and __THROW doesn't work for C++.  */
118 extern int __getpriority (__priority_which_t __which, id_t __who) __THROW;
119 libc_hidden_proto (__getpriority)
120 extern int __setpriority (__priority_which_t __which, id_t __who, int __prio)
121      __THROW;
122 libc_hidden_proto (__setpriority)
123 libc_hidden_proto (getrlimit64)
124 extern __typeof (getrlimit64) __getrlimit64;
125 libc_hidden_proto (__getrlimit64);
126 
127 /* Now define the internal interfaces.  */
128 extern int __getrlimit (enum __rlimit_resource __resource,
129 			struct rlimit *__rlimits) __nonnull ((2));
130 libc_hidden_proto (__getrlimit)
131 extern int __getrusage (enum __rusage_who __who, struct rusage *__usage)
132 	attribute_hidden;
133 
134 extern int __setrlimit (enum __rlimit_resource __resource,
135 			const struct rlimit *__rlimits) __nonnull ((2));
136 libc_hidden_proto (__setrlimit);
137 
138 #if __TIMESIZE == 64
139 # define __getrusage64 __getrusage
140 # define __wait4_time64 __wait4
141 # define __wait3_time64 __wait3
142 #else
143 extern int __getrusage64 (enum __rusage_who who, struct __rusage64 *usage);
144 libc_hidden_proto (__getrusage64)
145 extern pid_t __wait4_time64 (pid_t pid, int *stat_loc, int options,
146                              struct __rusage64 *usage);
147 libc_hidden_proto (__wait4_time64)
148 extern pid_t __wait3_time64 (int *stat_loc, int options,
149                              struct __rusage64 *usage);
150 libc_hidden_proto (__wait3_time64)
151 #endif
152 #endif
153 #endif
154