summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/resource_limit.cpp
blob: 0ef5fc57d023216bb5236321ccba1a35f0151980 (plain) (blame)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright 2015 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <cstring>
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/hle/kernel/resource_limit.h"

namespace Kernel {

static SharedPtr<ResourceLimit> resource_limits[4];

ResourceLimit::ResourceLimit() {}
ResourceLimit::~ResourceLimit() {}

SharedPtr<ResourceLimit> ResourceLimit::Create(std::string name) {
    SharedPtr<ResourceLimit> resource_limit(new ResourceLimit);

    resource_limit->name = std::move(name);
    return resource_limit;
}

SharedPtr<ResourceLimit> ResourceLimit::GetForCategory(ResourceLimitCategory category) {
    switch (category) {
    case ResourceLimitCategory::APPLICATION:
    case ResourceLimitCategory::SYS_APPLET:
    case ResourceLimitCategory::LIB_APPLET:
    case ResourceLimitCategory::OTHER:
        return resource_limits[static_cast<u8>(category)];
    default:
        NGLOG_CRITICAL(Kernel, "Unknown resource limit category");
        UNREACHABLE();
    }
}

s32 ResourceLimit::GetCurrentResourceValue(ResourceType resource) const {
    switch (resource) {
    case ResourceType::Commit:
        return current_commit;
    case ResourceType::Thread:
        return current_threads;
    case ResourceType::Event:
        return current_events;
    case ResourceType::Mutex:
        return current_mutexes;
    case ResourceType::Semaphore:
        return current_semaphores;
    case ResourceType::Timer:
        return current_timers;
    case ResourceType::SharedMemory:
        return current_shared_mems;
    case ResourceType::AddressArbiter:
        return current_address_arbiters;
    case ResourceType::CPUTime:
        return current_cpu_time;
    default:
        NGLOG_ERROR(Kernel, "Unknown resource type={:08X}", static_cast<u32>(resource));
        UNIMPLEMENTED();
        return 0;
    }
}

u32 ResourceLimit::GetMaxResourceValue(ResourceType resource) const {
    switch (resource) {
    case ResourceType::Priority:
        return max_priority;
    case ResourceType::Commit:
        return max_commit;
    case ResourceType::Thread:
        return max_threads;
    case ResourceType::Event:
        return max_events;
    case ResourceType::Mutex:
        return max_mutexes;
    case ResourceType::Semaphore:
        return max_semaphores;
    case ResourceType::Timer:
        return max_timers;
    case ResourceType::SharedMemory:
        return max_shared_mems;
    case ResourceType::AddressArbiter:
        return max_address_arbiters;
    case ResourceType::CPUTime:
        return max_cpu_time;
    default:
        NGLOG_ERROR(Kernel, "Unknown resource type={:08X}", static_cast<u32>(resource));
        UNIMPLEMENTED();
        return 0;
    }
}

void ResourceLimitsInit() {
    // Create the four resource limits that the system uses
    // Create the APPLICATION resource limit
    SharedPtr<ResourceLimit> resource_limit = ResourceLimit::Create("Applications");
    resource_limit->max_priority = 0x18;
    resource_limit->max_commit = 0x4000000;
    resource_limit->max_threads = 0x20;
    resource_limit->max_events = 0x20;
    resource_limit->max_mutexes = 0x20;
    resource_limit->max_semaphores = 0x8;
    resource_limit->max_timers = 0x8;
    resource_limit->max_shared_mems = 0x10;
    resource_limit->max_address_arbiters = 0x2;
    resource_limit->max_cpu_time = 0x1E;
    resource_limits[static_cast<u8>(ResourceLimitCategory::APPLICATION)] = resource_limit;

    // Create the SYS_APPLET resource limit
    resource_limit = ResourceLimit::Create("System Applets");
    resource_limit->max_priority = 0x4;
    resource_limit->max_commit = 0x5E00000;
    resource_limit->max_threads = 0x1D;
    resource_limit->max_events = 0xB;
    resource_limit->max_mutexes = 0x8;
    resource_limit->max_semaphores = 0x4;
    resource_limit->max_timers = 0x4;
    resource_limit->max_shared_mems = 0x8;
    resource_limit->max_address_arbiters = 0x3;
    resource_limit->max_cpu_time = 0x2710;
    resource_limits[static_cast<u8>(ResourceLimitCategory::SYS_APPLET)] = resource_limit;

    // Create the LIB_APPLET resource limit
    resource_limit = ResourceLimit::Create("Library Applets");
    resource_limit->max_priority = 0x4;
    resource_limit->max_commit = 0x600000;
    resource_limit->max_threads = 0xE;
    resource_limit->max_events = 0x8;
    resource_limit->max_mutexes = 0x8;
    resource_limit->max_semaphores = 0x4;
    resource_limit->max_timers = 0x4;
    resource_limit->max_shared_mems = 0x8;
    resource_limit->max_address_arbiters = 0x1;
    resource_limit->max_cpu_time = 0x2710;
    resource_limits[static_cast<u8>(ResourceLimitCategory::LIB_APPLET)] = resource_limit;

    // Create the OTHER resource limit
    resource_limit = ResourceLimit::Create("Others");
    resource_limit->max_priority = 0x4;
    resource_limit->max_commit = 0x2180000;
    resource_limit->max_threads = 0xE1;
    resource_limit->max_events = 0x108;
    resource_limit->max_mutexes = 0x25;
    resource_limit->max_semaphores = 0x43;
    resource_limit->max_timers = 0x2C;
    resource_limit->max_shared_mems = 0x1F;
    resource_limit->max_address_arbiters = 0x2D;
    resource_limit->max_cpu_time = 0x3E8;
    resource_limits[static_cast<u8>(ResourceLimitCategory::OTHER)] = resource_limit;
}

void ResourceLimitsShutdown() {}

} // namespace Kernel