custom message type for VM_QUERY_EXIT
[minix3.git] / lib / libc / sys-minix / getrusage.c
blob43767e32ed7b1c6449fbb8fa31e21c1a65bd399a
1 #include <sys/cdefs.h>
2 #include "namespace.h"
3 #include <lib.h>
5 #include <string.h>
6 #include <unistd.h>
7 #include <sys/resource.h>
9 int getrusage(int who, struct rusage *r_usage)
11 int rc;
12 message m;
14 memset(&m, 0, sizeof(m));
15 m.m_lc_pm_rusage.who = who;
16 m.m_lc_pm_rusage.addr = (vir_bytes)r_usage;
18 if (r_usage == NULL) {
19 errno = EFAULT;
20 return -1;
22 if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN) {
23 errno = EINVAL;
24 return -1;
27 memset(r_usage, 0, sizeof(struct rusage));
28 if ((rc = _syscall(PM_PROC_NR, PM_GETRUSAGE, &m)) < 0)
29 return rc;
31 memset(&m, 0, sizeof(m));
32 m.m_lc_vfs_rusage.addr = (vir_bytes)r_usage;
33 if ((rc = _syscall(VFS_PROC_NR, VFS_GETRUSAGE, &m)) < 0)
34 return rc;
36 memset(&m, 0, sizeof(m));
37 m.m_lc_vm_rusage.addr = (vir_bytes)r_usage;
38 return _syscall(VM_PROC_NR, VM_GETRUSAGE, &m);