2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-04-05 20:39:08 +02:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
2021-06-23 23:18:27 +02:00
|
|
|
#include "common/literals.h"
|
2021-02-13 00:47:05 +01:00
|
|
|
#include "core/hle/kernel/k_address_space_info.h"
|
2020-04-05 20:39:08 +02:00
|
|
|
|
2021-02-13 00:47:05 +01:00
|
|
|
namespace Kernel {
|
2020-04-05 20:39:08 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2021-06-23 23:18:27 +02:00
|
|
|
using namespace Common::Literals;
|
|
|
|
|
|
|
|
constexpr u64 Size_Invalid = UINT64_MAX;
|
|
|
|
|
2020-04-05 20:39:08 +02:00
|
|
|
// clang-format off
|
2021-02-13 00:47:05 +01:00
|
|
|
constexpr std::array<KAddressSpaceInfo, 13> AddressSpaceInfos{{
|
2021-06-23 23:18:27 +02:00
|
|
|
{ .bit_width = 32, .address = 2_MiB , .size = 1_GiB - 2_MiB , .type = KAddressSpaceInfo::Type::MapSmall, },
|
|
|
|
{ .bit_width = 32, .address = 1_GiB , .size = 4_GiB - 1_GiB , .type = KAddressSpaceInfo::Type::MapLarge, },
|
|
|
|
{ .bit_width = 32, .address = Size_Invalid, .size = 1_GiB , .type = KAddressSpaceInfo::Type::Alias, },
|
|
|
|
{ .bit_width = 32, .address = Size_Invalid, .size = 1_GiB , .type = KAddressSpaceInfo::Type::Heap, },
|
|
|
|
{ .bit_width = 36, .address = 128_MiB , .size = 2_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::MapSmall, },
|
|
|
|
{ .bit_width = 36, .address = 2_GiB , .size = 64_GiB - 2_GiB , .type = KAddressSpaceInfo::Type::MapLarge, },
|
2023-02-23 04:03:15 +01:00
|
|
|
{ .bit_width = 36, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, },
|
2021-06-23 23:18:27 +02:00
|
|
|
{ .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Alias, },
|
2023-11-20 14:52:18 +01:00
|
|
|
#ifdef HAS_NCE
|
2023-11-17 22:44:53 +01:00
|
|
|
// With NCE, we use a 38-bit address space due to memory limitations. This should (safely) truncate ASLR region.
|
2023-01-01 18:12:01 +01:00
|
|
|
{ .bit_width = 39, .address = 128_MiB , .size = 256_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, },
|
|
|
|
#else
|
2021-06-23 23:18:27 +02:00
|
|
|
{ .bit_width = 39, .address = 128_MiB , .size = 512_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, },
|
2023-01-01 18:12:01 +01:00
|
|
|
#endif
|
2021-06-23 23:18:27 +02:00
|
|
|
{ .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::MapSmall },
|
2023-02-23 04:03:15 +01:00
|
|
|
{ .bit_width = 39, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, },
|
2021-06-23 23:18:27 +02:00
|
|
|
{ .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::Alias, },
|
|
|
|
{ .bit_width = 39, .address = Size_Invalid, .size = 2_GiB , .type = KAddressSpaceInfo::Type::Stack, },
|
2020-04-05 20:39:08 +02:00
|
|
|
}};
|
|
|
|
// clang-format on
|
|
|
|
|
2023-02-23 04:03:15 +01:00
|
|
|
const KAddressSpaceInfo& GetAddressSpaceInfo(size_t width, KAddressSpaceInfo::Type type) {
|
|
|
|
for (auto& info : AddressSpaceInfos) {
|
|
|
|
if (info.bit_width == width && info.type == type) {
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
UNREACHABLE_MSG("Could not find AddressSpaceInfo");
|
2020-04-05 20:39:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-03-08 02:03:24 +01:00
|
|
|
std::size_t KAddressSpaceInfo::GetAddressSpaceStart(size_t width, KAddressSpaceInfo::Type type) {
|
2023-02-23 04:03:15 +01:00
|
|
|
return GetAddressSpaceInfo(width, type).address;
|
2020-04-05 20:39:08 +02:00
|
|
|
}
|
|
|
|
|
2023-03-08 02:03:24 +01:00
|
|
|
std::size_t KAddressSpaceInfo::GetAddressSpaceSize(size_t width, KAddressSpaceInfo::Type type) {
|
2023-02-23 04:03:15 +01:00
|
|
|
return GetAddressSpaceInfo(width, type).size;
|
2020-04-05 20:39:08 +02:00
|
|
|
}
|
|
|
|
|
2021-02-13 00:47:05 +01:00
|
|
|
} // namespace Kernel
|