hle: kernel: Migrate KTransferMemory to KAutoObject.
parent
7444963bbb
commit
c7d8b7421c
@ -0,0 +1,45 @@
|
||||
// Copyright 2021 yuzu emulator team
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "core/hle/kernel/k_resource_limit.h"
|
||||
#include "core/hle/kernel/k_transfer_memory.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
KTransferMemory::KTransferMemory(KernelCore& kernel)
|
||||
: KAutoObjectWithSlabHeapAndContainer{kernel} {}
|
||||
|
||||
KTransferMemory::~KTransferMemory() = default;
|
||||
|
||||
ResultCode KTransferMemory::Initialize(VAddr address_, std::size_t size_,
|
||||
Svc::MemoryPermission owner_perm_) {
|
||||
// Set members.
|
||||
owner = kernel.CurrentProcess();
|
||||
|
||||
// TODO(bunnei): Lock for transfer memory
|
||||
|
||||
// Set remaining tracking members.
|
||||
owner->Open();
|
||||
owner_perm = owner_perm_;
|
||||
address = address_;
|
||||
size = size_;
|
||||
is_initialized = true;
|
||||
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void KTransferMemory::Finalize() {
|
||||
// Perform inherited finalization.
|
||||
KAutoObjectWithSlabHeapAndContainer<KTransferMemory, KAutoObjectWithList>::Finalize();
|
||||
}
|
||||
|
||||
void KTransferMemory::PostDestroy(uintptr_t arg) {
|
||||
Process* owner = reinterpret_cast<Process*>(arg);
|
||||
owner->GetResourceLimit()->Release(LimitableResource::TransferMemory, 1);
|
||||
owner->Close();
|
||||
}
|
||||
|
||||
} // namespace Kernel
|
@ -0,0 +1,82 @@
|
||||
// Copyright 2021 yuzu emulator team
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "core/hle/kernel/slab_helpers.h"
|
||||
#include "core/hle/kernel/svc_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
union ResultCode;
|
||||
|
||||
namespace Core::Memory {
|
||||
class Memory;
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class KernelCore;
|
||||
class Process;
|
||||
|
||||
class KTransferMemory final
|
||||
: public KAutoObjectWithSlabHeapAndContainer<KTransferMemory, KAutoObjectWithList> {
|
||||
KERNEL_AUTOOBJECT_TRAITS(KTransferMemory, KAutoObject);
|
||||
|
||||
public:
|
||||
explicit KTransferMemory(KernelCore& kernel);
|
||||
~KTransferMemory() override;
|
||||
|
||||
static constexpr HandleType HANDLE_TYPE = HandleType::TransferMemory;
|
||||
|
||||
ResultCode Initialize(VAddr address_, std::size_t size_, Svc::MemoryPermission owner_perm_);
|
||||
|
||||
virtual void Finalize() override;
|
||||
|
||||
virtual bool IsInitialized() const override {
|
||||
return is_initialized;
|
||||
}
|
||||
|
||||
virtual uintptr_t GetPostDestroyArgument() const override {
|
||||
return reinterpret_cast<uintptr_t>(owner);
|
||||
}
|
||||
|
||||
static void PostDestroy(uintptr_t arg);
|
||||
|
||||
Process* GetOwner() const {
|
||||
return owner;
|
||||
}
|
||||
|
||||
VAddr GetSourceAddress() const {
|
||||
return address;
|
||||
}
|
||||
|
||||
size_t GetSize() const {
|
||||
return is_initialized ? size * PageSize : 0;
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
|
||||
std::string GetTypeName() const override {
|
||||
return "TransferMemory";
|
||||
}
|
||||
|
||||
std::string GetName() const override {
|
||||
return GetTypeName();
|
||||
}
|
||||
|
||||
HandleType GetHandleType() const override {
|
||||
return HANDLE_TYPE;
|
||||
}
|
||||
|
||||
private:
|
||||
Process* owner{};
|
||||
VAddr address{};
|
||||
Svc::MemoryPermission owner_perm{};
|
||||
size_t size{};
|
||||
bool is_initialized{};
|
||||
};
|
||||
|
||||
} // namespace Kernel
|
Loading…
Reference in New Issue