diff --git a/troposphere/haze/include/haze/assert.hpp b/troposphere/haze/include/haze/assert.hpp index 233e31996..9f3ac1201 100644 --- a/troposphere/haze/include/haze/assert.hpp +++ b/troposphere/haze/include/haze/assert.hpp @@ -15,11 +15,12 @@ */ #pragma once -#define HAZE_ASSERT(expr) \ -{ \ - if (const bool __tmp_haze_assert_val = static_cast(expr); (!__tmp_haze_assert_val)) { \ - svcBreak(BreakReason_Assert, 0, 0); \ - } \ +#define HAZE_ASSERT(expr) \ +{ \ + const bool __tmp_haze_assert_val = static_cast(expr); \ + if (AMS_UNLIKELY(!__tmp_haze_assert_val)) { \ + svcBreak(BreakReason_Assert, 0, 0); \ + } \ } #define HAZE_R_ABORT_UNLESS(res_expr) \ diff --git a/troposphere/haze/include/haze/common.hpp b/troposphere/haze/include/haze/common.hpp index d4d412d6d..b0f1f6b12 100644 --- a/troposphere/haze/include/haze/common.hpp +++ b/troposphere/haze/include/haze/common.hpp @@ -15,6 +15,10 @@ */ #pragma once +#define ATMOSPHERE_OS_HORIZON +#define ATMOSPHERE_ARCH_ARM64 +#define ATMOSPHERE_ARCH_ARM_V8A + #include #include #include @@ -28,6 +32,8 @@ #include #include +#include +#include namespace haze { diff --git a/troposphere/haze/include/haze/console_main_loop.hpp b/troposphere/haze/include/haze/console_main_loop.hpp index 50caa17b5..b213ebede 100644 --- a/troposphere/haze/include/haze/console_main_loop.hpp +++ b/troposphere/haze/include/haze/console_main_loop.hpp @@ -60,12 +60,15 @@ namespace haze { explicit ConsoleMainLoop() : m_reactor(), m_pad(), m_thread(), m_event(), m_cancel_event(), m_last_heap_used(), m_last_heap_total(), m_is_applet_mode() { /* ... */ } Result Initialize(EventReactor *reactor, PtpObjectHeap *object_heap) { + /* Register event reactor and heap. */ m_reactor = reactor; m_object_heap = object_heap; + /* Get whether we are launched in applet mode. */ AppletType applet_type = appletGetAppletType(); m_is_applet_mode = applet_type != AppletType_Application && applet_type != AppletType_SystemApplication; + /* Initialize events. */ ueventCreate(std::addressof(m_event), true); ueventCreate(std::addressof(m_cancel_event), true); @@ -73,8 +76,8 @@ namespace haze { padConfigureInput(1, HidNpadStyleSet_NpadStandard); padInitializeAny(std::addressof(m_pad)); - /* Create the delay thread with higher priority than the main thread. */ - R_TRY(threadCreate(std::addressof(m_thread), ConsoleMainLoop::Run, this, nullptr, 4_KB, 0x2b, -2)); + /* Create the delay thread with higher priority than the main thread (which runs at priority 0x2c). */ + R_TRY(threadCreate(std::addressof(m_thread), ConsoleMainLoop::Run, this, nullptr, 4_KB, 0x2b, svc::IdealCoreUseProcessValue)); /* Ensure we close the thread on failure. */ ON_RESULT_FAILURE { threadClose(std::addressof(m_thread)); }; diff --git a/troposphere/haze/include/haze/event_reactor.hpp b/troposphere/haze/include/haze/event_reactor.hpp index e1ab44d64..86a79a212 100644 --- a/troposphere/haze/include/haze/event_reactor.hpp +++ b/troposphere/haze/include/haze/event_reactor.hpp @@ -27,8 +27,8 @@ namespace haze { class EventReactor { private: - EventConsumer *m_consumers[MAX_WAIT_OBJECTS]; - Waiter m_waiters[MAX_WAIT_OBJECTS]; + EventConsumer *m_consumers[svc::ArgumentHandleCountMax]; + Waiter m_waiters[svc::ArgumentHandleCountMax]; s32 m_num_wait_objects; bool m_stop_requested; public: diff --git a/troposphere/haze/source/event_reactor.cpp b/troposphere/haze/source/event_reactor.cpp index 1db2abeb5..8cd44d0ac 100644 --- a/troposphere/haze/source/event_reactor.cpp +++ b/troposphere/haze/source/event_reactor.cpp @@ -18,7 +18,7 @@ namespace haze { bool EventReactor::AddConsumer(EventConsumer *consumer, Waiter waiter) { - HAZE_ASSERT(m_num_wait_objects + 1 <= MAX_WAIT_OBJECTS); + HAZE_ASSERT(m_num_wait_objects + 1 <= svc::ArgumentHandleCountMax); /* Add to the end of the list. */ m_consumers[m_num_wait_objects] = consumer; @@ -49,7 +49,7 @@ namespace haze { } Result EventReactor::WaitForImpl(s32 *out_arg_waiter, const Waiter *arg_waiters, s32 num_arg_waiters) { - HAZE_ASSERT(m_num_wait_objects + num_arg_waiters <= MAX_WAIT_OBJECTS); + HAZE_ASSERT(m_num_wait_objects + num_arg_waiters <= svc::ArgumentHandleCountMax); while (true) { R_UNLESS(!m_stop_requested, haze::ResultStopRequested()); @@ -60,7 +60,7 @@ namespace haze { } s32 idx; - HAZE_R_ABORT_UNLESS(waitObjects(std::addressof(idx), m_waiters, m_num_wait_objects + num_arg_waiters, -1)); + HAZE_R_ABORT_UNLESS(waitObjects(std::addressof(idx), m_waiters, m_num_wait_objects + num_arg_waiters, svc::WaitInfinite)); /* If a waiter in the argument list was signaled, return it. */ if (idx >= m_num_wait_objects) { diff --git a/troposphere/haze/source/ptp_object_heap.cpp b/troposphere/haze/source/ptp_object_heap.cpp index 20d11b94b..4a62ab217 100644 --- a/troposphere/haze/source/ptp_object_heap.cpp +++ b/troposphere/haze/source/ptp_object_heap.cpp @@ -33,7 +33,7 @@ namespace haze { } /* Estimate how much memory we can reserve. */ - HAZE_R_ABORT_UNLESS(svcGetInfo(std::addressof(mem_used), InfoType_UsedMemorySize, CUR_PROCESS_HANDLE, 0)); + HAZE_R_ABORT_UNLESS(svcGetInfo(std::addressof(mem_used), InfoType_UsedMemorySize, svc::CurrentProcess, 0)); HAZE_ASSERT(mem_used > LibnxReservedMemorySize); mem_used -= LibnxReservedMemorySize; diff --git a/troposphere/haze/source/ptp_responder.cpp b/troposphere/haze/source/ptp_responder.cpp index 9228a7924..95eed8036 100644 --- a/troposphere/haze/source/ptp_responder.cpp +++ b/troposphere/haze/source/ptp_responder.cpp @@ -59,12 +59,12 @@ namespace haze { PtpOperationCode_DeleteObject, }; - constexpr PtpEventCode SupportedEventCodes[] = { /* ... */}; - constexpr PtpDevicePropertyCode SupportedPropertyCodes[] = { /* ...*/ }; - constexpr PtpObjectFormatCode SupportedCaptureFormats[] = { /* ...*/ }; - constexpr PtpObjectFormatCode SupportedPlaybackFormats[] = { /* ...*/ }; + constexpr const PtpEventCode SupportedEventCodes[] = { /* ... */}; + constexpr const PtpDevicePropertyCode SupportedPropertyCodes[] = { /* ...*/ }; + constexpr const PtpObjectFormatCode SupportedCaptureFormats[] = { /* ...*/ }; + constexpr const PtpObjectFormatCode SupportedPlaybackFormats[] = { /* ...*/ }; - constexpr StorageId SupportedStorageIds[] = { + constexpr const StorageId SupportedStorageIds[] = { StorageId_SdmcFs, }; @@ -391,7 +391,7 @@ namespace haze { R_TRY(db.AddDataHeader(m_request_header, sizeof(u32) + (entry_count * sizeof(u32)))); R_TRY(db.Add(static_cast(entry_count))); - /* Enumerate the directory, writing results to the data builder as we progres. */ + /* Enumerate the directory, writing results to the data builder as we progress. */ /* TODO: How should we handle the directory contents changing during enumeration? */ /* Is this even feasible to handle? */ while (true) { @@ -442,7 +442,7 @@ namespace haze { FsDirEntryType entry_type; R_TRY(m_fs.GetEntryType(fileobj->GetName(), std::addressof(entry_type))); - /* Get the size of the file. */ + /* Get the size, if we are requesting info about a file. */ s64 size = 0; if (entry_type == FsDirEntryType_File) { FsFile file;