From 07c95662b145c42951a7fe74abcda528427fc4c2 Mon Sep 17 00:00:00 2001 From: SciresM Date: Tue, 31 Mar 2020 12:50:55 -0700 Subject: [PATCH] nim: add DestroySystemUpdateTask/ListSystemUpdateTask (#863) --- .../libstratosphere/include/stratosphere.hpp | 2 +- .../include/stratosphere/nim.hpp | 19 +++++++ .../nim/nim_network_install_manager_api.hpp | 31 +++++++++++ .../nim/nim_system_update_task_id.hpp | 24 +++++++++ .../stratosphere/nim/nim_task_id_common.hpp | 43 +++++++++++++++ .../nim/nim_network_install_manager_api.cpp | 53 +++++++++++++++++++ 6 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 libraries/libstratosphere/include/stratosphere/nim.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/nim/nim_network_install_manager_api.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/nim/nim_system_update_task_id.hpp create mode 100644 libraries/libstratosphere/include/stratosphere/nim/nim_task_id_common.hpp create mode 100644 libraries/libstratosphere/source/nim/nim_network_install_manager_api.cpp diff --git a/libraries/libstratosphere/include/stratosphere.hpp b/libraries/libstratosphere/include/stratosphere.hpp index eafde1b2b..215d6f5f4 100644 --- a/libraries/libstratosphere/include/stratosphere.hpp +++ b/libraries/libstratosphere/include/stratosphere.hpp @@ -48,6 +48,7 @@ #include "stratosphere/lr.hpp" #include "stratosphere/map.hpp" #include "stratosphere/ncm.hpp" +#include "stratosphere/nim.hpp" #include "stratosphere/patcher.hpp" #include "stratosphere/pm.hpp" #include "stratosphere/reg.hpp" @@ -58,7 +59,6 @@ #include "stratosphere/spl.hpp" #include "stratosphere/updater.hpp" - /* Include FS last. */ #include "stratosphere/fs.hpp" #include "stratosphere/fssrv.hpp" diff --git a/libraries/libstratosphere/include/stratosphere/nim.hpp b/libraries/libstratosphere/include/stratosphere/nim.hpp new file mode 100644 index 000000000..ec080dec5 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/nim.hpp @@ -0,0 +1,19 @@ +/* + * 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 . + */ + +#pragma once + +#include diff --git a/libraries/libstratosphere/include/stratosphere/nim/nim_network_install_manager_api.hpp b/libraries/libstratosphere/include/stratosphere/nim/nim_network_install_manager_api.hpp new file mode 100644 index 000000000..6456444f5 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/nim/nim_network_install_manager_api.hpp @@ -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 . + */ + +#pragma once +#include + +namespace ams::nim { + + /* Management. */ + void InitializeForNetworkInstallManager(); + void FinalizeForNetworkInstallManager(); + + /* Service API. */ + Result DestroySystemUpdateTask(const SystemUpdateTaskId& id); + s32 ListSystemUpdateTask(SystemUpdateTaskId *out_list, size_t out_list_size); + + +} diff --git a/libraries/libstratosphere/include/stratosphere/nim/nim_system_update_task_id.hpp b/libraries/libstratosphere/include/stratosphere/nim/nim_system_update_task_id.hpp new file mode 100644 index 000000000..6310247d3 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/nim/nim_system_update_task_id.hpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2019-2020 Adubbz, 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 . + */ +#pragma once +#include +#include + +namespace ams::nim { + + AMS_NIM_DEFINE_TASK_ID(SystemUpdateTaskId, 8); + +} diff --git a/libraries/libstratosphere/include/stratosphere/nim/nim_task_id_common.hpp b/libraries/libstratosphere/include/stratosphere/nim/nim_task_id_common.hpp new file mode 100644 index 000000000..7b87ecc2c --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/nim/nim_task_id_common.hpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2019-2020 Adubbz, 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 . + */ +#pragma once +#include +#include + +namespace ams::nim { + + #define AMS_NIM_DEFINE_TASK_ID(ID, ALIGN) \ + struct alignas(ALIGN) ID { \ + util::Uuid uuid; \ + \ + ALWAYS_INLINE bool IsValid() const { \ + return this->uuid != util::InvalidUuid; \ + } \ + }; \ + \ + static_assert(alignof(ID) == ALIGN); \ + \ + ALWAYS_INLINE bool operator==(const ID &lhs, const ID &rhs) { \ + return lhs.uuid == rhs.uuid; \ + } \ + \ + ALWAYS_INLINE bool operator!=(const ID &lhs, const ID &rhs) { \ + return lhs.uuid != rhs.uuid; \ + } \ + \ + constexpr inline ID Invalid##ID = { util::InvalidUuid } + +} diff --git a/libraries/libstratosphere/source/nim/nim_network_install_manager_api.cpp b/libraries/libstratosphere/source/nim/nim_network_install_manager_api.cpp new file mode 100644 index 000000000..4a77452a7 --- /dev/null +++ b/libraries/libstratosphere/source/nim/nim_network_install_manager_api.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2019-2020 Adubbz, 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 . + */ +#include + +namespace ams::nim { + + namespace { + + bool g_initialized; + + } + /* Management. */ + void InitializeForNetworkInstallManager() { + AMS_ASSERT(!g_initialized); + R_ABORT_UNLESS(nimInitialize()); + g_initialized = true; + } + + void FinalizeForNetworkInstallManager() { + AMS_ASSERT(g_initialized); + nimExit(); + g_initialized = false; + } + + /* Service API. */ + Result DestroySystemUpdateTask(const SystemUpdateTaskId& id) { + static_assert(sizeof(SystemUpdateTaskId) == sizeof(::NimSystemUpdateTaskId)); + return nimDestroySystemUpdateTask(reinterpret_cast(std::addressof(id))); + } + + s32 ListSystemUpdateTask(SystemUpdateTaskId *out_list, size_t out_list_size) { + static_assert(sizeof(SystemUpdateTaskId) == sizeof(::NimSystemUpdateTaskId)); + + s32 count; + R_ABORT_UNLESS(nimListSystemUpdateTask(std::addressof(count), reinterpret_cast<::NimSystemUpdateTaskId *>(out_list), out_list_size)); + + return count; + } + +}