Welcome to The Fiwix Project
A UNIX-like kernel for the i386 architecture
1 /* 2 * fiwix/kernel/syscalls/getrusage.c 3 * 4 * Copyright 2018, Jordi Sanfeliu. All rights reserved. 5 * Distributed under the terms of the Fiwix License. 6 */ 7 8 #include <fiwix/fs.h> 9 #include <fiwix/resource.h> 10 #include <fiwix/process.h> 11 #include <fiwix/errno.h> 12 #include <fiwix/string.h> 13 14 #ifdef __DEBUG__ 15 #include <fiwix/stdio.h> 16 #endif /*__DEBUG__ */ 17 18 int sys_getrusage(int who, struct rusage *usage) 19 { 20 int errno; 21 22 #ifdef __DEBUG__ 23 printk("(pid %d) sys_getrusage(%d, 0x%08x)\n", current->pid, who, (unsigned int)usage); 24 #endif /*__DEBUG__ */ 25 26 if((errno = check_user_area(VERIFY_WRITE, usage, sizeof(struct rusage)))) { 27 return errno; 28 } 29 switch(who) { 30 case RUSAGE_SELF: 31 memcpy_b(usage, ¤t->usage, sizeof(struct rusage)); 32 break; 33 case RUSAGE_CHILDREN: 34 memcpy_b(usage, ¤t->cusage, sizeof(struct rusage)); 35 break; 36 default: 37 return -EINVAL; 38 } 39 return 0; 40 }