summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/resource.cpp
blob: 97b130efc2321b97a6772e51ccbd2053f51da27d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * Copyright (c) 2022, Lucas Chollet <lucas.chollet@free.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <Kernel/Process.h>

namespace Kernel {

ErrorOr<FlatPtr> Process::sys$getrusage(int who, Userspace<rusage*> user_usage)
{
    VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);

    rusage usage {};

    auto const ticks_per_second = TimeManagement::the().ticks_per_second();

    switch (who) {
    case RUSAGE_SELF:
        usage.ru_utime = Time::from_ticks(m_ticks_in_user, ticks_per_second).to_timeval();
        usage.ru_stime = Time::from_ticks(m_ticks_in_kernel, ticks_per_second).to_timeval();
        break;
    case RUSAGE_CHILDREN:
        usage.ru_utime = Time::from_ticks(m_ticks_in_user_for_dead_children, ticks_per_second).to_timeval();
        usage.ru_stime = Time::from_ticks(m_ticks_in_kernel_for_dead_children, ticks_per_second).to_timeval();
        break;
    default:
        return EINVAL;
    }

    TRY(copy_to_user(user_usage, &usage));

    return 0;
}

}