mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
os: add DetachIoRegionHandle
This commit is contained in:
parent
8e258bde9d
commit
4ad8dad416
3 changed files with 24 additions and 0 deletions
|
@ -26,6 +26,7 @@ namespace ams::os {
|
||||||
Result CreateIoRegion(IoRegionType *io_region, NativeHandle io_pool_handle, uintptr_t address, size_t size, MemoryMapping mapping, MemoryPermission permission);
|
Result CreateIoRegion(IoRegionType *io_region, NativeHandle io_pool_handle, uintptr_t address, size_t size, MemoryMapping mapping, MemoryPermission permission);
|
||||||
|
|
||||||
void AttachIoRegionHandle(IoRegionType *io_region, size_t size, NativeHandle handle, bool managed);
|
void AttachIoRegionHandle(IoRegionType *io_region, size_t size, NativeHandle handle, bool managed);
|
||||||
|
os::NativeHandle DetachIoRegionHandle(IoRegionType *io_region);
|
||||||
|
|
||||||
void DestroyIoRegion(IoRegionType *io_region);
|
void DestroyIoRegion(IoRegionType *io_region);
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace ams::os {
|
||||||
State_NotInitialized = 0,
|
State_NotInitialized = 0,
|
||||||
State_Initialized = 1,
|
State_Initialized = 1,
|
||||||
State_Mapped = 2,
|
State_Mapped = 2,
|
||||||
|
State_Detached = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
NativeHandle handle;
|
NativeHandle handle;
|
||||||
|
|
|
@ -69,6 +69,28 @@ namespace ams::os {
|
||||||
InitializeIoRegion(io_region, handle, size, managed);
|
InitializeIoRegion(io_region, handle, size, managed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os::NativeHandle DetachIoRegionHandle(IoRegionType *io_region) {
|
||||||
|
/* Check pre-conditions. */
|
||||||
|
AMS_ASSERT(io_region->state != IoRegionType::State_NotInitialized);
|
||||||
|
|
||||||
|
/* Acquire exclusive access to the io region. */
|
||||||
|
std::scoped_lock lk(util::GetReference(io_region->cs_io_region));
|
||||||
|
|
||||||
|
/* Check that we can detach. */
|
||||||
|
AMS_ASSERT(io_region->state == IoRegionType::State_Initialized);
|
||||||
|
|
||||||
|
/* Set state as detached. */
|
||||||
|
io_region->state = IoRegionType::State_Detached;
|
||||||
|
|
||||||
|
/* Detach the handle. */
|
||||||
|
const auto handle = io_region->handle;
|
||||||
|
|
||||||
|
io_region->handle = os::InvalidNativeHandle;
|
||||||
|
io_region->handle_managed = false;
|
||||||
|
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
void DestroyIoRegion(IoRegionType *io_region) {
|
void DestroyIoRegion(IoRegionType *io_region) {
|
||||||
/* Check pre-conditions. */
|
/* Check pre-conditions. */
|
||||||
AMS_ASSERT(io_region->state != IoRegionType::State_NotInitialized);
|
AMS_ASSERT(io_region->state != IoRegionType::State_NotInitialized);
|
||||||
|
|
Loading…
Reference in a new issue