diff --git a/nx/include/switch/kernel/svc.h b/nx/include/switch/kernel/svc.h index 1dd1c142..21a8cc92 100644 --- a/nx/include/switch/kernel/svc.h +++ b/nx/include/switch/kernel/svc.h @@ -205,6 +205,35 @@ typedef enum { PhysicalMemoryInfo_SystemUnsafe = 3, ///< Memory allocated for unsafe system usage (accessible to devices). } PhysicalMemoryInfo; +/// SleepThread yield types. +typedef enum { + YieldType_WithoutCoreMigration = 0l, ///< Yields to another thread on the same core. + YieldType_WithCoreMigration = -1l, ///< Yields to another thread (possibly on a different core). + YieldType_ToAnyThread = -2l, ///< Yields and performs forced load-balancing. +} YieldType; + +/// SignalToAddress behaviors. +typedef enum { + SignalType_Signal = 0, ///< Signals the address. + SignalType_SignalAndIncrementIfEqual = 1, ///< Signals the address and increments its value if equal to argument. + SignalType_SignalAndModifyBasedOnWaitingThreadCountIfEqual = 2, ///< Signals the address and updates its value if equal to argument. +} SignalType; + +/// WaitForAddress behaviors. +typedef enum { + ArbitrationType_WaitIfLessThan = 0, ///< Wait if the value is less than argument. + ArbitrationType_DecrementAndWaitIfLessThan = 1, ///< Decrement the value and wait if it is less than argument. + ArbitrationType_WaitIfEqual = 2, ///< Wait if the value is equal to argument. +} ArbitrationType; + +/// Context of a scheduled thread. +typedef struct { + u64 fp; ///< Frame Pointer for the thread. + u64 sp; ///< Stack Pointer for the thread. + u64 lr; ///< Link Register for the thread. + u64 pc; ///< Program Counter for the thread. +} LastThreadContext; + ///@name Memory management ///@{ @@ -306,7 +335,7 @@ void NORETURN svcExitThread(void); /** * @brief Sleeps the current thread for the specified amount of time. - * @param[in] nano Number of nanoseconds to sleep, or 0, -1, -2 for yield. + * @param[in] nano Number of nanoseconds to sleep, or \ref YieldType for yield. * @note Syscall number 0x0B. */ void svcSleepThread(s64 nano); @@ -500,6 +529,13 @@ u64 svcGetSystemTick(void); */ Result svcConnectToNamedPort(Handle* session, const char* name); +/** + * @brief Sends a light IPC synchronization request to a session. + * @return Result code. + * @note Syscall number 0x20. + */ +Result svcSendSyncRequestLight(Handle session); + /** * @brief Sends an IPC synchronization request to a session. * @return Result code. @@ -597,6 +633,28 @@ Result svcGetInfo(u64* out, u32 id0, Handle handle, u64 id1); ///@} +///@name Cache Management +///@{ + +/** + * @brief Flushes the entire data cache (by set/way). + * @note Syscall number 0x2A. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + * @warning This syscall is dangerous, and should not be used. + */ +void svcFlushEntireDataCache(void); + +/** + * @brief Flushes data cache for a virtual address range. + * @param[in] address Address of region to flush. + * @param[in] size Size of region to flush. + * @remark armDCacheFlush should be used instead of this syscall whenever possible. + * @note Syscall number 0x2B. + */ +Result svcFlushDataCache(void *address, size_t size); + +///@} + ///@name Memory management ///@{ @@ -604,7 +662,6 @@ Result svcGetInfo(u64* out, u32 id0, Handle handle, u64 id1); * @brief Maps new heap memory at the desired address. [3.0.0+] * @return Result code. * @note Syscall number 0x2C. - * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. */ Result svcMapPhysicalMemory(void *address, u64 size); @@ -612,12 +669,38 @@ Result svcMapPhysicalMemory(void *address, u64 size); * @brief Undoes the effects of \ref svcMapPhysicalMemory. [3.0.0+] * @return Result code. * @note Syscall number 0x2D. - * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. */ Result svcUnmapPhysicalMemory(void *address, u64 size); ///@} +///@name Process and thread management +///@{ + +/** + * @brief Gets information about a thread that will be scheduled in the future. [5.0.0+] + * @param[out] out_context Output \ref LastThreadContext for the thread that will be scheduled. + * @param[out] out_thread_id Output thread id for the thread that will be scheduled. + * @param[in] debug Debug handle. + * @param[in] ns Nanoseconds in the future to get scheduled thread at. + * @return Result code. + * @note Syscall number 0x2E. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +Result svcGetDebugFutureThreadInfo(LastThreadContext *out_context, u64 *out_thread_id, Handle debug, s64 ns); + +/** + * @brief Gets information about the previously-scheduled thread. + * @param[out] out_context Output \ref LastThreadContext for the previously scheduled thread. + * @param[out] out_tls_address Output tls address for the previously scheduled thread. + * @param[out] out_flags Output flags for the previously scheduled thread. + * @return Result code. + * @note Syscall number 0x2F. + */ +Result svcGetLastThreadInfo(LastThreadContext *out_context, u64 *out_tls_address, u32 *out_flags); + +///@} + ///@name Resource Limit Management ///@{ @@ -661,6 +744,76 @@ Result svcGetThreadContext3(ThreadContext* ctx, Handle thread); ///@} +///@name Synchronization +///@{ + +/** + * @brief Arbitrates an address depending on type and value. [4.0.0+] + * @param[in] address Address to arbitrate. + * @param[in] arb_type \ref ArbitrationType to use. + * @param[in] value Value to arbitrate on. + * @param[in] timeout Maximum time in nanoseconds to wait. + * @return Result code. + * @note Syscall number 0x34. + */ +Result svcWaitForAddress(void *address, u32 arb_type, s32 value, s64 timeout); + +/** + * @brief Signals (and updates) an address depending on type and value. [4.0.0+] + * @param[in] address Address to arbitrate. + * @param[in] signal_type \ref SignalType to use. + * @param[in] value Value to arbitrate on. + * @param[in] count Number of waiting threads to signal. + * @return Result code. + * @note Syscall number 0x35. + */ +Result svcSignalToAddress(void *address, u32 signal_type, s32 value, s32 count); + +///@} + +///@name Miscellaneous +///@{ + +/** + * @brief Sets thread preemption state (used during abort/panic). [8.0.0+] + * @note Syscall number 0x36. + */ +void svcSynchronizePreemptionState(void); + +///@} + +///@name Debugging +///@{ +/** + * @brief Causes the kernel to dump debug information. [1.0.0-3.0.2] + * @param[in] dump_info_type Type of information to dump. + * @param[in] arg0 Argument to the debugging operation. + * @note Syscall number 0x3C. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +void svcDumpInfo(u32 dump_info_type, u64 arg0); + +/** + * @brief Performs a debugging operation on the kernel. [4.0.0+] + * @param[in] kern_debug_type Type of debugging operation to perform. + * @param[in] arg0 First argument to the debugging operation. + * @param[in] arg1 Second argument to the debugging operation. + * @param[in] arg2 Third argument to the debugging operation. + * @note Syscall number 0x3C. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +void svcKernelDebug(u32 kern_debug_type, u64 arg0, u64 arg1, u64 arg2); + +/** + * @brief Performs a debugging operation on the kernel. [4.0.0+] + * @param[in] kern_trace_state Type of tracing the kernel should perform. + * @note Syscall number 0x3D. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +void svcChangeKernelTraceState(u32 kern_trace_state); + +///@} + \ ///@name Inter-process communication (IPC) ///@{ @@ -680,6 +833,15 @@ Result svcCreateSession(Handle *server_handle, Handle *client_handle, u32 unk0, */ Result svcAcceptSession(Handle *session_handle, Handle port_handle); +/** + * @brief Performs light IPC input/output. + * @return Result code. + * @param[in] handle Server or port handle to act on. + * @note Syscall number 0x42. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +Result svcReplyAndReceiveLight(Handle handle); + /** * @brief Performs IPC input/output. * @return Result code. @@ -762,6 +924,18 @@ Result svcControlCodeMemory(Handle code_handle, CodeMapOperation op, void* dst_a ///@} +///@name Power Management +///@{ + +/** + * @brief Causes the system to enter deep sleep. + * @note Syscall number 0x4D. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +void svcSleepSystem(void); + +///@} + ///@name Device memory-mapped I/O (MMIO) ///@{ @@ -775,6 +949,19 @@ Result svcReadWriteRegister(u32* outVal, u64 regAddr, u32 rwMask, u32 inVal); ///@} +///@name Process and thread management +///@{ + +/** + * @brief Configures the pause/unpause status of a process. + * @return Result code. + * @note Syscall number 0x4F. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +Result svcSetProcessActivity(Handle process, bool paused); + +///@} + ///@name Inter-process memory sharing ///@{ @@ -878,6 +1065,15 @@ Result svcMapDeviceAddressSpaceByForce(Handle handle, Handle proc_handle, u64 ma */ Result svcMapDeviceAddressSpaceAligned(Handle handle, Handle proc_handle, u64 map_addr, u64 dev_size, u64 dev_addr, u32 perm); +/** + * @brief Maps an attached device address space to an userspace address. + * @return Result code. + * @remark The userspace destination address must have the \ref MemState_MapDeviceAlignedAllowed bit set. + * @note Syscall number 0x5B. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +Result svcMapDeviceAddressSpace(u64 *out_mapped_size, Handle handle, Handle proc_handle, u64 map_addr, u64 dev_size, u64 dev_addr, u32 perm); + /** * @brief Unmaps an attached device address space from an userspace address. * @return Result code. @@ -888,6 +1084,38 @@ Result svcUnmapDeviceAddressSpace(Handle handle, Handle proc_handle, u64 map_add ///@} +///@name Cache Management +///@{ + +/** + * @brief Invalidates data cache for a virtual address range within a process. + * @param[in] address Address of region to invalidate. + * @param[in] size Size of region to invalidate. + * @note Syscall number 0x5D. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +Result svcInvalidateProcessDataCache(Handle process, uintptr_t address, size_t size); + +/** + * @brief Stores data cache for a virtual address range within a process. + * @param[in] address Address of region to store. + * @param[in] size Size of region to store. + * @note Syscall number 0x5E. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +Result svcStoreProcessDataCache(Handle process, uintptr_t address, size_t size); + +/** + * @brief Flushes data cache for a virtual address range within a process. + * @param[in] address Address of region to flush. + * @param[in] size Size of region to flush. + * @note Syscall number 0x5F. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +Result svcFlushProcessDataCache(Handle process, uintptr_t address, size_t size); + +///@} + ///@name Debugging ///@{ @@ -1017,6 +1245,14 @@ Result svcReadDebugProcessMemory(void* buffer, Handle debug, u64 addr, u64 size) */ Result svcWriteDebugProcessMemory(Handle debug, const void* buffer, u64 addr, u64 size); +/** + * @brief Sets one of the hardware breakpoints. + * @return Result code. + * @note Syscall number 0x6C. + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +Result svcSetHardwareBreakPoint(u32 which, u64 flags, u64 value); + /** * @brief Gets parameters from a thread in a debugging session. * @return Result code. diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 38cec328..ee02c6f0 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -368,7 +368,7 @@ Service* appletGetServiceSession_DisplayController(void); Service* appletGetServiceSession_DebugFunctions(void); /// Get the cached AppletResourceUserId. -Result appletGetAppletResourceUserId(u64 *out); +u64 appletGetAppletResourceUserId(void); /// Get the \ref AppletType. AppletType appletGetAppletType(void); diff --git a/nx/include/switch/services/caps.h b/nx/include/switch/services/caps.h index 1fa9f5a6..0aa966f1 100644 --- a/nx/include/switch/services/caps.h +++ b/nx/include/switch/services/caps.h @@ -18,13 +18,13 @@ typedef enum { /// AlbumReportOption typedef enum { - AlbumReportOption_Disable = 0, ///< Don't display the screenshot-taken Overlay-applet notification. - AlbumReportOption_Enable = 1, ///< Display the screenshot-taken Overlay notification. + AlbumReportOption_Disable = 0, ///< Don't display the screenshot-taken Overlay-applet notification. + AlbumReportOption_Enable = 1, ///< Display the screenshot-taken Overlay notification. } AlbumReportOption; typedef enum { - CapsAlbumStorage_Nand = 0, ///< Nand - CapsAlbumStorage_Sd = 1, ///< Sd + CapsAlbumStorage_Nand = 0, ///< Nand + CapsAlbumStorage_Sd = 1, ///< Sd } CapsAlbumStorage; /// ContentType @@ -70,38 +70,38 @@ typedef struct { /// AlbumFileDateTime. This corresponds to each field in the Album entry filename, prior to the "-": "YYYYMMDDHHMMSSII". typedef struct { - u16 year; ///< Year. - u8 month; ///< Month. - u8 day; ///< Day of the month. - u8 hour; ///< Hour. - u8 minute; ///< Minute. - u8 second; ///< Second. - u8 id; ///< Unique ID for when there's multiple Album files with the same timestamp. + u16 year; ///< Year. + u8 month; ///< Month. + u8 day; ///< Day of the month. + u8 hour; ///< Hour. + u8 minute; ///< Minute. + u8 second; ///< Second. + u8 id; ///< Unique ID for when there's multiple Album files with the same timestamp. } CapsAlbumFileDateTime; /// AlbumEntryId typedef struct { - u64 application_id; ///< ApplicationId - CapsAlbumFileDateTime datetime; ///< \ref CapsAlbumFileDateTime - u8 storage; ///< \ref CapsAlbumStorage - u8 content; ///< \ref CapsAlbumFileContents - u32 pad_x12; ///< Set to 0 by official software - u16 pad_x16; ///< Set to 0 by official software + u64 application_id; ///< ApplicationId + CapsAlbumFileDateTime datetime; ///< \ref CapsAlbumFileDateTime + u8 storage; ///< \ref CapsAlbumStorage + u8 content; ///< \ref CapsAlbumFileContents + u32 pad_x12; ///< Set to 0 by official software + u16 pad_x16; ///< Set to 0 by official software } PACKED CapsAlbumFileId; /// AlbumEntry typedef struct { - u64 size; ///< Size. - CapsAlbumFileId file_id; ///< \ref CapsAlbumFileId + u64 size; ///< Size. + CapsAlbumFileId file_id; ///< \ref CapsAlbumFileId } CapsAlbumEntry; /// ApplicationAlbumEntry typedef struct { union { - u8 data[0x20]; ///< Data. + u8 data[0x20]; ///< Data. struct { - u8 unk_x0[0x20]; ///< Unknown. + u8 unk_x0[0x20]; ///< Unknown. } v0; ///< Pre-7.0.0 struct { @@ -115,15 +115,15 @@ typedef struct { /// ApplicationAlbumFileEntry typedef struct { - CapsApplicationAlbumEntry entry; ///< \ref CapsApplicationAlbumEntry - CapsAlbumFileDateTime datetime; ///< \ref CapsAlbumFileDateTime - u64 unk_x28; ///< Unknown. + CapsApplicationAlbumEntry entry; ///< \ref CapsApplicationAlbumEntry + CapsAlbumFileDateTime datetime; ///< \ref CapsAlbumFileDateTime + u64 unk_x28; ///< Unknown. } CapsApplicationAlbumFileEntry; /// ApplicationData typedef struct { - u8 userdata[0x400]; ///< UserData. - u32 size; ///< UserData size. + u8 userdata[0x400]; ///< UserData. + u32 size; ///< UserData size. } CapsApplicationData; /// AlbumFileContents @@ -140,25 +140,31 @@ typedef enum { } CapsAlbumContentsUsageFlag; typedef struct { - s64 count; - s64 size; - u32 flags; - u8 file_contents; - u8 pad_x15[0x3]; + s64 count; ///< Count. + s64 size; ///< Size. Used storage space. + u32 flags; ///< \ref CapsAlbumContentsUsageFlag + u8 file_contents; ///< \ref CapsAlbumFileContents + u8 pad_x15[0x3]; ///< Unused } CapsAlbumContentsUsage; typedef struct { - CapsAlbumContentsUsage usages[2]; + CapsAlbumContentsUsage usages[2]; ///< \ref CapsAlbumContentsUsage } CapsAlbumUsage2; typedef struct { - CapsAlbumContentsUsage usages[3]; + CapsAlbumContentsUsage usages[3]; ///< \ref CapsAlbumContentsUsage } CapsAlbumUsage3; typedef struct { - CapsAlbumContentsUsage usages[16]; + CapsAlbumContentsUsage usages[16]; ///< \ref CapsAlbumContentsUsage } CapsAlbumUsage16; +/// OverlayThumbnailData +typedef struct { + CapsAlbumFileId file_id; ///< \ref CapsAlbumFileId + u64 size; ///< Size. +} CapsOverlayThumbnailData; + /// UserIdList typedef struct { AccountUid uids[ACC_USER_LIST_SIZE]; ///< \ref AccountUid @@ -175,6 +181,26 @@ typedef struct { u8 reserved[0xac]; ///< Unused. } CapsLoadAlbumScreenShotImageOutputForApplication; +/// LoadAlbumScreenShotImageOutput +typedef struct { + s64 width; ///< Width. Official sw copies this to a s32 output field. + s64 height; ///< Height. Official sw copies this to a s32 output field. + CapsScreenShotAttribute attr; ///< \ref CapsScreenShotAttribute + u8 unk_x50[0x400]; ///< Unused. +} CapsLoadAlbumScreenShotImageOutput; + +/// AlbumFileContentsFlag +typedef enum { + CapsAlbumFileContentsFlag_ScreenShot = BIT(0), ///< Query for ScreenShot files. + CapsAlbumFileContentsFlag_Movie = BIT(1), ///< Query for Movie files. +} CapsAlbumFileContentsFlag; + +/// AlbumCache +typedef struct { + u64 count; ///< Count + u8 unk_x8[8]; ///< Unknown +} CapsAlbumCache; + /// Gets the ShimLibraryVersion. u64 capsGetShimLibraryVersion(void); diff --git a/nx/include/switch/services/capsa.h b/nx/include/switch/services/capsa.h index 2f5d458a..7dce12b8 100644 --- a/nx/include/switch/services/capsa.h +++ b/nx/include/switch/services/capsa.h @@ -18,31 +18,377 @@ void capsaExit(void); /// Gets the Service for caps:a. Service* capsaGetServiceSession(void); -Result capsaGetAlbumFileCount(CapsAlbumStorage storage, u64* count); -Result capsaGetAlbumFileList(CapsAlbumStorage storage, u64* count, CapsAlbumEntry* buffer, u64 size); -Result capsaLoadAlbumFile(const CapsAlbumFileId *file_id, u64 *out_size, void* workbuf, u64 workbuf_size); +/// Gets the Service for IAlbumAccessorSession, only initialized after \ref capsaOpenAlbumMovieStream was used (unaffected by using \ref capsaCloseAlbumMovieStream). +Service* capsaGetServiceSession_Accessor(void); + +/** + * @brief Gets the amount of files at a AlbumStorage. + * @param[in] storage \ref CapsAlbumStorage + * @param[out] count Amount of files. + */ +Result capsaGetAlbumFileCount(CapsAlbumStorage storage, u64 *count); + +/** + * @brief Gets a listing of \ref CapsAlbumEntry, where the AlbumFile's storage matches the input one. + * @param[in] storage \ref CapsAlbumStorage + * @param[out] out Total output entries. + * @param[out] entries Output array of \ref CapsAlbumEntry. + * @param[in] count Reserved entry count. + */ +Result capsaGetAlbumFileList(CapsAlbumStorage storage, u64 *out, CapsAlbumEntry *entries, u64 count); + +/** + * @brief Loads a file into the specified buffer. + * @param[in] file_id \ref CapsAlbumFileId + * @param[out] out_size Size of the AlbumFile. + * @param[out] filebuf File output buffer. + * @param[in] filebuf_size Size of the filebuf. + */ +Result capsaLoadAlbumFile(const CapsAlbumFileId *file_id, u64 *out_size, void* filebuf, u64 filebuf_size); + +/** + * @brief Deletes an AlbumFile corresponding to the specified \ref CapsAlbumFileId. + * @param[in] file_id \ref CapsAlbumFileId + */ Result capsaDeleteAlbumFile(const CapsAlbumFileId *file_id); + +/** + * @brief Copies an AlbumFile to the specified \ref CapsAlbumStorage. + * @param[in] file_id \ref CapsAlbumFileId + * @param[in] dst_storage \ref CapsAlbumStorage + */ Result capsaStorageCopyAlbumFile(const CapsAlbumFileId *file_id, CapsAlbumStorage dst_storage); -Result capsaIsAlbumMounted(CapsAlbumStorage storage, bool* is_mounted); + +/** + * @brief Gets the mount status of the specified \ref CapsAlbumStorage. + * @param[in] storage \ref CapsAlbumStorage + * @param[out] is_mounted Boolean over whether the storage is mounted or not. + */ +Result capsaIsAlbumMounted(CapsAlbumStorage storage, bool *is_mounted); + +/** + * @brief Returns the AlbumUsage for a specified \ref CapsAlbumStorage. + * @param[in] storage \ref CapsAlbumStorage + * @param[out] out \ref CapsAlbumUsage2 + */ Result capsaGetAlbumUsage(CapsAlbumStorage storage, CapsAlbumUsage2 *out); -Result capsaGetAlbumFileSize(const CapsAlbumFileId *file_id, u64* size); -Result capsaLoadAlbumFileThumbnail(const CapsAlbumFileId *file_id, u64 *out_size, void* workbuf, u64 workbuf_size); -/// Only available on [2.0.0+]. -Result capsaLoadAlbumScreenShotImage(u64* width, u64* height, const CapsAlbumFileId *file_id, void* workbuf, u64 workbuf_size, void* rawbuf, u64 rawbuf_size); -Result capsaLoadAlbumScreenShotThumbnailImage(u64* width, u64* height, const CapsAlbumFileId *file_id, void* workbuf, u64 workbuf_size, void* rawbuf, u64 rawbuf_size); -/// Only available on [3.0.0+]. -Result capsaLoadAlbumScreenShotImageEx(u64* width, u64* height, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* workbuf, u64 workbuf_size, void* rawbuf, u64 rawbuf_size); -Result capsaLoadAlbumScreenShotThumbnailImageEx(u64* width, u64* height, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* workbuf, u64 workbuf_size, void* rawbuf, u64 rawbuf_size); -/// Only available on [4.0.0+]. + +/** + * @brief Gets the size for the specified AlbumFile. + * @param[in] file_id \ref CapsAlbumFileId + * @param[out] size Size of the file. + */ +Result capsaGetAlbumFileSize(const CapsAlbumFileId *file_id, u64 *size); + +/** + * @brief Load the Thumbnail for the specified AlbumFile. + * @note Will always be 320x180. + * @param[in] file_id \ref CapsAlbumFileId + * @param[out] out_size Size of the Thumbnail. + * @param[out] image JPEG image output buffer. + * @param[in] image_size Image buffer size. + */ +Result capsaLoadAlbumFileThumbnail(const CapsAlbumFileId *file_id, u64 *out_size, void* image, u64 image_size); + +/** + * @brief Load the ScreenShotImage for the specified AlbumFile. + * @note Only available on [2.0.0+]. + * @param[out] width Output image width. Optional, can be NULL. + * @param[out] height Output image height. Optional, can be NULL. + * @param[in] file_id \ref CapsAlbumFileId + * @param[out] image RGBA8 image output buffer. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 1280x720. + * @param[out] workbuf Work buffer, cleared to 0 by the cmd before it returns. + * @param[in] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. + */ +Result capsaLoadAlbumScreenShotImage(u64 *width, u64 *height, const CapsAlbumFileId *file_id, void* image, u64 image_size, void* workbuf, u64 workbuf_size); + +/** + * @brief Load the ScreenShotThumbnailImage for the specified AlbumFile. + * @note Only available on [2.0.0+]. + * @param[out] width Output image width. Optional, can be NULL. + * @param[out] height Output image height. Optional, can be NULL. + * @param[in] file_id \ref CapsAlbumFileId + * @param[out] image RGBA8 image output buffer. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 320x180. + * @param[out] workbuf Work buffer, cleared to 0 by the cmd before it returns. + * @param[in] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. + */ +Result capsaLoadAlbumScreenShotThumbnailImage(u64 *width, u64 *height, const CapsAlbumFileId *file_id, void* image, u64 image_size, void* workbuf, u64 workbuf_size); + +/** + * @brief Load the ScreenShotImage for the specified AlbumFile. + * @note Only available on [3.0.0+]. + * @param[out] width Output image width. Optional, can be NULL. + * @param[out] height Output image height. Optional, can be NULL. + * @param[in] file_id \ref CapsAlbumFileId + * @param[in] opts \ref CapsScreenShotDecodeOption + * @param[out] image RGBA8 image output buffer. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 1280x720. + * @param[out] workbuf Work buffer, cleared to 0 by the cmd before it returns. + * @param[in] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. + */ +Result capsaLoadAlbumScreenShotImageEx(u64 *width, u64 *height, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* image, u64 image_size, void* workbuf, u64 workbuf_size); + +/** + * @brief Load the ScreenShotThumbnailImage for the specified AlbumFile. + * @note Only available on [3.0.0+]. + * @param[out] width Output image width. Optional, can be NULL. + * @param[out] height Output image height. Optional, can be NULL. + * @param[in] file_id \ref CapsAlbumFileId + * @param[in] opts \ref CapsScreenShotDecodeOption + * @param[out] image RGBA8 image output buffer. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 320x180. + * @param[out] workbuf Work buffer, cleared to 0 by the cmd before it returns. + * @param[in] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. + */ +Result capsaLoadAlbumScreenShotThumbnailImageEx(u64 *width, u64 *height, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* image, u64 image_size, void* workbuf, u64 workbuf_size); + +/** + * @brief Load the ScreenShotImage for the specified AlbumFile. + * @note Only available on [3.0.0+]. + * @param[out] width Output image width. Optional, can be NULL. + * @param[out] height Output image height. Optional, can be NULL. + * @param[out] attr \ref CapsScreenShotAttribute + * @param[in] file_id \ref CapsAlbumFileId + * @param[in] opts \ref CapsScreenShotDecodeOption + * @param[out] image RGBA8 image output buffer. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 1280x720. + * @param[out] workbuf Work buffer, cleared to 0 by the cmd before it returns. + * @param[in] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. + */ +Result capsaLoadAlbumScreenShotImageEx0(u64 *width, u64 *height, CapsScreenShotAttribute *attr, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* image, u64 image_size, void* workbuf, u64 workbuf_size); + +/** + * @brief Returns the AlbumUsage for a specified \ref CapsAlbumStorage. + * @note Only available on [4.0.0+]. + * @param[in] storage \ref CapsAlbumStorage + * @param[out] out \ref CapsAlbumUsage3 + */ Result capsaGetAlbumUsage3(CapsAlbumStorage storage, CapsAlbumUsage3 *out); + +/** + * @brief Returns the result for a AlbumStorage mount. + * @note Only available on [4.0.0+]. + * @param[in] storage \ref CapsAlbumStorage + */ Result capsaGetAlbumMountResult(CapsAlbumStorage storage); + +/** + * @brief Returns the AlbumUsage for a specified \ref CapsAlbumStorage. + * @note Only available on [4.0.0+]. + * @param[in] storage \ref CapsAlbumStorage + * @param[out] out \ref CapsAlbumUsage16 + */ Result capsaGetAlbumUsage16(CapsAlbumStorage storage, CapsAlbumUsage16 *out); -Result capsaGetAutoSavingStorage(CapsAlbumStorage* storage); -Result capsaGetRequiredStorageSpaceSizeToCopyAll(CapsAlbumStorage dst_storage, CapsAlbumStorage src_storage, u64* out); -/// Only available on [4.0.0+]. -Result capsaLoadAlbumScreenShotThumbnailImageEx1(const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* workbuf, u64 workbuf_size, void* rawbuf, u64 rawbuf_size, void* out, u64 out_size); +/** + * @brief Returns the start and end of the Applet Id range. + * @note Only available on [6.0.0+]. + * @param[out] success Returns bool over whether the call was handled or not. + * @param[out] min Mimimum applet id. Always 0x0100000000001000 + * @param[out] max Maximum applet id. Always 0x0100000000001FFF + */ +Result capsaGetMinMaxAppletId(bool* success, u64* min, u64* max); +/** + * @brief Gets the amount of files of the specified type at a AlbumStorage. + * @note Only available on [5.0.0+]. + * @param[in] storage \ref CapsAlbumStorage + * @param[in] flags \ref CapsAlbumFileContentsFlag + * @param[out] count Amount of files. + */ +Result capsaGetAlbumFileCountEx0(CapsAlbumStorage storage, u8 flags, u64 *count); + +/** + * @brief Gets a listing of \ref CapsAlbumEntry, where the AlbumFile's storage and type matches the input one. + * @note Only available on [5.0.0+]. + * @param[in] storage \ref CapsAlbumStorage + * @param[in] flags \ref CapsAlbumFileContentsFlag + * @param[out] out Total output entries. + * @param[out] entries Output array of \ref CapsAlbumEntry. + * @param[in] count Reserved entry count. + */ +Result capsaGetAlbumFileListEx0(CapsAlbumStorage storage, u8 flags, u64 *out, CapsAlbumEntry *entries, u64 count); + +/** + * @brief Returns the image from the last shown ScreenShot Overlay. + * @param[out] data \ref CapsOverlayThumbnailData + * @param[out] image RGBA8 image output buffer. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 96×54. + */ +Result capsaGetLastOverlayScreenShotThumbnail(CapsOverlayThumbnailData *data, void* image, u64 image_size); + +/** + * @brief Returns the image from the last shown Movie Overlay. + * @note Only available on [4.0.0+]. + * @param[out] data \ref CapsOverlayThumbnailData + * @param[out] image RGBA8 image output buffer. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 96×54. + */ +Result capsaGetLastOverlayMovieThumbnail(CapsOverlayThumbnailData *data, void* image, u64 image_size); + +/** + * @brief Gets the currently set autosaving storage. + * @note Wrapper around setsysGetPrimaryAlbumStorage but defaults to NAND if SD isn't available. + * @param[out] storage \ref CapsAlbumStorage + */ +Result capsaGetAutoSavingStorage(CapsAlbumStorage *storage); + +/** + * @brief Gets required size to copy all files from one Storage to another. + * @param[in] dst_storage \ref CapsAlbumStorage + * @param[in] src_storage \ref CapsAlbumStorage + * @param[out] out Required storage space size. + */ +Result capsaGetRequiredStorageSpaceSizeToCopyAll(CapsAlbumStorage dst_storage, CapsAlbumStorage src_storage, u64 *out); + +/** + * @brief Load the ScreenShotThumbnailImage for the specified AlbumFile. + * @note Only available on [3.0.0+]. + * @param[out] width Output image width. Optional, can be NULL. + * @param[out] height Output image height. Optional, can be NULL. + * @param[out] attr \ref CapsScreenShotAttribute + * @param[in] file_id \ref CapsAlbumFileId + * @param[in] opts \ref CapsScreenShotDecodeOption + * @param[out] image RGBA8 image output buffer. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 320x180. + * @param[out] workbuf Work buffer, cleared to 0 by the cmd before it returns. + * @param[in] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. + */ +Result capsLoadAlbumScreenShotThumbnailImageEx0(u64 *width, u64 *height, CapsScreenShotAttribute *attr, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* image, u64 image_size, void* workbuf, u64 workbuf_size); + +/** + * @brief Load the ScreenShotImage for the specified AlbumFile. + * @note Only available on [4.0.0+]. + * @param[in] file_id \ref CapsAlbumFileId + * @param[in] opts \ref CapsScreenShotDecodeOption + * @param[out] out \ref CapsLoadAlbumScreenShotImageOutput + * @param[out] image RGBA8 image output buffer. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 1280x720. + * @param[out] workbuf Work buffer, cleared to 0 by the cmd before it returns. + * @param[in] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. + */ +Result capsaLoadAlbumScreenShotImageEx1(const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, CapsLoadAlbumScreenShotImageOutput *out, void* image, u64 image_size, void* workbuf, u64 workbuf_size); + +/** + * @brief Load the ScreenShotThumbnailImage for the specified AlbumFile. + * @note Only available on [4.0.0+]. + * @param[in] file_id \ref CapsAlbumFileId + * @param[in] opts \ref CapsScreenShotDecodeOption + * @param[out] out \ref CapsLoadAlbumScreenShotImageOutput + * @param[out] image RGBA8 image output buffer. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 320x180. + * @param[out] workbuf Work buffer, cleared to 0 by the cmd before it returns. + * @param[in] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. + */ +Result capsaLoadAlbumScreenShotThumbnailImageEx1(const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, CapsLoadAlbumScreenShotImageOutput *out, void* image, u64 image_size, void* workbuf, u64 workbuf_size); + +/** + * @brief Unmounts the specified AlbumStorage. + * @param[in] storage \ref CapsAlbumStorage + */ Result capsaForceAlbumUnmounted(CapsAlbumStorage storage); + +/** + * @brief Resets mount status for the specified AlbumStorage. + * @note Mounts the Storage if available. + * @param[in] storage \ref CapsAlbumStorage + */ Result capsaResetAlbumMountStatus(CapsAlbumStorage storage); + +/** + * @brief Refreshs Album Cache for the specified AlbumStorage. + * @param[in] storage \ref CapsAlbumStorage + */ Result capsaRefreshAlbumCache(CapsAlbumStorage storage); + +/** + * @brief Gets the AlbumCache of the specified AlbumStorage. + * @note use \ref capsaGetAlbumCacheEx instead. + * @param[in] storage \ref CapsAlbumStorage + * @param[out] cache \ref CapsAlbumCache + */ +Result capsaGetAlbumCache(CapsAlbumStorage storage, CapsAlbumCache *cache); + +/** + * @brief Gets the AlbumCache for the specified type of the specified AlbumStorage. + * @note Stubbed on [4.0.0+]. + * @param[in] storage \ref CapsAlbumStorage + * @param[in] contents \ref CapsAlbumFileContents + * @param[out] cache \ref CapsAlbumCache + */ +Result capsaGetAlbumCacheEx(CapsAlbumStorage storage, CapsAlbumFileContents contents, CapsAlbumCache *cache); + +/** + * @brief Opens an AlbumMovieStream. + * @note This opens IAlbumAccessorSession if not previously opened, it's closed during \ref capsaExit. + * @note Up to 4 streams can be open at the same time. Multiple streams can be open at the same time for the same \ref CapsAlbumFileId. + * @note Only available on [4.0.0+]. + * @param[out] stream Stream handle. + * @param[in] entry \ref CapsAlbumFileId + */ +Result capsaOpenAlbumMovieStream(u64 *stream, const CapsAlbumFileId *file_id); + +/** + * @brief Closes an AlbumMovieStream. + * @note Only available on [4.0.0+]. + * @param[in] stream Stream handle. + */ +Result capsaCloseAlbumMovieStream(u64 stream); + +/** + * @brief Gets the data size of an AlbumMovieStream. + * @note Only available on [4.0.0+]. + * @param[in] stream Stream handle. + * @param[out] size Size of the actual MP4, without the JPEG at the end. + */ +Result capsaGetAlbumMovieStreamSize(u64 stream, u64 *size); + +/** + * @brief Reads data from an AlbumMovieStream. + * @note offset(+size) must not be negative. offset and size must be aligned to 0x40000-bytes. + * @note When offset(+size) goes beyond the size from \ref capsaGetAlbumMovieStreamSize, the regions of the buffer which goes beyond that are cleared to 0, and actual_size is still set to the input size. + * @note Only available on [4.0.0+]. + * @param[in] stream Stream handle. + * @param[in] offset Offset. + * @param[out] Output data buffer. + * @param[in] size Data buffer size. + * @param[out] actual_size Actual read size. + */ +Result capsaReadMovieDataFromAlbumMovieReadStream(u64 stream, s64 offset, void* buffer, size_t size, u64 *actual_size); + +/** + * @brief Gets the BrokenReason for an AlbumMovieStream. + * @note Official sw doesn't use this. + * @note Only available on [4.0.0+]. + * @param[in] stream Stream handle. + */ +Result capsaGetAlbumMovieReadStreamBrokenReason(u64 stream); + +/** + * @brief Gets the data size of an Image taken from an AlbumMovieStream. + * @note Only available on [4.0.0+]. + * @param[in] stream Stream handle. + * @param[out] size Expected size of an Image. + */ +Result capsaGetAlbumMovieReadStreamImageDataSize(u64 stream, u64 *size); + +/** + * @brief Reads data of an Image taken from an AlbumMovieStream. + * @note Only available on [4.0.0+]. + * @param[in] stream Stream handle. + * @param[in] offset Offset. + * @param[out] Output data buffer. + * @param[in] size Data buffer size. + * @param[out] actual_size Actual read size. + */ +Result capsaReadImageDataFromAlbumMovieReadStream(u64 stream, s64 offset, void* buffer, size_t size, u64 *actual_size); + +/** + * @brief Gets the file attribute of an AlbumMovieStream. + * @note Only available on [4.0.0+]. + * @param[in] stream Stream handle. + * @param[out] attr \ref CapsScreenShotAttribute + */ +Result capsaReadFileAttributeFromAlbumMovieReadStream(u64 stream, CapsScreenShotAttribute *attr); diff --git a/nx/include/switch/services/capsu.h b/nx/include/switch/services/capsu.h index 7e4a11b8..06dfd090 100644 --- a/nx/include/switch/services/capsu.h +++ b/nx/include/switch/services/capsu.h @@ -98,9 +98,9 @@ Result capsuGetAlbumFileSize(const CapsApplicationAlbumFileEntry *entry, u64 *si * @param[in] userdata_maxsize Max size of the userdata buffer. Optional, can be 0. * @param[out] userdata_size Userdata size field, clamped to max size sizeof(CapsApplicationData::userdata) when needed. * @param[out] image RGBA8 image output buffer. - * @param[out] image_size Image buffer size, should be at least large enough for RGBA8 1280x720. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 1280x720. * @param[out] workbuf Work buffer, cleared to 0 by the cmd before it returns. - * @param[out] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. + * @param[in] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. * @param[in] entry \ref CapsApplicationAlbumFileEntry * @param[in] option \ref CapsScreenShotDecodeOption */ @@ -115,9 +115,9 @@ Result capsuLoadAlbumScreenShotImage(s32 *width, s32 *height, CapsScreenShotAttr * @param[in] userdata_maxsize Max size of the userdata buffer. Optional, can be 0. * @param[out] userdata_size Userdata size field, clamped to max size sizeof(CapsApplicationData::userdata) when needed. * @param[out] image RGBA8 image output buffer. - * @param[out] image_size Image buffer size, should be at least large enough for RGBA8 320x180. + * @param[in] image_size Image buffer size, should be at least large enough for RGBA8 320x180. * @param[out] workbuf Work buffer, cleared to 0 by the cmd before it returns. - * @param[out] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. + * @param[in] workbuf_size Work buffer size, must be at least the size of the JPEG within the AlbumFile. * @param[in] entry \ref CapsApplicationAlbumFileEntry * @param[in] option \ref CapsScreenShotDecodeOption */ diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 527646e6..0da76c50 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -170,6 +170,12 @@ typedef enum { FsCustomStorageId_SdCard = 1, } FsCustomStorageId; +/// ImageDirectoryId +typedef enum { + FsImageDirectoryId_Nand = 0, + FsImageDirectoryId_Sd = 1, +} FsImageDirectoryId; + /// SaveDataSpaceId typedef enum { FsSaveDataSpaceId_System = 0, ///< System @@ -329,6 +335,7 @@ Result fsWriteSaveDataFileSystemExtraData(const void* buf, size_t len, FsSaveDat Result fsOpenSaveDataInfoReader(FsSaveDataInfoReader* out, FsSaveDataSpaceId save_data_space_id); +Result fsOpenImageDirectoryFileSystem(FsFileSystem* out, FsImageDirectoryId image_directory_id); Result fsOpenContentStorageFileSystem(FsFileSystem* out, FsContentStorageId content_storage_id); Result fsOpenCustomStorageFileSystem(FsFileSystem* out, FsCustomStorageId custom_storage_id); /// [7.0.0+] diff --git a/nx/include/switch/services/fsldr.h b/nx/include/switch/services/fsldr.h index 03ad7d0e..c022a093 100644 --- a/nx/include/switch/services/fsldr.h +++ b/nx/include/switch/services/fsldr.h @@ -20,4 +20,3 @@ Service* fsldrGetServiceSession(void); Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out); Result fsldrIsArchivedProgram(u64 pid, bool *out); -Result fsldrSetCurrentProcess(void); diff --git a/nx/include/switch/services/hid.h b/nx/include/switch/services/hid.h index ed5725ce..f926d6cd 100644 --- a/nx/include/switch/services/hid.h +++ b/nx/include/switch/services/hid.h @@ -323,6 +323,13 @@ typedef enum { CONTROLLER_P1_AUTO = 10, ///< Not an actual HID-sysmodule ID. Only for hidKeys*()/hidJoystickRead()/hidSixAxisSensorValuesRead()/hidGetControllerType()/hidGetControllerColors()/hidIsControllerConnected(). Automatically uses CONTROLLER_PLAYER_1 when connected, otherwise uses CONTROLLER_HANDHELD. } HidControllerID; +/// GyroscopeZeroDriftMode +typedef enum { + HidGyroscopeZeroDriftMode_Loose = 0, ///< Loose + HidGyroscopeZeroDriftMode_Standard = 1, ///< Standard + HidGyroscopeZeroDriftMode_Tight = 2, ///< Tight +} HidGyroscopeZeroDriftMode; + /// JoyHoldType typedef enum { HidJoyHoldType_Default = 0, ///< Default / Joy-Con held vertically. @@ -415,7 +422,7 @@ typedef struct SixAxisSensorValues { HidVector orientation[3]; } SixAxisSensorValues; -#define JOYSTICK_MAX (0x8000) +#define JOYSTICK_MAX (0x7FFF) #define JOYSTICK_MIN (-0x8000) // End enums and output structs @@ -769,6 +776,15 @@ Result hidGetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle, float *unk0, /// ResetSixAxisSensorFusionParameters Result hidResetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle); +/// Sets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle. +Result hidSetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode mode); + +/// Gets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle. +Result hidGetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode *mode); + +/// Resets the ::HidGyroscopeZeroDriftMode for the specified SixAxisSensorHandle to ::HidGyroscopeZeroDriftMode_Standard. +Result hidResetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle); + /// Sets which controller types are supported. This is automatically called with all types in \ref hidInitialize. Result hidSetSupportedNpadStyleSet(HidControllerType type); diff --git a/nx/include/switch/services/set.h b/nx/include/switch/services/set.h index 7fe5015d..fda2445b 100644 --- a/nx/include/switch/services/set.h +++ b/nx/include/switch/services/set.h @@ -959,7 +959,7 @@ Result setsysSetChineseTraditionalInputMethod(SetChineseTraditionalInputMethod m /** * @brief Gets the \ref SetSysHomeMenuScheme. - * @note Only available on [9.0.0+]. + * @note Only available on [8.1.1+]. * @param[out] out \ref SetSysHomeMenuScheme */ Result setsysGetHomeMenuScheme(SetSysHomeMenuScheme *out); diff --git a/nx/source/kernel/svc.s b/nx/source/kernel/svc.s index 047cebf5..3fc62974 100644 --- a/nx/source/kernel/svc.s +++ b/nx/source/kernel/svc.s @@ -191,6 +191,11 @@ SVC_BEGIN svcConnectToNamedPort ret SVC_END +SVC_BEGIN svcSendSyncRequestLight + svc 0x20 + ret +SVC_END + SVC_BEGIN svcSendSyncRequest svc 0x21 ret @@ -248,6 +253,16 @@ SVC_BEGIN svcGetInfo ret SVC_END +SVC_BEGIN svcFlushEntireDataCache + svc 0x2A + ret +SVC_END + +SVC_BEGIN svcFlushDataCache + svc 0x2B + ret +SVC_END + SVC_BEGIN svcMapPhysicalMemory svc 0x2C ret @@ -258,6 +273,29 @@ SVC_BEGIN svcUnmapPhysicalMemory ret SVC_END +SVC_BEGIN svcGetDebugFutureThreadInfo + stp x0, x1, [sp, #-16]! + svc 0x2E + ldp x6, x7, [sp], #16 + stp x1, x2, [x6] + stp x3, x4, [x6, #16] + str x5, [x7] + ret +SVC_END + +SVC_BEGIN svcGetLastThreadInfo + stp x1, x2, [sp, #-16]! + str x0, [sp, #-16]! + svc 0x2F + ldr x7, [sp], #16 + stp x1, x2, [x7] + stp x3, x4, [x7, #16] + ldp x1, x2, [sp], #16 + str x5, [x1] + str w6, [x2] + ret +SVC_END + SVC_BEGIN svcGetResourceLimitLimitValue str x0, [sp, #-16]! svc 0x30 @@ -284,6 +322,36 @@ SVC_BEGIN svcGetThreadContext3 ret SVC_END +SVC_BEGIN svcWaitForAddress + svc 0x34 + ret +SVC_END + +SVC_BEGIN svcSignalToAddress + svc 0x35 + ret +SVC_END + +SVC_BEGIN svcSynchronizePreemptionState + svc 0x36 + ret +SVC_END + +SVC_BEGIN svcDumpInfo + svc 0x3C + ret +SVC_END + +SVC_BEGIN svcKernelDebug + svc 0x3C + ret +SVC_END + +SVC_BEGIN svcChangeKernelTraceState + svc 0x3D + ret +SVC_END + SVC_BEGIN svcCreateSession stp x0, x1, [sp, #-16]! svc 0x40 @@ -301,6 +369,11 @@ SVC_BEGIN svcAcceptSession ret SVC_END +SVC_BEGIN svcReplyAndReceiveLight + svc 0x42 + ret +SVC_END + SVC_BEGIN svcReplyAndReceive str x0, [sp, #-16]! svc 0x43 @@ -354,6 +427,11 @@ SVC_BEGIN svcControlCodeMemory ret SVC_END +SVC_BEGIN svcSleepSystem + svc 0x4D + ret +SVC_END + SVC_BEGIN svcReadWriteRegister str x0, [sp, #-16]! svc 0x4E @@ -362,6 +440,11 @@ SVC_BEGIN svcReadWriteRegister ret SVC_END +SVC_BEGIN svcSetProcessActivity + svc 0x4F + ret +SVC_END + SVC_BEGIN svcCreateSharedMemory str x0, [sp, #-16]! svc 0x50 @@ -433,11 +516,34 @@ SVC_BEGIN svcMapDeviceAddressSpaceAligned ret SVC_END +SVC_BEGIN svcMapDeviceAddressSpace + str x0, [sp, #-16]! + svc 0x5B + ldr x2, [sp], #16 + str w1, [x2] + ret +SVC_END + SVC_BEGIN svcUnmapDeviceAddressSpace svc 0x5C ret SVC_END +SVC_BEGIN svcInvalidateProcessDataCache + svc 0x5D + ret +SVC_END + +SVC_BEGIN svcStoreProcessDataCache + svc 0x5E + ret +SVC_END + +SVC_BEGIN svcFlushProcessDataCache + svc 0x5F + ret +SVC_END + SVC_BEGIN svcDebugActiveProcess str x0, [sp, #-16]! svc 0x60 @@ -515,6 +621,11 @@ SVC_BEGIN svcWriteDebugProcessMemory ret SVC_END +SVC_BEGIN svcSetHardwareBreakPoint + svc 0x6C + ret +SVC_END + SVC_BEGIN svcGetDebugThreadParam stp x0, x1, [sp, #-16]! svc 0x6D diff --git a/nx/source/runtime/devices/romfs_dev.c b/nx/source/runtime/devices/romfs_dev.c index 117841b6..43dcff0f 100644 --- a/nx/source/runtime/devices/romfs_dev.c +++ b/nx/source/runtime/devices/romfs_dev.c @@ -62,6 +62,43 @@ static romfs_file *romFS_file(romfs_mount *mount, u32 off) return curFile; } +static ssize_t _romfs_read_safe(romfs_mount *mount, u64 pos, void* buffer, u64 size) +{ + u8 tmp_buffer[0x1000]; + u64 total_read = 0; + + while (size) + { + u64 cur_size = size > sizeof(tmp_buffer) ? sizeof(tmp_buffer) : size; + u64 cur_read = 0; + Result rc = 0; + + if (mount->fd_type == RomfsSource_FsFile) + { + rc = fsFileRead(&mount->fd, pos, tmp_buffer, cur_size, FsReadOption_None, &cur_read); + } + else if (mount->fd_type == RomfsSource_FsStorage) + { + rc = fsStorageRead(&mount->fd_storage, pos, tmp_buffer, cur_size); + cur_read = cur_size; + } + + if (R_FAILED(rc)) + return -1; + + memcpy(buffer, tmp_buffer, cur_read); + buffer = (u8*)buffer + cur_read; + pos += cur_read; + total_read += cur_read; + size -= cur_read; + + if (cur_read != cur_size) + break; + } + + return total_read; +} + static ssize_t _romfs_read(romfs_mount *mount, u64 offset, void* buffer, u64 size) { s64 pos = mount->offset + offset; @@ -76,6 +113,7 @@ static ssize_t _romfs_read(romfs_mount *mount, u64 offset, void* buffer, u64 siz rc = fsStorageRead(&mount->fd_storage, pos, buffer, size); read = size; } + if (rc == 0xD401) return _romfs_read_safe(mount, pos, buffer, size); if (R_FAILED(rc)) return -1; return read; } diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 2a275b33..e66ac5ba 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -1169,12 +1169,8 @@ Result appletSetApplicationAlbumUserData(const void* buffer, size_t size) { IPC_MAKE_CMD_IMPL(static Result _appletGetAppletResourceUserId(u64 *out), &g_appletIWindowController, 1, _appletCmdNoInOutU64, out) -Result appletGetAppletResourceUserId(u64 *out) { - if (!serviceIsActive(&g_appletSrv)) - return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); - - *out = g_appletResourceUserId; - return 0; +u64 appletGetAppletResourceUserId(void) { + return g_appletResourceUserId; } IPC_MAKE_CMD_IMPL_HOSVER(Result appletGetAppletResourceUserIdOfCallerApplet(u64 *out), &g_appletIWindowController, 2, _appletCmdNoInOutU64, (6,0,0), out) @@ -1432,11 +1428,7 @@ static Result _appletCreateLibraryApplet(Service* srv_out, AppletId id, LibApple } static Result _appletGetIndirectLayerConsumerHandle(Service* srv, u64 *out) { - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) return rc; + u64 AppletResourceUserId = appletGetAppletResourceUserId(); serviceAssumeDomain(srv); return serviceDispatchInOut(srv, 160, AppletResourceUserId, *out, diff --git a/nx/source/services/auddev.c b/nx/source/services/auddev.c index b309f0e7..a900b6a1 100644 --- a/nx/source/services/auddev.c +++ b/nx/source/services/auddev.c @@ -13,14 +13,10 @@ static Result _auddevGetAudioDeviceService(Service* srv, Service* srv_out, u64 a NX_GENERATE_SERVICE_GUARD(auddev); Result _auddevInitialize(void) { - Result rc=0; - u64 aruid = 0; - rc = appletGetAppletResourceUserId(&aruid); - Service audrenMgrSrv; - rc = smGetService(&audrenMgrSrv, "audren:u"); + Result rc = smGetService(&audrenMgrSrv, "audren:u"); if (R_SUCCEEDED(rc)) { - rc = _auddevGetAudioDeviceService(&audrenMgrSrv, &g_auddevIAudioDevice, aruid); + rc = _auddevGetAudioDeviceService(&audrenMgrSrv, &g_auddevIAudioDevice, appletGetAppletResourceUserId()); serviceClose(&audrenMgrSrv); } diff --git a/nx/source/services/audren.c b/nx/source/services/audren.c index b9b5a29d..663b03e0 100644 --- a/nx/source/services/audren.c +++ b/nx/source/services/audren.c @@ -29,7 +29,7 @@ typedef struct { u32 revision; } AudioRendererParameter; -static Result _audrenOpenAudioRenderer(Service* srv, Service* srv_out, const AudioRendererParameter* param, u64 aruid); +static Result _audrenOpenAudioRenderer(Service* srv, Service* srv_out, const AudioRendererParameter* param); static Result _audrenGetWorkBufferSize(Service* srv, const AudioRendererParameter* param, u64* out_size); static Result _audrenQuerySystemEvent(Event* out_event); @@ -76,11 +76,6 @@ Result _audrenInitialize(const AudioRendererConfig* config) { param.effect_count = config->num_effects; param.revision = g_audrenRevision; - // Get aruid - u64 aruid = 0; - rc = appletGetAppletResourceUserId(&aruid); - //if (R_FAILED(rc)) return rc; // apparently audren still inits fine with aruid = 0 so this isn't a fatal error condition - // Open IAudioRendererManager Service audrenMgrSrv; rc = smGetService(&audrenMgrSrv, "audren:u"); @@ -94,7 +89,7 @@ Result _audrenInitialize(const AudioRendererConfig* config) { rc = tmemCreate(&g_audrenWorkBuf, workBufSize, Perm_None); if (R_SUCCEEDED(rc)) { // Create the IAudioRenderer service - rc = _audrenOpenAudioRenderer(&audrenMgrSrv, &g_audrenIAudioRenderer, ¶m, aruid); + rc = _audrenOpenAudioRenderer(&audrenMgrSrv, &g_audrenIAudioRenderer, ¶m); if (R_SUCCEEDED(rc)) { // Finally, get the handle to the system event rc = _audrenQuerySystemEvent(&g_audrenEvent); @@ -144,13 +139,13 @@ void audrenWaitFrame(void) { eventWait(&g_audrenEvent, U64_MAX); } -Result _audrenOpenAudioRenderer(Service* srv, Service* srv_out, const AudioRendererParameter* param, u64 aruid) { +Result _audrenOpenAudioRenderer(Service* srv, Service* srv_out, const AudioRendererParameter* param) { const struct { AudioRendererParameter param; u32 pad; u64 work_buffer_size; u64 aruid; - } in = { *param, 0, g_audrenWorkBuf.size, aruid }; + } in = { *param, 0, g_audrenWorkBuf.size, appletGetAppletResourceUserId() }; return serviceDispatchIn(srv, 0, in, .in_send_pid = true, diff --git a/nx/source/services/capsa.c b/nx/source/services/capsa.c index 2d004a33..bf571a1c 100644 --- a/nx/source/services/capsa.c +++ b/nx/source/services/capsa.c @@ -7,6 +7,7 @@ #include "services/capsa.h" static Service g_capsaSrv; +static Service g_capsaAccessor; NX_GENERATE_SERVICE_GUARD(capsa); @@ -15,6 +16,7 @@ Result _capsaInitialize(void) { } void _capsaCleanup(void) { + serviceClose(&g_capsaAccessor); serviceClose(&g_capsaSrv); } @@ -22,27 +24,31 @@ Service* capsaGetServiceSession(void) { return &g_capsaSrv; } -static Result _capsaCmdInU8NoOut(Service* srv, u8 inval, u32 cmd_id) { +Service* capsaGetServiceSession_Accessor(void) { + return &g_capsaAccessor; +} + +static Result _capsaCmdInU8NoOut(Service *srv, u8 inval, u32 cmd_id) { return serviceDispatchIn(srv, cmd_id, inval); } -Result capsaGetAlbumFileCount(CapsAlbumStorage storage, u64* count) { +Result capsaGetAlbumFileCount(CapsAlbumStorage storage, u64 *count) { u8 inval = storage; return serviceDispatchInOut(&g_capsaSrv, 0, inval, *count); } -Result capsaGetAlbumFileList(CapsAlbumStorage storage, u64* count, CapsAlbumEntry* buffer, u64 buffer_size) { +Result capsaGetAlbumFileList(CapsAlbumStorage storage, u64 *out, CapsAlbumEntry *entries, u64 count) { u8 inval = storage; - return serviceDispatchInOut(&g_capsaSrv, 1, inval, *count, + return serviceDispatchInOut(&g_capsaSrv, 1, inval, *out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { buffer, buffer_size } }, + .buffers = { { entries, count * sizeof(CapsAlbumEntry) } }, ); } -Result capsaLoadAlbumFile(const CapsAlbumFileId *file_id, u64 *out_size, void* workbuf, u64 workbuf_size) { +Result capsaLoadAlbumFile(const CapsAlbumFileId *file_id, u64 *out_size, void* filebuf, u64 filebuf_size) { return serviceDispatchInOut(&g_capsaSrv, 2, *file_id, *out_size, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { workbuf, workbuf_size } }, + .buffers = { { filebuf, filebuf_size } }, ); } @@ -50,8 +56,8 @@ Result capsaDeleteAlbumFile(const CapsAlbumFileId *file_id) { return serviceDispatchIn(&g_capsaSrv, 3, *file_id); } -Result capsaStorageCopyAlbumFile(const CapsAlbumFileId* file_id, CapsAlbumStorage dst_storage) { - struct { +Result capsaStorageCopyAlbumFile(const CapsAlbumFileId *file_id, CapsAlbumStorage dst_storage) { + const struct { u8 storage; u8 pad_x1[0x7]; CapsAlbumFileId file_id; @@ -59,7 +65,7 @@ Result capsaStorageCopyAlbumFile(const CapsAlbumFileId* file_id, CapsAlbumStorag return serviceDispatchIn(&g_capsaSrv, 4, in); } -Result capsaIsAlbumMounted(CapsAlbumStorage storage, bool* is_mounted) { +Result capsaIsAlbumMounted(CapsAlbumStorage storage, bool *is_mounted) { u8 inval = storage; return serviceDispatchInOut(&g_capsaSrv, 5, inval, *is_mounted); } @@ -69,18 +75,18 @@ Result capsaGetAlbumUsage(CapsAlbumStorage storage, CapsAlbumUsage2 *out) { return serviceDispatchInOut(&g_capsaSrv, 6, inval, *out); } -Result capsaGetAlbumFileSize(const CapsAlbumFileId *file_id, u64* size) { +Result capsaGetAlbumFileSize(const CapsAlbumFileId *file_id, u64 *size) { return serviceDispatchInOut(&g_capsaSrv, 7, *file_id, *size); } -Result capsaLoadAlbumFileThumbnail(const CapsAlbumFileId *file_id, u64 *out_size, void* workbuf, u64 workbuf_size) { +Result capsaLoadAlbumFileThumbnail(const CapsAlbumFileId *file_id, u64 *out_size, void* image, u64 image_size) { return serviceDispatchInOut(&g_capsaSrv, 8, *file_id, *out_size, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { workbuf, workbuf_size } }, + .buffers = { { image, image_size } }, ); } -static Result _capsaLoadAlbumScreenshot(u64* width, u64* height, const CapsAlbumFileId *file_id, void* workbuf, u64 workbuf_size, void* rawbuf, u64 rawbuf_size, u32 cmd_id) { +static Result _capsaLoadAlbumScreenshot(u64 *width, u64 *height, const CapsAlbumFileId *file_id, void* image, u64 image_size, void* workbuf, u64 workbuf_size, u32 cmd_id) { if (hosversionBefore(2,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); struct { @@ -89,25 +95,27 @@ static Result _capsaLoadAlbumScreenshot(u64* width, u64* height, const CapsAlbum } out; Result rc = serviceDispatchInOut(&g_capsaSrv, cmd_id, *file_id, out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out | SfBufferAttr_HipcMapTransferAllowsNonSecure, SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { rawbuf, rawbuf_size }, { workbuf, workbuf_size } }, + .buffers = { { image, image_size }, { workbuf, workbuf_size } }, ); - *width = out.width; - *height = out.height; + if (R_SUCCEEDED(rc)) { + if (width) *width = out.width; + if (height) *height = out.height; + } return rc; } -Result capsaLoadAlbumScreenShotImage(u64* width, u64* height, const CapsAlbumFileId *file_id, void* workbuf, u64 workbuf_size, void* rawbuf, u64 rawbuf_size) { - return _capsaLoadAlbumScreenshot(width, height, file_id, workbuf, workbuf_size, rawbuf, rawbuf_size, 9); +Result capsaLoadAlbumScreenShotImage(u64 *width, u64 *height, const CapsAlbumFileId *file_id, void* image, u64 image_size, void* workbuf, u64 workbuf_size) { + return _capsaLoadAlbumScreenshot(width, height, file_id, image, image_size, workbuf, workbuf_size, 9); } -Result capsaLoadAlbumScreenShotThumbnailImage(u64* width, u64* height, const CapsAlbumFileId *file_id, void* workbuf, u64 workbuf_size, void* rawbuf, u64 rawbuf_size) { - return _capsaLoadAlbumScreenshot(width, height, file_id, workbuf, workbuf_size, rawbuf, rawbuf_size, 10); +Result capsaLoadAlbumScreenShotThumbnailImage(u64 *width, u64 *height, const CapsAlbumFileId *file_id, void* image, u64 image_size, void* workbuf, u64 workbuf_size) { + return _capsaLoadAlbumScreenshot(width, height, file_id, image, image_size, workbuf, workbuf_size, 10); } -static Result _capsaLoadAlbumScreenshotEx(u64* width, u64* height, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* workbuf, u64 workbuf_size, void* rawbuf, u64 rawbuf_size, u32 cmd_id) { +static Result _capsaLoadAlbumScreenshotEx(u64 *width, u64 *height, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* image, u64 image_size, void* workbuf, u64 workbuf_size, u32 cmd_id) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - struct { + const struct { CapsAlbumFileId file_id; CapsScreenShotDecodeOption opts; } in = { *file_id, *opts }; @@ -117,19 +125,49 @@ static Result _capsaLoadAlbumScreenshotEx(u64* width, u64* height, const CapsAlb } out; Result rc = serviceDispatchInOut(&g_capsaSrv, cmd_id, in, out, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out | SfBufferAttr_HipcMapTransferAllowsNonSecure, SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { rawbuf, rawbuf_size }, { workbuf, workbuf_size } }, + .buffers = { { image, image_size }, { workbuf, workbuf_size } }, ); - *width = out.width; - *height = out.height; + if (R_SUCCEEDED(rc)) { + if (width) *width = out.width; + if (height) *height = out.height; + } return rc; } -Result capsaLoadAlbumScreenShotImageEx(u64* width, u64* height, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* workbuf, u64 workbuf_size, void* rawbuf, u64 rawbuf_size) { - return _capsaLoadAlbumScreenshotEx(width, height, file_id, opts, workbuf, workbuf_size, rawbuf, rawbuf_size, 12); +Result capsaLoadAlbumScreenShotImageEx(u64 *width, u64 *height, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* image, u64 image_size, void* workbuf, u64 workbuf_size) { + return _capsaLoadAlbumScreenshotEx(width, height, file_id, opts, image, image_size, workbuf, workbuf_size, 12); } -Result capsaLoadAlbumScreenShotThumbnailImageEx(u64* width, u64* height, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* workbuf, u64 workbuf_size, void* rawbuf, u64 rawbuf_size) { - return _capsaLoadAlbumScreenshotEx(width, height, file_id, opts, workbuf, workbuf_size, rawbuf, rawbuf_size, 13); +Result capsaLoadAlbumScreenShotThumbnailImageEx(u64 *width, u64 *height, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* image, u64 image_size, void* workbuf, u64 workbuf_size) { + return _capsaLoadAlbumScreenshotEx(width, height, file_id, opts, image, image_size, workbuf, workbuf_size, 13); +} + +Result _capsaLoadAlbumScreenShotEx0(u64 *width, u64 *height, CapsScreenShotAttribute *attr, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* image, u64 image_size, void* workbuf, u64 workbuf_size, u32 cmd_id) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + const struct { + CapsAlbumFileId file_id; + CapsScreenShotDecodeOption opts; + } in = { *file_id, *opts }; + struct { + CapsScreenShotAttribute attr; + s64 width; + s64 height; + } out = {0}; + Result rc = serviceDispatchInOut(&g_capsaSrv, cmd_id, in, out, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out | SfBufferAttr_HipcMapTransferAllowsNonSecure, SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { image, image_size }, { workbuf, workbuf_size } }, + ); + if (R_SUCCEEDED(rc)) { + if (attr) *attr = out.attr; + if (width) *width = out.width; + if (height) *height = out.height; + } + return rc; +} + +Result capsaLoadAlbumScreenShotImageEx0(u64 *width, u64 *height, CapsScreenShotAttribute *attr, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* image, u64 image_size, void* workbuf, u64 workbuf_size) { + return _capsaLoadAlbumScreenShotEx0(width, height, attr, file_id, opts, image, image_size, workbuf, workbuf_size, 14); } Result capsaGetAlbumUsage3(CapsAlbumStorage storage, CapsAlbumUsage3 *out) { @@ -152,34 +190,112 @@ Result capsaGetAlbumUsage16(CapsAlbumStorage storage, CapsAlbumUsage16 *out) { return serviceDispatchInOut(&g_capsaSrv, 17, inval, *out); } -Result capsaGetAutoSavingStorage(CapsAlbumStorage* storage) { - u8 tmpval = 0; - Result rc = serviceDispatchOut(&g_capsaSrv, 401, tmpval); - *storage = tmpval; +Result capsaGetMinMaxAppletId(bool *success, u64* min, u64* max) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + u64 app_ids[2]; + struct { + bool success; + u8 pad[0x3]; + } out; + Result rc = serviceDispatchOut(&g_capsaSrv, 18, out, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out | SfBufferAttr_HipcMapTransferAllowsNonSecure, }, + .buffers = { { app_ids, sizeof(app_ids) }, }, + ); + if (R_SUCCEEDED(rc)) { + if (min) *min = app_ids[0]; + if (max) *max = app_ids[1]; + if (success) *success = out.success; + } return rc; } -Result capsaGetRequiredStorageSpaceSizeToCopyAll(CapsAlbumStorage dst_storage, CapsAlbumStorage src_storage, u64* out) { +Result capsaGetAlbumFileCountEx0(CapsAlbumStorage storage, u8 flags, u64 *count) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); struct { + u8 storage; + u8 pad_x1[7]; + u8 flags; + u8 pad_x9[7]; + } in = { storage, {0}, flags, {0} }; + return serviceDispatchInOut(&g_capsaSrv, 100, in, *count); +} + +Result capsaGetAlbumFileListEx0(CapsAlbumStorage storage, u8 flags, u64 *out, CapsAlbumEntry *entries, u64 count) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + struct { + u8 storage; + u8 pad_x1[7]; + u8 contents; + u8 pad_x9[7]; + } in = { storage, {0}, flags, {0} }; + return serviceDispatchInOut(&g_capsaSrv, 101, in, *out, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { entries, count * sizeof(CapsAlbumEntry) } }, + ); +} + +Result _capsaGetLastOverlayThumbnail(CapsOverlayThumbnailData *data, void* image, u64 image_size, u32 cmd_id) { + return serviceDispatchOut(&g_capsaSrv, cmd_id, *data, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out, }, + .buffers = { { image, image_size }, }, + ); +} + +Result capsaGetLastOverlayScreenShotThumbnail(CapsOverlayThumbnailData *data, void* image, u64 image_size) { + return _capsaGetLastOverlayThumbnail(data, image, image_size, 301); +} + +Result capsaGetLastOverlayMovieThumbnail(CapsOverlayThumbnailData *data, void* image, u64 image_size) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + return _capsaGetLastOverlayThumbnail(data, image, image_size, 302); +} + +Result capsaGetAutoSavingStorage(CapsAlbumStorage *storage) { + u8 tmpval = 0; + Result rc = serviceDispatchOut(&g_capsaSrv, 401, tmpval); + if (R_SUCCEEDED(rc)) { + if (storage) *storage = tmpval; + } + return rc; +} + +Result capsaGetRequiredStorageSpaceSizeToCopyAll(CapsAlbumStorage dst_storage, CapsAlbumStorage src_storage, u64 *out) { + const struct { u8 dest; u8 src; } in = { dst_storage, src_storage }; return serviceDispatchInOut(&g_capsaSrv, 501, in, *out); } -Result capsaLoadAlbumScreenShotThumbnailImageEx1(const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* work_buffer, u64 work_buffer_size, void* raw_buffer, u64 raw_buffer_size, void* out, u64 out_size) { +Result capsLoadAlbumScreenShotThumbnailImageEx0(u64 *width, u64 *height, CapsScreenShotAttribute *attr, const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, void* image, u64 image_size, void* workbuf, u64 workbuf_size) { + return _capsaLoadAlbumScreenShotEx0(width, height, attr, file_id, opts, image, image_size, workbuf, workbuf_size, 1001); +} + +Result _capsaLoadAlbumScreenShotEx1(const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, CapsLoadAlbumScreenShotImageOutput *out, void* image, u64 image_size, void* workbuf, u64 workbuf_size, u32 cmd_id) { if (hosversionBefore(4,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - struct { + const struct { CapsAlbumFileId file_id; CapsScreenShotDecodeOption opts; } in = { *file_id, *opts }; - return serviceDispatchIn(&g_capsaSrv, 1003, in, + return serviceDispatchIn(&g_capsaSrv, cmd_id, in, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out | SfBufferAttr_FixedSize, SfBufferAttr_HipcMapAlias | SfBufferAttr_Out | SfBufferAttr_HipcMapTransferAllowsNonSecure, SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, - .buffers = { { out, out_size }, { raw_buffer, raw_buffer_size }, { work_buffer, work_buffer_size } }, + .buffers = { { out, sizeof(CapsLoadAlbumScreenShotImageOutput) }, { image, image_size }, { workbuf, workbuf_size } }, ); } +Result capsaLoadAlbumScreenShotImageEx1(const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, CapsLoadAlbumScreenShotImageOutput *out, void* image, u64 image_size, void* workbuf, u64 workbuf_size) { + return _capsaLoadAlbumScreenShotEx1(file_id, opts, out, image, image_size, workbuf, workbuf_size, 1002); +} + +Result capsaLoadAlbumScreenShotThumbnailImageEx1(const CapsAlbumFileId *file_id, const CapsScreenShotDecodeOption *opts, CapsLoadAlbumScreenShotImageOutput *out, void* image, u64 image_size, void* workbuf, u64 workbuf_size) { + return _capsaLoadAlbumScreenShotEx1(file_id, opts, out, image, image_size, workbuf, workbuf_size, 1003); +} + Result capsaForceAlbumUnmounted(CapsAlbumStorage storage) { return _capsaCmdInU8NoOut(&g_capsaSrv, storage, 8001); } @@ -191,3 +307,138 @@ Result capsaResetAlbumMountStatus(CapsAlbumStorage storage) { Result capsaRefreshAlbumCache(CapsAlbumStorage storage) { return _capsaCmdInU8NoOut(&g_capsaSrv, storage, 8011); } + +Result capsaGetAlbumCache(CapsAlbumStorage storage, CapsAlbumCache *cache) { + return serviceDispatchInOut(&g_capsaSrv, 8012, storage, *cache); +} + +Result capsaGetAlbumCacheEx(CapsAlbumStorage storage, CapsAlbumFileContents contents, CapsAlbumCache *cache) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + struct { + u8 storage; + u8 contents; + } in = { storage, contents }; + return serviceDispatchInOut(&g_capsaSrv, 8013, in, *cache); +} + +static Result _capsaOpenAccessorSession(Service *srv_out) { + u64 AppletResourceUserId = appletGetAppletResourceUserId(); + + return serviceDispatchIn(&g_capsaSrv, 60002, AppletResourceUserId, + .in_send_pid = true, + .out_num_objects = 1, + .out_objects = srv_out, + ); +} + +static Result _capsaOpenAlbumMovieReadStream(u64 *stream, const CapsAlbumFileId *file_id) { + return serviceDispatchInOut(&g_capsaAccessor, 2001, *file_id, *stream); +} + +static Result _capsaReadMovieDataFromAlbumMovieReadStream(u64 stream, s64 offset, void* buffer, size_t size, u64 *actual_size) { + const struct { + u64 stream; + s64 offset; + } in = { stream, offset }; + + return serviceDispatchInOut(&g_capsaAccessor, 2004, in, *actual_size, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { buffer, size } }, + ); +} + +static Result _capsaReadImageDataFromAlbumMovieReadStream(u64 stream, s64 offset, void* buffer, size_t size, u64 *actual_size) { + const struct { + u64 stream; + s64 offset; + } in = { stream, offset }; + + return serviceDispatchInOut(&g_capsaAccessor, 2007, in, *actual_size, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, + .buffers = { { buffer, size } }, + ); +} + +Result capsaOpenAlbumMovieStream(u64 *stream, const CapsAlbumFileId *file_id) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + Result rc=0; + + if (!serviceIsActive(&g_capsaAccessor)) rc = _capsaOpenAccessorSession(&g_capsaAccessor); + + if (R_SUCCEEDED(rc)) rc = _capsaOpenAlbumMovieReadStream(stream, file_id); + + return rc; +} + +Result capsaCloseAlbumMovieStream(u64 stream) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + if (!serviceIsActive(&g_capsaAccessor)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return serviceDispatchIn(&g_capsaAccessor, 2002, stream); +} + +Result capsaGetAlbumMovieStreamSize(u64 stream, u64 *size) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + if (!serviceIsActive(&g_capsaAccessor)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return serviceDispatchInOut(&g_capsaAccessor, 2003, stream, *size); +} + +Result capsaReadMovieDataFromAlbumMovieReadStream(u64 stream, s64 offset, void* buffer, size_t size, u64 *actual_size) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + if (!serviceIsActive(&g_capsaAccessor)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return _capsaReadMovieDataFromAlbumMovieReadStream(stream, offset, buffer, size, actual_size); +} + +Result capsaGetAlbumMovieReadStreamBrokenReason(u64 stream) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + if (!serviceIsActive(&g_capsaAccessor)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return serviceDispatchIn(&g_capsaAccessor, 2005, stream); +} + +Result capsaGetAlbumMovieReadStreamImageDataSize(u64 stream, u64 *size) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + if (!serviceIsActive(&g_capsaAccessor)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return serviceDispatchInOut(&g_capsaAccessor, 2006, stream, *size); +} + +Result capsaReadImageDataFromAlbumMovieReadStream(u64 stream, s64 offset, void* buffer, size_t size, u64 *actual_size) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + if (!serviceIsActive(&g_capsaAccessor)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return _capsaReadImageDataFromAlbumMovieReadStream(stream, offset, buffer, size, actual_size); +} + +Result capsaReadFileAttributeFromAlbumMovieReadStream(u64 stream, CapsScreenShotAttribute *attribute) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + if (!serviceIsActive(&g_capsaAccessor)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return serviceDispatchInOut(&g_capsaAccessor, 2008, stream, *attribute); +} diff --git a/nx/source/services/capssu.c b/nx/source/services/capssu.c index 81304829..26f90a77 100644 --- a/nx/source/services/capssu.c +++ b/nx/source/services/capssu.c @@ -36,13 +36,10 @@ static Result _capssuSetShimLibraryVersion(u64 version) { if (hosversionBefore(7,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { u64 version; u64 AppletResourceUserId; - } in = { version, AppletResourceUserId }; + } in = { version, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_capssuSrv, 32, in, .in_send_pid = true, @@ -50,15 +47,12 @@ static Result _capssuSetShimLibraryVersion(u64 version) { } static Result _capssuSaveScreenShotEx0(const void* buffer, size_t size, const CapsScreenShotAttribute *attr, AlbumReportOption reportoption, CapsApplicationAlbumEntry *out) { - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { CapsScreenShotAttribute attr; u32 reportoption; u32 pad; u64 AppletResourceUserId; - } in = { *attr, reportoption, 0, AppletResourceUserId }; + } in = { *attr, reportoption, 0, appletGetAppletResourceUserId() }; return serviceDispatchInOut(&g_capssuSrv, 203, in, *out, .buffer_attrs = { SfBufferAttr_HipcMapTransferAllowsNonSecure | SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, @@ -68,15 +62,12 @@ static Result _capssuSaveScreenShotEx0(const void* buffer, size_t size, const Ca } static Result _capssuSaveScreenShotEx(u32 cmd_id, bool pid, const void* argbuf, size_t argbuf_size, const void* buffer, size_t size, const CapsScreenShotAttribute *attr, AlbumReportOption reportoption, CapsApplicationAlbumEntry *out) { - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { CapsScreenShotAttribute attr; u32 reportoption; u32 pad; u64 AppletResourceUserId; - } in = { *attr, reportoption, 0, AppletResourceUserId }; + } in = { *attr, reportoption, 0, appletGetAppletResourceUserId() }; return serviceDispatchInOut(&g_capssuSrv, cmd_id, in, *out, .buffer_attrs = { diff --git a/nx/source/services/capsu.c b/nx/source/services/capsu.c index 0c5e37f4..f9bd8919 100644 --- a/nx/source/services/capsu.c +++ b/nx/source/services/capsu.c @@ -47,13 +47,10 @@ static Result _capsuSetShimLibraryVersion(u64 version) { if (hosversionBefore(7,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { u64 version; u64 AppletResourceUserId; - } in = { version, AppletResourceUserId }; + } in = { version, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_capsuSrv, 32, in, .in_send_pid = true, @@ -61,16 +58,13 @@ static Result _capsuSetShimLibraryVersion(u64 version) { } static Result _capsuGetAlbumFileList0AafeAruidDeprecated(void* entries, size_t entrysize, s32 count, u8 type, u64 start_timestamp, u64 end_timestamp, s32 *total_entries) { - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { u8 type; u8 pad[7]; u64 start_timestamp; u64 end_timestamp; u64 AppletResourceUserId; - } in = { type, {0}, start_timestamp, end_timestamp, AppletResourceUserId }; + } in = { type, {0}, start_timestamp, end_timestamp, appletGetAppletResourceUserId() }; u64 total_out=0; Result rc = serviceDispatchInOut(&g_capsuSrv, 102, in, total_out, @@ -83,15 +77,12 @@ static Result _capsuGetAlbumFileList0AafeAruidDeprecated(void* entries, size_t e } static Result _capsuDeleteAlbumFileByAruid(u32 cmd_id, u8 type, const CapsApplicationAlbumFileEntry *entry) { - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { u8 type; u8 pad[7]; CapsApplicationAlbumFileEntry entry; u64 AppletResourceUserId; - } in = { type, {0}, *entry, AppletResourceUserId }; + } in = { type, {0}, *entry, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_capsuSrv, 103, in, .in_send_pid = true, @@ -99,13 +90,10 @@ static Result _capsuDeleteAlbumFileByAruid(u32 cmd_id, u8 type, const CapsApplic } static Result _capsuGetAlbumFileSizeByAruid(const CapsApplicationAlbumFileEntry *entry, u64 *size) { - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { CapsApplicationAlbumFileEntry entry; u64 AppletResourceUserId; - } in = { *entry, AppletResourceUserId }; + } in = { *entry, appletGetAppletResourceUserId() }; return serviceDispatchInOut(&g_capsuSrv, 104, in, *size, .in_send_pid = true, @@ -113,15 +101,12 @@ static Result _capsuGetAlbumFileSizeByAruid(const CapsApplicationAlbumFileEntry } static Result _capsuPrecheckToCreateContentsByAruid(u8 type, u64 unk) { - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { u8 type; u8 pad[7]; u64 unk; u64 AppletResourceUserId; - } in = { type, {0}, unk, AppletResourceUserId }; + } in = { type, {0}, unk, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_capsuSrv, 130, in, .in_send_pid = true, @@ -129,14 +114,11 @@ static Result _capsuPrecheckToCreateContentsByAruid(u8 type, u64 unk) { } static Result _capsuLoadAlbumScreenShotImageByAruid(u32 cmd_id, CapsLoadAlbumScreenShotImageOutputForApplication *out, void* image, size_t image_size, void* workbuf, size_t workbuf_size, const CapsApplicationAlbumFileEntry *entry, const CapsScreenShotDecodeOption *option) { - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { CapsApplicationAlbumFileEntry entry; CapsScreenShotDecodeOption option; u64 AppletResourceUserId; - } in = { *entry, *option, AppletResourceUserId }; + } in = { *entry, *option, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_capsuSrv, cmd_id, in, .buffer_attrs = { @@ -154,9 +136,6 @@ static Result _capsuLoadAlbumScreenShotImageByAruid(u32 cmd_id, CapsLoadAlbumScr } static Result _capsuGetAlbumFileListAaeAruid(u32 cmd_id, void* entries, size_t entrysize, s32 count, u8 type, const CapsAlbumFileDateTime *start_datetime, const CapsAlbumFileDateTime *end_datetime, s32 *total_entries) { - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { u8 type; u8 pad; @@ -164,7 +143,7 @@ static Result _capsuGetAlbumFileListAaeAruid(u32 cmd_id, void* entries, size_t e CapsAlbumFileDateTime end_datetime; u8 pad2[6]; u64 AppletResourceUserId; - } in = { type, 0, *start_datetime, *end_datetime, {0}, AppletResourceUserId }; + } in = { type, 0, *start_datetime, *end_datetime, {0}, appletGetAppletResourceUserId() }; u64 total_out=0; Result rc = serviceDispatchInOut(&g_capsuSrv, cmd_id, in, total_out, @@ -177,9 +156,6 @@ static Result _capsuGetAlbumFileListAaeAruid(u32 cmd_id, void* entries, size_t e } static Result _capsuGetAlbumFileListAaeUidAruid(u32 cmd_id, void* entries, size_t entrysize, s32 count, u8 type, const CapsAlbumFileDateTime *start_datetime, const CapsAlbumFileDateTime *end_datetime, AccountUid uid, s32 *total_entries) { - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { u8 type; u8 pad; @@ -188,7 +164,7 @@ static Result _capsuGetAlbumFileListAaeUidAruid(u32 cmd_id, void* entries, size_ u8 pad2[6]; AccountUid uid; u64 AppletResourceUserId; - } in = { type, 0, *start_datetime, *end_datetime, {0}, uid, AppletResourceUserId }; + } in = { type, 0, *start_datetime, *end_datetime, {0}, uid, appletGetAppletResourceUserId() }; u64 total_out=0; Result rc = serviceDispatchInOut(&g_capsuSrv, cmd_id, in, total_out, @@ -201,13 +177,10 @@ static Result _capsuGetAlbumFileListAaeUidAruid(u32 cmd_id, void* entries, size_ } static Result _capsuOpenAccessorSessionForApplication(Service* srv_out, const CapsApplicationAlbumFileEntry *entry) { - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { CapsApplicationAlbumFileEntry entry; u64 AppletResourceUserId; - } in = { *entry, AppletResourceUserId }; + } in = { *entry, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_capsuSrv, 60002, in, .in_send_pid = true, @@ -217,13 +190,10 @@ static Result _capsuOpenAccessorSessionForApplication(Service* srv_out, const Ca } static Result _capsuOpenAlbumMovieReadStream(u64 *stream, const CapsApplicationAlbumFileEntry *entry) { - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - const struct { CapsApplicationAlbumFileEntry entry; u64 AppletResourceUserId; - } in = { *entry, AppletResourceUserId }; + } in = { *entry, appletGetAppletResourceUserId() }; return serviceDispatchInOut(&g_capsuAccessor, 2001, in, *stream, .in_send_pid = true, @@ -348,7 +318,7 @@ Result capsuPrecheckToCreateContents(CapsContentType type, u64 unk) { Result capsuOpenAlbumMovieStream(u64 *stream, const CapsApplicationAlbumFileEntry *entry) { Result rc=0; - if (!serviceIsActive(&g_capsuAccessor)) rc =_capsuOpenAccessorSessionForApplication(&g_capsuAccessor, entry); + if (!serviceIsActive(&g_capsuAccessor)) rc = _capsuOpenAccessorSessionForApplication(&g_capsuAccessor, entry); if (R_SUCCEEDED(rc)) rc = _capsuOpenAlbumMovieReadStream(stream, entry); diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 8ab67afa..ba5bda71 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -351,6 +351,14 @@ Result fsOpenSaveDataInfoReader(FsSaveDataInfoReader* out, FsSaveDataSpaceId sav } } +Result fsOpenImageDirectoryFileSystem(FsFileSystem* out, FsImageDirectoryId image_directory_id) { + u32 tmp=image_directory_id; + return _fsObjectDispatchIn(&g_fsSrv, 100, tmp, + .out_num_objects = 1, + .out_objects = &out->s, + ); +} + Result fsOpenContentStorageFileSystem(FsFileSystem* out, FsContentStorageId content_storage_id) { u32 tmp=content_storage_id; return _fsObjectDispatchIn(&g_fsSrv, 110, tmp, diff --git a/nx/source/services/hid.c b/nx/source/services/hid.c index bab1f175..9cba884a 100644 --- a/nx/source/services/hid.c +++ b/nx/source/services/hid.c @@ -40,7 +40,7 @@ static TransferMemory g_sevenSixAxisSensorTmem1; static RwLock g_hidLock; -static Result _hidCreateAppletResource(Service* srv, Service* srv_out, u64 AppletResourceUserId); +static Result _hidCreateAppletResource(Service* srv, Service* srv_out); static Result _hidGetSharedMemoryHandle(Service* srv, Handle* handle_out); static Result _hidActivateNpad(void); @@ -65,15 +65,11 @@ Result _hidInitialize(void) { Result rc=0; Handle sharedmem_handle; - // If this failed (for example because we're a sysmodule) AppletResourceUserId stays zero - u64 AppletResourceUserId = 0; - appletGetAppletResourceUserId(&AppletResourceUserId); - rc = smGetService(&g_hidSrv, "hid"); if (R_FAILED(rc)) return rc; - rc = _hidCreateAppletResource(&g_hidSrv, &g_hidIAppletResource, AppletResourceUserId); + rc = _hidCreateAppletResource(&g_hidSrv, &g_hidIAppletResource); if (R_SUCCEEDED(rc)) rc = _hidGetSharedMemoryHandle(&g_hidIAppletResource, &sharedmem_handle); @@ -649,12 +645,7 @@ static Result _hidCmdGetSession(Service* srv_out, u32 cmd_id) { } static Result _hidCmdWithNoInput(u32 cmd_id) { - Result rc=0; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; + u64 AppletResourceUserId = appletGetAppletResourceUserId(); return serviceDispatchIn(&g_hidSrv, cmd_id, AppletResourceUserId, .in_send_pid = true, @@ -674,17 +665,10 @@ static Result _hidCmdInU32NoOut(Service* srv, u32 inval, u32 cmd_id) { } static Result _hidCmdWithInputU32(u32 inval, u32 cmd_id) { - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; - const struct { u32 inval; u64 AppletResourceUserId; - } in = { inval, AppletResourceUserId }; + } in = { inval, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_hidSrv, cmd_id, in, .in_send_pid = true, @@ -692,17 +676,10 @@ static Result _hidCmdWithInputU32(u32 inval, u32 cmd_id) { } static Result _hidCmdWithInputU64(u64 inval, u32 cmd_id) { - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; - const struct { u64 AppletResourceUserId; u64 inval; - } in = { AppletResourceUserId, inval }; + } in = { appletGetAppletResourceUserId(), inval }; return serviceDispatchIn(&g_hidSrv, cmd_id, in, .in_send_pid = true, @@ -710,12 +687,7 @@ static Result _hidCmdWithInputU64(u64 inval, u32 cmd_id) { } static Result _hidCmdOutU32(u32 *out, u32 cmd_id) { - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; + u64 AppletResourceUserId = appletGetAppletResourceUserId(); return serviceDispatchInOut(&g_hidSrv, cmd_id, AppletResourceUserId, *out, .in_send_pid = true, @@ -723,12 +695,7 @@ static Result _hidCmdOutU32(u32 *out, u32 cmd_id) { } static Result _hidCmdOutU64(u64 *out, u32 cmd_id) { - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; + u64 AppletResourceUserId = appletGetAppletResourceUserId(); return serviceDispatchInOut(&g_hidSrv, cmd_id, AppletResourceUserId, *out, .in_send_pid = true, @@ -746,7 +713,9 @@ static Result _hidCmdNoInOutBool(bool *out, u32 cmd_id) { return rc; } -static Result _hidCreateAppletResource(Service* srv, Service* srv_out, u64 AppletResourceUserId) { +static Result _hidCreateAppletResource(Service* srv, Service* srv_out) { + u64 AppletResourceUserId = appletGetAppletResourceUserId(); + return serviceDispatchIn(srv, 0, AppletResourceUserId, .in_send_pid = true, .out_num_objects = 1, @@ -762,20 +731,13 @@ Result hidSetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle, float unk0, if (unk0 < 0.0f || unk0 > 1.0f) return MAKERESULT(Module_Libnx, LibnxError_BadInput); - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; - const struct { u32 SixAxisSensorHandle; float unk0; float unk1; u32 pad; u64 AppletResourceUserId; - } in = { SixAxisSensorHandle, unk0, unk1, 0, AppletResourceUserId }; + } in = { SixAxisSensorHandle, unk0, unk1, 0, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_hidSrv, 70, in, .in_send_pid = true, @@ -784,17 +746,12 @@ Result hidSetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle, float unk0, Result hidGetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle, float *unk0, float *unk1) { Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; const struct { u32 SixAxisSensorHandle; u32 pad; u64 AppletResourceUserId; - } in = { SixAxisSensorHandle, 0, AppletResourceUserId }; + } in = { SixAxisSensorHandle, 0, appletGetAppletResourceUserId() }; struct { float unk0; @@ -813,6 +770,39 @@ Result hidResetSixAxisSensorFusionParameters(u32 SixAxisSensorHandle) { return _hidCmdWithInputU32(SixAxisSensorHandle, 72); } +Result hidSetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode mode) { + const struct { + u32 SixAxisSensorHandle; + u32 mode; + u64 AppletResourceUserId; + } in = { SixAxisSensorHandle, mode, appletGetAppletResourceUserId() }; + + return serviceDispatchIn(&g_hidSrv, 79, in, + .in_send_pid = true, + ); +} + +Result hidGetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle, HidGyroscopeZeroDriftMode *mode) { + Result rc; + + const struct { + u32 SixAxisSensorHandle; + u32 pad; + u64 AppletResourceUserId; + } in = { SixAxisSensorHandle, 0, appletGetAppletResourceUserId() }; + + u32 tmp=0; + rc = serviceDispatchInOut(&g_hidSrv, 80, in, tmp, + .in_send_pid = true, + ); + if (R_SUCCEEDED(rc) && mode) *mode = tmp; + return rc; +} + +Result hidResetGyroscopeZeroDriftMode(u32 SixAxisSensorHandle) { + return _hidCmdWithInputU32(SixAxisSensorHandle, 81); +} + Result hidSetSupportedNpadStyleSet(HidControllerType type) { return _hidCmdWithInputU32(type, 100); } @@ -825,16 +815,11 @@ Result hidGetSupportedNpadStyleSet(HidControllerType *type) { } Result hidSetSupportedNpadIdType(HidControllerID *buf, size_t count) { - Result rc; - u64 AppletResourceUserId; + u64 AppletResourceUserId = appletGetAppletResourceUserId(); size_t i; u32 tmpval=0; u32 tmpbuf[10]; - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; - if (count > 10) return MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); @@ -880,18 +865,13 @@ static Result _hidDeactivateNpad(void) { Result hidAcquireNpadStyleSetUpdateEventHandle(HidControllerID id, Event* out_event, bool autoclear) { Result rc; Handle tmp_handle = INVALID_HANDLE; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; const struct { u32 id; u32 pad; u64 AppletResourceUserId; u64 event_ptr; // Official sw sets this to a ptr, which the sysmodule doesn't seem to use. - } in = { hidControllerIDToOfficial(id), 0, AppletResourceUserId, 0 }; + } in = { hidControllerIDToOfficial(id), 0, appletGetAppletResourceUserId(), 0 }; rc = serviceDispatchIn(&g_hidSrv, 106, in, .in_send_pid = true, @@ -922,17 +902,10 @@ Result hidSetNpadJoyAssignmentModeDual(HidControllerID id) { } Result hidMergeSingleJoyAsDualJoy(HidControllerID id0, HidControllerID id1) { - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; - const struct { u32 id0, id1; u64 AppletResourceUserId; - } in = { hidControllerIDToOfficial(id0), hidControllerIDToOfficial(id1), AppletResourceUserId }; + } in = { hidControllerIDToOfficial(id0), hidControllerIDToOfficial(id1), appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_hidSrv, 125, in, .in_send_pid = true, @@ -952,19 +925,12 @@ Result hidGetVibrationDeviceInfo(const u32 *VibrationDeviceHandle, HidVibrationD } Result hidSendVibrationValue(const u32 *VibrationDeviceHandle, HidVibrationValue *VibrationValue) { - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; - const struct { u32 VibrationDeviceHandle; HidVibrationValue VibrationValue; u32 pad; u64 AppletResourceUserId; - } in = { *VibrationDeviceHandle, *VibrationValue, 0, AppletResourceUserId }; + } in = { *VibrationDeviceHandle, *VibrationValue, 0, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_hidSrv, 201, in, .in_send_pid = true, @@ -972,17 +938,10 @@ Result hidSendVibrationValue(const u32 *VibrationDeviceHandle, HidVibrationValue } Result hidGetActualVibrationValue(const u32 *VibrationDeviceHandle, HidVibrationValue *VibrationValue) { - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; - const struct { u32 VibrationDeviceHandle; u64 AppletResourceUserId; - } in = { *VibrationDeviceHandle, AppletResourceUserId }; + } in = { *VibrationDeviceHandle, appletGetAppletResourceUserId() }; return serviceDispatchInOut(&g_hidSrv, 202, in, *VibrationValue, .in_send_pid = true, @@ -998,12 +957,7 @@ Result hidIsVibrationPermitted(bool *flag) { } Result hidSendVibrationValues(const u32 *VibrationDeviceHandles, HidVibrationValue *VibrationValues, s32 count) { - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; + u64 AppletResourceUserId = appletGetAppletResourceUserId(); return serviceDispatchIn(&g_hidSrv, 206, AppletResourceUserId, .buffer_attrs = { @@ -1022,16 +976,11 @@ Result hidIsVibrationDeviceMounted(const u32 *VibrationDeviceHandle, bool *flag) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; const struct { u32 VibrationDeviceHandle; u64 AppletResourceUserId; - } in = { *VibrationDeviceHandle, AppletResourceUserId }; + } in = { *VibrationDeviceHandle, appletGetAppletResourceUserId() }; u8 tmp=0; rc = serviceDispatchInOut(&g_hidSrv, 211, in, tmp, @@ -1179,18 +1128,11 @@ Result hidStopSevenSixAxisSensor(void) { } static Result _hidInitializeSevenSixAxisSensor(TransferMemory *tmem0, TransferMemory *tmem1) { - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; - const struct { u64 AppletResourceUserId; u64 size0; u64 size1; - } in = { AppletResourceUserId, tmem0->size, tmem1->size }; + } in = { appletGetAppletResourceUserId(), tmem0->size, tmem1->size }; return serviceDispatchIn(&g_hidSrv, 306, in, .in_send_pid = true, @@ -1255,17 +1197,10 @@ Result hidSetSevenSixAxisSensorFusionStrength(float strength) { if (hosversionBefore(5,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; - const struct { float strength; u64 AppletResourceUserId; - } in = { strength, AppletResourceUserId }; + } in = { strength, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_hidSrv, 308, in, .in_send_pid = true, @@ -1276,12 +1211,7 @@ Result hidGetSevenSixAxisSensorFusionStrength(float *strength) { if (hosversionBefore(5,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - Result rc; - u64 AppletResourceUserId; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - AppletResourceUserId = 0; + u64 AppletResourceUserId = appletGetAppletResourceUserId(); return serviceDispatchInOut(&g_hidSrv, 309, AppletResourceUserId, *strength, .in_send_pid = true, diff --git a/nx/source/services/hidsys.c b/nx/source/services/hidsys.c index b5e92f09..4a871bb3 100644 --- a/nx/source/services/hidsys.c +++ b/nx/source/services/hidsys.c @@ -15,12 +15,9 @@ Result _hidsysInitialize(void) { Result rc = smGetService(&g_hidsysSrv, "hid:sys"); if (R_FAILED(rc)) return rc; - - rc = appletGetAppletResourceUserId(&g_hidsysAppletResourceUserId); - if (R_FAILED(rc)) - g_hidsysAppletResourceUserId = 0; - return 0; + g_hidsysAppletResourceUserId = appletGetAppletResourceUserId(); + return 0; } void _hidsysCleanup(void) { diff --git a/nx/source/services/irs.c b/nx/source/services/irs.c index 571a9607..1211ed92 100644 --- a/nx/source/services/irs.c +++ b/nx/source/services/irs.c @@ -18,7 +18,7 @@ static bool g_irsSensorActivated; static IrsCameraEntry g_irsCameras[8]; -static Result _irsGetIrsensorSharedMemoryHandle(Handle* handle_out, u64 AppletResourceUserId); +static Result _irsGetIrsensorSharedMemoryHandle(Handle* handle_out); NX_GENERATE_SERVICE_GUARD(irs); @@ -29,15 +29,11 @@ Result _irsInitialize(void) { g_irsSensorActivated = 0; memset(g_irsCameras, 0, sizeof(g_irsCameras)); - // If this failed (for example because we're a sysmodule) AppletResourceUserId stays zero - u64 AppletResourceUserId=0; - appletGetAppletResourceUserId(&AppletResourceUserId); - rc = smGetService(&g_irsSrv, "irs"); if (R_FAILED(rc)) return rc; - rc = _irsGetIrsensorSharedMemoryHandle(&sharedmem_handle, AppletResourceUserId); + rc = _irsGetIrsensorSharedMemoryHandle(&sharedmem_handle); if (R_SUCCEEDED(rc)) { shmemLoadRemote(&g_irsSharedmem, sharedmem_handle, 0x8000, Perm_R); @@ -131,11 +127,7 @@ Result irsActivateIrsensor(bool activate) { if (g_irsSensorActivated==activate) return 0; Result rc=0; - u64 AppletResourceUserId=0; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - return rc; + u64 AppletResourceUserId = appletGetAppletResourceUserId(); rc = serviceDispatchIn(&g_irsSrv, activate ? 302 : 303, AppletResourceUserId, .in_send_pid = true, @@ -144,7 +136,9 @@ Result irsActivateIrsensor(bool activate) { return rc; } -static Result _irsGetIrsensorSharedMemoryHandle(Handle* handle_out, u64 AppletResourceUserId) { +static Result _irsGetIrsensorSharedMemoryHandle(Handle* handle_out) { + u64 AppletResourceUserId = appletGetAppletResourceUserId(); + return serviceDispatchIn(&g_irsSrv, 304, AppletResourceUserId, .in_send_pid = true, .out_handle_attrs = { SfOutHandleAttr_HipcCopy }, @@ -152,11 +146,11 @@ static Result _irsGetIrsensorSharedMemoryHandle(Handle* handle_out, u64 AppletRe ); } -static Result _irsStopImageProcessor(u32 IrCameraHandle, u64 AppletResourceUserId) { +static Result _irsStopImageProcessor(u32 IrCameraHandle) { const struct { u32 IrCameraHandle; u64 AppletResourceUserId; - } in = { IrCameraHandle, AppletResourceUserId }; + } in = { IrCameraHandle, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_irsSrv, 305, in, .in_send_pid = true, @@ -165,16 +159,11 @@ static Result _irsStopImageProcessor(u32 IrCameraHandle, u64 AppletResourceUserI Result irsStopImageProcessor(u32 IrCameraHandle) { Result rc=0; - u64 AppletResourceUserId=0; IrsCameraEntry *entry = NULL; if (!serviceIsActive(&g_irsSrv)) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - return rc; - rc = _IrsCameraEntryGet(IrCameraHandle, &entry); if (R_FAILED(rc)) return rc; @@ -182,19 +171,19 @@ Result irsStopImageProcessor(u32 IrCameraHandle) { if (entry->transfermem.handle == INVALID_HANDLE) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); - rc = _irsStopImageProcessor(IrCameraHandle, AppletResourceUserId); + rc = _irsStopImageProcessor(IrCameraHandle); _IrsCameraEntryFree(entry); return rc; } -static Result _irsRunImageTransferProcessor(u32 IrCameraHandle, u64 AppletResourceUserId, IrsPackedImageTransferProcessorConfig *config, TransferMemory *tmem) { +static Result _irsRunImageTransferProcessor(u32 IrCameraHandle, IrsPackedImageTransferProcessorConfig *config, TransferMemory *tmem) { const struct { u32 IrCameraHandle; u32 pad; u64 AppletResourceUserId; IrsPackedImageTransferProcessorConfig config; u64 TransferMemory_size; - } in = { IrCameraHandle, 0, AppletResourceUserId, *config, tmem->size }; + } in = { IrCameraHandle, 0, appletGetAppletResourceUserId(), *config, tmem->size }; return serviceDispatchIn(&g_irsSrv, 308, in, .in_send_pid = true, @@ -205,7 +194,6 @@ static Result _irsRunImageTransferProcessor(u32 IrCameraHandle, u64 AppletResour Result irsRunImageTransferProcessor(u32 IrCameraHandle, IrsImageTransferProcessorConfig *config, size_t size) { Result rc=0; - u64 AppletResourceUserId=0; IrsCameraEntry *entry = NULL; IrsPackedImageTransferProcessorConfig packed_config; @@ -218,10 +206,6 @@ Result irsRunImageTransferProcessor(u32 IrCameraHandle, IrsImageTransferProcesso packed_config.unk_constant = 0xa0003; packed_config.sensor_res = config->sensor_res; - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - return rc; - rc = _IrsCameraEntryAlloc(IrCameraHandle, &entry); if (R_FAILED(rc)) return rc; @@ -229,18 +213,18 @@ Result irsRunImageTransferProcessor(u32 IrCameraHandle, IrsImageTransferProcesso rc = tmemCreate(&entry->transfermem, size, Perm_None); if (R_FAILED(rc)) return rc; - rc = _irsRunImageTransferProcessor(IrCameraHandle, AppletResourceUserId, &packed_config, &entry->transfermem); + rc = _irsRunImageTransferProcessor(IrCameraHandle, &packed_config, &entry->transfermem); if (R_FAILED(rc)) _IrsCameraEntryFree(entry); return rc; } -static Result _irsGetImageTransferProcessorState(u32 IrCameraHandle, u64 AppletResourceUserId, void* buffer, size_t size, IrsImageTransferProcessorState *state) { +Result irsGetImageTransferProcessorState(u32 IrCameraHandle, void* buffer, size_t size, IrsImageTransferProcessorState *state) { const struct { u32 IrCameraHandle; u64 AppletResourceUserId; - } in = { IrCameraHandle, AppletResourceUserId }; + } in = { IrCameraHandle, appletGetAppletResourceUserId() }; return serviceDispatchInOut(&g_irsSrv, 309, in, *state, .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out }, @@ -249,18 +233,6 @@ static Result _irsGetImageTransferProcessorState(u32 IrCameraHandle, u64 AppletR ); } -Result irsGetImageTransferProcessorState(u32 IrCameraHandle, void* buffer, size_t size, IrsImageTransferProcessorState *state) { - Result rc=0; - u64 AppletResourceUserId=0; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - return rc; - - rc = _irsGetImageTransferProcessorState(IrCameraHandle, AppletResourceUserId, buffer, size, state); - return rc; -} - void irsGetDefaultImageTransferProcessorConfig(IrsImageTransferProcessorConfig *config) { memset(config, 0, sizeof(IrsImageTransferProcessorConfig)); @@ -276,26 +248,13 @@ Result irsGetIrCameraHandle(u32 *IrCameraHandle, HidControllerID id) { return serviceDispatchInOut(&g_irsSrv, 311, tmp, *IrCameraHandle); } -static Result _irsSuspendImageProcessor(u32 IrCameraHandle, u64 AppletResourceUserId) { +Result irsSuspendImageProcessor(u32 IrCameraHandle) { const struct { u32 IrCameraHandle; u64 AppletResourceUserId; - } in = { IrCameraHandle, AppletResourceUserId }; + } in = { IrCameraHandle, appletGetAppletResourceUserId() }; return serviceDispatchIn(&g_irsSrv, 313, in, .in_send_pid = true, ); } - -Result irsSuspendImageProcessor(u32 IrCameraHandle) { - Result rc=0; - u64 AppletResourceUserId=0; - - rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_FAILED(rc)) - return rc; - - rc = _irsSuspendImageProcessor(IrCameraHandle, AppletResourceUserId); - return rc; -} - diff --git a/nx/source/services/ldr.c b/nx/source/services/ldr.c index a7708c15..e0e5f911 100644 --- a/nx/source/services/ldr.c +++ b/nx/source/services/ldr.c @@ -45,7 +45,7 @@ Result ldrShellSetProgramArguments(u64 program_id, const void *args, size_t args return _ldrSetProgramArguments(&g_ldrShellSrv, program_id, args, args_size); } -Result ldrShellClearLaunchQueue(void) { +Result ldrShellFlushArguments(void) { return _ldrFlushArguments(&g_ldrShellSrv); } @@ -53,7 +53,7 @@ Result ldrDmntSetProgramArguments(u64 program_id, const void *args, size_t args_ return _ldrSetProgramArguments(&g_ldrDmntSrv, program_id, args, args_size); } -Result ldrDmntClearLaunchQueue(void) { +Result ldrDmntFlushArguments(void) { return _ldrFlushArguments(&g_ldrDmntSrv); } diff --git a/nx/source/services/nfc.c b/nx/source/services/nfc.c index 062a505a..e3a28bb1 100644 --- a/nx/source/services/nfc.c +++ b/nx/source/services/nfc.c @@ -23,7 +23,7 @@ static const NfcRequiredMcuVersionData g_nfcVersionData[2] = { }; static Result _nfcCreateInterface(Service* srv, Service* srv_out); -static Result _nfcInterfaceInitialize(Service* srv, u64 aruid, const NfcRequiredMcuVersionData *version, s32 count, u32 cmd_id); +static Result _nfcInterfaceInitialize(Service* srv, const NfcRequiredMcuVersionData *version, s32 count, u32 cmd_id); static Result _nfcCmdNoIO(Service* srv, u32 cmd_id); static Result _nfcCmdInDevhandleNoOut(Service* srv, const NfcDeviceHandle *handle, u32 cmd_id); @@ -34,10 +34,6 @@ NX_GENERATE_SERVICE_GUARD_PARAMS(nfp, (NfpServiceType service_type), (service_ty Result _nfpInitialize(NfpServiceType service_type) { Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); - u64 aruid = 0; - - // If this fails (for example because we're a sysmodule) aruid stays zero - appletGetAppletResourceUserId(&aruid); g_nfpServiceType = service_type; switch (g_nfpServiceType) { @@ -59,7 +55,7 @@ Result _nfpInitialize(NfpServiceType service_type) { rc = _nfcCreateInterface(&g_nfpSrv, &g_nfpInterface); if (R_SUCCEEDED(rc)) - rc = _nfcInterfaceInitialize(&g_nfpInterface, aruid, g_nfcVersionData, 2, 0); + rc = _nfcInterfaceInitialize(&g_nfpInterface, g_nfcVersionData, 2, 0); return rc; } @@ -74,10 +70,6 @@ NX_GENERATE_SERVICE_GUARD_PARAMS(nfc, (NfcServiceType service_type), (service_ty Result _nfcInitialize(NfcServiceType service_type) { Result rc=0; - u64 aruid = 0; - - // If this fails (for example because we're a sysmodule) aruid stays zero - appletGetAppletResourceUserId(&aruid); g_nfcServiceType = service_type; switch (g_nfcServiceType) { @@ -96,7 +88,7 @@ Result _nfcInitialize(NfcServiceType service_type) { rc = _nfcCreateInterface(&g_nfcSrv, &g_nfcInterface); if (R_SUCCEEDED(rc)) - rc = _nfcInterfaceInitialize(&g_nfcInterface, aruid, g_nfcVersionData, 2, hosversionBefore(4,0,0) ? 0 : 400); + rc = _nfcInterfaceInitialize(&g_nfcInterface, g_nfcVersionData, 2, hosversionBefore(4,0,0) ? 0 : 400); return rc; } @@ -199,11 +191,11 @@ static Result _nfcCmdInDevhandleOutBuffer(Service* srv, const NfcDeviceHandle *h ); } -static Result _nfcInterfaceInitialize(Service* srv, u64 aruid, const NfcRequiredMcuVersionData *version, s32 count, u32 cmd_id) { +static Result _nfcInterfaceInitialize(Service* srv, const NfcRequiredMcuVersionData *version, s32 count, u32 cmd_id) { const struct { u64 aruid; u64 zero; - } in = { aruid, 0 }; + } in = { appletGetAppletResourceUserId(), 0 }; serviceAssumeDomain(srv); return serviceDispatchIn(srv, cmd_id, in, diff --git a/nx/source/services/nv.c b/nx/source/services/nv.c index 2c0b1373..80a2a7cb 100644 --- a/nx/source/services/nv.c +++ b/nx/source/services/nv.c @@ -21,7 +21,6 @@ NX_GENERATE_SERVICE_GUARD(nv); Result _nvInitialize(void) { Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); - u64 AppletResourceUserId = 0; switch (appletGetAppletType()) { case AppletType_None: @@ -56,10 +55,10 @@ Result _nvInitialize(void) { rc = serviceCloneEx(&g_nvSrv, 1, &g_nvSrvClone); if (R_SUCCEEDED(rc)) { - // Send aruid if available (non-fatal condition if get-aruid fails) - Result aruid_rc = appletGetAppletResourceUserId(&AppletResourceUserId); - if (R_SUCCEEDED(aruid_rc)) - rc = _nvSetClientPID(AppletResourceUserId); + // Send aruid if available + u64 aruid = appletGetAppletResourceUserId(); + if (aruid) + rc = _nvSetClientPID(aruid); } } diff --git a/nx/source/services/set.c b/nx/source/services/set.c index 3655e81f..131a5e07 100644 --- a/nx/source/services/set.c +++ b/nx/source/services/set.c @@ -727,7 +727,7 @@ Result setsysSetChineseTraditionalInputMethod(SetChineseTraditionalInputMethod m } Result setsysGetHomeMenuScheme(SetSysHomeMenuScheme *out) { - if (hosversionBefore(9,0,0)) + if (hosversionBefore(8,1,1)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return serviceDispatchOut(&g_setsysSrv, 174, *out); diff --git a/nx/source/services/spl.c b/nx/source/services/spl.c index fb267182..239d56b0 100644 --- a/nx/source/services/spl.c +++ b/nx/source/services/spl.c @@ -118,7 +118,7 @@ static void _spl##name##Cleanup() { \ splExit(); \ } \ } \ -Service* _spl##name##GetServiceSession() { \ +Service* spl##name##GetServiceSession() { \ return _splGet##name##Srv(); \ } diff --git a/nx/source/services/vi.c b/nx/source/services/vi.c index 367dad51..db661701 100644 --- a/nx/source/services/vi.c +++ b/nx/source/services/vi.c @@ -285,7 +285,7 @@ Result viSetContentVisibility(bool v) { return serviceDispatchIn(&g_viIManagerDisplayService, 7000, tmp); } -static Result _viOpenLayer(const ViDisplay *display, u64 layer_id, u64 aruid, u8 native_window[0x100], u64 *native_window_size) { +static Result _viOpenLayer(const ViDisplay *display, u64 layer_id, u8 native_window[0x100], u64 *native_window_size) { if (!display->initialized) { return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); } @@ -294,7 +294,7 @@ static Result _viOpenLayer(const ViDisplay *display, u64 layer_id, u64 aruid, u8 ViDisplayName display_name; u64 layer_id; u64 aruid; - } in = { display->display_name, layer_id, aruid }; + } in = { display->display_name, layer_id, appletGetAppletResourceUserId() }; return serviceDispatchInOut(&g_viIApplicationDisplayService, 2020, in, *native_window_size, .in_send_pid = true, .buffer_attrs = { SfBufferAttr_Out | SfBufferAttr_HipcMapAlias }, @@ -359,20 +359,17 @@ Result viCreateLayer(const ViDisplay *display, ViLayer *layer) { alignas(8) u8 native_window_raw[0x100]; u64 native_window_size = 0; - u64 aruid = 0; - appletGetAppletResourceUserId(&aruid); // failure is not fatal - memset(layer, 0, sizeof(ViLayer)); layer->layer_id = __nx_vi_layer_id; Result rc = 0; - if (!layer->layer_id && aruid) { + if (!layer->layer_id && appletGetAppletResourceUserId()) { rc = appletCreateManagedDisplayLayer(&layer->layer_id); if (R_FAILED(rc)) return rc; } if (layer->layer_id) { - rc = _viOpenLayer(display, layer->layer_id, aruid, native_window_raw, &native_window_size); + rc = _viOpenLayer(display, layer->layer_id, native_window_raw, &native_window_size); } else { layer->stray_layer = true; rc = _viCreateStrayLayer(display, __nx_vi_stray_layer_flags, &layer->layer_id, native_window_raw, &native_window_size); @@ -468,16 +465,14 @@ Result viSetLayerScalingMode(ViLayer *layer, ViScalingMode scaling_mode) { } Result viGetIndirectLayerImageMap(void* buffer, size_t size, s32 width, s32 height, u64 IndirectLayerConsumerHandle, u64 *out_size, u64 *out_stride) { - u64 aruid = 0; - Result rc = appletGetAppletResourceUserId(&aruid); - if (R_FAILED(rc)) return rc; + Result rc = 0; const struct { s64 width; s64 height; u64 IndirectLayerConsumerHandle; u64 aruid; - } in = { width, height, IndirectLayerConsumerHandle, aruid }; + } in = { width, height, IndirectLayerConsumerHandle, appletGetAppletResourceUserId() }; struct { s64 size;