chore: make yuzu REUSE compliant
[REUSE] is a specification that aims at making file copyright
information consistent, so that it can be both human and machine
readable. It basically requires that all files have a header containing
copyright and licensing information. When this isn't possible, like
when dealing with binary assets, generated files or embedded third-party
dependencies, it is permitted to insert copyright information in the
`.reuse/dep5` file.
Oh, and it also requires that all the licenses used in the project are
present in the `LICENSES` folder, that's why the diff is so huge.
This can be done automatically with `reuse download --all`.
The `reuse` tool also contains a handy subcommand that analyzes the
project and tells whether or not the project is (still) compliant,
`reuse lint`.
Following REUSE has a few advantages over the current approach:
- Copyright information is easy to access for users / downstream
- Files like `dist/license.md` do not need to exist anymore, as
`.reuse/dep5` is used instead
- `reuse lint` makes it easy to ensure that copyright information of
files like binary assets / images is always accurate and up to date
To add copyright information of files that didn't have it I looked up
who committed what and when, for each file. As yuzu contributors do not
have to sign a CLA or similar I couldn't assume that copyright ownership
was of the "yuzu Emulator Project", so I used the name and/or email of
the commit author instead.
[REUSE]: https://reuse.software
Follow-up to 01cf05bc75b1e47beb08937439f3ed9339e7b254
2022-05-15 02:06:02 +02:00
|
|
|
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-07-05 06:55:39 +02:00
|
|
|
|
2018-07-31 14:06:09 +02:00
|
|
|
#include "common/assert.h"
|
2020-04-09 00:53:52 +02:00
|
|
|
#include "core/core.h"
|
2021-02-13 02:58:31 +01:00
|
|
|
#include "core/hle/kernel/k_page_table.h"
|
2021-02-05 02:06:54 +01:00
|
|
|
#include "core/hle/kernel/k_scoped_resource_reservation.h"
|
2021-02-06 08:14:31 +01:00
|
|
|
#include "core/hle/kernel/k_shared_memory.h"
|
2022-12-23 19:40:30 +01:00
|
|
|
#include "core/hle/kernel/k_system_resource.h"
|
2018-09-25 02:01:45 +02:00
|
|
|
#include "core/hle/kernel/kernel.h"
|
2021-04-21 06:28:11 +02:00
|
|
|
#include "core/hle/kernel/svc_results.h"
|
2014-07-05 06:55:39 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2023-03-07 16:49:41 +01:00
|
|
|
KSharedMemory::KSharedMemory(KernelCore& kernel) : KAutoObjectWithSlabHeapAndContainer{kernel} {}
|
2023-01-08 00:32:10 +01:00
|
|
|
KSharedMemory::~KSharedMemory() = default;
|
2018-08-03 05:37:44 +02:00
|
|
|
|
2023-03-07 04:47:06 +01:00
|
|
|
Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory, KProcess* owner_process,
|
|
|
|
Svc::MemoryPermission owner_permission,
|
|
|
|
Svc::MemoryPermission user_permission, std::size_t size) {
|
2021-04-21 06:28:11 +02:00
|
|
|
// Set members.
|
2023-03-07 04:47:06 +01:00
|
|
|
m_owner_process = owner_process;
|
|
|
|
m_device_memory = std::addressof(device_memory);
|
|
|
|
m_owner_permission = owner_permission;
|
|
|
|
m_user_permission = user_permission;
|
|
|
|
m_size = Common::AlignUp(size, PageSize);
|
2016-05-09 00:10:53 +02:00
|
|
|
|
2022-12-23 19:40:30 +01:00
|
|
|
const size_t num_pages = Common::DivideUp(size, PageSize);
|
|
|
|
|
2021-04-21 06:28:11 +02:00
|
|
|
// Get the resource limit.
|
2023-03-07 16:49:41 +01:00
|
|
|
KResourceLimit* reslimit = m_kernel.GetSystemResourceLimit();
|
2021-04-21 06:28:11 +02:00
|
|
|
|
|
|
|
// Reserve memory for ourselves.
|
2022-11-03 15:22:05 +01:00
|
|
|
KScopedResourceReservation memory_reservation(reslimit, LimitableResource::PhysicalMemoryMax,
|
2023-03-07 04:47:06 +01:00
|
|
|
size);
|
2021-04-21 06:28:11 +02:00
|
|
|
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
|
|
|
|
2022-12-23 19:40:30 +01:00
|
|
|
// Allocate the memory.
|
|
|
|
|
|
|
|
//! HACK: Open continuous mapping from sysmodule pool.
|
|
|
|
auto option = KMemoryManager::EncodeOption(KMemoryManager::Pool::Secure,
|
|
|
|
KMemoryManager::Direction::FromBack);
|
2023-03-07 16:49:41 +01:00
|
|
|
m_physical_address = m_kernel.MemoryManager().AllocateAndOpenContinuous(num_pages, 1, option);
|
2023-03-07 04:47:06 +01:00
|
|
|
R_UNLESS(m_physical_address != 0, ResultOutOfMemory);
|
2022-12-23 19:40:30 +01:00
|
|
|
|
|
|
|
//! Insert the result into our page group.
|
2023-03-07 18:01:07 +01:00
|
|
|
m_page_group.emplace(m_kernel,
|
|
|
|
std::addressof(m_kernel.GetSystemSystemResource().GetBlockInfoManager()));
|
2023-03-07 04:47:06 +01:00
|
|
|
m_page_group->AddBlock(m_physical_address, num_pages);
|
2022-12-23 19:40:30 +01:00
|
|
|
|
2021-04-21 06:28:11 +02:00
|
|
|
// Commit our reservation.
|
2021-02-05 02:06:54 +01:00
|
|
|
memory_reservation.Commit();
|
2021-04-04 08:22:07 +02:00
|
|
|
|
2021-04-21 06:28:11 +02:00
|
|
|
// Set our resource limit.
|
2023-03-07 04:47:06 +01:00
|
|
|
m_resource_limit = reslimit;
|
|
|
|
m_resource_limit->Open();
|
2021-04-21 06:28:11 +02:00
|
|
|
|
|
|
|
// Mark initialized.
|
2023-03-07 04:47:06 +01:00
|
|
|
m_is_initialized = true;
|
2021-04-21 06:28:11 +02:00
|
|
|
|
|
|
|
// Clear all pages in the memory.
|
2023-03-07 04:47:06 +01:00
|
|
|
for (const auto& block : *m_page_group) {
|
|
|
|
std::memset(m_device_memory->GetPointer<void>(block.GetAddress()), 0, block.GetSize());
|
2022-12-23 19:40:30 +01:00
|
|
|
}
|
2021-04-21 06:28:11 +02:00
|
|
|
|
2023-03-07 02:34:25 +01:00
|
|
|
R_SUCCEED();
|
2021-04-04 08:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KSharedMemory::Finalize() {
|
2022-12-23 19:40:30 +01:00
|
|
|
// Close and finalize the page group.
|
2023-03-07 04:47:06 +01:00
|
|
|
m_page_group->Close();
|
|
|
|
m_page_group->Finalize();
|
2022-12-23 19:40:30 +01:00
|
|
|
|
2021-04-04 08:22:07 +02:00
|
|
|
// Release the memory reservation.
|
2023-03-07 04:47:06 +01:00
|
|
|
m_resource_limit->Release(LimitableResource::PhysicalMemoryMax, m_size);
|
|
|
|
m_resource_limit->Close();
|
2016-05-09 00:10:53 +02:00
|
|
|
}
|
|
|
|
|
2023-03-18 02:26:04 +01:00
|
|
|
Result KSharedMemory::Map(KProcess& target_process, KProcessAddress address, std::size_t map_size,
|
2022-12-23 19:40:30 +01:00
|
|
|
Svc::MemoryPermission map_perm) {
|
|
|
|
// Validate the size.
|
2023-03-07 04:47:06 +01:00
|
|
|
R_UNLESS(m_size == map_size, ResultInvalidSize);
|
2015-12-31 15:46:32 +01:00
|
|
|
|
2022-12-23 19:40:30 +01:00
|
|
|
// Validate the permission.
|
|
|
|
const Svc::MemoryPermission test_perm =
|
2023-03-07 04:47:06 +01:00
|
|
|
std::addressof(target_process) == m_owner_process ? m_owner_permission : m_user_permission;
|
2022-12-23 19:40:30 +01:00
|
|
|
if (test_perm == Svc::MemoryPermission::DontCare) {
|
|
|
|
ASSERT(map_perm == Svc::MemoryPermission::Read || map_perm == Svc::MemoryPermission::Write);
|
|
|
|
} else {
|
|
|
|
R_UNLESS(map_perm == test_perm, ResultInvalidNewMemoryPermission);
|
2016-04-19 18:59:44 +02:00
|
|
|
}
|
2014-07-05 16:22:03 +02:00
|
|
|
|
2023-07-15 03:43:15 +02:00
|
|
|
R_RETURN(target_process.GetPageTable().MapPageGroup(
|
|
|
|
address, *m_page_group, KMemoryState::Shared, ConvertToKMemoryPermission(map_perm)));
|
2021-04-30 23:53:22 +02:00
|
|
|
}
|
|
|
|
|
2023-03-18 02:26:04 +01:00
|
|
|
Result KSharedMemory::Unmap(KProcess& target_process, KProcessAddress address,
|
|
|
|
std::size_t unmap_size) {
|
2022-12-23 19:40:30 +01:00
|
|
|
// Validate the size.
|
2023-03-07 04:47:06 +01:00
|
|
|
R_UNLESS(m_size == unmap_size, ResultInvalidSize);
|
2021-04-30 23:53:22 +02:00
|
|
|
|
2023-03-07 04:47:06 +01:00
|
|
|
R_RETURN(
|
2023-07-15 03:43:15 +02:00
|
|
|
target_process.GetPageTable().UnmapPageGroup(address, *m_page_group, KMemoryState::Shared));
|
2018-11-19 15:00:32 +01:00
|
|
|
}
|
|
|
|
|
2017-10-01 20:57:50 +02:00
|
|
|
} // namespace Kernel
|