Fork me on GitHub

root/kernel/syscalls/getrusage.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_getrusage

   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, &current->usage, sizeof(struct rusage));
  32                         break;
  33                 case RUSAGE_CHILDREN:
  34                         memcpy_b(usage, &current->cusage, sizeof(struct rusage));
  35                         break;
  36                 default:
  37                         return -EINVAL;
  38         }
  39         return 0;
  40 }

/* [previous][next][first][last][top][bottom][index][help] */