diff --git a/stratosphere/libstratosphere/Makefile b/stratosphere/libstratosphere/Makefile index 5a8943afd..677d95526 100644 --- a/stratosphere/libstratosphere/Makefile +++ b/stratosphere/libstratosphere/Makefile @@ -16,7 +16,7 @@ include $(DEVKITPRO)/libnx/switch_rules # INCLUDES is a list of directories containing header files #--------------------------------------------------------------------------------- TARGET := $(notdir $(CURDIR)) -SOURCES := source source/os source/os/impl source/spl source/spl/smc source/updater source/patcher source/map source/rnd source/util source/sm source/cfg source/pm source/hid source/ldr source/kvdb +SOURCES := source source/ams source/os source/os/impl source/spl source/spl/smc source/updater source/patcher source/map source/rnd source/util source/sm source/cfg source/pm source/hid source/ldr source/kvdb DATA := data INCLUDES := include diff --git a/stratosphere/libstratosphere/include/stratosphere.hpp b/stratosphere/libstratosphere/include/stratosphere.hpp index 5c3d899e9..a5b239d13 100644 --- a/stratosphere/libstratosphere/include/stratosphere.hpp +++ b/stratosphere/libstratosphere/include/stratosphere.hpp @@ -23,18 +23,13 @@ #include "stratosphere/version_check.hpp" -#include "stratosphere/iwaitable.hpp" - -#include "stratosphere/waitable_manager.hpp" - -#include "stratosphere/ipc.hpp" -#include "stratosphere/mitm.hpp" - #include "stratosphere/results.hpp" #include "stratosphere/on_crash.hpp" +#include "stratosphere/util.hpp" #include "stratosphere/svc.hpp" +#include "stratosphere/ams.hpp" #include "stratosphere/os.hpp" #include "stratosphere/cfg.hpp" #include "stratosphere/fatal.hpp" @@ -42,5 +37,4 @@ #include "stratosphere/ncm.hpp" #include "stratosphere/pm.hpp" #include "stratosphere/rnd.hpp" -#include "stratosphere/sm.hpp" -#include "stratosphere/util.hpp" \ No newline at end of file +#include "stratosphere/sm.hpp" \ No newline at end of file diff --git a/stratosphere/libstratosphere/include/stratosphere/waitable_manager_base.hpp b/stratosphere/libstratosphere/include/stratosphere/ams.hpp similarity index 56% rename from stratosphere/libstratosphere/include/stratosphere/waitable_manager_base.hpp rename to stratosphere/libstratosphere/include/stratosphere/ams.hpp index 3f2997ca1..4a679b34e 100644 --- a/stratosphere/libstratosphere/include/stratosphere/waitable_manager_base.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/ams.hpp @@ -15,24 +15,6 @@ */ #pragma once -#include - -class IWaitable; - -class WaitableManagerBase { - std::atomic cur_priority = 0; - public: - WaitableManagerBase() = default; - virtual ~WaitableManagerBase() = default; - - u64 GetNextPriority() { - return std::atomic_fetch_add(&cur_priority, (u64)1); - } - - virtual void AddWaitable(IWaitable *w) = 0; - virtual void NotifySignaled(IWaitable *w) = 0; - - virtual void RequestStop() = 0; - virtual void Process() = 0; -}; +#include "ams/ams_types.hpp" +#include "ams/ams_firmware_version_api.hpp" \ No newline at end of file diff --git a/stratosphere/libstratosphere/include/stratosphere/mitm.hpp b/stratosphere/libstratosphere/include/stratosphere/ams/ams_firmware_version_api.hpp similarity index 78% rename from stratosphere/libstratosphere/include/stratosphere/mitm.hpp rename to stratosphere/libstratosphere/include/stratosphere/ams/ams_firmware_version_api.hpp index bdfa8562e..d509d77cd 100644 --- a/stratosphere/libstratosphere/include/stratosphere/mitm.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/ams/ams_firmware_version_api.hpp @@ -15,12 +15,11 @@ */ #pragma once +#include "ams_types.hpp" -#include "sm.hpp" +namespace sts::ams { -#include "ipc.hpp" + FirmwareVersion GetRuntimeFirmwareVersion(); + void SetFirmwareVersionForLibnx(); -#include "mitm/imitmserviceobject.hpp" -#include "mitm/mitm_query_service.hpp" -#include "mitm/mitm_session.hpp" -#include "mitm/mitm_server.hpp" \ No newline at end of file +} diff --git a/stratosphere/libstratosphere/include/stratosphere/ams/ams_types.hpp b/stratosphere/libstratosphere/include/stratosphere/ams/ams_types.hpp new file mode 100644 index 000000000..9989e6237 --- /dev/null +++ b/stratosphere/libstratosphere/include/stratosphere/ams/ams_types.hpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018-2019 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 "../defines.hpp" + +/* Define firmware version in global namespace, for convenience. */ +namespace sts { + + enum FirmwareVersion : u32 { + FirmwareVersion_Min = 0, + FirmwareVersion_100 = FirmwareVersion_Min, + FirmwareVersion_200 = 1, + FirmwareVersion_300 = 2, + FirmwareVersion_400 = 3, + FirmwareVersion_500 = 4, + FirmwareVersion_600 = 5, + FirmwareVersion_700 = 6, + FirmwareVersion_800 = 7, + FirmwareVersion_810 = 8, + FirmwareVersion_900 = 9, + FirmwareVersion_Current = FirmwareVersion_900, + FirmwareVersion_Max = 32, + }; + +} + +namespace sts::ams { + + enum TargetFirmware : u32 { + TargetFirmware_100 = 1, + TargetFirmware_200 = 2, + TargetFirmware_300 = 3, + TargetFirmware_400 = 4, + TargetFirmware_500 = 5, + TargetFirmware_600 = 6, + TargetFirmware_620 = 7, + TargetFirmware_700 = 8, + TargetFirmware_800 = 9, + TargetFirmware_810 = 10, + TargetFirmware_900 = 11, + }; + +} diff --git a/stratosphere/libstratosphere/include/stratosphere/firmware_version.hpp b/stratosphere/libstratosphere/include/stratosphere/firmware_version.hpp deleted file mode 100644 index 3fc5507cc..000000000 --- a/stratosphere/libstratosphere/include/stratosphere/firmware_version.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2018-2019 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 - -enum FirmwareVersion : u32 { - FirmwareVersion_Min = 0, - FirmwareVersion_100 = FirmwareVersion_Min, - FirmwareVersion_200 = 1, - FirmwareVersion_300 = 2, - FirmwareVersion_400 = 3, - FirmwareVersion_500 = 4, - FirmwareVersion_600 = 5, - FirmwareVersion_700 = 6, - FirmwareVersion_800 = 7, - FirmwareVersion_810 = 8, - FirmwareVersion_900 = 9, - FirmwareVersion_Current = FirmwareVersion_900, - FirmwareVersion_Max = 32, -}; - -enum AtmosphereTargetFirmware : u32 { - AtmosphereTargetFirmware_100 = 1, - AtmosphereTargetFirmware_200 = 2, - AtmosphereTargetFirmware_300 = 3, - AtmosphereTargetFirmware_400 = 4, - AtmosphereTargetFirmware_500 = 5, - AtmosphereTargetFirmware_600 = 6, - AtmosphereTargetFirmware_620 = 7, - AtmosphereTargetFirmware_700 = 8, - AtmosphereTargetFirmware_800 = 9, - AtmosphereTargetFirmware_810 = 10, - AtmosphereTargetFirmware_900 = 11, -}; - -FirmwareVersion GetRuntimeFirmwareVersion(); - -void SetFirmwareVersionForLibnx(); \ No newline at end of file diff --git a/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_buffers.hpp b/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_buffers.hpp deleted file mode 100644 index 903ee4355..000000000 --- a/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_buffers.hpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2018-2019 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 - -enum class IpcBufferType { - InBuffer, - OutBuffer, - InPointer, - OutPointer, -}; - -/* Base for In/Out Buffers. */ -struct IpcBufferBase {}; - -struct InOutBufferBase : public IpcBufferBase {}; - -/* Represents an A descriptor. */ -struct InBufferBase : public InOutBufferBase {}; - -template -struct InBuffer : public InBufferBase { - T *buffer; - size_t num_elements; - BufferType type; - static const BufferType expected_type = e_t; - - /* Convenience. */ - T& operator[](size_t i) const { - return buffer[i]; - } - - InBuffer(void *b, size_t n, BufferType t) : buffer((T *)b), num_elements(n/sizeof(T)), type(t) { } -}; - -/* Represents a B descriptor. */ -struct OutBufferBase : public InOutBufferBase {}; - -template -struct OutBuffer : OutBufferBase { - T *buffer; - size_t num_elements; - BufferType type; - static const BufferType expected_type = e_t; - - /* Convenience. */ - T& operator[](size_t i) const { - return buffer[i]; - } - - OutBuffer(void *b, size_t n, BufferType t) : buffer((T *)b), num_elements(n/sizeof(T)), type(t) { } -}; - -/* Represents an X descriptor. */ -struct InPointerBase : public IpcBufferBase {}; - -template -struct InPointer : public InPointerBase { - T *pointer; - size_t num_elements; - - /* Convenience. */ - T& operator[](size_t i) const { - return pointer[i]; - } - - InPointer(void *p, size_t n) : pointer((T *)p), num_elements(n/sizeof(T)) { } -}; - -/* Represents a C descriptor. */ -struct OutPointerWithServerSizeBase : public IpcBufferBase {}; - -template -struct OutPointerWithServerSize : public OutPointerWithServerSizeBase { - T *pointer; - static const size_t num_elements = N; - static const size_t element_size = sizeof(T); - - /* Convenience. */ - T& operator[](size_t i) const { - return pointer[i]; - } - - OutPointerWithServerSize(void *p) : pointer((T *)p) { } - OutPointerWithServerSize(void *p, size_t n) : pointer((T *)p) { } -}; - -struct OutPointerWithClientSizeBase : public IpcBufferBase {}; - -/* Represents a C descriptor with size in raw data. */ -template -struct OutPointerWithClientSize : public OutPointerWithClientSizeBase { - T *pointer; - size_t num_elements; - - /* Convenience. */ - T& operator[](size_t i) const { - return pointer[i]; - } - - OutPointerWithClientSize(void *p, size_t n) : pointer((T *)p), num_elements(n/sizeof(T)) { } -}; diff --git a/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_domain_object.hpp b/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_domain_object.hpp deleted file mode 100644 index 3cc9cbca2..000000000 --- a/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_domain_object.hpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2018-2019 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 -#include -#include - -#include "ipc_service_object.hpp" - -class IDomainObject; - -class DomainManager { - public: - static constexpr u32 MinimumDomainId = 1; - public: - virtual std::shared_ptr AllocateDomain() = 0; - virtual void FreeDomain(IDomainObject *domain) = 0; - virtual Result ReserveObject(IDomainObject *domain, u32 *out_object_id) = 0; - virtual Result ReserveSpecificObject(IDomainObject *domain, u32 object_id) = 0; - virtual void SetObject(IDomainObject *domain, u32 object_id, ServiceObjectHolder&& holder) = 0; - virtual ServiceObjectHolder *GetObject(IDomainObject *domain, u32 object_id) = 0; - virtual Result FreeObject(IDomainObject *domain, u32 object_id) = 0; - virtual Result ForceFreeObject(u32 object_id) = 0; -}; - -class IDomainObject : public IServiceObject { - private: - DomainManager *manager; - public: - IDomainObject(DomainManager *m) : manager(m) {} - - virtual ~IDomainObject() override { - this->manager->FreeDomain(this); - } - - DomainManager *GetManager() { - return this->manager; - } - - ServiceObjectHolder *GetObject(u32 object_id) { - return this->manager->GetObject(this, object_id); - } - - Result ReserveObject(u32 *out_object_id) { - return this->manager->ReserveObject(this, out_object_id); - } - - Result ReserveSpecificObject(u32 object_id) { - return this->manager->ReserveSpecificObject(this, object_id); - } - - void SetObject(u32 object_id, ServiceObjectHolder&& holder) { - this->manager->SetObject(this, object_id, std::move(holder)); - } - - Result FreeObject(u32 object_id) { - return this->manager->FreeObject(this, object_id); - } - - Result ForceFreeObject(u32 object_id) { - return this->manager->ForceFreeObject(object_id); - } - - public: - DEFINE_SERVICE_DISPATCH_TABLE { - /* IDomainObject has no callable functions. */ - }; -}; - -static constexpr bool IsDomainObject(ServiceObjectHolder &holder) { - return holder.GetServiceId() == ServiceObjectId(); -} - -static constexpr bool IsDomainObject(ServiceObjectHolder *holder) { - return holder->GetServiceId() == ServiceObjectId(); -} - -/* Out for service impl. */ -template -class Out> : public OutSessionTag { - static_assert(std::is_base_of_v, "OutSessions must be shared_ptr!"); - - template - friend class Out; - - private: - std::shared_ptr *srv; - IDomainObject *domain = nullptr; - u32 *object_id = nullptr; - public: - Out>(std::shared_ptr *s, IDomainObject *dm, u32 *o) : srv(reinterpret_cast *>(s)), domain(dm), object_id(o) { } - - ServiceObjectHolder GetHolder() { - std::shared_ptr clone = *srv; - return ServiceObjectHolder(std::move(clone)); - } - - bool IsDomain() { - return domain != nullptr; - } - - u32 GetObjectId() { - return *object_id; - } - - void ChangeObjectId(u32 o) { - domain->ForceFreeObject(*object_id); - domain->ReserveSpecificObject(o); - *object_id = o; - } - - void SetValue(std::shared_ptr &&s) { - *this->srv = std::move(s); - } -}; diff --git a/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_out.hpp b/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_out.hpp deleted file mode 100644 index aba2254ec..000000000 --- a/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_out.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2018-2019 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 - -/* Declare false allowed struct. */ -template -struct AllowedOut : std::false_type {}; - -struct OutDataTag{}; -struct OutHandleTag{}; -struct OutSessionTag{}; - -/* Define out struct, so that we can get errors on enable_if */ -template -class Out { - static_assert(std::is_pod::value && !std::is_pod::value, "Invalid IPC Out Type!"); -}; - -template -class Out::value || AllowedOut::value>::type> : public OutDataTag { -private: - T *obj; -public: - Out(T *o) : obj(o) { } - - void SetValue(const T& t) { - *obj = t; - } - - const T& GetValue() { - return *obj; - } - - T *GetPointer() { - return obj; - } - - /* Convenience operators. */ - T& operator*() { - return *obj; - } - - T* operator->() { - return obj; - } -}; - -template -class Out { - static_assert(std::is_pod::value && !std::is_pod::value, "Invalid IPC Out Type (Raw Pointer)!"); -}; - -template -struct OutHelper; - -template -struct OutHelper> { - using type = T; -}; \ No newline at end of file diff --git a/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_response_context.hpp b/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_response_context.hpp deleted file mode 100644 index f1f874822..000000000 --- a/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_response_context.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2018-2019 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 "ipc_service_object.hpp" -#include "ipc_domain_object.hpp" - -#include "ipc_special.hpp" - -#include "ipc_session_manager_base.hpp" - -struct IpcResponseContext { - /* Request/Reply data. */ - IpcParsedCommand request; - IpcCommand reply; - u8 out_data[0x100]; - std::shared_ptr *out_objs[8]; - Handle out_object_server_handles[8]; - IpcHandle out_handles[8]; - u32 out_object_ids[8]; - IpcCommandType cmd_type; - u64 cmd_id; - Result rc; - /* Context. */ - SessionManagerBase *manager; - ServiceObjectHolder *obj_holder; - unsigned char *pb; - size_t pb_size; -}; \ No newline at end of file diff --git a/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_serialization.hpp b/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_serialization.hpp deleted file mode 100644 index 278626c30..000000000 --- a/stratosphere/libstratosphere/include/stratosphere/ipc/ipc_serialization.hpp +++ /dev/null @@ -1,672 +0,0 @@ -/* - * Copyright (c) 2018-2019 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 -#include -#include -#include -#include - -#include "../results.hpp" - -#include "ipc_out.hpp" -#include "ipc_buffers.hpp" -#include "ipc_special.hpp" - -#include "ipc_domain_object.hpp" - -#include "ipc_response_context.hpp" - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" - -template -struct TypeList{}; - -template -constexpr auto Concatenate(TypeList, TypeList) { - return TypeList{}; -} - -template