Skip to content

Commit

Permalink
Use arc for result stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Jun 15, 2024
1 parent 217d3de commit dc09573
Show file tree
Hide file tree
Showing 31 changed files with 110 additions and 160 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SdOut/
*.nacp
*.nro
*.lst
*.gen.hpp
.vs/
bin/
obj/
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "Atmosphere-libs"]
path = libs/Atmosphere-libs
url = https://github.com/Atmosphere-NX/Atmosphere-libs
[submodule "arc"]
path = arc
url = https://github.com/XorTroll/arc
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ VERSION := $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_MICRO)

export UL_DEFS := -DUL_VERSION=\"$(VERSION)\"

.PHONY: all fresh clean pu usystem uloader umenu umanager uscreen
.PHONY: all fresh clean pu arc usystem uloader umenu umanager uscreen

all: usystem uloader umenu umanager uscreen
all: arc usystem uloader umenu umanager uscreen

fresh: clean all

pu:
@$(MAKE) -C libs/Plutonium/

arc:
@python arc/arc.py gen_db default+./libs/uCommon/include/ul/ul_Results.rc.hpp
@python arc/arc.py gen_cpp rc UL ./libs/uCommon/include/ul/ul_Results.gen.hpp

clean:
@$(MAKE) clean -C projects/uSystem
@$(MAKE) clean -C projects/uLoader
Expand Down
1 change: 1 addition & 0 deletions arc
Submodule arc added at 44cf5d
Binary file added assets/default/Cursor.xcf
Binary file not shown.
Binary file modified assets/uManager.xcf
Binary file not shown.
6 changes: 5 additions & 1 deletion libs/uCommon/include/extras/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
#ifndef INCLUDE_NLOHMANN_JSON_HPP_
#define INCLUDE_NLOHMANN_JSON_HPP_

//////////////////////////////////////////////////////////////////////////////////
// Custom config for this project

#include <ul/ul_Result.hpp>
#define JSON_THROW_USER(exception) ::ul::OnAssertionFailed(::ul::res::ResultAssertionFailed, "JSON libraries threw " #exception "...\n")
#define JSON_THROW_USER(exception) ::ul::OnAssertionFailed(::rc::ulaunch::ResultAssertionFailed, "JSON libraries threw " #exception "...\n")
#define JSON_TRY_USER if(true)
#define JSON_CATCH_USER(exception) if(false)
#define JSON_INTERNAL_CATCH_USER(exception) if(false)

//////////////////////////////////////////////////////////////////////////////////

#include <algorithm> // all_of, find, for_each
#include <cstddef> // nullptr_t, ptrdiff_t, size_t
#include <functional> // hash, less
Expand Down
2 changes: 1 addition & 1 deletion libs/uCommon/include/ul/smi/smi_Protocol.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#pragma once
#include <ul/loader/loader_TargetTypes.hpp>
#include <ul/smi/smi_Results.hpp>
#include <ul/ul_Result.hpp>
#include <functional>

