sysupdater: implement (untested) rest of the api

This commit is contained in:
Michael Scire
2020-06-26 19:22:50 -07:00
parent 015537f9bf
commit 76fa4db2ed
22 changed files with 957 additions and 57 deletions

View File

@@ -29,6 +29,7 @@
#include <stratosphere/os/os_condition_variable.hpp>
#include <stratosphere/os/os_sdk_mutex.hpp>
#include <stratosphere/os/os_rw_lock.hpp>
#include <stratosphere/os/os_transfer_memory.hpp>
#include <stratosphere/os/os_semaphore.hpp>
#include <stratosphere/os/os_event.hpp>
#include <stratosphere/os/os_system_event.hpp>

View File

@@ -70,6 +70,11 @@ namespace ams::os {
return h;
}
void Detach() {
const Handle h = this->Move();
AMS_UNUSED(h);
}
void Reset(Handle h) {
ManagedHandle(h).Swap(*this);
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/os_transfer_memory_types.hpp>
#include <stratosphere/os/os_transfer_memory_api.hpp>
namespace ams::os {
class TransferMemory {
NON_COPYABLE(TransferMemory);
NON_MOVEABLE(TransferMemory);
private:
TransferMemoryType tmem;
public:
constexpr TransferMemory() : tmem{ .state = TransferMemoryType::State_NotInitialized } {
/* ... */
}
TransferMemory(void *address, size_t size, MemoryPermission perm) {
R_ABORT_UNLESS(CreateTransferMemory(std::addressof(this->tmem), address, size, perm));
}
TransferMemory(size_t size, Handle handle, bool managed) {
this->Attach(size, handle, managed);
}
~TransferMemory() {
if (this->tmem.state == TransferMemoryType::State_NotInitialized) {
return;
}
DestroyTransferMemory(std::addressof(this->tmem));
}
void Attach(size_t size, Handle handle, bool managed) {
AttachTransferMemory(std::addressof(this->tmem), size, handle, managed);
}
Handle Detach() {
return DetachTransferMemory(std::addressof(this->tmem));
}
Result Map(void **out, MemoryPermission owner_perm) {
return MapTransferMemory(out, std::addressof(this->tmem), owner_perm);
}
void Unmap() {
UnmapTransferMemory(std::addressof(this->tmem));
}
operator TransferMemoryType &() {
return this->tmem;
}
operator const TransferMemoryType &() const {
return this->tmem;
}
TransferMemoryType *GetBase() {
return std::addressof(this->tmem);
}
};
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/os_memory_permission.hpp>
namespace ams::os {
struct TransferMemoryType;
Result CreateTransferMemory(TransferMemoryType *tmem, void *address, size_t size, MemoryPermission perm);
Result AttachTransferMemory(TransferMemoryType *tmem, size_t size, Handle handle, bool managed);
Handle DetachTransferMemory(TransferMemoryType *tmem);
void DestroyTransferMemory(TransferMemoryType *tmem);
Result MapTransferMemory(void **out, TransferMemoryType *tmem, MemoryPermission owner_perm);
void UnmapTransferMemory(TransferMemoryType *tmem);
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/os/impl/os_internal_critical_section.hpp>
namespace ams::os {
struct TransferMemoryType {
enum State {
State_NotInitialized = 0,
State_Created = 1,
State_Mapped = 2,
State_Detached = 3,
};
u8 state;
bool handle_managed;
bool allocated;
void *address;
size_t size;
Handle handle;
mutable impl::InternalCriticalSectionStorage cs_transfer_memory;
};
static_assert(std::is_trivial<TransferMemoryType>::value);
}

View File

@@ -23,6 +23,7 @@
#include <stratosphere/settings/factory/settings_device_certificate.hpp>
#include <stratosphere/settings/system/settings_error_report.hpp>
#include <stratosphere/settings/system/settings_firmware_version.hpp>
#include <stratosphere/settings/system/settings_platform_region.hpp>
#include <stratosphere/settings/system/settings_product_model.hpp>
#include <stratosphere/settings/system/settings_region.hpp>
#include <stratosphere/settings/system/settings_serial_number.hpp>

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/settings/settings_types.hpp>
namespace ams::settings::system {
enum PlatformRegion {
PlatformRegion_Invalid = 0,
PlatformRegion_Global = 1,
PlatformRegion_China = 2,
};
PlatformRegion GetPlatformRegion();
}