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"
|
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 {
|
|
|
|
|
2021-05-08 18:11:36 +02:00
|
|
|
KSharedMemory::KSharedMemory(KernelCore& kernel_) : KAutoObjectWithSlabHeapAndContainer{kernel_} {}
|
2018-08-03 05:37:44 +02:00
|
|
|
|
2021-02-06 08:14:31 +01:00
|
|
|
KSharedMemory::~KSharedMemory() {
|
2022-11-03 15:22:05 +01:00
|
|
|
kernel.GetSystemResourceLimit()->Release(LimitableResource::PhysicalMemoryMax, size);
|
2021-02-13 01:05:24 +01:00
|
|
|
}
|
2018-08-03 05:37:44 +02:00
|
|
|
|
2022-06-26 05:44:19 +02:00
|
|
|
Result KSharedMemory::Initialize(Core::DeviceMemory& device_memory_, KProcess* owner_process_,
|
2022-06-26 06:15:31 +02:00
|
|
|
KPageGroup&& page_list_, Svc::MemoryPermission owner_permission_,
|
2022-06-26 05:44:19 +02:00
|
|
|
Svc::MemoryPermission user_permission_, PAddr physical_address_,
|
|
|
|
std::size_t size_, std::string name_) {
|
2021-04-21 06:28:11 +02:00
|
|
|
// Set members.
|
2021-04-04 08:22:07 +02:00
|
|
|
owner_process = owner_process_;
|
|
|
|
device_memory = &device_memory_;
|
|
|
|
page_list = std::move(page_list_);
|
|
|
|
owner_permission = owner_permission_;
|
|
|
|
user_permission = user_permission_;
|
|
|
|
physical_address = physical_address_;
|
|
|
|
size = size_;
|
2021-05-08 18:11:36 +02:00
|
|
|
name = std::move(name_);
|
2016-05-09 00:10:53 +02:00
|
|
|
|
2021-04-21 06:28:11 +02:00
|
|
|
// Get the resource limit.
|
|
|
|
KResourceLimit* reslimit = kernel.GetSystemResourceLimit();
|
|
|
|
|
|
|
|
// Reserve memory for ourselves.
|
2022-11-03 15:22:05 +01:00
|
|
|
KScopedResourceReservation memory_reservation(reslimit, LimitableResource::PhysicalMemoryMax,
|
2021-04-21 06:28:11 +02:00
|
|
|
size_);
|
|
|
|
R_UNLESS(memory_reservation.Succeeded(), ResultLimitReached);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
resource_limit = reslimit;
|
|
|
|
resource_limit->Open();
|
|
|
|
|
|
|
|
// Mark initialized.
|
|
|
|
is_initialized = true;
|
|
|
|
|
|
|
|
// Clear all pages in the memory.
|
2022-09-06 02:42:24 +02:00
|
|
|
std::memset(device_memory_.GetPointer<void>(physical_address_), 0, size_);
|
2021-04-21 06:28:11 +02:00
|
|
|
|
2021-05-21 07:05:04 +02:00
|
|
|
return ResultSuccess;
|
2021-04-04 08:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KSharedMemory::Finalize() {
|
|
|
|
// Release the memory reservation.
|
2022-11-03 15:22:05 +01:00
|
|
|
resource_limit->Release(LimitableResource::PhysicalMemoryMax, size);
|
2021-04-04 08:22:07 +02:00
|
|
|
resource_limit->Close();
|
|
|
|
|
|
|
|
// Perform inherited finalization.
|
|
|
|
KAutoObjectWithSlabHeapAndContainer<KSharedMemory, KAutoObjectWithList>::Finalize();
|
2016-05-09 00:10:53 +02:00
|
|
|
}
|
|
|
|
|
2022-06-26 05:44:19 +02:00
|
|
|
Result KSharedMemory::Map(KProcess& target_process, VAddr address, std::size_t map_size,
|
|
|
|
Svc::MemoryPermission permissions) {
|
2021-05-08 18:11:36 +02:00
|
|
|
const u64 page_count{(map_size + PageSize - 1) / PageSize};
|
2016-04-18 04:58:51 +02:00
|
|
|
|
2020-04-09 00:53:52 +02:00
|
|
|
if (page_list.GetNumPages() != page_count) {
|
2020-04-17 06:59:08 +02:00
|
|
|
UNIMPLEMENTED_MSG("Page count does not match");
|
2016-04-18 04:58:51 +02:00
|
|
|
}
|
2015-12-31 15:46:32 +01:00
|
|
|
|
2021-04-30 23:53:22 +02:00
|
|
|
const Svc::MemoryPermission expected =
|
2020-04-09 00:53:52 +02:00
|
|
|
&target_process == owner_process ? owner_permission : user_permission;
|
2015-05-11 00:47:07 +02:00
|
|
|
|
2020-04-24 00:42:11 +02:00
|
|
|
if (permissions != expected) {
|
2020-04-17 06:59:08 +02:00
|
|
|
UNIMPLEMENTED_MSG("Permission does not match");
|
2016-04-19 18:59:44 +02:00
|
|
|
}
|
2014-07-05 16:22:03 +02:00
|
|
|
|
2021-02-13 02:02:51 +01:00
|
|
|
return target_process.PageTable().MapPages(address, page_list, KMemoryState::Shared,
|
2021-04-30 23:53:22 +02:00
|
|
|
ConvertToKMemoryPermission(permissions));
|
|
|
|
}
|
|
|
|
|
2022-06-26 05:44:19 +02:00
|
|
|
Result KSharedMemory::Unmap(KProcess& target_process, VAddr address, std::size_t unmap_size) {
|
2021-05-08 18:11:36 +02:00
|
|
|
const u64 page_count{(unmap_size + PageSize - 1) / PageSize};
|
2021-04-30 23:53:22 +02:00
|
|
|
|
|
|
|
if (page_list.GetNumPages() != page_count) {
|
|
|
|
UNIMPLEMENTED_MSG("Page count does not match");
|
|
|
|
}
|
|
|
|
|
|
|
|
return target_process.PageTable().UnmapPages(address, page_list, KMemoryState::Shared);
|
2018-11-19 15:00:32 +01:00
|
|
|
}
|
|
|
|
|
2017-10-01 20:57:50 +02:00
|
|
|
} // namespace Kernel
|