namespace ul::smi {
Expand Down
15 changes: 0 additions & 15 deletions libs/uCommon/include/ul/smi/smi_Results.hpp

This file was deleted.

35 changes: 6 additions & 29 deletions libs/uCommon/include/ul/ul_Result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,23 @@
#include <stratosphere.hpp>
#endif

namespace ul {

// All 2380-**** results are from us

constexpr u32 Module = 380;
constexpr u32 SubmoduleOffset = 100;

#define UL_RC_DEFINE_SUBMODULE(val) constexpr u32 Submodule = val
#define UL_RC_DEFINE(name, val) constexpr Result Result ## name = MAKERESULT(Module, Submodule * SubmoduleOffset + val)
#include <ul/ul_Results.gen.hpp>

constexpr Result ResultSuccess = 0;
namespace ul {

/*
Result submodules:
0 -> misc
1 -> smi
2 -> sf (ipc)
3 -> loader
4 -> smi
5 -> util
6 -> menu
*/
using namespace rc;
using namespace rc::ulaunch;

namespace res {

UL_RC_DEFINE_SUBMODULE(0);

UL_RC_DEFINE(AssertionFailed, 1);
UL_RC_DEFINE(InvalidTransform, 2);

template<typename T>
inline ::Result TransformIntoResult(const T t) {
return static_cast<::Result>(t);
}

#ifdef ATMOSPHERE
template<>
inline ::Result TransformIntoResult<ams::Result>(const ams::Result ams_rc) {
inline ::Result TransformIntoResult<::ams::Result>(const ::ams::Result ams_rc) {
return ams_rc.GetValue();
}
#endif
Expand Down Expand Up @@ -90,7 +67,7 @@ namespace ul {
#define UL_ASSERT_TRUE(expr) ({ \
const auto _tmp_expr = (expr); \
if(!_tmp_expr) { \
::ul::OnAssertionFailed(::ul::res::ResultAssertionFailed, #expr " asserted to be false...\n"); \
::ul::OnAssertionFailed(::rc::ulaunch::ResultAssertionFailed, #expr " asserted to be false...\n"); \
} \
})

Expand Down
38 changes: 38 additions & 0 deletions libs/uCommon/include/ul/ul_Results.rc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
R_DEFINE_NAMESPACE_RESULT_MODULE(ulaunch, 380);

namespace ulaunch {

R_DEFINE_ERROR_RANGE(Misc, 1, 99);
R_DEFINE_ERROR_RESULT(AssertionFailed, 1);
R_DEFINE_ERROR_RESULT(InvalidTransform, 2);

R_DEFINE_ERROR_RANGE(Smi, 101, 199);
R_DEFINE_ERROR_RESULT(OutOfPushSpace, 101);
R_DEFINE_ERROR_RESULT(OutOfPopSpace, 102);
R_DEFINE_ERROR_RESULT(InvalidInHeaderMagic, 103);
R_DEFINE_ERROR_RESULT(InvalidOutHeaderMagic, 104);
R_DEFINE_ERROR_RESULT(WaitTimeout, 105);

R_DEFINE_ERROR_RANGE(SystemSf, 201, 299);
R_DEFINE_ERROR_RESULT(InvalidProcess, 201);
R_DEFINE_ERROR_RESULT(NoMessagesAvailable, 202);

R_DEFINE_ERROR_RANGE(Loader, 301, 399);
R_DEFINE_ERROR_RESULT(InvalidProcessType, 301);
R_DEFINE_ERROR_RESULT(InvalidTargetInputMagic, 302);
R_DEFINE_ERROR_RESULT(InvalidTargetInputSize, 303);

R_DEFINE_ERROR_RANGE(SystemSmi, 401, 499);
R_DEFINE_ERROR_RESULT(ApplicationActive, 401);
R_DEFINE_ERROR_RESULT(InvalidSelectedUser, 402);
R_DEFINE_ERROR_RESULT(AlreadyQueued, 403);
R_DEFINE_ERROR_RESULT(ApplicationNotActive, 404);
R_DEFINE_ERROR_RESULT(NoHomebrewTakeoverApplication, 405);

R_DEFINE_ERROR_RANGE(Util, 501, 599);
R_DEFINE_ERROR_RESULT(InvalidJson, 501);

R_DEFINE_ERROR_RANGE(Menu, 601, 699);
R_DEFINE_ERROR_RESULT(RomfsNotFound, 601);

}
11 changes: 0 additions & 11 deletions libs/uCommon/include/ul/util/util_Results.hpp

This file was deleted.

1 change: 0 additions & 1 deletion libs/uCommon/include/ul/util/util_String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ namespace ul::util {

std::string FormatAccount(const AccountUid value);
std::string FormatResultDisplay(const Result rc);
std::string FormatResultHex(const Result rc);

}
2 changes: 1 addition & 1 deletion libs/uCommon/source/ul/util/util_Json.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <ul/util/util_Json.hpp>
#include <ul/fs/fs_Stdio.hpp>
#include <ul/util/util_Results.hpp>
#include <ul/ul_Result.hpp>

namespace ul::util {

Expand Down
20 changes: 12 additions & 8 deletions libs/uCommon/source/ul/util/util_String.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <ul/util/util_String.hpp>
#include <ul/ul_Result.hpp>

namespace ul::util {

Expand Down Expand Up @@ -37,14 +38,17 @@ namespace ul::util {
}

std::string FormatResultDisplay(const Result rc) {
char res[0x20] = {};
sprintf(res, "%04d-%04d", R_MODULE(rc) + 2000, R_DESCRIPTION(rc));
return res;
}

std::string FormatResultHex(const Result rc) {
char res[0x20] = {};
sprintf(res, "0x%X", rc);
char res[0x40] = {};

const char *mod_name;
const char *rc_name;
if(rc::GetResultNameAny(rc, mod_name, rc_name)) {
sprintf(res, "%04d-%04d/0x%X/%s::%s", R_MODULE(rc) + 2000, R_DESCRIPTION(rc), R_VALUE(rc), mod_name, rc_name);
}
else {
sprintf(res, "%04d-%04d/0x%X", R_MODULE(rc) + 2000, R_DESCRIPTION(rc), R_VALUE(rc));
}

return res;
}

Expand Down
13 changes: 0 additions & 13 deletions projects/uLoader/include/ul/loader/loader_Results.hpp

This file was deleted.

1 change: 0 additions & 1 deletion projects/uLoader/source/ul/loader/loader_Input.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <ul/loader/loader_Input.hpp>
#include <ul/loader/loader_ProgramIdUtils.hpp>
#include <ul/loader/loader_Results.hpp>
#include <ul/ul_Result.hpp>
#include <ul/util/util_Scope.hpp>
#include <ul/util/util_String.hpp>
Expand Down
Binary file modified projects/uManager/uManager.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions projects/uMenu/include/ul/menu/menu_Results.hpp

This file was deleted.

Binary file modified projects/uMenu/romfs/default/ui/Cursor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions projects/uMenu/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <ul/menu/smi/smi_MenuMessageHandler.hpp>
#include <ul/menu/am/am_LibraryAppletUtils.hpp>
#include <ul/menu/am/am_LibnxLibappletWrap.hpp>
#include <ul/menu/menu_Results.hpp>

using namespace ul::util::size;

Expand Down Expand Up @@ -79,7 +78,7 @@ int main() {

// Check if our RomFs data exists...
if(!ul::fs::ExistsFile(RomfsFile)) {
UL_RC_ASSERT(ul::menu::ResultRomfsNotFound);
UL_RC_ASSERT(ul::ResultRomfsNotFound);
}

// Try to mount it
Expand Down
2 changes: 1 addition & 1 deletion projects/uMenu/source/ul/menu/ui/ui_IMenuLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace ul::menu::ui {
}
case smi::MenuMessage::GameCardMountFailure: {
// TODO: move somewhere else?
g_MenuApplication->DisplayDialog(GetLanguageString("gamecard"), GetLanguageString("gamecard_mount_failed") + " " + util::FormatResultHex(first_msg.gc_mount_failure.mount_rc), { GetLanguageString("ok") }, true);
g_MenuApplication->DisplayDialog(GetLanguageString("gamecard"), GetLanguageString("gamecard_mount_failed") + " " + util::FormatResultDisplay(first_msg.gc_mount_failure.mount_rc), { GetLanguageString("ok") }, true);
this->msg_queue.pop();
break;
}
Expand Down
12 changes: 6 additions & 6 deletions projects/uSystem/include/ul/system/sf/sf_IPrivateService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

namespace ul::system::sf {

struct MenuMessageContext : ams::sf::LargeData, ams::sf::PrefersMapAliasTransferMode {
struct MenuMessageContext : ::ams::sf::LargeData, ::ams::sf::PrefersMapAliasTransferMode {
smi::MenuMessageContext actual_ctx;
};

}

#define UL_SYSTEM_SF_I_PRIVATE_SERVICE_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, Initialize, (const ams::sf::ClientProcessId &client_pid), (client_pid)) \
AMS_SF_METHOD_INFO(C, H, 1, Result, TryPopMessageContext, (ams::sf::Out<::ul::system::sf::MenuMessageContext> out_msg), (out_msg))
AMS_SF_METHOD_INFO(C, H, 0, Result, Initialize, (const ::ams::sf::ClientProcessId &client_pid), (client_pid)) \
AMS_SF_METHOD_INFO(C, H, 1, Result, TryPopMessageContext, (::ams::sf::Out<::ul::system::sf::MenuMessageContext> out_msg), (out_msg))

AMS_SF_DEFINE_INTERFACE(ams::ul::system::sf, IPrivateService, UL_SYSTEM_SF_I_PRIVATE_SERVICE_INTERFACE_INFO, 0xCAFEBABE)

Expand All @@ -26,9 +26,9 @@ namespace ul::system::sf {
public:
PrivateService() : initialized(false) {}

ams::Result Initialize(const ams::sf::ClientProcessId &client_pid);
ams::Result TryPopMessageContext(ams::sf::Out<MenuMessageContext> out_msg);
::ams::Result Initialize(const ::ams::sf::ClientProcessId &client_pid);
::ams::Result TryPopMessageContext(::ams::sf::Out<MenuMessageContext> out_msg);
};
static_assert(ams::ul::system::sf::IsIPrivateService<PrivateService>);
static_assert(::ams::ul::system::sf::IsIPrivateService<PrivateService>);

}
14 changes: 7 additions & 7 deletions projects/uSystem/include/ul/system/sf/sf_IpcManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace ul::system::sf {

// Note: domains and pointer buffer are required since ECS sessions will make use of them (like normal fs interfaces)

using Allocator = ams::sf::ExpHeapAllocator;
using ObjectFactory = ams::sf::ObjectFactory<ams::sf::ExpHeapAllocator::Policy>;
using Allocator = ::ams::sf::ExpHeapAllocator;
using ObjectFactory = ::ams::sf::ObjectFactory<::ams::sf::ExpHeapAllocator::Policy>;

struct ServerOptions {
static constexpr size_t PointerBufferSize = 0x800;
Expand All @@ -26,25 +26,25 @@ namespace ul::system::sf {
};

constexpr size_t MaxPrivateSessions = 1;
constexpr ams::sm::ServiceName PrivateServiceName = ams::sm::ServiceName::Encode(ul::sf::PrivateServiceName);
constexpr ::ams::sm::ServiceName PrivateServiceName = ::ams::sm::ServiceName::Encode(ul::sf::PrivateServiceName);

/*
constexpr size_t MaxPublicSessions = 0x20;
constexpr ams::sm::ServiceName PublicServiceName = ams::sm::ServiceName::Encode(ul::sf::PublicServiceName);
constexpr ::ams::sm::ServiceName PublicServiceName = ::ams::sm::ServiceName::Encode(ul::sf::PublicServiceName);
*/

constexpr size_t MaxEcsExtraSessions = 5;
constexpr size_t MaxSessions = MaxPrivateSessions + MaxEcsExtraSessions;

class ServerManager final : public ams::sf::hipc::ServerManager<Port_Count, ServerOptions, MaxSessions> {
class ServerManager final : public ::ams::sf::hipc::ServerManager<Port_Count, ServerOptions, MaxSessions> {
private:
virtual ams::Result OnNeedsToAccept(int port_index, Server *server) override;
virtual ::ams::Result OnNeedsToAccept(int port_index, Server *server) override;
};

Result Initialize();
Allocator &GetManagerAllocator();

ams::Result RegisterSession(const ams::os::NativeHandle session_handle, ams::sf::cmif::ServiceObjectHolder &&obj);
::ams::Result RegisterSession(const ::ams::os::NativeHandle session_handle, ::ams::sf::cmif::ServiceObjectHolder &&obj);

template<typename Impl, typename T, typename ...Args>
inline auto MakeShared(Args ...args) {
Expand Down
12 changes: 0 additions & 12 deletions projects/uSystem/include/ul/system/sf/sf_Results.hpp

This file was deleted.

Loading

0 comments on commit dc09573

Please sign in to comment.