├── sp2Module ├── libnx │ ├── nx │ │ ├── .gitignore │ │ ├── external │ │ │ └── bsd │ │ │ │ └── include │ │ │ │ ├── sys │ │ │ │ ├── poll.h │ │ │ │ ├── _iovec.h │ │ │ │ ├── ioctl.h │ │ │ │ └── _sockaddr_storage.h │ │ │ │ ├── arpa │ │ │ │ └── inet.h │ │ │ │ └── netinet │ │ │ │ └── udp.h │ │ ├── default_icon.jpg │ │ ├── data │ │ │ └── default_font.bin │ │ ├── include │ │ │ ├── switch │ │ │ │ ├── runtime │ │ │ │ │ ├── nxlink.h │ │ │ │ │ ├── devices │ │ │ │ │ │ ├── usb_comms.h │ │ │ │ │ │ ├── fs_dev.h │ │ │ │ │ │ └── socket.h │ │ │ │ │ └── hosversion.h │ │ │ │ ├── nvidia │ │ │ │ │ ├── gpu.h │ │ │ │ │ ├── channel.h │ │ │ │ │ ├── fence.h │ │ │ │ │ ├── address_space.h │ │ │ │ │ ├── map.h │ │ │ │ │ ├── graphic_buffer.h │ │ │ │ │ └── gpu_channel.h │ │ │ │ ├── services │ │ │ │ │ ├── spsm.h │ │ │ │ │ ├── csrng.h │ │ │ │ │ ├── apm.h │ │ │ │ │ ├── fsldr.h │ │ │ │ │ ├── smm.h │ │ │ │ │ ├── bpc.h │ │ │ │ │ ├── auddev.h │ │ │ │ │ ├── caps.h │ │ │ │ │ ├── pcv.h │ │ │ │ │ ├── fspr.h │ │ │ │ │ ├── lbl.h │ │ │ │ │ ├── hidsys.h │ │ │ │ │ ├── ro.h │ │ │ │ │ ├── wlaninf.h │ │ │ │ │ ├── i2c.h │ │ │ │ │ ├── capssu.h │ │ │ │ │ ├── nv.h │ │ │ │ │ ├── gpio.h │ │ │ │ │ ├── psc.h │ │ │ │ │ ├── capssc.h │ │ │ │ │ ├── pl.h │ │ │ │ │ ├── time.h │ │ │ │ │ ├── hwopus.h │ │ │ │ │ ├── ldr.h │ │ │ │ │ ├── lr.h │ │ │ │ │ ├── psm.h │ │ │ │ │ ├── nifm.h │ │ │ │ │ ├── sfdnsres.h │ │ │ │ │ ├── pm.h │ │ │ │ │ ├── audin.h │ │ │ │ │ ├── audout.h │ │ │ │ │ └── acc.h │ │ │ │ ├── arm │ │ │ │ │ ├── tls.h │ │ │ │ │ ├── atomics.h │ │ │ │ │ ├── counter.h │ │ │ │ │ └── cache.h │ │ │ │ ├── audio │ │ │ │ │ └── audio.h │ │ │ │ ├── kernel │ │ │ │ │ ├── random.h │ │ │ │ │ ├── barrier.h │ │ │ │ │ ├── event.h │ │ │ │ │ ├── rwlock.h │ │ │ │ │ ├── semaphore.h │ │ │ │ │ ├── uevent.h │ │ │ │ │ ├── virtmem.h │ │ │ │ │ ├── utimer.h │ │ │ │ │ ├── mutex.h │ │ │ │ │ ├── jit.h │ │ │ │ │ ├── detect.h │ │ │ │ │ ├── condvar.h │ │ │ │ │ ├── shmem.h │ │ │ │ │ └── thread.h │ │ │ │ ├── nro.h │ │ │ │ ├── display │ │ │ │ │ ├── parcel.h │ │ │ │ │ ├── binder.h │ │ │ │ │ └── buffer_producer.h │ │ │ │ ├── nacp.h │ │ │ │ └── types.h │ │ │ └── machine │ │ │ │ └── _threads.h │ │ ├── switch.specs │ │ ├── source │ │ │ ├── runtime │ │ │ │ ├── readtp.s │ │ │ │ ├── hosversion.c │ │ │ │ ├── util │ │ │ │ │ └── utf │ │ │ │ │ │ ├── encode_utf16.c │ │ │ │ │ │ ├── decode_utf16.c │ │ │ │ │ │ ├── utf8_to_utf32.c │ │ │ │ │ │ ├── utf16_to_utf32.c │ │ │ │ │ │ ├── utf32_to_utf16.c │ │ │ │ │ │ ├── utf32_to_utf8.c │ │ │ │ │ │ ├── utf8_to_utf16.c │ │ │ │ │ │ ├── encode_utf8.c │ │ │ │ │ │ ├── utf16_to_utf8.c │ │ │ │ │ │ └── decode_utf8.c │ │ │ │ ├── nxlink.c │ │ │ │ ├── dynamic.c │ │ │ │ ├── nxlink_stdio.c │ │ │ │ ├── nacp.c │ │ │ │ └── switch_crt0.s │ │ │ ├── kernel │ │ │ │ ├── condvar.c │ │ │ │ ├── barrier.c │ │ │ │ ├── semaphore.c │ │ │ │ ├── rwlock.c │ │ │ │ ├── event.c │ │ │ │ ├── shmem.c │ │ │ │ ├── uevent.c │ │ │ │ ├── wait.h │ │ │ │ └── mutex.c │ │ │ ├── internal.h │ │ │ ├── nvidia │ │ │ │ ├── channel.c │ │ │ │ ├── gpu.c │ │ │ │ └── ioctl │ │ │ │ │ └── nvhost-ctrl-gpu.c │ │ │ ├── audio │ │ │ │ ├── sink.c │ │ │ │ ├── mix_object.c │ │ │ │ ├── driver_internal.h │ │ │ │ └── mempool.c │ │ │ ├── services │ │ │ │ ├── csrng.c │ │ │ │ ├── capssc.c │ │ │ │ ├── spsm.c │ │ │ │ ├── smm.c │ │ │ │ ├── fatal.c │ │ │ │ ├── wlaninf.c │ │ │ │ ├── i2c.c │ │ │ │ ├── capssu.c │ │ │ │ └── bpc.c │ │ │ ├── arm │ │ │ │ └── cache.s │ │ │ └── display │ │ │ │ └── default_window.c │ │ └── switch_rules │ ├── Makefile │ ├── .gitignore │ ├── README.md │ ├── CODESTYLE.md │ ├── LICENSE.md │ └── .doozer.json ├── Makefile ├── .gitignore ├── sp2Module │ ├── source │ │ ├── Result.hpp │ │ ├── ProcessMemory.hpp │ │ ├── FsLogger.hpp │ │ ├── TcpLogger.hpp │ │ ├── ArmNeon.cpp │ │ ├── ArmNeon.hpp │ │ ├── Result.cpp │ │ ├── Pong │ │ │ └── PongGame.hpp │ │ ├── Draw.hpp │ │ ├── ProcessMemory.cpp │ │ ├── TcpLogger.cpp │ │ └── FsLogger.cpp │ └── patchConfig.txt ├── libnx changes.txt ├── README.md └── .vscode │ ├── c_cpp_properties.json │ └── settings.json ├── README.md └── Sp2Patcher ├── README.md ├── Sp2Patcher ├── packages.config ├── App.config ├── Properties │ └── AssemblyInfo.cs ├── ListingFile.cs └── Sp2Patcher.csproj └── Sp2Patcher.sln /sp2Module/libnx/nx/.gitignore: -------------------------------------------------------------------------------- 1 | debug 2 | release 3 | lib 4 | 5 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/external/bsd/include/sys/poll.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/default_icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Random06457/Sp2Module/HEAD/sp2Module/libnx/nx/default_icon.jpg -------------------------------------------------------------------------------- /sp2Module/libnx/nx/data/default_font.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Random06457/Sp2Module/HEAD/sp2Module/libnx/nx/data/default_font.bin -------------------------------------------------------------------------------- /sp2Module/libnx/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C nx/ 3 | 4 | install: 5 | $(MAKE) -C nx/ install 6 | 7 | clean: 8 | $(MAKE) -C nx/ clean 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sp2Module 2 | 3 | Sp2Module: The c++ code that'll run in the game 4 | 5 | Sp2Patcher: The patcher that'll be used to apply patches easily 6 | -------------------------------------------------------------------------------- /sp2Module/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | $(MAKE) -C libnx/nx/ 3 | $(MAKE) -C sp2Module/ 4 | clean: 5 | $(MAKE) -C libnx/nx/ clean 6 | $(MAKE) -C sp2Module/ clean 7 | -------------------------------------------------------------------------------- /Sp2Patcher/README.md: -------------------------------------------------------------------------------- 1 | # Sp2Patcher 2 | 3 | This is a patcher that'll apply some modifications to the binaries in order to make our custom code valid and to hook game's code to it -------------------------------------------------------------------------------- /Sp2Patcher/Sp2Patcher/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /sp2Module/libnx/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | *.bz2 4 | *.nro 5 | *.nso 6 | *.elf 7 | *.npdm 8 | *.pfs0 9 | Thumbs.db 10 | .*/ 11 | debug/ 12 | release/ 13 | lib/ 14 | docs/ 15 | -------------------------------------------------------------------------------- /sp2Module/.gitignore: -------------------------------------------------------------------------------- 1 | *.bat 2 | *.exe 3 | *.dll 4 | *.zip 5 | *.nso 6 | *.nsp 7 | *.npdm 8 | *.elf 9 | **/build 10 | 11 | rtld 12 | main 13 | sdk 14 | subsdk0 15 | 16 | .vscode/ipch -------------------------------------------------------------------------------- /Sp2Patcher/Sp2Patcher/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/runtime/nxlink.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct in_addr; 4 | 5 | extern struct in_addr __nxlink_host; 6 | 7 | #define NXLINK_SERVER_PORT 28280 8 | #define NXLINK_CLIENT_PORT 28771 9 | 10 | int nxlinkStdio(void); 11 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/switch.specs: -------------------------------------------------------------------------------- 1 | %rename link old_link 2 | 3 | *link: 4 | %(old_link) -T %:getenv(DEVKITPRO /libnx/switch.ld) -pie --gc-sections -z text -z nodynamic-undefined-weak --build-id=sha1 5 | 6 | *startfile: 7 | crti%O%s crtbegin%O%s 8 | 9 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/nvidia/gpu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | #include "ioctl.h" 4 | 5 | Result nvGpuInit(void); 6 | void nvGpuExit(void); 7 | 8 | const nvioctl_gpu_characteristics* nvGpuGetCharacteristics(void); 9 | u32 nvGpuGetZcullCtxSize(void); 10 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/readtp.s: -------------------------------------------------------------------------------- 1 | .section .text.__aarch64_read_tp, "ax", %progbits 2 | .global __aarch64_read_tp 3 | .type __aarch64_read_tp, %function 4 | .align 2 5 | .cfi_startproc 6 | __aarch64_read_tp: 7 | mrs x0, tpidrro_el0 8 | ldr x0, [x0, #0x1F8] 9 | ret 10 | .cfi_endproc 11 | -------------------------------------------------------------------------------- /sp2Module/libnx/README.md: -------------------------------------------------------------------------------- 1 | # Nintendo Switch AArch64-only userland library. 2 | Based on libctru. 3 | 4 | [![Build status](https://doozer.io/badge/switchbrew/libnx/buildstatus/master)](https://doozer.io/switchbrew/libnx) 5 | 6 | # Install instructions 7 | See [Switchbrew](https://switchbrew.org/wiki/Setting_up_Development_Environment). 8 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/hosversion.c: -------------------------------------------------------------------------------- 1 | #include "runtime/hosversion.h" 2 | 3 | static u32 g_hosVersion; 4 | 5 | u32 hosversionGet(void) 6 | { 7 | return __atomic_load_n(&g_hosVersion, __ATOMIC_SEQ_CST); 8 | } 9 | 10 | void hosversionSet(u32 version) 11 | { 12 | __atomic_store_n(&g_hosVersion, version, __ATOMIC_SEQ_CST); 13 | } 14 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/spsm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file spsm.h 3 | * @brief SPSM service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | Result spsmInitialize(void); 11 | void spsmExit(void); 12 | 13 | Result spsmShutdown(bool reboot); 14 | Result spsmPutErrorState(void); 15 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/csrng.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file csrng.h 3 | * @brief Cryptographically-Secure Random Number Generation (csrng) service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | Result csrngInitialize(void); 11 | void csrngExit(void); 12 | 13 | Result csrngGetRandomBytes(void *out, size_t out_size); 14 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/nvidia/channel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | #include "ioctl.h" 4 | 5 | typedef struct NvChannel { 6 | u32 fd; 7 | bool has_init; 8 | } NvChannel; 9 | 10 | Result nvChannelCreate(NvChannel* c, const char* dev); 11 | void nvChannelClose(NvChannel* c); 12 | 13 | Result nvChannelSetPriority(NvChannel* c, NvChannelPriority prio); 14 | Result nvChannelSetTimeout(NvChannel* c, u32 timeout); 15 | -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/Result.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Sp2Utils.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | enum class Sp2Error : u32 11 | { 12 | Breakpoint = 0, 13 | setInitialize = 1, 14 | fsInitialize = 2, 15 | setMakeLanguageCode = 3, 16 | nnSocket = 4, 17 | nnSocketConnect = 5, 18 | }; 19 | 20 | void showAppError(const char* format, ...); -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/ProcessMemory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class ProcessMemory 6 | { 7 | public: 8 | static u64 ModuleAddr(u64 addr, int moduleIndex); 9 | static u64 ImageAddr(u64 addr); 10 | static u64 RtldAddr(u64 addr); 11 | static u64 MainAddr(u64 addr); 12 | static u64 SdkAddr(u64 addr); 13 | static u64 ThisAddr(u64 addr); 14 | static HidSharedMemory* GetHidSharedMemory(); 15 | }; -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/FsLogger.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include "Sp2Utils.hpp" 9 | #include "Result.hpp" 10 | 11 | class FsLogger 12 | { 13 | public: 14 | static void Initialize(); 15 | static void Log(u8* data, size_t size); 16 | static void Log(std::string str); 17 | static void Log(std::vector vec); 18 | static void LogFormat(const char* format, ...); 19 | }; -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/arm/tls.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file tls.h 3 | * @brief AArch64 thread local storage. 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | /** 11 | * @brief Gets the thread local storage buffer. 12 | * @return The thread local storage buffer. 13 | */ 14 | static inline void* armGetTls(void) { 15 | void* ret; 16 | __asm__ ("mrs %x[data], tpidrro_el0" : [data] "=r" (ret)); 17 | return ret; 18 | } 19 | -------------------------------------------------------------------------------- /sp2Module/libnx changes.txt: -------------------------------------------------------------------------------- 1 | https://github.com/switchbrew/libnx/tree/2729cafbe08d0b21fa7923d0eebef9f129e6e97a 2 | 3 | ---------------sm.c / sm.h----------------------- 4 | void smSetHandle(Handle session) 5 | { 6 | g_smHandle = session; 7 | } 8 | 9 | -----------------switch.h---------------------- 10 | #include "switch/services/bsd.h" 11 | 12 | ----------------hid.c/hid.h-------------------- 13 | 14 | void hidSetSharedMemPtr(HidSharedMemory* mem) 15 | { 16 | g_overwriteSharedMemPtr = mem; 17 | } -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/util/utf/encode_utf16.c: -------------------------------------------------------------------------------- 1 | #include "runtime/util/utf.h" 2 | 3 | ssize_t 4 | encode_utf16(uint16_t *out, 5 | uint32_t in) 6 | { 7 | if(in < 0x10000) 8 | { 9 | if(out != NULL) 10 | *out++ = in; 11 | return 1; 12 | } 13 | else if(in < 0x110000) 14 | { 15 | if(out != NULL) 16 | { 17 | *out++ = (in >> 10) + 0xD7C0; 18 | *out++ = (in & 0x3FF) + 0xDC00; 19 | } 20 | return 2; 21 | } 22 | 23 | return -1; 24 | } 25 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/kernel/condvar.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 plutoo 2 | #include "types.h" 3 | #include "result.h" 4 | #include "kernel/svc.h" 5 | #include "kernel/condvar.h" 6 | #include "../internal.h" 7 | 8 | Result condvarWaitTimeout(CondVar* c, Mutex* m, u64 timeout) { 9 | Result rc; 10 | 11 | rc = svcWaitProcessWideKeyAtomic((u32*)m, c, getThreadVars()->handle, timeout); 12 | 13 | // On timeout, we need to acquire it manually. 14 | if (rc == 0xEA01) 15 | mutexLock(m); 16 | 17 | return rc; 18 | } 19 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/audio/audio.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file audio.h 3 | * @brief Global audio service. 4 | * @author hexkyz 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | 9 | #include "../types.h" 10 | 11 | typedef enum { 12 | PcmFormat_Invalid = 0, 13 | PcmFormat_Int8 = 1, 14 | PcmFormat_Int16 = 2, 15 | PcmFormat_Int24 = 3, 16 | PcmFormat_Int32 = 4, 17 | PcmFormat_Float = 5, 18 | PcmFormat_Adpcm = 6, 19 | } PcmFormat; 20 | 21 | typedef struct { 22 | char name[0x100]; 23 | } AudioDeviceName; 24 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/apm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file apm.h 3 | * @brief Performance management (apm) service IPC wrapper. 4 | * @author yellows8 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | /// These are used internally by applet. 11 | 12 | Result apmInitialize(void); 13 | void apmExit(void); 14 | 15 | Result apmSetPerformanceConfiguration(u32 PerformanceMode, u32 PerformanceConfiguration); 16 | Result apmGetPerformanceConfiguration(u32 PerformanceMode, u32 *PerformanceConfiguration); 17 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/fsldr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file fsldr.h 3 | * @brief FilesystemProxy-ForLoader (fsp-ldr) service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../services/sm.h" 10 | #include "../services/fs.h" 11 | 12 | Result fsldrInitialize(void); 13 | void fsldrExit(void); 14 | 15 | Result fsldrOpenCodeFileSystem(u64 tid, const char *path, FsFileSystem* out); 16 | Result fsldrIsArchivedProgram(u64 pid, bool *out); 17 | Result fsldrSetCurrentProcess(void); -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/smm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file smm.h 3 | * @brief ServiceManager-IManager (sm:m) service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../services/sm.h" 10 | #include "../services/fs.h" 11 | 12 | Result smManagerInitialize(void); 13 | void smManagerExit(void); 14 | 15 | Result smManagerRegisterProcess(u64 pid, const void *acid_sac, size_t acid_sac_size, const void *aci0_sac, size_t aci0_sac_size); 16 | Result smManagerUnregisterProcess(u64 pid); 17 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/kernel/barrier.c: -------------------------------------------------------------------------------- 1 | #include "kernel/barrier.h" 2 | 3 | void barrierInit(Barrier *b, u64 total) { 4 | b->count = 0; 5 | b->total = total - 1; 6 | mutexInit(&b->mutex); 7 | condvarInit(&b->condvar); 8 | } 9 | 10 | void barrierWait(Barrier *b) { 11 | mutexLock(&b->mutex); 12 | 13 | if (b->count++ == b->total) { 14 | b->count = 0; 15 | condvarWake(&b->condvar, b->total); 16 | } 17 | else { 18 | condvarWait(&b->condvar, &b->mutex); 19 | } 20 | 21 | mutexUnlock(&b->mutex); 22 | } 23 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/arm/atomics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../types.h" 3 | 4 | static inline u32 atomicIncrement32(u32* p) { 5 | return __atomic_fetch_add(p, 1, __ATOMIC_SEQ_CST); 6 | } 7 | 8 | static inline u32 atomicDecrement32(u32* p) { 9 | return __atomic_sub_fetch(p, 1, __ATOMIC_SEQ_CST); 10 | } 11 | 12 | static inline u64 atomicIncrement64(u64* p) { 13 | return __atomic_fetch_add(p, 1, __ATOMIC_SEQ_CST); 14 | } 15 | 16 | static inline u64 atomicDecrement64(u64* p) { 17 | return __atomic_sub_fetch(p, 1, __ATOMIC_SEQ_CST); 18 | } 19 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/nvidia/fence.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ioctl.h" 3 | 4 | typedef nvioctl_fence NvFence; 5 | 6 | typedef struct { 7 | u32 num_fences; 8 | NvFence fences[4]; 9 | } NvMultiFence; 10 | 11 | Result nvFenceInit(void); 12 | void nvFenceExit(void); 13 | 14 | Result nvFenceWait(NvFence* f, s32 timeout_us); 15 | 16 | static inline void nvMultiFenceCreate(NvMultiFence* mf, const NvFence* fence) { 17 | mf->num_fences = 1; 18 | mf->fences[0] = *fence; 19 | } 20 | 21 | Result nvMultiFenceWait(NvMultiFence* mf, s32 timeout_us); 22 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/util/utf/decode_utf16.c: -------------------------------------------------------------------------------- 1 | #include "runtime/util/utf.h" 2 | 3 | ssize_t 4 | decode_utf16(uint32_t *out, 5 | const uint16_t *in) 6 | { 7 | uint16_t code1, code2; 8 | 9 | code1 = *in++; 10 | if(code1 >= 0xD800 && code1 < 0xDC00) 11 | { 12 | /* surrogate pair */ 13 | code2 = *in++; 14 | if(code2 >= 0xDC00 && code2 < 0xE000) 15 | { 16 | *out = (code1 << 10) + code2 - 0x35FDC00; 17 | return 2; 18 | } 19 | 20 | return -1; 21 | } 22 | 23 | *out = code1; 24 | return 1; 25 | } 26 | -------------------------------------------------------------------------------- /sp2Module/libnx/CODESTYLE.md: -------------------------------------------------------------------------------- 1 | # Code Style 2 | 3 | ## Types 4 | `TypesAreCapitalizedLikeThis` 5 | 6 | ## Enums 7 | `EnumType_EnumName` 8 | 9 | ## Struct members 10 | `like_this` 11 | 12 | `notlikethis` 13 | 14 | ## Local variables 15 | `like_this` 16 | 17 | `notlikethis` 18 | 19 | ## Global variables (or global statics) 20 | `g_variableName` 21 | 22 | ## Functions 23 | `modulenameFunctionName` 24 | 25 | ### Submodule function naming 26 | Singletons use names like smInitialize/smExit 27 | 28 | Objects use names like tmemCreate/tmemClose 29 | 30 | ## Macros 31 | `LIKE_THIS` 32 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/bpc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file bpc.h 3 | * @brief Board power control (bpc) service IPC wrapper. 4 | * @author XorTroll, SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | typedef enum { 11 | BpcSleepButtonState_Held = 0, 12 | BpcSleepButtonState_Released = 1, 13 | } BpcSleepButtonState; 14 | 15 | Result bpcInitialize(void); 16 | void bpcExit(void); 17 | 18 | Result bpcShutdownSystem(void); 19 | Result bpcRebootSystem(void); 20 | Result bpcGetSleepButtonState(BpcSleepButtonState *out); 21 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/random.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file random.h 3 | * @brief OS-seeded pseudo-random number generation support (ChaCha algorithm). 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | /** 11 | * @brief Fills a buffer with random data. 12 | * @param buf Pointer to the buffer. 13 | * @param len Size of the buffer in bytes. 14 | */ 15 | void randomGet(void* buf, size_t len); 16 | 17 | /** 18 | * @brief Returns a random 64-bit value. 19 | * @return Random value. 20 | */ 21 | u64 randomGet64(void); 22 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/auddev.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file auddev.h 3 | * @brief Audio device. 4 | * @author yellows8 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | 9 | #include "../audio/audio.h" 10 | 11 | Result auddevInitialize(void); 12 | void auddevExit(void); 13 | 14 | Result auddevListAudioDeviceName(AudioDeviceName *DeviceNames, s32 max_names, s32 *total_names); 15 | Result auddevSetAudioDeviceOutputVolume(const AudioDeviceName *DeviceName, float volume); 16 | Result auddevGetAudioDeviceOutputVolume(const AudioDeviceName *DeviceName, float *volume); 17 | 18 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/caps.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file caps.h 3 | * @brief Common caps (caps:*) service IPC header. 4 | * @author yellows8 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../services/sm.h" 10 | 11 | typedef struct { 12 | u32 unk_x0; 13 | u8 unk_x4[0x3c]; 14 | } CapsScreenShotAttribute; 15 | 16 | /// AlbumEntry 17 | typedef struct { 18 | u8 unk_x0[0x20]; 19 | } CapsAlbumEntry; 20 | 21 | /// ApplicationAlbumEntry 22 | typedef struct { 23 | u8 unk_x0[0x20]; 24 | } CapsApplicationAlbumEntry; 25 | 26 | -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/TcpLogger.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include "Sp2Utils.hpp" 14 | #include "Result.hpp" 15 | 16 | class TcpLogger 17 | { 18 | public: 19 | static void Initialize(); 20 | static void Log(u8* data, size_t size); 21 | static void Log(std::string str); 22 | static void Log(std::vector vec); 23 | static void LogFormat(const char* format, ...); 24 | }; -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/pcv.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pcv.h 3 | * @brief PCV service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | typedef enum { 11 | PcvModule_Cpu = 0, 12 | PcvModule_Gpu = 1, 13 | PcvModule_Emc = 56, 14 | } PcvModule; 15 | 16 | Result pcvInitialize(void); 17 | void pcvExit(void); 18 | 19 | Result pcvGetClockRate(PcvModule module, u32 *out_hz); 20 | Result pcvSetClockRate(PcvModule module, u32 hz); 21 | Result pcvSetVoltageEnabled(bool state, u32 voltage); 22 | Result pcvGetVoltageEnabled(bool *isEnabled, u32 voltage); 23 | 24 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/nxlink.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | // System globals we define here 7 | extern int __system_argc; 8 | extern char** __system_argv; 9 | 10 | struct in_addr __nxlink_host; 11 | 12 | 13 | void nxlinkSetup(void) 14 | { 15 | if ( __system_argc > 1 && 16 | strlen(__system_argv[__system_argc - 1]) == 16 && 17 | strncmp(&__system_argv[__system_argc - 1][8], "_NXLINK_", 8) == 0 ) 18 | { 19 | __system_argc--; 20 | __nxlink_host.s_addr = strtoul(__system_argv[__system_argc], NULL, 16); 21 | } 22 | __system_argv[__system_argc] = NULL; 23 | } 24 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/fspr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file fspr.h 3 | * @brief FilesystemProxy-ProgramRegistry (fsp-pr) service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../services/sm.h" 10 | #include "../services/fs.h" 11 | 12 | Result fsprInitialize(void); 13 | void fsprExit(void); 14 | 15 | Result fsprRegisterProgram(u64 pid, u64 titleID, FsStorageId storageID, const void *fs_access_header, size_t fah_size, const void *fs_access_control, size_t fac_size); 16 | Result fsprUnregisterProgram(u64 pid); 17 | Result fsprSetCurrentProcess(void); 18 | Result fsprSetEnabledProgramVerification(bool enabled); 19 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/util/utf/utf8_to_utf32.c: -------------------------------------------------------------------------------- 1 | #include "runtime/util/utf.h" 2 | 3 | ssize_t 4 | utf8_to_utf32(uint32_t *out, 5 | const uint8_t *in, 6 | size_t len) 7 | { 8 | ssize_t rc = 0; 9 | ssize_t units; 10 | uint32_t code; 11 | 12 | do 13 | { 14 | units = decode_utf8(&code, in); 15 | if(units == -1) 16 | return -1; 17 | 18 | if(code > 0) 19 | { 20 | in += units; 21 | 22 | if(out != NULL) 23 | { 24 | if(rc < len) 25 | *out++ = code; 26 | } 27 | 28 | if(SSIZE_MAX - 1 >= rc) 29 | ++rc; 30 | else 31 | return -1; 32 | } 33 | } while(code > 0); 34 | 35 | return rc; 36 | } 37 | -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/ArmNeon.cpp: -------------------------------------------------------------------------------- 1 | #include "ArmNeon.hpp" 2 | 3 | 4 | /* maybe rewrite this part in asm for optimisation purpose */ 5 | 6 | 7 | float32x4_t vmlaq_lane_f32(float32x4_t* a, float32x4_t* b, float v) 8 | { 9 | float32x4_t f; 10 | for (size_t i = 0; i < 4; i++) 11 | f.f[i] = a->f[i] + (b->f[i] * v); 12 | return f; 13 | } 14 | float32x4_t vmulq_n_f32(float32x4_t* a, float b) 15 | { 16 | float32x4_t f; 17 | for (size_t i = 0; i < 4; i++) 18 | f.f[i] = a->f[i] * b; 19 | return f; 20 | } 21 | 22 | float32x4_t vaddq_f32(float32x4_t* a, float32x4_t* b) 23 | { 24 | float32x4_t f; 25 | for (size_t i = 0; i < 4; i++) 26 | f.f[i] = a->f[i] + b->f[i]; 27 | return f; 28 | } -------------------------------------------------------------------------------- /sp2Module/libnx/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2017-2018 libnx Authors 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 4 | 5 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/util/utf/utf16_to_utf32.c: -------------------------------------------------------------------------------- 1 | #include "runtime/util/utf.h" 2 | 3 | ssize_t 4 | utf16_to_utf32(uint32_t *out, 5 | const uint16_t *in, 6 | size_t len) 7 | { 8 | ssize_t rc = 0; 9 | ssize_t units; 10 | uint32_t code; 11 | 12 | do 13 | { 14 | units = decode_utf16(&code, in); 15 | if(units == -1) 16 | return -1; 17 | 18 | if(code > 0) 19 | { 20 | in += units; 21 | 22 | if(out != NULL) 23 | { 24 | if(rc < len) 25 | *out++ = code; 26 | } 27 | 28 | if(SSIZE_MAX - 1 >= rc) 29 | ++rc; 30 | else 31 | return -1; 32 | } 33 | } while(code > 0); 34 | 35 | return rc; 36 | } 37 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/lbl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lbl.h 3 | * @brief LBL service IPC wrapper. 4 | * @author SciresM, exelix 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | Result lblInitialize(void); 11 | void lblExit(void); 12 | 13 | Result lblSwitchBacklightOn(u64 fade_time); 14 | Result lblSwitchBacklightOff(u64 fade_time); 15 | 16 | /** 17 | * @note The brightness goes from 0 to 1.0. 18 | */ 19 | Result lblSetCurrentBrightnessSetting(float brightness); 20 | Result lblGetCurrentBrightnessSetting(float *out_value); 21 | 22 | Result lblEnableAutoBrightnessControl(void); 23 | Result lblDisableAutoBrightnessControl(void); 24 | Result lblIsAutoBrightnessControlEnabled(bool *out_value); 25 | -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/ArmNeon.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct float32x4_t; 6 | struct float32x2_t; 7 | 8 | #define ASSIGN_FARR(arr, f1, f2, f3, f4) arr[0] = f1; arr[1] = f2; arr[2] = f3; arr[3] = f4; 9 | 10 | struct float32x4_t 11 | { 12 | float32x4_t(float f1, float f2, float f3, float f4) 13 | { 14 | ASSIGN_FARR(f, f1, f2, f3, f4); 15 | } 16 | float32x4_t() 17 | { 18 | ASSIGN_FARR(f, 0, 0, 0, 0); 19 | } 20 | float f[4]; 21 | }; 22 | struct float32x2_t 23 | { 24 | float f[2]; 25 | }; 26 | 27 | float32x4_t vaddq_f32(float32x4_t* a, float32x4_t* b); 28 | float32x4_t vmlaq_lane_f32(float32x4_t* a, float32x4_t* b, float v); 29 | float32x4_t vmulq_n_f32(float32x4_t* a, float b); -------------------------------------------------------------------------------- /sp2Module/libnx/.doozer.json: -------------------------------------------------------------------------------- 1 | { 2 | "targets": { 3 | "lib": { 4 | 5 | "buildenv": "docker:devkitpro/devkita64", 6 | 7 | "buildcmd": [ 8 | "sudo -E make -j${PARALLEL} -C nx install" 9 | ] 10 | }, 11 | 12 | "docs": { 13 | // This target build and upload docs and will be trigged from doozer's CD script 14 | "auto": false, 15 | 16 | "buildenv": "xenial-amd64", 17 | "builddeps": [ 18 | "doxygen" 19 | ], 20 | 21 | "buildcmd": [ 22 | "cd nx", "doxygen" 23 | ], 24 | 25 | "artifacts": [{ 26 | "source": "nx/docs/html", 27 | "destination": { 28 | "type": "git", 29 | "branch": "gh-pages" 30 | } 31 | }] 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/util/utf/utf32_to_utf16.c: -------------------------------------------------------------------------------- 1 | #include "runtime/util/utf.h" 2 | 3 | 4 | ssize_t 5 | utf32_to_utf16(uint16_t *out, 6 | const uint32_t *in, 7 | size_t len) 8 | { 9 | ssize_t rc = 0; 10 | ssize_t units; 11 | uint16_t encoded[2]; 12 | 13 | while(*in > 0) 14 | { 15 | units = encode_utf16(encoded, *in++); 16 | if(units == -1) 17 | return -1; 18 | 19 | if(out != NULL) 20 | { 21 | if(rc + units <= len) 22 | { 23 | *out++ = encoded[0]; 24 | if(units > 1) 25 | *out++ = encoded[1]; 26 | } 27 | } 28 | 29 | if(SSIZE_MAX - units >= rc) 30 | rc += units; 31 | else 32 | return -1; 33 | } 34 | 35 | return rc; 36 | } 37 | -------------------------------------------------------------------------------- /sp2Module/README.md: -------------------------------------------------------------------------------- 1 | # Sp2Module 2 | This contains the c++ code that'll run with the game. 3 | 4 | This is currently just contains Pong as a POC that works on the version 2.3.1 of Splatoon 2. Preview here : https://twitter.com/random666_kys/status/1124817347414511622 5 | 6 | # Warning 7 | This project isn't for end users, any code modification will ban you on the latest versions of Splatoon if you go online 8 | 9 | # Setup 10 | - Grab `Sp2Patcher.exe` and `LZ4.dll` in the release section and copy them in `sp2Module/` 11 | - Create the folders `sp2Module/sp2` and `sp2Module/sp2_out` and copy your game's exefs content in `sp2` 12 | - Code whatever you want 13 | 14 | # Building 15 | After editing `sp2Module/patchConfig.txt`, run `make` and everything will be output in `sp2Module/sp2_out` 16 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/hidsys.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hidsys.h 3 | * @brief hid:sys service IPC wrapper. 4 | * @author exelix 5 | */ 6 | #pragma once 7 | #include "../types.h" 8 | #include "../kernel/event.h" 9 | #include "../services/sm.h" 10 | 11 | Result hidsysInitialize(void); 12 | void hidsysExit(void); 13 | 14 | Result hidsysEnableAppletToGetInput(bool enable); 15 | 16 | /** 17 | * @brief Returns an event that fires when the home button is pressed, this will prevent the home menu from opening when the button is pressed. This event does not auto clear. 18 | **/ 19 | Result hidsysAcquireHomeButtonEventHandle(Event* event_out); 20 | 21 | Result hidsysActivateHomeButton(void); 22 | Result hidsysActivateSleepButton(void); 23 | Result hidsysActivateCaptureButton(void); 24 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/ro.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ro.h 3 | * @brief Relocatable Objects (ro) service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../services/sm.h" 10 | #include "../services/ldr.h" 11 | 12 | Result ldrRoInitialize(void); 13 | void ldrRoExit(void); 14 | 15 | Result roDmntInitialize(void); 16 | void roDmntExit(void); 17 | 18 | Result ldrRoLoadNro(u64* out_address, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size); 19 | Result ldrRoUnloadNro(u64 nro_address); 20 | Result ldrRoLoadNrr(u64 nrr_address, u64 nrr_size); 21 | Result ldrRoUnloadNrr(u64 nrr_address); 22 | 23 | Result roDmntGetModuleInfos(u64 pid, LoaderModuleInfo *out_module_infos, size_t out_size, u32 *num_out); 24 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/machine/_threads.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../switch/types.h" 3 | #include "../switch/result.h" 4 | #include "../switch/kernel/mutex.h" 5 | #include "../switch/kernel/condvar.h" 6 | #include "../switch/kernel/thread.h" 7 | 8 | #define TSS_DTOR_ITERATIONS 1 9 | 10 | typedef struct { 11 | Thread thr; 12 | int rc; 13 | } __thrd_t; 14 | 15 | typedef CondVar cnd_t; 16 | typedef __thrd_t* thrd_t; 17 | typedef u32 tss_t; 18 | 19 | #define _MTX_INITIALIZER_NP {mtx_plain, {0}} 20 | typedef struct mtx_t { 21 | int type; 22 | union { 23 | Mutex mutex; 24 | RMutex rmutex; 25 | }; 26 | } mtx_t; 27 | 28 | #define ONCE_FLAG_INIT {0,_MTX_INITIALIZER_NP,0} 29 | typedef struct once_flag_t { 30 | int status; 31 | mtx_t mutex; 32 | cnd_t cond; 33 | } once_flag; 34 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/wlaninf.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file wlaninf.h 3 | * @brief WLAN InfraManager service IPC wrapper. 4 | * @author natinusala 5 | * @copyright libnx Authors 6 | */ 7 | 8 | #pragma once 9 | #include "../kernel/ipc.h" 10 | #include "../services/sm.h" 11 | 12 | /// WLAN State. 13 | typedef enum { 14 | WlanInfState_NotConnected = 1, ///< WLAN is disabled or enabled and not connected. 15 | WlanInfState_Connecting, ///< WLAN is connecting. 16 | WlanInfState_Connected, ///< WLAN is connected. 17 | } WlanInfState; 18 | 19 | Result wlaninfInitialize(void); 20 | void wlaninfExit(void); 21 | 22 | Result wlaninfGetState(WlanInfState* out); 23 | 24 | /// Value goes from -30 (really good signal) to -90 (barely enough to stay connected) 25 | /// on a logarithmic scale 26 | Result wlaninfGetRSSI(s32* out); 27 | -------------------------------------------------------------------------------- /sp2Module/sp2Module/patchConfig.txt: -------------------------------------------------------------------------------- 1 | #get the smHandle 2 | b -> sdk+0xA9D74 -> !svcConnectToNamedPortHook(unsigned int*, char*) 3 | 4 | #test 5 | bl -> main+0x808EC -> !ret_ShootinRangeName() 6 | 7 | #nn::socket::initialize 8 | b -> sdk+0x9AD70 -> !socketInitHook() 9 | 10 | #patch nn::diag::detail::PutImpl & nn::diag::detail::LogImpl 11 | b -> main+0x1553FC4 -> !diagPutImplHook(nn::diag::LogMetaData*, char const*, unsigned long) 12 | b -> main+0x1551454 -> !diagLogImplHook(nn::diag::LogMetaData*, char const*, ...) 13 | 14 | 15 | #MiniGame Draw Hook 16 | b -> main+0xC55274 -> !MiniGameEtcDrawHook(void*, agl::lyr::RenderInfo*) 17 | 18 | #disable layout text draw 19 | b -> main+0xC5CA6C -> !MiniGameSetTextBoxHook(void*) 20 | b -> main+0xC5CA88 -> !MiniGameSetTextBoxHook(void*) 21 | 22 | #disable MiniGame play (mov w1, #2) 23 | data -> main+0xC5B0DC -> 41008052 -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/Result.cpp: -------------------------------------------------------------------------------- 1 | #include "Result.hpp" 2 | 3 | //shouldn't be called too early 4 | 5 | void showAppError(const char* format, ...) 6 | { 7 | char buff[0x1000]; 8 | va_list args; 9 | Result rc; 10 | static u64 LanguageCode = 0; 11 | nn::err::ApplicationErrorArg arg; 12 | 13 | memset(&arg, 0, sizeof(arg)); 14 | memset(buff, 0, sizeof(buff)); 15 | 16 | if (!LanguageCode) 17 | { 18 | rc = setMakeLanguageCode(SetLanguage_FR, &LanguageCode); 19 | if (R_FAILED(rc)) 20 | nn::err::ShowError((u32)Sp2Error::setMakeLanguageCode); 21 | } 22 | 23 | va_start(args, format); 24 | vsnprintf(buff, sizeof(buff), format, args); 25 | 26 | nn::err::ApplicationErrorArg_Constructor2(&arg, 0, buff, buff, &LanguageCode); 27 | nn::err::ShowApplicationError(&arg); 28 | 29 | va_end (args); 30 | } -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/i2c.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file i2c.h 3 | * @brief I2C service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "sm.h" 10 | 11 | typedef enum { 12 | I2cDevice_AudioCodec = 4, 13 | } I2cDevice; 14 | 15 | typedef struct { 16 | Service s; 17 | } I2cSession; 18 | 19 | typedef enum { 20 | I2cTransactionOption_Start = (1 << 0), 21 | I2cTransactionOption_Stop = (1 << 1), 22 | 23 | I2cTransactionOption_All = I2cTransactionOption_Start | I2cTransactionOption_Stop, 24 | } I2cTransactionOption; 25 | 26 | Result i2cInitialize(void); 27 | void i2cExit(void); 28 | 29 | Result i2cOpenSession(I2cSession *out, I2cDevice dev); 30 | 31 | Result i2csessionSendAuto(I2cSession *s, void *buf, size_t size, I2cTransactionOption option); 32 | void i2csessionClose(I2cSession *s); 33 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/util/utf/utf32_to_utf8.c: -------------------------------------------------------------------------------- 1 | #include "runtime/util/utf.h" 2 | 3 | ssize_t 4 | utf32_to_utf8(uint8_t *out, 5 | const uint32_t *in, 6 | size_t len) 7 | { 8 | ssize_t rc = 0; 9 | ssize_t units; 10 | uint8_t encoded[4]; 11 | 12 | while(*in > 0) 13 | { 14 | units = encode_utf8(encoded, *in++); 15 | if(units == -1) 16 | return -1; 17 | 18 | if(out != NULL) 19 | { 20 | if(rc + units <= len) 21 | { 22 | *out++ = encoded[0]; 23 | if(units > 1) 24 | *out++ = encoded[1]; 25 | if(units > 2) 26 | *out++ = encoded[2]; 27 | if(units > 3) 28 | *out++ = encoded[3]; 29 | } 30 | } 31 | 32 | if(SSIZE_MAX - units >= rc) 33 | rc += units; 34 | else 35 | return -1; 36 | } 37 | 38 | return rc; 39 | } 40 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/internal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | #include "arm/tls.h" 4 | #include "kernel/thread.h" 5 | 6 | #define THREADVARS_MAGIC 0x21545624 // !TV$ 7 | 8 | // This structure is exactly 0x20 bytes, if more is needed modify getThreadVars() below 9 | typedef struct { 10 | // Magic value used to check if the struct is initialized 11 | u32 magic; 12 | 13 | // Thread handle, for mutexes 14 | Handle handle; 15 | 16 | // Pointer to the current thread (if exists) 17 | Thread* thread_ptr; 18 | 19 | // Pointer to this thread's newlib state 20 | struct _reent* reent; 21 | 22 | // Pointer to this thread's thread-local segment 23 | void* tls_tp; // !! Offset needs to be TLS+0x1F8 for __aarch64_read_tp !! 24 | } ThreadVars; 25 | 26 | static inline ThreadVars* getThreadVars(void) { 27 | return (ThreadVars*)((u8*)armGetTls() + 0x1E0); 28 | } 29 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/dynamic.c: -------------------------------------------------------------------------------- 1 | #include "result.h" 2 | #include "services/fatal.h" 3 | #include 4 | 5 | void __nx_dynamic(uintptr_t base, const Elf64_Dyn* dyn) 6 | { 7 | const Elf64_Rela* rela = NULL; 8 | u64 relasz = 0; 9 | 10 | for (; dyn->d_tag != DT_NULL; dyn++) 11 | { 12 | switch (dyn->d_tag) 13 | { 14 | case DT_RELA: 15 | rela = (const Elf64_Rela*)(base + dyn->d_un.d_ptr); 16 | break; 17 | case DT_RELASZ: 18 | relasz = dyn->d_un.d_val / sizeof(Elf64_Rela); 19 | break; 20 | } 21 | } 22 | 23 | if (rela == NULL) 24 | fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadReloc)); 25 | 26 | for (; relasz--; rela++) 27 | { 28 | switch (ELF64_R_TYPE(rela->r_info)) 29 | { 30 | case R_AARCH64_RELATIVE: 31 | { 32 | u64* ptr = (u64*)(base + rela->r_offset); 33 | *ptr = base + rela->r_addend; 34 | break; 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/barrier.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file barrier.h 3 | * @brief Multi-threading Barrier 4 | * @author tatehaga 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "mutex.h" 9 | #include "condvar.h" 10 | 11 | /// Barrier structure. 12 | typedef struct Barrier { 13 | u64 count; ///< Number of threads to reach the barrier. 14 | u64 total; ///< Number of threads to wait on. 15 | Mutex mutex; 16 | CondVar condvar; 17 | } Barrier; 18 | 19 | /** 20 | * @brief Initializes a barrier and the number of threads to wait on. 21 | * @param b Barrier object. 22 | * @param thread_count Initial value for the number of threads the barrier must wait for. 23 | */ 24 | void barrierInit(Barrier *b, u64 thread_count); 25 | 26 | /** 27 | * @brief Forces threads to wait until all threads have called barrierWait. 28 | * @param b Barrier object. 29 | */ 30 | void barrierWait(Barrier *b); 31 | -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/Pong/PongGame.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "../Sp2Utils.hpp" 5 | #include "../Draw.hpp" 6 | 7 | 8 | class PongBall 9 | { 10 | public: 11 | PongBall(); 12 | 13 | void Render(agl::lyr::RenderInfo* info); 14 | void Reset(sead::Vector2 startVec); 15 | sead::Vector2 mDirection; 16 | float mX, mY; 17 | }; 18 | 19 | class PongPlayer 20 | { 21 | private: 22 | float mX; 23 | public: 24 | PongPlayer(float x); 25 | void Render(agl::lyr::RenderInfo* info); 26 | void Reset(); 27 | 28 | float mY; 29 | int mScore; 30 | }; 31 | 32 | class PongGame 33 | { 34 | public: 35 | static void PongProcess(agl::lyr::RenderInfo* info); 36 | 37 | PongGame(); 38 | ~PongGame(); 39 | void Render(agl::lyr::RenderInfo* info); 40 | void Logic(); 41 | void Reset(); 42 | 43 | PongPlayer mPlayers[2]; 44 | PongBall mBall; 45 | }; 46 | 47 | -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/Draw.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Sp2Utils.hpp" 5 | #include "ArmNeon.hpp" 6 | #include 7 | #include 8 | #include 9 | #include "FsLogger.hpp" 10 | 11 | #define SCREEN_W 1280 12 | #define SCREEN_H 720 13 | 14 | void DrawRectLight(agl::DrawContext* drawCtx, float x, float y, float w, float h, sead::Color4f* color); 15 | void DrawTriangle(agl::DrawContext* drawCtx, sead::Vector2 pos1, sead::Vector2 pos2, sead::Vector2 pos3, sead::Color4f color); 16 | void DrawRect(agl::lyr::RenderInfo* info, sead::Vector2* pos, sead::Vector2* size, sead::Color4f* color); 17 | void DrawRect(agl::lyr::RenderInfo* info, float x, float y, float w, float h, sead::Color4f* color); 18 | void DrawText(sead::TextWriter* writer, float x, float y, float scale, sead::Color4f color, const char* Format, ...); 19 | float CalcTextWidth(sead::TextWriter* writer, const char* Format, ...); -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/util/utf/utf8_to_utf16.c: -------------------------------------------------------------------------------- 1 | #include "runtime/util/utf.h" 2 | 3 | ssize_t 4 | utf8_to_utf16(uint16_t *out, 5 | const uint8_t *in, 6 | size_t len) 7 | { 8 | ssize_t rc = 0; 9 | ssize_t units; 10 | uint32_t code; 11 | uint16_t encoded[2]; 12 | 13 | do 14 | { 15 | units = decode_utf8(&code, in); 16 | if(units == -1) 17 | return -1; 18 | 19 | if(code > 0) 20 | { 21 | in += units; 22 | 23 | units = encode_utf16(encoded, code); 24 | if(units == -1) 25 | return -1; 26 | 27 | if(out != NULL) 28 | { 29 | if(rc + units <= len) 30 | { 31 | *out++ = encoded[0]; 32 | if(units > 1) 33 | *out++ = encoded[1]; 34 | } 35 | } 36 | 37 | if(SSIZE_MAX - units >= rc) 38 | rc += units; 39 | else 40 | return -1; 41 | } 42 | } while(code > 0); 43 | 44 | return rc; 45 | } 46 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/event.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 plutoo 2 | #pragma once 3 | #include "../types.h" 4 | #include "../result.h" 5 | #include "wait.h" 6 | 7 | typedef struct { 8 | Handle revent; 9 | Handle wevent; 10 | bool autoclear; 11 | } Event; 12 | 13 | /// Creates a \ref Waiter for a kernel-mode event. 14 | static inline Waiter waiterForEvent(Event* t) 15 | { 16 | Waiter wait_obj; 17 | wait_obj.type = t->autoclear ? WaiterType_HandleWithClear : WaiterType_Handle; 18 | wait_obj.handle = t->revent; 19 | return wait_obj; 20 | } 21 | 22 | Result eventCreate(Event* t, bool autoclear); 23 | void eventLoadRemote(Event* t, Handle handle, bool autoclear); 24 | void eventClose(Event* t); 25 | 26 | /// Returns whether the Event is initialized. 27 | static inline bool eventActive(Event* t) 28 | { 29 | return t->revent != INVALID_HANDLE; 30 | } 31 | 32 | Result eventWait(Event* t, u64 timeout); 33 | Result eventFire(Event* t); 34 | Result eventClear(Event* t); 35 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/util/utf/encode_utf8.c: -------------------------------------------------------------------------------- 1 | #include "runtime/util/utf.h" 2 | 3 | ssize_t 4 | encode_utf8(uint8_t *out, 5 | uint32_t in) 6 | { 7 | if(in < 0x80) 8 | { 9 | if(out != NULL) 10 | *out++ = in; 11 | return 1; 12 | } 13 | else if(in < 0x800) 14 | { 15 | if(out != NULL) 16 | { 17 | *out++ = (in >> 6) + 0xC0; 18 | *out++ = (in & 0x3F) + 0x80; 19 | } 20 | return 2; 21 | } 22 | else if(in < 0x10000) 23 | { 24 | if(out != NULL) 25 | { 26 | *out++ = (in >> 12) + 0xE0; 27 | *out++ = ((in >> 6) & 0x3F) + 0x80; 28 | *out++ = (in & 0x3F) + 0x80; 29 | } 30 | return 3; 31 | } 32 | else if(in < 0x110000) 33 | { 34 | if(out != NULL) 35 | { 36 | *out++ = (in >> 18) + 0xF0; 37 | *out++ = ((in >> 12) & 0x3F) + 0x80; 38 | *out++ = ((in >> 6) & 0x3F) + 0x80; 39 | *out++ = (in & 0x3F) + 0x80; 40 | } 41 | return 4; 42 | } 43 | 44 | return -1; 45 | } 46 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/capssu.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file capssu.h 3 | * @brief Application screenshot saving (caps:su) service IPC wrapper. 4 | * @author yellows8 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../services/sm.h" 10 | #include "../services/caps.h" 11 | 12 | /// Initialize caps:su. Only available on 4.0.0+. 13 | Result capssuInitialize(void); 14 | void capssuExit(void); 15 | 16 | /// Same as \ref capssuSaveScreenShotEx0, except this uses an all-zero CapsScreenShotAttribute where the first u32 is set to attr_val. attr_val can be zero. 17 | Result capssuSaveScreenShot(const void* buffer, size_t size, u32 unk, u32 attr_val, CapsApplicationAlbumEntry *out); 18 | 19 | /// Saves an Album screenshot using the specified gfx data in buffer (1280x720 RGBA8), size must be at least 0x384000. unk can be zero. 20 | Result capssuSaveScreenShotEx0(const void* buffer, size_t size, CapsScreenShotAttribute *attr, u32 unk, CapsApplicationAlbumEntry *out); 21 | 22 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/nvidia/address_space.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | #include "ioctl.h" 4 | 5 | typedef struct NvAddressSpace { 6 | u32 fd; 7 | u32 page_size; 8 | bool has_init; 9 | } NvAddressSpace; 10 | 11 | Result nvAddressSpaceCreate(NvAddressSpace* a, u32 page_size); 12 | void nvAddressSpaceClose(NvAddressSpace* a); 13 | 14 | Result nvAddressSpaceAlloc(NvAddressSpace* a, bool sparse, u64 size, iova_t* iova_out); 15 | Result nvAddressSpaceAllocFixed(NvAddressSpace* a, bool sparse, u64 size, iova_t iova); 16 | Result nvAddressSpaceFree(NvAddressSpace* a, iova_t iova, u64 size); 17 | 18 | Result nvAddressSpaceMap(NvAddressSpace* a, u32 nvmap_handle, bool is_gpu_cacheable, NvKind kind, iova_t* iova_out); 19 | Result nvAddressSpaceMapFixed(NvAddressSpace* a, u32 nvmap_handle, bool is_gpu_cacheable, NvKind kind, iova_t iova); 20 | Result nvAddressSpaceModify(NvAddressSpace* a, iova_t iova, u64 offset, u64 size, NvKind kind); 21 | Result nvAddressSpaceUnmap(NvAddressSpace* a, iova_t iova); 22 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/kernel/semaphore.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Kevoot 2 | #include "kernel/semaphore.h" 3 | #include "kernel/svc.h" 4 | 5 | void semaphoreInit(Semaphore *s, u64 initial_count) { 6 | s->count = initial_count; 7 | mutexInit(&s->mutex); 8 | condvarInit(&s->condvar); 9 | } 10 | 11 | void semaphoreSignal(Semaphore *s) { 12 | mutexLock(&s->mutex); 13 | s->count++; 14 | condvarWakeOne(&s->condvar); 15 | mutexUnlock(&s->mutex); 16 | } 17 | 18 | void semaphoreWait(Semaphore *s) { 19 | mutexLock(&s->mutex); 20 | // Wait until signalled. 21 | while (!s->count) { 22 | condvarWait(&s->condvar, &s->mutex); 23 | } 24 | s->count--; 25 | mutexUnlock(&s->mutex); 26 | } 27 | 28 | bool semaphoreTryWait(Semaphore *s) { 29 | mutexLock(&s->mutex); 30 | bool success = false; 31 | // Check and immediately return success. 32 | if (s->count) { 33 | s->count--; 34 | success = true; 35 | } 36 | mutexUnlock(&s->mutex); 37 | return success; 38 | } 39 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/nxlink_stdio.c: -------------------------------------------------------------------------------- 1 | #include "runtime/nxlink.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static int sock = -1; 11 | 12 | int nxlinkStdio(void) 13 | { 14 | int ret = -1; 15 | struct sockaddr_in srv_addr; 16 | 17 | sock = socket(AF_INET, SOCK_STREAM, 0); 18 | if (!sock) { 19 | return ret; 20 | } 21 | 22 | bzero(&srv_addr, sizeof srv_addr); 23 | srv_addr.sin_family = AF_INET; 24 | srv_addr.sin_addr = __nxlink_host; 25 | srv_addr.sin_port = htons(NXLINK_CLIENT_PORT); 26 | 27 | ret = connect(sock, (struct sockaddr *) &srv_addr, sizeof(srv_addr)); 28 | if (ret != 0) { 29 | close(sock); 30 | return -1; 31 | } 32 | 33 | // redirect stdout 34 | fflush(stdout); 35 | dup2(sock, STDOUT_FILENO); 36 | // redirect stderr 37 | fflush(stderr); 38 | dup2(sock, STDERR_FILENO); 39 | 40 | return sock; 41 | } 42 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/nv.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file nv.h 3 | * @brief NVIDIA low level driver (nvdrv*) service IPC wrapper. 4 | * @author yellows8 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../kernel/event.h" 10 | 11 | Result nvInitialize(void); 12 | void nvExit(void); 13 | 14 | typedef enum { 15 | NvEventId_Gpu_SmException_BptIntReport=1, 16 | NvEventId_Gpu_SmException_BptPauseReport=2, 17 | NvEventId_Gpu_ErrorNotifier=3, 18 | 19 | NvEventId_CtrlGpu_ErrorEventHandle=1, 20 | NvEventId_CtrlGpu_Unknown=2, 21 | } NvEventId; 22 | 23 | #define NV_EVENT_ID_CTRL__SYNCPT(slot, syncpt) \ 24 | ((1u<<28) | ((syncpt) << 16) | (slot)) 25 | 26 | Result nvOpen(u32 *fd, const char *devicepath); 27 | Result nvIoctl(u32 fd, u32 request, void* argp); 28 | Result nvIoctl2(u32 fd, u32 request, void* argp, const void* inbuf, size_t inbuf_size); 29 | Result nvClose(u32 fd); 30 | Result nvQueryEvent(u32 fd, u32 event_id, Event *event_out); 31 | 32 | Result nvConvertError(int rc); 33 | -------------------------------------------------------------------------------- /sp2Module/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "NX", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "${workspaceFolder}/libnx/nx", 8 | "${workspaceFolder}/libnx/nx/external/bsd/include", 9 | "C:/devkitPro/devkitA64/aarch64-none-elf/include", 10 | "C:/devkitPro/portlibs/switch/include", 11 | "C:/devkitPro/devkitA64/aarch64-none-elf/include/c++/8.3.0", 12 | "C:/devkitPro/devkitA64/aarch64-none-elf/include/c++/8.3.0/tr1", 13 | "C:/devkitPro/devkitA64/aarch64-none-elf/include/c++/8.3.0/bits" 14 | ], 15 | "defines": [ 16 | "_DEBUG", 17 | "UNICODE", 18 | "_UNICODE" 19 | ], 20 | "compilerPath": "C:/devkitPro/devkitA64/bin/aarch64-none-elf-g++.exe", 21 | "cStandard": "c11", 22 | "cppStandard": "c++17", 23 | "intelliSenseMode": "gcc-x64" 24 | } 25 | ], 26 | "version": 4 27 | } -------------------------------------------------------------------------------- /sp2Module/libnx/nx/external/bsd/include/arpa/inet.h: -------------------------------------------------------------------------------- 1 | // FreeBSD's header was so full of s*it, I just picked libctru's version of 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | static inline uint32_t htonl(uint32_t hostlong) 9 | { 10 | return __builtin_bswap32(hostlong); 11 | } 12 | 13 | static inline uint16_t htons(uint16_t hostshort) 14 | { 15 | return __builtin_bswap16(hostshort); 16 | } 17 | 18 | static inline uint32_t ntohl(uint32_t netlong) 19 | { 20 | return __builtin_bswap32(netlong); 21 | } 22 | 23 | static inline uint16_t ntohs(uint16_t netshort) 24 | { 25 | return __builtin_bswap16(netshort); 26 | } 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | in_addr_t inet_addr(const char *cp); 33 | int inet_aton(const char *cp, struct in_addr *inp); 34 | char* inet_ntoa(struct in_addr in); 35 | 36 | const char *inet_ntop(int af, const void * src, char * dst, socklen_t size); 37 | int inet_pton(int af, const char * src, void * dst); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/util/utf/utf16_to_utf8.c: -------------------------------------------------------------------------------- 1 | #include "runtime/util/utf.h" 2 | 3 | ssize_t 4 | utf16_to_utf8(uint8_t *out, 5 | const uint16_t *in, 6 | size_t len) 7 | { 8 | ssize_t rc = 0; 9 | ssize_t units; 10 | uint32_t code; 11 | uint8_t encoded[4]; 12 | 13 | do 14 | { 15 | units = decode_utf16(&code, in); 16 | if(units == -1) 17 | return -1; 18 | 19 | if(code > 0) 20 | { 21 | in += units; 22 | 23 | units = encode_utf8(encoded, code); 24 | if(units == -1) 25 | return -1; 26 | 27 | if(out != NULL) 28 | { 29 | if(rc + units <= len) 30 | { 31 | *out++ = encoded[0]; 32 | if(units > 1) 33 | *out++ = encoded[1]; 34 | if(units > 2) 35 | *out++ = encoded[2]; 36 | if(units > 3) 37 | *out++ = encoded[3]; 38 | } 39 | } 40 | 41 | if(SSIZE_MAX - units >= rc) 42 | rc += units; 43 | else 44 | return -1; 45 | } 46 | } while(code > 0); 47 | 48 | return rc; 49 | } 50 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file i2c.h 3 | * @brief I2C service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "sm.h" 10 | 11 | typedef enum { 12 | GpioPadName_AudioCodec = 1, 13 | GpioPadName_ButtonVolUp = 25, 14 | GpioPadName_ButtonVolDown = 26, 15 | } GpioPadName; 16 | 17 | typedef struct { 18 | Service s; 19 | } GpioPadSession; 20 | 21 | typedef enum { 22 | GpioDirection_Input = 0, 23 | GpioDirection_Output = 1, 24 | } GpioDirection; 25 | 26 | typedef enum { 27 | GpioValue_Low = 0, 28 | GpioValue_High = 1, 29 | } GpioValue; 30 | 31 | Result gpioInitialize(void); 32 | void gpioExit(void); 33 | 34 | Result gpioOpenSession(GpioPadSession *out, GpioPadName name); 35 | 36 | Result gpioPadSetDirection(GpioPadSession *p, GpioDirection dir); 37 | Result gpioPadGetDirection(GpioPadSession *p, GpioDirection *out); 38 | Result gpioPadSetValue(GpioPadSession *p, GpioValue val); 39 | Result gpioPadGetValue(GpioPadSession *p, GpioValue *out); 40 | void gpioPadClose(GpioPadSession *p); 41 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/nvidia/map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | 4 | typedef struct NvMap { 5 | u32 handle; 6 | u32 id; 7 | u32 size; 8 | void* cpu_addr; 9 | NvKind kind; 10 | bool has_init; 11 | bool is_cpu_cacheable; 12 | } NvMap; 13 | 14 | Result nvMapInit(void); 15 | u32 nvMapGetFd(void); 16 | void nvMapExit(void); 17 | 18 | Result nvMapCreate(NvMap* m, void* cpu_addr, u32 size, u32 align, NvKind kind, bool is_cpu_cacheable); 19 | Result nvMapLoadRemote(NvMap* m, u32 id); 20 | void nvMapClose(NvMap* m); 21 | 22 | static inline u32 nvMapGetHandle(NvMap* m) 23 | { 24 | return m->handle; 25 | } 26 | 27 | static inline u32 nvMapGetId(NvMap* m) 28 | { 29 | return m->id; 30 | } 31 | 32 | static inline u32 nvMapGetSize(NvMap* m) 33 | { 34 | return m->size; 35 | } 36 | 37 | static inline void* nvMapGetCpuAddr(NvMap* m) 38 | { 39 | return m->cpu_addr; 40 | } 41 | 42 | static inline bool nvMapIsRemote(NvMap* m) 43 | { 44 | return !m->cpu_addr; 45 | } 46 | 47 | static inline NvKind nvMapGetKind(NvMap* m) 48 | { 49 | return m->kind; 50 | } 51 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/nvidia/channel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "types.h" 3 | #include "result.h" 4 | #include "arm/atomics.h" 5 | #include "kernel/svc.h" 6 | #include "services/nv.h" 7 | #include "nvidia/ioctl.h" 8 | #include "nvidia/map.h" 9 | #include "nvidia/channel.h" 10 | 11 | Result nvChannelCreate(NvChannel* c, const char* dev) 12 | { 13 | Result rc; 14 | 15 | c->has_init = true; 16 | 17 | rc = nvOpen(&c->fd, dev); 18 | 19 | if (R_FAILED(rc)) 20 | c->fd = -1; 21 | 22 | if (R_SUCCEEDED(rc)) 23 | rc = nvioctlChannel_SetNvmapFd(c->fd, nvMapGetFd()); 24 | 25 | if (R_FAILED(rc)) 26 | nvChannelClose(c); 27 | 28 | return rc; 29 | } 30 | 31 | void nvChannelClose(NvChannel* c) 32 | { 33 | if (!c->has_init) 34 | return; 35 | 36 | if (c->fd != -1) 37 | nvClose(c->fd); 38 | 39 | c->fd = -1; 40 | } 41 | 42 | Result nvChannelSetPriority(NvChannel* c, NvChannelPriority prio) { 43 | return nvioctlChannel_SetPriority(c->fd, prio); 44 | } 45 | 46 | Result nvChannelSetTimeout(NvChannel* c, u32 timeout) { 47 | return nvioctlChannel_SetTimeout(c->fd, timeout); 48 | } 49 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/nro.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file nro.h 3 | * @brief NRO headers. 4 | * @copyright libnx Authors 5 | */ 6 | 7 | #pragma once 8 | 9 | #define NROHEADER_MAGIC 0x304f524e 10 | 11 | #define NROASSETHEADER_MAGIC 0x54455341 12 | #define NROASSETHEADER_VERSION 0 13 | 14 | /// Entry for each segment in the codebin. 15 | typedef struct { 16 | u32 file_off; 17 | u32 size; 18 | } NroSegment; 19 | 20 | /// Offset 0x0 in the NRO. 21 | typedef struct { 22 | u32 unused; 23 | u32 mod_offset; 24 | u8 padding[8]; 25 | } NroStart; 26 | 27 | /// This follows NroStart, the actual nro-header. 28 | typedef struct { 29 | u32 magic; 30 | u32 unk1; 31 | u32 size; 32 | u32 unk2; 33 | NroSegment segments[3]; 34 | u32 bss_size; 35 | u32 unk3; 36 | u8 build_id[0x20]; 37 | u8 padding[0x20]; 38 | } NroHeader; 39 | 40 | /// Custom asset section. 41 | typedef struct { 42 | u64 offset; 43 | u64 size; 44 | } NroAssetSection; 45 | 46 | /// Custom asset header. 47 | typedef struct { 48 | u32 magic; 49 | u32 version; 50 | NroAssetSection icon; 51 | NroAssetSection nacp; 52 | NroAssetSection romfs; 53 | } NroAssetHeader; 54 | 55 | -------------------------------------------------------------------------------- /Sp2Patcher/Sp2Patcher.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28803.202 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sp2Patcher", "Sp2Patcher\Sp2Patcher.csproj", "{44043CE0-FBAB-491D-87F0-E2BFEDE77983}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {44043CE0-FBAB-491D-87F0-E2BFEDE77983}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {44043CE0-FBAB-491D-87F0-E2BFEDE77983}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {44043CE0-FBAB-491D-87F0-E2BFEDE77983}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {44043CE0-FBAB-491D-87F0-E2BFEDE77983}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {0657B16B-DDF0-485B-BF3F-E11877633FA7} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/rwlock.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file rwlock.h 3 | * @brief Read/write lock synchronization primitive. 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../kernel/mutex.h" 9 | #include "../kernel/condvar.h" 10 | 11 | /// Read/write lock structure. 12 | typedef struct { 13 | Mutex mutex; 14 | CondVar condvar_readers; 15 | CondVar condvar_writer; 16 | u32 readers : 31; 17 | bool writer : 1; 18 | } RwLock; 19 | 20 | /** 21 | * @brief Initializes the read/write lock. 22 | * @param r Read/write lock object. 23 | */ 24 | void rwlockInit(RwLock* r); 25 | 26 | /** 27 | * @brief Locks the read/write lock for reading. 28 | * @param r Read/write lock object. 29 | */ 30 | void rwlockReadLock(RwLock* r); 31 | 32 | /** 33 | * @brief Unlocks the read/write lock for reading. 34 | * @param r Read/write lock object. 35 | */ 36 | void rwlockReadUnlock(RwLock* r); 37 | 38 | /** 39 | * @brief Locks the read/write lock for writing. 40 | * @param r Read/write lock object. 41 | */ 42 | void rwlockWriteLock(RwLock* r); 43 | 44 | /** 45 | * @brief Unlocks the read/write lock for writing. 46 | * @param r Read/write lock object. 47 | */ 48 | void rwlockWriteUnlock(RwLock* r); 49 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/audio/sink.c: -------------------------------------------------------------------------------- 1 | #include "driver_internal.h" 2 | 3 | int audrvDeviceSinkAdd(AudioDriver* d, const char* device_name, int num_channels, const u8* channel_ids) 4 | { 5 | if (!device_name || num_channels < 1 || num_channels > 6 || !channel_ids) 6 | return -1; 7 | 8 | int id = d->etc->first_free_sink; 9 | if (id < 0) 10 | return -1; 11 | 12 | d->etc->first_free_sink = d->etc->sinks[id].next_free; 13 | d->in_sinks[id].type = AudioRendererSinkType_Device; 14 | d->in_sinks[id].is_used = true; 15 | d->in_sinks[id].node_id = AUDREN_NODEID(3,id,0); 16 | strncpy(d->in_sinks[id].device_sink.name, device_name, sizeof(d->in_sinks[id].device_sink.name)-1); 17 | d->in_sinks[id].device_sink.input_count = num_channels; 18 | memcpy(d->in_sinks[id].device_sink.inputs, channel_ids, num_channels); 19 | 20 | return id; 21 | } 22 | 23 | void audrvSinkRemove(AudioDriver* d, int id) 24 | { 25 | if (id < 0 || id >= d->config.num_sinks) 26 | return; 27 | if (!d->in_sinks[id].is_used) 28 | return; 29 | 30 | d->etc->sinks[id].next_free = d->etc->first_free_sink; 31 | d->etc->first_free_sink = id; 32 | memset(&d->in_sinks[id], 0, sizeof(AudioRendererSinkInfoIn)); 33 | } 34 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/arm/counter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file counter.h 3 | * @brief AArch64 system counter-timer. 4 | * @author fincs 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | /** 11 | * @brief Gets the current system tick. 12 | * @return The current system tick. 13 | */ 14 | static inline u64 armGetSystemTick(void) { 15 | u64 ret; 16 | __asm__ __volatile__ ("mrs %x[data], cntpct_el0" : [data] "=r" (ret)); 17 | return ret; 18 | } 19 | 20 | /** 21 | * @brief Gets the system counter-timer frequency 22 | * @return The system counter-timer frequency, in Hz. 23 | */ 24 | static inline u64 armGetSystemTickFreq(void) { 25 | u64 ret; 26 | __asm__ ("mrs %x[data], cntfrq_el0" : [data] "=r" (ret)); 27 | return ret; 28 | } 29 | 30 | /** 31 | * @brief Converts from nanoseconds to CPU ticks unit. 32 | * @param ns Time in nanoseconds. 33 | * @return Time in CPU ticks. 34 | */ 35 | static inline u64 armNsToTicks(u64 ns) { 36 | return (ns * 12) / 625; 37 | } 38 | 39 | /** 40 | * @brief Converts from CPU ticks unit to nanoseconds. 41 | * @param tick Time in ticks. 42 | * @return Time in nanoseconds. 43 | */ 44 | static inline u64 armTicksToNs(u64 tick) { 45 | return (tick * 625) / 12; 46 | } 47 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/display/parcel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../result.h" 3 | #include "../display/binder.h" 4 | 5 | typedef struct { 6 | u32 payload_size; 7 | u32 payload_off; 8 | u32 objects_size; 9 | u32 objects_off; 10 | } ParcelHeader; 11 | 12 | #define PARCEL_MAX_PAYLOAD 0x400 13 | 14 | typedef struct { 15 | u8 payload[PARCEL_MAX_PAYLOAD]; 16 | u32 payload_size; 17 | u8* objects; 18 | u32 objects_size; 19 | 20 | u32 capacity; 21 | u32 pos; 22 | } Parcel; 23 | 24 | void parcelCreate(Parcel *ctx); 25 | Result parcelTransact(Binder *session, u32 code, Parcel *in_parcel, Parcel *reply_parcel); 26 | 27 | void* parcelWriteData(Parcel *ctx, const void* data, size_t data_size); 28 | void* parcelReadData(Parcel *ctx, void* data, size_t data_size); 29 | 30 | void parcelWriteInt32(Parcel *ctx, s32 val); 31 | void parcelWriteUInt32(Parcel *ctx, u32 val); 32 | void parcelWriteString16(Parcel *ctx, const char *str); 33 | 34 | s32 parcelReadInt32(Parcel *ctx); 35 | u32 parcelReadUInt32(Parcel *ctx); 36 | void parcelWriteInterfaceToken(Parcel *ctx, const char *str); 37 | 38 | void* parcelReadFlattenedObject(Parcel *ctx, size_t *size); 39 | void* parcelWriteFlattenedObject(Parcel *ctx, const void* data, size_t size); 40 | 41 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/semaphore.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file semaphore.h 3 | * @brief Thread synchronization based on Mutex. 4 | * @author SciresM & Kevoot 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | 9 | #include "mutex.h" 10 | #include "condvar.h" 11 | 12 | /// Semaphore structure. 13 | typedef struct Semaphore 14 | { 15 | CondVar condvar; ///< Condition variable object. 16 | Mutex mutex; ///< Mutex object. 17 | u64 count; ///< Internal counter. 18 | } Semaphore; 19 | 20 | /** 21 | * @brief Initializes a semaphore and its internal counter. 22 | * @param s Semaphore object. 23 | * @param initial_count initial value for internal counter (typically the # of free resources). 24 | */ 25 | void semaphoreInit(Semaphore *s, u64 initial_count); 26 | 27 | /** 28 | * @brief Increments the Semaphore to allow other threads to continue. 29 | * @param s Semaphore object. 30 | */ 31 | void semaphoreSignal(Semaphore *s); 32 | 33 | /** 34 | * @brief Decrements Semaphore and waits if 0. 35 | * @param s Semaphore object. 36 | */ 37 | void semaphoreWait(Semaphore *s); 38 | 39 | /** 40 | * @brief Attempts to get lock without waiting. 41 | * @param s Semaphore object. 42 | * @return true if no wait and successful lock, false otherwise. 43 | */ 44 | bool semaphoreTryWait(Semaphore *s); 45 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/uevent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file uevent.h 3 | * @brief User-mode event synchronization primitive. 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "wait.h" 9 | 10 | typedef struct UEvent UEvent; 11 | 12 | /// User-mode event object. 13 | struct UEvent { 14 | Waitable waitable; 15 | bool signal; 16 | bool auto_clear; 17 | }; 18 | 19 | /// Creates a waiter for a user-mode event. 20 | static inline Waiter waiterForUEvent(UEvent* e) 21 | { 22 | Waiter wait_obj; 23 | wait_obj.type = WaiterType_Waitable; 24 | wait_obj.waitable = &e->waitable; 25 | return wait_obj; 26 | } 27 | 28 | /** 29 | * @brief Creates a user-mode event. 30 | * @param[out] e UEvent object. 31 | * @param[in] auto_clear Whether to automatically clear the event. 32 | * @note It is safe to wait on this event with several threads simultaneously. 33 | * @note If more than one thread is listening on it, at least one thread will get the signal. No other guarantees. 34 | */ 35 | void ueventCreate(UEvent* e, bool auto_clear); 36 | 37 | /** 38 | * @brief Clears the event signal. 39 | * @param[in] e UEvent object. 40 | */ 41 | void ueventClear(UEvent* e); 42 | 43 | /** 44 | * @brief Signals the event. 45 | * @param[in] e UEvent object. 46 | */ 47 | void ueventSignal(UEvent* e); 48 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/psc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file psc.h 3 | * @brief PSC service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../kernel/event.h" 10 | #include "../services/sm.h" 11 | 12 | typedef enum { 13 | PscPmState_Awake = 0, ///< Everything is awake. 14 | PscPmState_ReadyAwaken = 1, ///< Preparing to transition to awake. 15 | PscPmState_ReadySleep = 2, ///< Preparing to transition to sleep. 16 | PscPmState_ReadySleepCritical = 3, ///< Critical services are ready to sleep. 17 | PscPmState_ReadyAwakenCritical = 4, ///< Critical services are ready to wake up. 18 | PscPmState_ReadyShutdown = 5, ///< Preparing to transition to shutdown. 19 | } PscPmState; 20 | 21 | typedef struct { 22 | Event event; 23 | Service srv; 24 | u16 module_id; 25 | } PscPmModule; 26 | 27 | Result pscInitialize(void); 28 | void pscExit(void); 29 | 30 | Result pscGetPmModule(PscPmModule *out, u16 module_id, const u16 *dependencies, size_t dependency_count, bool autoclear); 31 | 32 | Result pscPmModuleGetRequest(PscPmModule *module, PscPmState *out_state, u32 *out_flags); 33 | Result pscPmModuleAcknowledge(PscPmModule *module, PscPmState state); 34 | Result pscPmModuleFinalize(PscPmModule *module); 35 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/kernel/rwlock.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 plutoo 2 | #include "kernel/mutex.h" 3 | #include "kernel/rwlock.h" 4 | 5 | void rwlockInit(RwLock* r) { 6 | mutexInit(&r->mutex); 7 | condvarInit(&r->condvar_readers); 8 | condvarInit(&r->condvar_writer); 9 | 10 | r->readers = 0; 11 | r->writer = false; 12 | } 13 | 14 | void rwlockReadLock(RwLock* r) { 15 | mutexLock(&r->mutex); 16 | 17 | while (r->writer) { 18 | condvarWait(&r->condvar_writer, &r->mutex); 19 | } 20 | 21 | r->readers++; 22 | 23 | mutexUnlock(&r->mutex); 24 | } 25 | 26 | void rwlockReadUnlock(RwLock* r) { 27 | mutexLock(&r->mutex); 28 | 29 | if (--r->readers == 0) { 30 | condvarWakeAll(&r->condvar_readers); 31 | } 32 | 33 | mutexUnlock(&r->mutex); 34 | } 35 | 36 | void rwlockWriteLock(RwLock* r) { 37 | mutexLock(&r->mutex); 38 | 39 | while (r->writer) { 40 | condvarWait(&r->condvar_writer, &r->mutex); 41 | } 42 | 43 | r->writer = true; 44 | 45 | while (r->readers > 0) { 46 | condvarWait(&r->condvar_readers, &r->mutex); 47 | } 48 | 49 | mutexUnlock(&r->mutex); 50 | } 51 | 52 | void rwlockWriteUnlock(RwLock* r) { 53 | mutexLock(&r->mutex); 54 | 55 | r->writer = false; 56 | condvarWakeAll(&r->condvar_writer); 57 | 58 | mutexUnlock(&r->mutex); 59 | } 60 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/capssc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file capssc.h 3 | * @brief Screenshot control (caps:sc) service IPC wrapper. 4 | * @author yellows8 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../services/sm.h" 10 | #include "../services/caps.h" 11 | 12 | /// Initialize caps:sc. Only available on 2.0.0+. 13 | Result capsscInitialize(void); 14 | void capsscExit(void); 15 | 16 | /** 17 | * @brief This takes a screenshot, with the screenshot being written into the output buffer. 18 | * @note Not available with 5.0.0+ (stubbed). 19 | * @note buffer_index and buffer_count correspond to buffers with size 0x384000(1280*720*4). These must not be negative. 20 | * @param buf Output buffer containing the RGBA8 image. 21 | * @param size Size of buf, should be 0x384000(1280*720*4) * buffer_count. 22 | * @param inval Value 0 can be used for this. 23 | * @param width Image width, must be 1280. 24 | * @param height Image height, must be 720. 25 | * @param buffer_count Total number of output image buffers. 26 | * @param buffer_index Starting image buffer index. Must be < buffer_count. 27 | * @param timeout Timeout in nanoseconds. A default value of 100000000 can be used. 28 | */ 29 | Result capsscCaptureScreenshot(void* buf, size_t size, u32 inval, u64 width, u64 height, s64 buffer_count, s64 buffer_index, u64 timeout); 30 | 31 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/nvidia/graphic_buffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../display/types.h" 3 | #include "types.h" 4 | 5 | typedef struct { 6 | u32 width; 7 | u32 height; 8 | NvColorFormat color_format; 9 | NvLayout layout; 10 | u32 pitch; 11 | u32 unused; // usually this field contains the nvmap handle, but it's completely unused/overwritten during marshalling 12 | u32 offset; 13 | NvKind kind; 14 | u32 block_height_log2; 15 | NvDisplayScanFormat scan; 16 | u32 second_field_offset; 17 | u64 flags; 18 | u64 size; 19 | u32 unk[6]; // compression related 20 | } NvSurface; 21 | 22 | typedef struct { 23 | NativeHandle header; 24 | s32 unk0; // -1 25 | s32 nvmap_id; // nvmap object id 26 | u32 unk2; // 0 27 | u32 magic; // 0xDAFFCAFF 28 | u32 pid; // 42 29 | u32 type; // ? 30 | u32 usage; // GRALLOC_USAGE_* bitmask 31 | u32 format; // PIXEL_FORMAT_* 32 | u32 ext_format; // copy of the above (in most cases) 33 | u32 stride; // in pixels! 34 | u32 total_size; // in bytes 35 | u32 num_planes; // usually 1 36 | u32 unk12; // 0 37 | NvSurface planes[3]; 38 | u64 unused; // official sw writes a pointer to bookkeeping data here, but it's otherwise completely unused/overwritten during marshalling 39 | } NvGraphicBuffer; 40 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/nvidia/gpu_channel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../kernel/event.h" 3 | #include "channel.h" 4 | #include "fence.h" 5 | 6 | #define GPFIFO_QUEUE_SIZE 0x800 7 | #define GPFIFO_ENTRY_NOT_MAIN BIT(9) 8 | #define GPFIFO_ENTRY_NO_PREFETCH BIT(31) 9 | 10 | typedef struct NvGpuChannel 11 | { 12 | NvChannel base; 13 | Event error_event; 14 | u64 object_id; 15 | NvFence fence; 16 | u32 fence_incr; 17 | nvioctl_gpfifo_entry entries[GPFIFO_QUEUE_SIZE]; 18 | u32 num_entries; 19 | } NvGpuChannel; 20 | 21 | Result nvGpuChannelCreate(NvGpuChannel* c, struct NvAddressSpace* as); 22 | void nvGpuChannelClose(NvGpuChannel* c); 23 | 24 | Result nvGpuChannelZcullBind(NvGpuChannel* c, iova_t iova); 25 | Result nvGpuChannelAppendEntry(NvGpuChannel* c, iova_t start, size_t num_cmds, u32 flags, u32 flush_threshold); 26 | Result nvGpuChannelKickoff(NvGpuChannel* c); 27 | Result nvGpuChannelGetErrorNotification(NvGpuChannel* c, NvError* error); 28 | 29 | static inline u32 nvGpuChannelGetSyncpointId(NvGpuChannel* c) 30 | { 31 | return c->fence.id; 32 | } 33 | 34 | static inline void nvGpuChannelGetFence(NvGpuChannel* c, NvFence* fence_out) 35 | { 36 | fence_out->id = c->fence.id; 37 | fence_out->value = c->fence.value + c->fence_incr; 38 | } 39 | 40 | static inline void nvGpuChannelIncrFence(NvGpuChannel* c) 41 | { 42 | ++c->fence_incr; 43 | } 44 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/virtmem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file virtmem.h 3 | * @brief Virtual memory mapping utilities 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | /** 11 | * @brief Reserves a slice of general purpose address space. 12 | * @param size The size of the slice of address space that will be reserved (rounded up to page alignment). 13 | * @return Pointer to the slice of address space, or NULL on failure. 14 | */ 15 | void* virtmemReserve(size_t size); 16 | 17 | /** 18 | * @brief Relinquishes a slice of address space reserved with virtmemReserve (currently no-op). 19 | * @param addr Pointer to the slice. 20 | * @param size Size of the slice. 21 | */ 22 | void virtmemFree(void* addr, size_t size); 23 | 24 | /** 25 | * @brief Reserves a slice of address space inside the stack memory mapping region (for use with svcMapMemory). 26 | * @param size The size of the slice of address space that will be reserved (rounded up to page alignment). 27 | * @return Pointer to the slice of address space, or NULL on failure. 28 | */ 29 | void* virtmemReserveStack(size_t size); 30 | 31 | /** 32 | * @brief Relinquishes a slice of address space reserved with virtmemReserveStack (currently no-op). 33 | * @param addr Pointer to the slice. 34 | * @param size Size of the slice. 35 | */ 36 | void virtmemFreeStack(void* addr, size_t size); 37 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/audio/mix_object.c: -------------------------------------------------------------------------------- 1 | #include "driver_internal.h" 2 | 3 | int audrvMixAdd(AudioDriver* d, int sample_rate, int num_channels) 4 | { 5 | if (num_channels < 1 || num_channels > 24) 6 | return -1; 7 | 8 | if (d->etc->free_mix_buffer_count < num_channels) 9 | return -1; 10 | 11 | int id = d->etc->first_free_mix; 12 | if (id < 0) 13 | return -1; 14 | 15 | d->etc->free_mix_buffer_count -= num_channels; 16 | d->etc->first_free_mix = d->etc->mixes[id].next_free; 17 | d->in_mixes[id].volume = 1.0f; 18 | d->in_mixes[id].sample_rate = sample_rate; 19 | d->in_mixes[id].buffer_count = num_channels; 20 | d->in_mixes[id].is_used = true; 21 | d->in_mixes[id].mix_id = id; 22 | d->in_mixes[id].node_id = AUDREN_NODEID(2,id,0); 23 | d->in_mixes[id].dest_mix_id = AUDREN_UNUSED_MIX_ID; 24 | d->in_mixes[id].dest_splitter_id = AUDREN_UNUSED_SPLITTER_ID; 25 | 26 | return id; 27 | } 28 | 29 | void audrvMixRemove(AudioDriver* d, int id) 30 | { 31 | if (id <= AUDREN_FINAL_MIX_ID || id >= d->config.num_mix_objs) 32 | return; 33 | if (!d->in_mixes[id].is_used) 34 | return; 35 | 36 | d->etc->free_mix_buffer_count += d->in_mixes[id].buffer_count; 37 | d->etc->mixes[id].next_free = d->etc->first_free_mix; 38 | d->etc->first_free_mix = id; 39 | memset(&d->in_mixes[id], 0, sizeof(AudioRendererMixInfoIn)); 40 | } 41 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/runtime/devices/usb_comms.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file usb_comms.h 3 | * @brief USB comms. 4 | * @author yellows8 5 | * @author plutoo 6 | * @copyright libnx Authors 7 | */ 8 | #pragma once 9 | #include "../../types.h" 10 | 11 | typedef struct { 12 | u8 bInterfaceClass; 13 | u8 bInterfaceSubClass; 14 | u8 bInterfaceProtocol; 15 | } UsbCommsInterfaceInfo; 16 | 17 | /// Initializes usbComms with the default number of interfaces (1) 18 | Result usbCommsInitialize(void); 19 | 20 | /// Initializes usbComms with a specific number of interfaces. 21 | Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *infos); 22 | 23 | /// Exits usbComms. 24 | void usbCommsExit(void); 25 | 26 | /// Sets whether to throw a fatal error in usbComms{Read/Write}* on failure, or just return the transferred size. By default (false) the latter is used. 27 | void usbCommsSetErrorHandling(bool flag); 28 | 29 | /// Read data with the default interface. 30 | size_t usbCommsRead(void* buffer, size_t size); 31 | 32 | /// Write data with the default interface. 33 | size_t usbCommsWrite(const void* buffer, size_t size); 34 | 35 | /// Same as usbCommsRead except with the specified interface. 36 | size_t usbCommsReadEx(void* buffer, size_t size, u32 interface); 37 | 38 | /// Same as usbCommsWrite except with the specified interface. 39 | size_t usbCommsWriteEx(const void* buffer, size_t size, u32 interface); 40 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/nvidia/gpu.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "types.h" 3 | #include "result.h" 4 | #include "arm/atomics.h" 5 | #include "kernel/svc.h" 6 | #include "services/nv.h" 7 | #include "nvidia/ioctl.h" 8 | #include "nvidia/gpu.h" 9 | 10 | static u32 g_ctrlgpu_fd = -1; 11 | static u64 g_refCnt; 12 | 13 | static nvioctl_gpu_characteristics g_gpu_characteristics; 14 | static u32 g_zcull_ctx_size; 15 | 16 | Result nvGpuInit(void) 17 | { 18 | Result rc; 19 | 20 | if (atomicIncrement64(&g_refCnt) > 0) 21 | return 0; 22 | 23 | rc = nvOpen(&g_ctrlgpu_fd, "/dev/nvhost-ctrl-gpu"); 24 | 25 | if (R_FAILED(rc)) 26 | g_ctrlgpu_fd = -1; 27 | 28 | if (R_SUCCEEDED(rc)) 29 | rc = nvioctlNvhostCtrlGpu_GetCharacteristics(g_ctrlgpu_fd, &g_gpu_characteristics); 30 | 31 | if (R_SUCCEEDED(rc)) 32 | rc = nvioctlNvhostCtrlGpu_ZCullGetCtxSize(g_ctrlgpu_fd, &g_zcull_ctx_size); 33 | 34 | if (R_FAILED(rc)) 35 | nvGpuExit(); 36 | 37 | return rc; 38 | } 39 | 40 | void nvGpuExit(void) 41 | { 42 | if (atomicDecrement64(&g_refCnt) == 0) { 43 | if (g_ctrlgpu_fd != -1) 44 | nvClose(g_ctrlgpu_fd); 45 | 46 | g_ctrlgpu_fd = -1; 47 | } 48 | } 49 | 50 | const nvioctl_gpu_characteristics* nvGpuGetCharacteristics(void) 51 | { 52 | return &g_gpu_characteristics; 53 | } 54 | 55 | u32 nvGpuGetZcullCtxSize(void) 56 | { 57 | return g_zcull_ctx_size; 58 | } 59 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/pl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pl.h 3 | * @brief pl:u service IPC wrapper. 4 | * @author yellows8 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | typedef enum 11 | { 12 | PlSharedFontType_Standard = 0, ///< Japan, US and Europe 13 | PlSharedFontType_ChineseSimplified = 1, ///< Chinese Simplified 14 | PlSharedFontType_ExtChineseSimplified = 2, ///< Extended Chinese Simplified 15 | PlSharedFontType_ChineseTraditional = 3, ///< Chinese Traditional 16 | PlSharedFontType_KO = 4, ///< Korean (Hangul) 17 | PlSharedFontType_NintendoExt = 5, ///< Nintendo Extended. This font only has the special Nintendo-specific characters, which aren't available with the other fonts. 18 | PlSharedFontType_Total, ///< Total fonts supported by this enum. 19 | } PlSharedFontType; 20 | 21 | typedef struct { 22 | u32 type; 23 | u32 offset; 24 | u32 size; 25 | void* address; 26 | } PlFontData; 27 | 28 | Result plInitialize(void); 29 | void plExit(void); 30 | void* plGetSharedmemAddr(void); 31 | 32 | ///< Gets a specific shared-font via SharedFontType, see \ref PlSharedFontType. 33 | Result plGetSharedFontByType(PlFontData* font, u32 SharedFontType); 34 | 35 | ///< Gets shared font(s). 36 | Result plGetSharedFont(u64 LanguageCode, PlFontData* fonts, size_t max_fonts, size_t* total_fonts); 37 | 38 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/services/csrng.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 SciresM 2 | #include 3 | #include "types.h" 4 | #include "result.h" 5 | #include "arm/atomics.h" 6 | #include "kernel/ipc.h" 7 | #include "services/csrng.h" 8 | #include "services/sm.h" 9 | #include "services/spl.h" 10 | 11 | static Service g_csrngSrv; 12 | static u64 g_csrngRefCnt; 13 | 14 | Result csrngInitialize(void) { 15 | atomicIncrement64(&g_csrngRefCnt); 16 | 17 | if (serviceIsActive(&g_csrngSrv)) 18 | return 0; 19 | 20 | return smGetService(&g_csrngSrv, "csrng"); 21 | } 22 | 23 | void csrngExit(void) { 24 | if (atomicDecrement64(&g_csrngRefCnt) == 0) 25 | serviceClose(&g_csrngSrv); 26 | } 27 | 28 | Result csrngGetRandomBytes(void *out, size_t out_size) { 29 | IpcCommand c; 30 | ipcInitialize(&c); 31 | 32 | ipcAddRecvBuffer(&c, out, out_size, BufferType_Normal); 33 | 34 | struct { 35 | u64 magic; 36 | u64 cmd_id; 37 | } *raw; 38 | 39 | raw = ipcPrepareHeader(&c, sizeof(*raw)); 40 | 41 | raw->magic = SFCI_MAGIC; 42 | raw->cmd_id = 0; 43 | 44 | Result rc = serviceIpcDispatch(&g_csrngSrv); 45 | 46 | if (R_SUCCEEDED(rc)) { 47 | IpcParsedCommand r; 48 | ipcParse(&r); 49 | 50 | struct { 51 | u64 magic; 52 | u64 result; 53 | } *resp = r.Raw; 54 | 55 | rc = resp->result; 56 | } 57 | 58 | return rc; 59 | } 60 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/display/binder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../types.h" 3 | #include "../kernel/event.h" 4 | 5 | #define BINDER_FIRST_CALL_TRANSACTION 0x1 6 | 7 | typedef struct { 8 | bool created : 1; 9 | bool initialized : 1; 10 | bool has_transact_auto : 1; 11 | s32 id; 12 | size_t ipc_buffer_size; 13 | } Binder; 14 | 15 | // Note: binderClose will not close the session_handle provided to binderCreate. 16 | void binderCreate(Binder* b, s32 id); 17 | void binderClose(Binder* b); 18 | 19 | Result binderInitSession(Binder* b); 20 | 21 | Result binderTransactParcel( 22 | Binder* b, u32 code, 23 | void* parcel_data, size_t parcel_data_size, 24 | void* parcel_reply, size_t parcel_reply_size, 25 | u32 flags); 26 | 27 | Result binderConvertErrorCode(s32 code); 28 | 29 | Result binderAdjustRefcount(Binder* b, s32 addval, s32 type); 30 | Result binderGetNativeHandle(Binder* b, u32 unk0, Event *event_out); 31 | 32 | static inline Result binderIncreaseWeakRef(Binder* b) 33 | { 34 | return binderAdjustRefcount(b, 1, 0); 35 | } 36 | 37 | static inline Result binderDecreaseWeakRef(Binder* b) 38 | { 39 | return binderAdjustRefcount(b, -1, 0); 40 | } 41 | 42 | static inline Result binderIncreaseStrongRef(Binder* b) 43 | { 44 | return binderAdjustRefcount(b, 1, 1); 45 | } 46 | 47 | static inline Result binderDecreaseStrongRef(Binder* b) 48 | { 49 | return binderAdjustRefcount(b, -1, 1); 50 | } 51 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/time.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file time.h 3 | * @brief Time services IPC wrapper. 4 | * @author yellows8 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | 9 | #include "../types.h" 10 | #include "../services/sm.h" 11 | 12 | /// Time clock type. 13 | typedef enum { 14 | TimeType_UserSystemClock, 15 | TimeType_NetworkSystemClock, 16 | TimeType_LocalSystemClock, 17 | TimeType_Default = TimeType_UserSystemClock, 18 | } TimeType; 19 | 20 | typedef struct { 21 | u16 year; 22 | u8 month; 23 | u8 day; 24 | u8 hour; 25 | u8 minute; 26 | u8 second; 27 | u8 pad; 28 | } TimeCalendarTime; 29 | 30 | typedef struct { 31 | u32 wday; ///< 0-based day-of-week. 32 | u32 yday; ///< 0-based day-of-year. 33 | char timezoneName[8]; ///< Timezone name string. 34 | u32 DST; ///< 0 = no DST, 1 = DST. 35 | s32 offset; ///< Seconds relative to UTC for this timezone. 36 | } TimeCalendarAdditionalInfo; 37 | 38 | Result timeInitialize(void); 39 | void timeExit(void); 40 | 41 | Service* timeGetSessionService(void); 42 | 43 | Result timeGetCurrentTime(TimeType type, u64 *timestamp); 44 | 45 | /** 46 | * @brief Sets the time for the specified clock. 47 | * @param[in] type Clock to use. 48 | * @param[in] timestamp POSIX UTC timestamp. 49 | * @return Result code. 50 | */ 51 | Result timeSetCurrentTime(TimeType type, u64 timestamp); 52 | 53 | Result timeToCalendarTimeWithMyRule(u64 timestamp, TimeCalendarTime *caltime, TimeCalendarAdditionalInfo *info); 54 | 55 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/nacp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file nacp.h 3 | * @brief Control.nacp structure / related code for nacp. 4 | * @copyright libnx Authors 5 | */ 6 | 7 | #pragma once 8 | 9 | /// Language entry. These strings are UTF-8. 10 | typedef struct { 11 | char name[0x200]; 12 | char author[0x100]; 13 | } NacpLanguageEntry; 14 | 15 | typedef struct { 16 | NacpLanguageEntry lang[16]; 17 | 18 | u8 x3000_unk[0x24];////Normally all-zero? 19 | u32 x3024_unk; 20 | u32 x3028_unk; 21 | u32 x302C_unk; 22 | u32 x3030_unk; 23 | u32 x3034_unk; 24 | u64 titleID0; 25 | 26 | u8 x3040_unk[0x20]; 27 | char version[0x10]; 28 | 29 | u64 titleID_DlcBase; 30 | u64 titleID1; 31 | 32 | u32 x3080_unk; 33 | u32 x3084_unk; 34 | u32 x3088_unk; 35 | u8 x308C_unk[0x24];//zeros? 36 | 37 | u64 titleID2; 38 | u64 titleIDs[7];//"Array of application titleIDs, normally the same as the above app-titleIDs. Only set for game-updates?" 39 | 40 | u32 x30F0_unk; 41 | u32 x30F4_unk; 42 | 43 | u64 titleID3;//"Application titleID. Only set for game-updates?" 44 | 45 | char bcatPassphrase[0x40]; 46 | u8 x3140_unk[0xEC0];//Normally all-zero? 47 | } NacpStruct; 48 | 49 | /// Get the NacpLanguageEntry from the input nacp corresponding to the current system language (this may fallback to other languages when needed). Output langentry is NULL if none found / content of entry is empty. 50 | Result nacpGetLanguageEntry(NacpStruct* nacp, NacpLanguageEntry** langentry); 51 | 52 | -------------------------------------------------------------------------------- /sp2Module/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "vector": "cpp", 4 | "type_traits": "cpp", 5 | "array": "cpp", 6 | "*.tcc": "cpp", 7 | "cctype": "cpp", 8 | "clocale": "cpp", 9 | "cmath": "cpp", 10 | "cstdarg": "cpp", 11 | "cstdint": "cpp", 12 | "cstdio": "cpp", 13 | "cstdlib": "cpp", 14 | "cwchar": "cpp", 15 | "cwctype": "cpp", 16 | "unordered_map": "cpp", 17 | "exception": "cpp", 18 | "fstream": "cpp", 19 | "initializer_list": "cpp", 20 | "iosfwd": "cpp", 21 | "iostream": "cpp", 22 | "istream": "cpp", 23 | "limits": "cpp", 24 | "new": "cpp", 25 | "optional": "cpp", 26 | "ostream": "cpp", 27 | "sstream": "cpp", 28 | "stdexcept": "cpp", 29 | "streambuf": "cpp", 30 | "string_view": "cpp", 31 | "system_error": "cpp", 32 | "tuple": "cpp", 33 | "typeinfo": "cpp", 34 | "utility": "cpp", 35 | "ios": "cpp", 36 | "fs.h": "c", 37 | "fs_dev.h": "c", 38 | "memory": "cpp", 39 | "xmemory0": "cpp", 40 | "xtr1common": "cpp", 41 | "xutility": "cpp", 42 | "cstddef": "cpp", 43 | "cstring": "cpp", 44 | "string": "cpp", 45 | "xfacet": "cpp", 46 | "xiosbase": "cpp", 47 | "xlocale": "cpp", 48 | "xlocinfo": "cpp", 49 | "xlocnum": "cpp", 50 | "xmemory": "cpp", 51 | "xstddef": "cpp", 52 | "xstring": "cpp", 53 | "list": "cpp" 54 | } 55 | } -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/hwopus.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hwopus.h 3 | * @brief Hardware Opus audio service. 4 | * @author yellows8 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | 9 | #include "../services/sm.h" 10 | #include "../kernel/tmem.h" 11 | 12 | typedef struct { 13 | Service s; 14 | TransferMemory tmem; 15 | bool multistream; 16 | } HwopusDecoder; 17 | 18 | /// This structure is the start of opusin for \ref hwopusDecodeInterleaved, with the actual opus packet following this. 19 | /// These fields are big-endian. 20 | typedef struct { 21 | u32 size; ///< Size of the packet following this header. 22 | u32 final_range; ///< Indicates the final range of the codec encoder's entropy coder. This can be left at zero. 23 | } HwopusHeader; 24 | 25 | /// Used internally. 26 | typedef struct { 27 | s32 SampleRate; 28 | s32 ChannelCount; 29 | s32 TotalStreamCount; 30 | s32 StereoStreamCount; 31 | u8 channel_mapping[256]; 32 | } HwopusMultistreamState; 33 | 34 | Result hwopusDecoderInitialize(HwopusDecoder* decoder, s32 SampleRate, s32 ChannelCount); 35 | void hwopusDecoderExit(HwopusDecoder* decoder); 36 | 37 | /// Only available on 3.0.0+. 38 | /// See libopus multistream docs. 39 | Result hwopusDecoderMultistreamInitialize(HwopusDecoder* decoder, s32 SampleRate, s32 ChannelCount, s32 TotalStreamCount, s32 StereoStreamCount, u8 *channel_mapping); 40 | 41 | /// Decodes opus data. 42 | Result hwopusDecodeInterleaved(HwopusDecoder* decoder, s32 *DecodedDataSize, s32 *DecodedSampleCount, const void* opusin, size_t opusin_size, s16 *pcmbuf, size_t pcmbuf_size); 43 | 44 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/display/buffer_producer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "types.h" 3 | #include "binder.h" 4 | #include "../nvidia/fence.h" 5 | 6 | typedef struct { 7 | s32 left; 8 | s32 top; 9 | s32 right; 10 | s32 bottom; 11 | } BqRect; 12 | 13 | typedef struct { 14 | struct { s64 timestamp; } PACKED; 15 | s32 isAutoTimestamp; 16 | BqRect crop; 17 | s32 scalingMode; 18 | u32 transform; // See the NATIVE_WINDOW_TRANSFORM_* enums. 19 | u32 stickyTransform; 20 | u32 unk; 21 | u32 swapInterval; 22 | NvMultiFence fence; 23 | } BqBufferInput; 24 | 25 | typedef struct { 26 | u32 width; 27 | u32 height; 28 | u32 transformHint; 29 | u32 numPendingBuffers; 30 | } BqBufferOutput; 31 | 32 | typedef struct { 33 | u32 width; 34 | u32 height; 35 | u32 stride; 36 | u32 format; 37 | u32 usage; 38 | NativeHandle* native_handle; 39 | } BqGraphicBuffer; 40 | 41 | Result bqRequestBuffer(Binder *b, s32 bufferIdx, BqGraphicBuffer *buf); 42 | Result bqDequeueBuffer(Binder *b, bool async, u32 width, u32 height, s32 format, u32 usage, s32 *buf, NvMultiFence *fence); 43 | Result bqDetachBuffer(Binder *b, s32 slot); 44 | Result bqQueueBuffer(Binder *b, s32 buf, const BqBufferInput *input, BqBufferOutput *output); 45 | Result bqCancelBuffer(Binder *b, s32 buf, const NvMultiFence *fence); 46 | Result bqQuery(Binder *b, s32 what, s32* value); 47 | Result bqConnect(Binder *b, s32 api, bool producerControlledByApp, BqBufferOutput *output); 48 | Result bqDisconnect(Binder *b, s32 api); 49 | Result bqSetPreallocatedBuffer(Binder *b, s32 buf, const BqGraphicBuffer *input); 50 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/kernel/event.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 plutoo 2 | #include "types.h" 3 | #include "result.h" 4 | #include "arm/counter.h" 5 | #include "kernel/svc.h" 6 | #include "kernel/wait.h" 7 | #include "kernel/event.h" 8 | 9 | Result eventCreate(Event* t, bool autoclear) 10 | { 11 | Result rc; 12 | 13 | rc = svcCreateEvent(&t->wevent, &t->revent); 14 | t->autoclear = autoclear; 15 | 16 | if (R_FAILED(rc)) { 17 | t->revent = INVALID_HANDLE; 18 | t->wevent = INVALID_HANDLE; 19 | } 20 | 21 | return rc; 22 | } 23 | 24 | void eventLoadRemote(Event* t, Handle handle, bool autoclear) 25 | { 26 | t->revent = handle; 27 | t->wevent = INVALID_HANDLE; 28 | t->autoclear = autoclear; 29 | } 30 | 31 | Result eventWait(Event* t, u64 timeout) 32 | { 33 | return waitSingle(waiterForEvent(t), timeout); 34 | } 35 | 36 | Result eventFire(Event* t) 37 | { 38 | if (t->wevent == INVALID_HANDLE) 39 | return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); 40 | 41 | return svcSignalEvent(t->wevent); 42 | } 43 | 44 | Result eventClear(Event* t) 45 | { 46 | if (t->wevent != INVALID_HANDLE) 47 | return svcClearEvent(t->wevent); 48 | 49 | if (t->revent != INVALID_HANDLE) 50 | return svcResetSignal(t->revent); 51 | 52 | return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); 53 | } 54 | 55 | void eventClose(Event* t) 56 | { 57 | if (t->revent != INVALID_HANDLE) 58 | svcCloseHandle(t->revent); 59 | if (t->wevent != INVALID_HANDLE) 60 | svcCloseHandle(t->wevent); 61 | 62 | t->revent = INVALID_HANDLE; 63 | t->wevent = INVALID_HANDLE; 64 | } 65 | -------------------------------------------------------------------------------- /Sp2Patcher/Sp2Patcher/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Les informations générales relatives à un assembly dépendent de 6 | // l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations 7 | // associées à un assembly. 8 | [assembly: AssemblyTitle("Sp2Patcher")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Sp2Patcher")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly 18 | // aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de 19 | // COM, affectez la valeur true à l'attribut ComVisible sur ce type. 20 | [assembly: ComVisible(false)] 21 | 22 | // Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM 23 | [assembly: Guid("44043ce0-fbab-491d-87f0-e2bfede77983")] 24 | 25 | // Les informations de version pour un assembly se composent des quatre valeurs suivantes : 26 | // 27 | // Version principale 28 | // Version secondaire 29 | // Numéro de build 30 | // Révision 31 | // 32 | // Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut 33 | // en utilisant '*', comme indiqué ci-dessous : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/ldr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ldr.h 3 | * @brief Loader (ldr*) service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../services/sm.h" 10 | #include "../services/fs.h" 11 | 12 | typedef struct { 13 | u8 main_thread_priority; 14 | u8 default_cpu_id; 15 | u16 application_type; 16 | u32 main_thread_stack_size; 17 | u64 title_id; 18 | u32 acid_sac_size; 19 | u32 aci0_sac_size; 20 | u32 acid_fac_size; 21 | u32 aci0_fah_size; 22 | u8 ac_buffer[0x3E0]; 23 | } LoaderProgramInfo; 24 | 25 | typedef struct { 26 | u64 base_address; 27 | u64 size; 28 | u8 build_id[0x20]; 29 | } LoaderModuleInfo; 30 | 31 | Result ldrShellInitialize(void); 32 | void ldrShellExit(void); 33 | 34 | Result ldrDmntInitialize(void); 35 | void ldrDmntExit(void); 36 | 37 | Result ldrPmInitialize(void); 38 | void ldrPmExit(void); 39 | 40 | Result ldrShellAddTitleToLaunchQueue(u64 tid, const void *args, size_t args_size); 41 | Result ldrShellClearLaunchQueue(void); 42 | 43 | Result ldrDmntAddTitleToLaunchQueue(u64 tid, const void *args, size_t args_size); 44 | Result ldrDmntClearLaunchQueue(void); 45 | Result ldrDmntGetModuleInfos(u64 pid, LoaderModuleInfo *out_module_infos, size_t out_size, u32 *num_out); 46 | 47 | Result ldrPmCreateProcess(u64 flags, u64 launch_index, Handle reslimit_h, Handle *out_process_h); 48 | Result ldrPmGetProgramInfo(u64 title_id, FsStorageId storage_id, LoaderProgramInfo *out_program_info); 49 | Result ldrPmRegisterTitle(u64 title_id, FsStorageId storage_id, u64 *out_index); 50 | Result ldrPmUnregisterTitle(u64 launch_index); 51 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/arm/cache.s: -------------------------------------------------------------------------------- 1 | .macro CODE_BEGIN name 2 | .section .text.\name, "ax", %progbits 3 | .global \name 4 | .type \name, %function 5 | .align 2 6 | .cfi_startproc 7 | \name: 8 | .endm 9 | 10 | .macro CODE_END 11 | .cfi_endproc 12 | .endm 13 | 14 | CODE_BEGIN armDCacheFlush 15 | add x1, x1, x0 16 | mrs x8, CTR_EL0 17 | lsr x8, x8, #16 18 | and x8, x8, #0xf 19 | mov x9, #4 20 | lsl x9, x9, x8 21 | sub x10, x9, #1 22 | bic x8, x0, x10 23 | mov x10, x1 24 | 25 | armDCacheFlush_L0: 26 | dc civac, x8 27 | add x8, x8, x9 28 | cmp x8, x10 29 | bcc armDCacheFlush_L0 30 | 31 | dsb sy 32 | ret 33 | CODE_END 34 | 35 | CODE_BEGIN armDCacheClean 36 | add x1, x1, x0 37 | mrs x8, CTR_EL0 38 | lsr x8, x8, #16 39 | and x8, x8, #0xf 40 | mov x9, #4 41 | lsl x9, x9, x8 42 | sub x10, x9, #1 43 | bic x8, x0, x10 44 | mov x10, x1 45 | 46 | armDCacheClean_L0: 47 | dc cvac, x8 48 | add x8, x8, x9 49 | cmp x8, x10 50 | bcc armDCacheClean_L0 51 | 52 | dsb sy 53 | ret 54 | CODE_END 55 | 56 | CODE_BEGIN armICacheInvalidate 57 | add x1, x1, x0 58 | mrs x8, CTR_EL0 59 | and x8, x8, #0xf 60 | mov x9, #4 61 | lsl x9, x9, x8 62 | sub x10, x9, #1 63 | bic x8, x0, x10 64 | mov x10, x1 65 | 66 | armICacheInvalidate_L0: 67 | ic ivau, x8 68 | add x8, x8, x9 69 | cmp x8, x10 70 | bcc armICacheInvalidate_L0 71 | 72 | dsb sy 73 | ret 74 | CODE_END 75 | 76 | CODE_BEGIN armDCacheZero 77 | add x1, x1, x0 78 | mrs x8, CTR_EL0 79 | lsr x8, x8, #16 80 | and x8, x8, #0xf 81 | mov x9, #4 82 | lsl x9, x9, x8 83 | sub x10, x9, #1 84 | bic x8, x0, x10 85 | mov x10, x1 86 | 87 | armDCacheZero_L0: 88 | dc zva, x8 89 | add x8, x8, x9 90 | cmp x8, x10 91 | bcc armDCacheZero_L0 92 | 93 | dsb sy 94 | ret 95 | CODE_END 96 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/display/default_window.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "types.h" 3 | #include "result.h" 4 | #include "services/vi.h" 5 | #include "services/fatal.h" 6 | #include "display/binder.h" 7 | #include "display/buffer_producer.h" 8 | #include "display/native_window.h" 9 | #include "nvidia/graphic_buffer.h" 10 | 11 | static ViDisplay g_viDisplay; 12 | static ViLayer g_viLayer; 13 | static NWindow g_defaultWin; 14 | 15 | NWindow* nwindowGetDefault(void) 16 | { 17 | return &g_defaultWin; 18 | } 19 | 20 | void __nx_win_init(void) 21 | { 22 | Result rc; 23 | rc = viInitialize(ViServiceType_Default); 24 | if (R_SUCCEEDED(rc)) { 25 | rc = viOpenDefaultDisplay(&g_viDisplay); 26 | if (R_SUCCEEDED(rc)) { 27 | rc = viCreateLayer(&g_viDisplay, &g_viLayer); 28 | if (R_SUCCEEDED(rc)) { 29 | rc = viSetLayerScalingMode(&g_viLayer, ViScalingMode_FitToLayer); 30 | if (R_SUCCEEDED(rc)) { 31 | rc = nwindowCreateFromLayer(&g_defaultWin, &g_viLayer); 32 | if (R_SUCCEEDED(rc)) 33 | nwindowSetDimensions(&g_defaultWin, 1280, 720); 34 | } 35 | if (R_FAILED(rc)) 36 | viCloseLayer(&g_viLayer); 37 | } 38 | if (R_FAILED(rc)) 39 | viCloseDisplay(&g_viDisplay); 40 | } 41 | if (R_FAILED(rc)) 42 | viExit(); 43 | } 44 | if (R_FAILED(rc)) 45 | fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGfxInit)); 46 | } 47 | 48 | void __nx_win_exit(void) 49 | { 50 | nwindowClose(&g_defaultWin); 51 | viCloseLayer(&g_viLayer); 52 | viCloseDisplay(&g_viDisplay); 53 | viExit(); 54 | } 55 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/arm/cache.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file cache.h 3 | * @brief AArch64 cache operations. 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | /** 11 | * @brief Performs a data cache flush on the specified buffer. 12 | * @param addr Address of the buffer. 13 | * @param size Size of the buffer, in bytes. 14 | * @remarks Cache flush is defined as Clean + Invalidate. 15 | * @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register). 16 | */ 17 | void armDCacheFlush(void* addr, size_t size); 18 | 19 | /** 20 | * @brief Performs a data cache clean on the specified buffer. 21 | * @param addr Address of the buffer. 22 | * @param size Size of the buffer, in bytes. 23 | * @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register). 24 | */ 25 | void armDCacheClean(void* addr, size_t size); 26 | 27 | /** 28 | * @brief Performs an instruction cache invalidation clean on the specified buffer. 29 | * @param addr Address of the buffer. 30 | * @param size Size of the buffer, in bytes. 31 | * @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register). 32 | */ 33 | void armICacheInvalidate(void* addr, size_t size); 34 | 35 | /** 36 | * @brief Performs a data cache zeroing operation on the specified buffer. 37 | * @param addr Address of the buffer. 38 | * @param size Size of the buffer, in bytes. 39 | * @note The start and end addresses of the buffer are forcibly rounded to cache line boundaries (read from CTR_EL0 system register). 40 | */ 41 | void armDCacheZero(void* addr, size_t size); 42 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/lr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lr.h 3 | * @brief Location Resolver (lr) service IPC wrapper. 4 | * @author SciresM 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../services/sm.h" 10 | #include "../services/fs.h" 11 | 12 | typedef struct { 13 | Service s; 14 | } LrLocationResolver; 15 | 16 | typedef struct { 17 | Service s; 18 | } LrRegisteredLocationResolver; 19 | 20 | Result lrInitialize(void); 21 | void lrExit(void); 22 | 23 | Result lrOpenLocationResolver(FsStorageId storage, LrLocationResolver* out); 24 | Result lrOpenRegisteredLocationResolver(LrRegisteredLocationResolver* out); 25 | // TODO: Other ILocationResolverManager commands 26 | 27 | // ILocationResolver 28 | Result lrLrResolveProgramPath(LrLocationResolver* lr, u64 tid, char *out); 29 | Result lrLrRedirectProgramPath(LrLocationResolver* lr, u64 tid, const char *path); 30 | Result lrLrResolveApplicationControlPath(LrLocationResolver* lr, u64 tid, char *out); 31 | Result lrLrResolveApplicationHtmlDocumentPath(LrLocationResolver* lr, u64 tid, char *out); 32 | Result lrLrResolveDataPath(LrLocationResolver* lr, u64 tid, char *out); 33 | Result lrLrRedirectApplicationControlPath(LrLocationResolver* lr, u64 tid, const char *path); 34 | Result lrLrRedirectApplicationHtmlDocumentPath(LrLocationResolver* lr, u64 tid, const char *path); 35 | Result lrLrResolveLegalInformationPath(LrLocationResolver* lr, u64 tid, char *out); 36 | Result lrLrRedirectLegalInformationPath(LrLocationResolver* lr, u64 tid, const char *path); 37 | Result lrLrRefresh(LrLocationResolver* lr); 38 | 39 | // IRegisteredLocationResolver 40 | Result lrRegLrResolveProgramPath(LrRegisteredLocationResolver* reg, u64 tid, char *out); 41 | // TODO: Other IRegisteredLocationResolver commands 42 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/util/utf/decode_utf8.c: -------------------------------------------------------------------------------- 1 | #include "runtime/util/utf.h" 2 | 3 | ssize_t 4 | decode_utf8(uint32_t *out, 5 | const uint8_t *in) 6 | { 7 | uint8_t code1, code2, code3, code4; 8 | 9 | code1 = *in++; 10 | if(code1 < 0x80) 11 | { 12 | /* 1-byte sequence */ 13 | *out = code1; 14 | return 1; 15 | } 16 | else if(code1 < 0xC2) 17 | { 18 | return -1; 19 | } 20 | else if(code1 < 0xE0) 21 | { 22 | /* 2-byte sequence */ 23 | code2 = *in++; 24 | if((code2 & 0xC0) != 0x80) 25 | { 26 | return -1; 27 | } 28 | 29 | *out = (code1 << 6) + code2 - 0x3080; 30 | return 2; 31 | } 32 | else if(code1 < 0xF0) 33 | { 34 | /* 3-byte sequence */ 35 | code2 = *in++; 36 | if((code2 & 0xC0) != 0x80) 37 | { 38 | return -1; 39 | } 40 | if(code1 == 0xE0 && code2 < 0xA0) 41 | { 42 | return -1; 43 | } 44 | 45 | code3 = *in++; 46 | if((code3 & 0xC0) != 0x80) 47 | { 48 | return -1; 49 | } 50 | 51 | *out = (code1 << 12) + (code2 << 6) + code3 - 0xE2080; 52 | return 3; 53 | } 54 | else if(code1 < 0xF5) 55 | { 56 | /* 4-byte sequence */ 57 | code2 = *in++; 58 | if((code2 & 0xC0) != 0x80) 59 | { 60 | return -1; 61 | } 62 | if(code1 == 0xF0 && code2 < 0x90) 63 | { 64 | return -1; 65 | } 66 | if(code1 == 0xF4 && code2 >= 0x90) 67 | { 68 | return -1; 69 | } 70 | 71 | code3 = *in++; 72 | if((code3 & 0xC0) != 0x80) 73 | { 74 | return -1; 75 | } 76 | 77 | code4 = *in++; 78 | if((code4 & 0xC0) != 0x80) 79 | { 80 | return -1; 81 | } 82 | 83 | *out = (code1 << 18) + (code2 << 12) + (code3 << 6) + code4 - 0x3C82080; 84 | return 4; 85 | } 86 | 87 | return -1; 88 | } 89 | -------------------------------------------------------------------------------- /Sp2Patcher/Sp2Patcher/ListingFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.IO; 7 | using System.Globalization; 8 | 9 | namespace Sp2Patcher 10 | { 11 | 12 | [Serializable] 13 | public class ListingFileException : Exception 14 | { 15 | public ListingFileException() { } 16 | public ListingFileException(string message) : base(message) { } 17 | public ListingFileException(string message, Exception inner) : base(message, inner) { } 18 | protected ListingFileException( 19 | System.Runtime.Serialization.SerializationInfo info, 20 | System.Runtime.Serialization.StreamingContext context) : base(info, context) { } 21 | } 22 | public static class ListingFile 23 | { 24 | public static List> GetSymbols(string filename) 25 | { 26 | List> symbols = new List>(); 27 | 28 | var lines = File.ReadAllLines(filename); 29 | foreach (var line in lines) 30 | { 31 | var parts = line.Split(new char[] { ' ' }, 4); 32 | string symbol = ""; 33 | switch (parts.Length) 34 | { 35 | case 3: symbol = parts[2]; break; 36 | case 4: symbol = parts[3]; break; 37 | default: continue; 38 | } 39 | 40 | //int index = symbol.IndexOf("("); 41 | //if (index > 0) 42 | // symbol = symbol.Substring(0, index); 43 | 44 | symbols.Add(new Tuple(symbol, uint.Parse(parts[0], NumberStyles.HexNumber))); 45 | } 46 | return symbols; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/utimer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file utimer.h 3 | * @brief User-mode timer synchronization primitive. 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "wait.h" 9 | 10 | typedef struct UTimer UTimer; 11 | 12 | /// Valid types for a user-mode timer. 13 | typedef enum { 14 | TimerType_OneShot, ///< Timers of this kind fire once and then stop automatically. 15 | TimerType_Repeating, ///< Timers of this kind fire periodically. 16 | } TimerType; 17 | 18 | /// User-mode timer object. 19 | struct UTimer { 20 | Waitable waitable; 21 | TimerType type : 8; 22 | bool started : 1; 23 | u64 next_tick; 24 | u64 interval; 25 | }; 26 | 27 | /// Creates a waiter for a user-mode timer. 28 | static inline Waiter waiterForUTimer(UTimer* t) 29 | { 30 | Waiter wait_obj; 31 | wait_obj.type = WaiterType_Waitable; 32 | wait_obj.waitable = &t->waitable; 33 | return wait_obj; 34 | } 35 | 36 | /** 37 | * @brief Creates a user-mode timer. 38 | * @param[out] t UTimer object. 39 | * @param[in] interval Interval (in nanoseconds). 40 | * @param[in] type Type of timer to create (see \ref TimerType). 41 | * @note The timer is stopped when it is created. Use \ref utimerStart to start it. 42 | * @note It is safe to wait on this timer with several threads simultaneously. 43 | * @note If more than one thread is listening on it, at least one thread will get the signal. No other guarantees. 44 | * @note For a repeating timer: If the timer triggers twice before you wait on it, you will only get one signal. 45 | */ 46 | void utimerCreate(UTimer* t, u64 interval, TimerType type); 47 | 48 | /** 49 | * @brief Starts the timer. 50 | * @param[in] t UTimer object. 51 | */ 52 | void utimerStart(UTimer* t); 53 | 54 | /** 55 | * @brief Stops the timer. 56 | * @param[in] t UTimer object. 57 | */ 58 | void utimerStop(UTimer* t); 59 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/mutex.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file mutex.h 3 | * @brief Mutex synchronization primitive. 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include 9 | #include "../types.h" 10 | 11 | /// Mutex datatype, defined in newlib. 12 | typedef _LOCK_T Mutex; 13 | /// Recursive mutex datatype, defined in newlib. 14 | typedef _LOCK_RECURSIVE_T RMutex; 15 | 16 | /** 17 | * @brief Initializes a mutex. 18 | * @param m Mutex object. 19 | * @note A mutex can also be statically initialized by assigning 0 to it. 20 | */ 21 | static inline void mutexInit(Mutex* m) 22 | { 23 | *m = 0; 24 | } 25 | 26 | /** 27 | * @brief Locks a mutex. 28 | * @param m Mutex object. 29 | */ 30 | void mutexLock(Mutex* m); 31 | 32 | /** 33 | * @brief Attempts to lock a mutex without waiting. 34 | * @param m Mutex object. 35 | * @return 1 if the mutex has been acquired successfully, and 0 on contention. 36 | */ 37 | bool mutexTryLock(Mutex* m); 38 | 39 | /** 40 | * @brief Unlocks a mutex. 41 | * @param m Mutex object. 42 | */ 43 | void mutexUnlock(Mutex* m); 44 | 45 | /** 46 | * @brief Initializes a recursive mutex. 47 | * @param m Recursive mutex object. 48 | * @note A recursive mutex can also be statically initialized by assigning {0,0,0} to it. 49 | */ 50 | static inline void rmutexInit(RMutex* m) 51 | { 52 | m->lock = 0; 53 | m->thread_tag = 0; 54 | m->counter = 0; 55 | } 56 | 57 | /** 58 | * @brief Locks a recursive mutex. 59 | * @param m Recursive mutex object. 60 | */ 61 | void rmutexLock(RMutex* m); 62 | 63 | /** 64 | * @brief Attempts to lock a recursive mutex without waiting. 65 | * @param m Recursive mutex object. 66 | * @return 1 if the mutex has been acquired successfully, and 0 on contention. 67 | */ 68 | bool rmutexTryLock(RMutex* m); 69 | 70 | /** 71 | * @brief Unlocks a recursive mutex. 72 | * @param m Recursive mutex object. 73 | */ 74 | void rmutexUnlock(RMutex* m); 75 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/jit.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file jit.h 3 | * @brief Just-in-time compilation support. 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | /// JIT implementation type. 11 | typedef enum { 12 | JitType_CodeMemory, ///< JIT supported using svcSetProcessMemoryPermission 13 | JitType_JitMemory, ///< JIT supported using 4.0.0+ code-memory syscalls (this isn't usable on 5.0.0+ so JitType_CodeMemory is used instead). 14 | } JitType; 15 | 16 | /// JIT buffer object. 17 | typedef struct { 18 | JitType type; 19 | size_t size; 20 | void* src_addr; 21 | void* rx_addr; 22 | void* rw_addr; 23 | bool is_executable; 24 | Handle handle; 25 | } Jit; 26 | 27 | /** 28 | * @brief Creates a JIT buffer. 29 | * @param j JIT buffer. 30 | * @param size Size of the JIT buffer. 31 | * @return Result code. 32 | */ 33 | Result jitCreate(Jit* j, size_t size); 34 | 35 | /** 36 | * @brief Transition a JIT buffer to have writable permission. 37 | * @param j JIT buffer. 38 | * @return Result code. 39 | */ 40 | Result jitTransitionToWritable(Jit* j); 41 | 42 | /** 43 | * @brief Transition a JIT buffer to have executable permission. 44 | * @param j JIT buffer. 45 | * @return Result code. 46 | */ 47 | Result jitTransitionToExecutable(Jit* j); 48 | 49 | /** 50 | * @brief Destroys a JIT buffer. 51 | * @param j JIT buffer. 52 | * @return Result code. 53 | */ 54 | Result jitClose(Jit* j); 55 | 56 | /** 57 | * @brief Gets the address of the writable memory alias of a JIT buffer. 58 | * @param j JIT buffer. 59 | * @return Pointer to alias of the JIT buffer that can be written to. 60 | */ 61 | void* jitGetRwAddr(Jit* j); 62 | 63 | /** 64 | * @brief Gets the address of the executable memory alias of a JIT buffer. 65 | * @param j JIT buffer. 66 | * @return Pointer to alias of the JIT buffer that can be executed. 67 | */ 68 | void* jitGetRxAddr(Jit* j); 69 | -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/ProcessMemory.cpp: -------------------------------------------------------------------------------- 1 | #include "ProcessMemory.hpp" 2 | 3 | 4 | u64 ProcessMemory::ModuleAddr(u64 addr, int moduleIndex) 5 | { 6 | MemoryInfo mi; 7 | u32 pi; 8 | u64 curaddr = 0; 9 | int moduleCount = 0; 10 | 11 | while (true) 12 | { 13 | svcQueryMemory(&mi, &pi, curaddr); 14 | if (mi.perm == Perm_Rx && moduleCount++ == moduleIndex) 15 | break; 16 | 17 | curaddr = mi.addr + mi.size; 18 | } 19 | 20 | return mi.addr + addr; 21 | } 22 | 23 | u64 ProcessMemory::ImageAddr(u64 addr) 24 | { 25 | return ProcessMemory::RtldAddr(addr); 26 | } 27 | u64 ProcessMemory::RtldAddr(u64 addr) 28 | { 29 | static u64 rtldAddr = 0; 30 | if (!rtldAddr) 31 | { 32 | rtldAddr = ProcessMemory::ModuleAddr(0, 0); 33 | } 34 | return rtldAddr + addr; 35 | } 36 | u64 ProcessMemory::MainAddr(u64 addr) 37 | { 38 | static u64 mainAddr = 0; 39 | if (!mainAddr) 40 | { 41 | mainAddr = ProcessMemory::ModuleAddr(0, 1); 42 | } 43 | return mainAddr + addr; 44 | } 45 | u64 ProcessMemory::SdkAddr(u64 addr) 46 | { 47 | static u64 sdkAddr = 0; 48 | if (!sdkAddr) 49 | { 50 | sdkAddr = ProcessMemory::ModuleAddr(0, 2); 51 | } 52 | return sdkAddr + addr; 53 | } 54 | 55 | u64 ProcessMemory::ThisAddr(u64 addr) 56 | { 57 | static u64 sdkAddr = 0; 58 | if (!sdkAddr) 59 | { 60 | sdkAddr = ProcessMemory::ModuleAddr(0, 3); 61 | } 62 | return sdkAddr + addr; 63 | } 64 | 65 | HidSharedMemory* ProcessMemory::GetHidSharedMemory() 66 | { 67 | MemoryInfo mi; 68 | u32 pi; 69 | u64 curaddr = 0; 70 | 71 | while (true) 72 | { 73 | svcQueryMemory(&mi, &pi, curaddr); 74 | if (mi.perm == Perm_R && mi.type == MemType_SharedMem && mi.size == 0x40000) 75 | break; 76 | 77 | curaddr = mi.addr + mi.size; 78 | } 79 | 80 | return (HidSharedMemory*)mi.addr; 81 | } -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/kernel/shmem.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 plutoo 2 | #include 3 | #include "types.h" 4 | #include "result.h" 5 | #include "kernel/svc.h" 6 | #include "kernel/virtmem.h" 7 | #include "kernel/shmem.h" 8 | 9 | Result shmemCreate(SharedMemory* s, size_t size, Permission local_perm, Permission remote_perm) 10 | { 11 | Result rc; 12 | 13 | s->handle = INVALID_HANDLE; 14 | s->size = size; 15 | s->map_addr = NULL; 16 | s->perm = local_perm; 17 | 18 | rc = svcCreateSharedMemory(&s->handle, size, local_perm, remote_perm); 19 | 20 | return rc; 21 | } 22 | 23 | void shmemLoadRemote(SharedMemory* s, Handle handle, size_t size, Permission perm) 24 | { 25 | s->handle = handle; 26 | s->size = size; 27 | s->map_addr = NULL; 28 | s->perm = perm; 29 | } 30 | 31 | Result shmemMap(SharedMemory* s) 32 | { 33 | Result rc = 0; 34 | 35 | if (s->map_addr == NULL) 36 | { 37 | void* addr = virtmemReserve(s->size); 38 | 39 | rc = svcMapSharedMemory(s->handle, addr, s->size, s->perm); 40 | 41 | if (R_SUCCEEDED(rc)) { 42 | s->map_addr = addr; 43 | } 44 | else { 45 | virtmemFree(addr, s->size); 46 | } 47 | } 48 | else { 49 | rc = LibnxError_AlreadyMapped; 50 | } 51 | 52 | return rc; 53 | } 54 | 55 | Result shmemUnmap(SharedMemory* s) 56 | { 57 | Result rc; 58 | 59 | rc = svcUnmapSharedMemory(s->handle, s->map_addr, s->size); 60 | 61 | if (R_SUCCEEDED(rc)) { 62 | virtmemFree(s->map_addr, s->size); 63 | s->map_addr = NULL; 64 | } 65 | 66 | return rc; 67 | } 68 | 69 | Result shmemClose(SharedMemory* s) 70 | { 71 | Result rc = 0; 72 | 73 | if (s->map_addr != NULL) { 74 | rc = shmemUnmap(s); 75 | } 76 | 77 | if (R_SUCCEEDED(rc)) { 78 | if (s->handle != INVALID_HANDLE) { 79 | rc = svcCloseHandle(s->handle); 80 | } 81 | 82 | s->handle = INVALID_HANDLE; 83 | } 84 | 85 | return rc; 86 | } 87 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/detect.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file detect.h 3 | * @brief Kernel capability detection 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | /// Returns the kernel version that can be detected by checking kernel capabilities. This only goes from 1 (representing 1.0.0) up to 6 (representing 6.0.0 and above). Generally, \ref hosversionGet should be used instead of this function. 11 | int detectKernelVersion(void); 12 | /// Returns true if the process has a debugger attached. 13 | bool detectDebugger(void); 14 | /// Returns true if the kernel is patched to allow self-process-jit. 15 | bool detectJitKernelPatch(void); 16 | /// After this has been called, libnx will ignore the self-process-jit kernel patch. For testing purposes only. 17 | void detectIgnoreJitKernelPatch(void); 18 | 19 | /// Returns true if the kernel version is equal to or above 2.0.0. Generally, \ref hosversionAtLeast should be used instead of this function. 20 | static inline bool kernelAbove200(void) { 21 | return detectKernelVersion() >= 2; 22 | } 23 | 24 | /// Returns true if the kernel version is equal to or above 3.0.0. Generally, \ref hosversionAtLeast should be used instead of this function. 25 | static inline bool kernelAbove300(void) { 26 | return detectKernelVersion() >= 3; 27 | } 28 | 29 | /// Returns true if the kernel version is equal to or above 4.0.0. Generally, \ref hosversionAtLeast should be used instead of this function. 30 | static inline bool kernelAbove400(void) { 31 | return detectKernelVersion() >= 4; 32 | } 33 | 34 | /// Returns true if the kernel version is equal to or above 5.0.0. Generally, \ref hosversionAtLeast should be used instead of this function. 35 | static inline bool kernelAbove500(void) { 36 | return detectKernelVersion() >= 5; 37 | } 38 | 39 | /// Returns true if the kernel version is equal to or above 6.0.0. Generally, \ref hosversionAtLeast should be used instead of this function. 40 | static inline bool kernelAbove600(void) { 41 | return detectKernelVersion() >= 6; 42 | } 43 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/runtime/hosversion.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hosversion.h 3 | * @brief Horizon OS (HOS) version detection utilities. 4 | * @author fincs 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | /// Builds a HOS version value from its constituent components. 11 | #define MAKEHOSVERSION(_major,_minor,_micro) (((u32)(_major) << 16) | ((u32)(_minor) << 8) | (u32)(_micro)) 12 | 13 | /// Extracts the major number from a HOS version value. 14 | #define HOSVER_MAJOR(_version) (((_version) >> 16) & 0xFF) 15 | 16 | /// Extracts the minor number from a HOS version value. 17 | #define HOSVER_MINOR(_version) (((_version) >> 8) & 0xFF) 18 | 19 | /// Extracts the micro number from a HOS version value. 20 | #define HOSVER_MICRO(_version) ( (_version) & 0xFF) 21 | 22 | /// Returns the current HOS version that was previously set with \ref hosversionSet. If version initialization fails during startup (such as in the case set:sys is not available), this function returns zero. 23 | u32 hosversionGet(void); 24 | 25 | /// Sets or overrides the current HOS version. This function is normally called automatically by libnx on startup with the version info obtained with \ref setsysGetFirmwareVersion. 26 | void hosversionSet(u32 version); 27 | 28 | /// Returns true if the current HOS version is equal to or above the specified major/minor/micro version. 29 | static inline bool hosversionAtLeast(u8 major, u8 minor, u8 micro) { 30 | return hosversionGet() >= MAKEHOSVERSION(major,minor,micro); 31 | } 32 | 33 | /// Returns true if the current HOS version is earlier than the specified major/minor/micro version. 34 | static inline bool hosversionBefore(u8 major, u8 minor, u8 micro) { 35 | return !hosversionAtLeast(major, minor, micro); 36 | } 37 | 38 | /// Returns true if the current HOS version is between the two specified major versions, i.e. [major1, major2). 39 | static inline bool hosversionBetween(u8 major1, u8 major2) { 40 | u32 ver = hosversionGet(); 41 | return ver >= MAKEHOSVERSION(major1,0,0) && ver < MAKEHOSVERSION(major2,0,0); 42 | } 43 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/audio/driver_internal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "types.h" 5 | #include "result.h" 6 | #include "arm/atomics.h" 7 | #include "services/audren.h" 8 | #include "audio/driver.h" 9 | 10 | typedef struct { 11 | int next_free; 12 | int padding; 13 | } AudioDriverEtcMemPool; 14 | 15 | typedef struct { 16 | int* prev_next_voice; 17 | int next_free_channel; 18 | int next_used_voice; 19 | u16 node_counter; 20 | u32 num_wavebufs_consumed; 21 | u32 voice_drops_count; 22 | u64 played_sample_count; 23 | AudioDriverWaveBuf* first_wavebuf; 24 | AudioDriverWaveBuf* waiting_wavebuf; 25 | AudioDriverWaveBuf* last_wavebuf; 26 | } AudioDriverEtcVoice; 27 | 28 | typedef struct { 29 | int next_free; 30 | int padding; 31 | } AudioDriverEtcMix; 32 | 33 | typedef struct { 34 | int next_free; 35 | int padding; 36 | } AudioDriverEtcSink; 37 | 38 | struct AudioDriverEtc { 39 | int mempool_count; 40 | int free_channel_count; 41 | int free_mix_buffer_count; 42 | int first_used_voice; 43 | int first_free_mempool; 44 | int first_free_channel; 45 | int first_free_mix; 46 | int first_free_sink; 47 | AudioDriverEtcMemPool* mempools; 48 | AudioDriverEtcVoice* voices; 49 | AudioDriverEtcMix* mixes; 50 | AudioDriverEtcSink* sinks; 51 | AudioRendererBehaviorInfoIn* in_behavior; 52 | AudioRendererPerformanceBufferInfoIn* in_perfbuf; 53 | void* in_buf; 54 | size_t in_buf_size; 55 | void* out_buf; 56 | size_t out_buf_size; 57 | }; 58 | 59 | static inline size_t _audrvGetEtcSize(const AudioRendererConfig* config) 60 | { 61 | size_t size = 0; 62 | size += sizeof(AudioDriverEtc); 63 | size += sizeof(AudioDriverEtcMemPool) * audrenGetMemPoolCount(config); 64 | size += sizeof(AudioDriverEtcVoice) * config->num_voices; 65 | size += sizeof(AudioDriverEtcMix) * config->num_mix_objs; 66 | size += sizeof(AudioDriverEtcSink) * config->num_sinks; 67 | return size; 68 | } 69 | 70 | void _audrvVoiceUpdate(AudioDriver* d, int id, AudioRendererVoiceInfoOut* out_voice); 71 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/services/capssc.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "result.h" 3 | #include "arm/atomics.h" 4 | #include "kernel/ipc.h" 5 | #include "runtime/hosversion.h" 6 | #include "services/caps.h" 7 | #include "services/capssc.h" 8 | #include "services/sm.h" 9 | 10 | static Service g_capsscSrv; 11 | static u64 g_capsscRefCnt; 12 | 13 | Result capsscInitialize(void) { 14 | Result rc=0; 15 | 16 | atomicIncrement64(&g_capsscRefCnt); 17 | 18 | if (serviceIsActive(&g_capsscSrv)) 19 | return 0; 20 | 21 | if (hosversionBefore(2,0,0)) 22 | rc = MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); 23 | 24 | if (R_SUCCEEDED(rc)) rc = smGetService(&g_capsscSrv, "caps:sc"); 25 | 26 | if (R_FAILED(rc)) capsscExit(); 27 | 28 | return rc; 29 | } 30 | 31 | void capsscExit(void) { 32 | if (atomicDecrement64(&g_capsscRefCnt) == 0) 33 | serviceClose(&g_capsscSrv); 34 | } 35 | 36 | Result capsscCaptureScreenshot(void* buf, size_t size, u32 inval, u64 width, u64 height, s64 buffer_count, s64 buffer_index, u64 timeout) { 37 | IpcCommand c; 38 | ipcInitialize(&c); 39 | 40 | struct { 41 | u64 magic; 42 | u64 cmd_id; 43 | u32 inval; 44 | u64 width; 45 | u64 height; 46 | s64 buffer_count; 47 | s64 buffer_index; 48 | u64 timeout; 49 | } *raw; 50 | 51 | ipcAddRecvBuffer(&c, buf, size, 1); 52 | 53 | raw = serviceIpcPrepareHeader(&g_capsscSrv, &c, sizeof(*raw)); 54 | 55 | raw->magic = SFCI_MAGIC; 56 | raw->cmd_id = 2; 57 | raw->inval = inval; 58 | raw->width = width; 59 | raw->height = height; 60 | raw->buffer_count = buffer_count; 61 | raw->buffer_index = buffer_index; 62 | raw->timeout = timeout; 63 | 64 | Result rc = serviceIpcDispatch(&g_capsscSrv); 65 | 66 | if (R_SUCCEEDED(rc)) { 67 | IpcParsedCommand r; 68 | struct { 69 | u64 magic; 70 | u64 result; 71 | } *resp; 72 | 73 | serviceIpcParse(&g_capsscSrv, &r, sizeof(*resp)); 74 | resp = r.Raw; 75 | 76 | rc = resp->result; 77 | } 78 | 79 | return rc; 80 | } 81 | 82 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/services/spsm.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "result.h" 3 | #include "arm/atomics.h" 4 | #include "kernel/ipc.h" 5 | #include "services/spsm.h" 6 | #include "services/sm.h" 7 | 8 | static Service g_spsmSrv; 9 | static u64 g_refCnt; 10 | 11 | Result spsmInitialize(void) { 12 | Result rc = 0; 13 | 14 | atomicIncrement64(&g_refCnt); 15 | 16 | if (serviceIsActive(&g_spsmSrv)) 17 | return 0; 18 | 19 | rc = smGetService(&g_spsmSrv, "spsm"); 20 | 21 | if (R_FAILED(rc)) spsmExit(); 22 | 23 | return rc; 24 | } 25 | 26 | void spsmExit(void) { 27 | if (atomicDecrement64(&g_refCnt) == 0) { 28 | serviceClose(&g_spsmSrv); 29 | } 30 | } 31 | 32 | Result spsmShutdown(bool reboot) { 33 | IpcCommand c; 34 | ipcInitialize(&c); 35 | 36 | struct { 37 | u64 magic; 38 | u64 cmd_id; 39 | u32 reboot; 40 | } *raw; 41 | 42 | raw = serviceIpcPrepareHeader(&g_spsmSrv, &c, sizeof(*raw)); 43 | 44 | raw->magic = SFCI_MAGIC; 45 | raw->cmd_id = 3; 46 | raw->reboot = reboot; 47 | 48 | Result rc = serviceIpcDispatch(&g_spsmSrv); 49 | 50 | if (R_SUCCEEDED(rc)) { 51 | IpcParsedCommand r; 52 | struct { 53 | u64 magic; 54 | u64 result; 55 | } *resp; 56 | 57 | serviceIpcParse(&g_spsmSrv, &r, sizeof(*resp)); 58 | resp = r.Raw; 59 | 60 | rc = resp->result; 61 | } 62 | 63 | return rc; 64 | } 65 | 66 | Result spsmPutErrorState(void) { 67 | IpcCommand c; 68 | ipcInitialize(&c); 69 | 70 | struct { 71 | u64 magic; 72 | u64 cmd_id; 73 | } *raw; 74 | 75 | raw = serviceIpcPrepareHeader(&g_spsmSrv, &c, sizeof(*raw)); 76 | 77 | raw->magic = SFCI_MAGIC; 78 | raw->cmd_id = 10; 79 | 80 | Result rc = serviceIpcDispatch(&g_spsmSrv); 81 | 82 | if (R_SUCCEEDED(rc)) { 83 | IpcParsedCommand r; 84 | struct { 85 | u64 magic; 86 | u64 result; 87 | } *resp; 88 | 89 | serviceIpcParse(&g_spsmSrv, &r, sizeof(*resp)); 90 | resp = r.Raw; 91 | 92 | rc = resp->result; 93 | } 94 | 95 | return rc; 96 | } 97 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/psm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file psm.h 3 | * @brief PSM service IPC wrapper. 4 | * @author XorTroll, endrift, and yellows8 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../services/sm.h" 10 | #include "../kernel/event.h" 11 | 12 | typedef enum { 13 | ChargerType_None = 0, ///< No charger 14 | ChargerType_Charger = 1, ///< Official charger or dock 15 | ChargerType_Usb = 2 ///< Other USB-C chargers 16 | } ChargerType; 17 | 18 | typedef enum { 19 | PsmBatteryVoltageState_NeedsShutdown = 0, ///< Power state should transition to shutdown 20 | PsmBatteryVoltageState_NeedsSleep = 1, ///< Power state should transition to sleep 21 | PsmBatteryVoltageState_NoPerformanceBoost = 2, ///< Performance boost modes cannot be entered 22 | PsmBatteryVoltageState_Normal = 3, ///< Everything is normal 23 | } PsmBatteryVoltageState; 24 | 25 | /// IPsmSession 26 | typedef struct { 27 | Service s; 28 | Event StateChangeEvent; ///< autoclear=false 29 | } PsmSession; 30 | 31 | Result psmInitialize(void); 32 | void psmExit(void); 33 | 34 | Result psmGetBatteryChargePercentage(u32 *out); 35 | Result psmGetChargerType(ChargerType *out); 36 | Result psmGetBatteryVoltageState(PsmBatteryVoltageState *out); 37 | 38 | /** 39 | * @brief Wrapper func which opens a PsmSession and handles event setup. 40 | * @note Uses the actual BindStateChangeEvent cmd internally. 41 | * @note The event is not signalled on BatteryChargePercentage changes. 42 | * @param[out] s PsmSession object. 43 | * @param[in] ChargerType Passed to SetChargerTypeChangeEventEnabled. 44 | * @param[in] PowerSupply Passed to SetPowerSupplyChangeEventEnabled. 45 | * @param[in] BatteryVoltage Passed to SetBatteryVoltageStateChangeEventEnabled. 46 | */ 47 | Result psmBindStateChangeEvent(PsmSession* s, bool ChargerType, bool PowerSupply, bool BatteryVoltage); 48 | 49 | /// Wait on the Event setup by \ref psmBindStateChangeEvent. 50 | Result psmWaitStateChangeEvent(PsmSession* s, u64 timeout); 51 | 52 | /// Cleanup version of \ref psmBindStateChangeEvent. Must be called by the user once the PsmSession is done being used. 53 | Result psmUnbindStateChangeEvent(PsmSession* s); 54 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/runtime/devices/fs_dev.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file fs_dev.h 3 | * @brief FS driver, using devoptab. 4 | * @author yellows8 5 | * @author mtheall 6 | * @copyright libnx Authors 7 | */ 8 | #pragma once 9 | 10 | #include 11 | #include "../../services/fs.h" 12 | 13 | #define FSDEV_DIRITER_MAGIC 0x66736476 ///< "fsdv" 14 | 15 | /// Open directory struct 16 | typedef struct 17 | { 18 | u32 magic; ///< "fsdv" 19 | FsDir fd; ///< File descriptor 20 | ssize_t index; ///< Current entry index 21 | size_t size; ///< Current batch size 22 | FsDirectoryEntry entry_data[32]; ///< Temporary storage for reading entries 23 | } fsdev_dir_t; 24 | 25 | /// Initializes and mounts the sdmc device if accessible. Also initializes current working directory to point to the folder containing the path to the executable (argv[0]), if it is provided by the environment. 26 | Result fsdevMountSdmc(void); 27 | 28 | /// Mounts the input fs with the specified device name. fsdev will handle closing the fs when required, including when fsdevMountDevice() fails. 29 | /// Returns -1 when any errors occur. 30 | int fsdevMountDevice(const char *name, FsFileSystem fs); 31 | 32 | /// Unmounts the specified device. 33 | int fsdevUnmountDevice(const char *name); 34 | 35 | /// Uses fsFsCommit() with the specified device. This must be used after any savedata-write operations(not just file-write). This should be used after each file-close where file-writing was done. 36 | /// This is not used automatically at device unmount. 37 | Result fsdevCommitDevice(const char *name); 38 | 39 | /// Returns the FsFileSystem for the specified device. Returns NULL when the specified device isn't found. 40 | FsFileSystem* fsdevGetDeviceFileSystem(const char *name); 41 | 42 | /// Returns the FsFileSystem for the default device (SD card), if mounted. Used internally by romfs_dev. 43 | FsFileSystem* fsdevGetDefaultFileSystem(void); 44 | 45 | /// This calls fsFsSetArchiveBit on the filesystem specified by the input absolute path. 46 | Result fsdevSetArchiveBit(const char *path); 47 | 48 | /// Unmounts all devices and cleans up any resources used by the FS driver. 49 | Result fsdevUnmountAll(void); 50 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/external/bsd/include/sys/_iovec.h: -------------------------------------------------------------------------------- 1 | // TuxSH: removed definitions under _KERNEL ifdef blocks, modify the prototype of some functions, some other cleanup, etc. 2 | 3 | /*- 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | * 6 | * Copyright (c) 1982, 1986, 1993, 1994 7 | * The Regents of the University of California. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#)uio.h 8.5 (Berkeley) 2/22/94 34 | * $FreeBSD$ 35 | */ 36 | 37 | #ifndef _SYS__IOVEC_H_ 38 | #define _SYS__IOVEC_H_ 39 | 40 | #include // changed 41 | #include 42 | 43 | struct iovec { 44 | void *iov_base; /* Base address. */ 45 | size_t iov_len; /* Length. */ 46 | }; 47 | 48 | #endif /* !_SYS__IOVEC_H_ */ 49 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/nacp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "result.h" 5 | #include "runtime/env.h" 6 | #include "kernel/svc.h" 7 | #include "services/set.h" 8 | #include "nacp.h" 9 | 10 | static u32 g_nacpLanguageTable[15] = { 11 | [SetLanguage_JA] = 2, 12 | [SetLanguage_ENUS] = 0, 13 | [SetLanguage_ENGB] = 1, 14 | [SetLanguage_FR] = 3, 15 | [SetLanguage_DE] = 4, 16 | [SetLanguage_ES419] = 5, 17 | [SetLanguage_ES] = 6, 18 | [SetLanguage_IT] = 7, 19 | [SetLanguage_NL] = 8, 20 | [SetLanguage_FRCA] = 9, 21 | [SetLanguage_PT] = 10, 22 | [SetLanguage_RU] = 11, 23 | [SetLanguage_KO] = 12, 24 | [SetLanguage_ZHTW] = 13, 25 | [SetLanguage_ZHCN] = 14, 26 | }; 27 | 28 | //Official sw uses nsam for this, but since that's a privileged service, use set-service instead for compatibility with newer system-versions. 29 | Result nacpGetLanguageEntry(NacpStruct* nacp, NacpLanguageEntry** langentry) { 30 | Result rc=0; 31 | u64 LanguageCode=0; 32 | s32 Language=0; 33 | NacpLanguageEntry *entry = NULL; 34 | u32 i=0; 35 | 36 | if (nacp==NULL || langentry==NULL) 37 | return MAKERESULT(Module_Libnx, LibnxError_BadInput); 38 | 39 | *langentry = NULL; 40 | 41 | rc = setInitialize(); 42 | if (R_FAILED(rc)) 43 | return rc; 44 | 45 | rc = setGetSystemLanguage(&LanguageCode); 46 | if (R_SUCCEEDED(rc)) 47 | rc = setMakeLanguage(LanguageCode, &Language); 48 | 49 | if (Language < 0) 50 | rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); 51 | 52 | if (R_SUCCEEDED(rc) && Language >= 15) 53 | Language = SetLanguage_ENUS;//Use ENUS for unsupported system languages. 54 | 55 | setExit(); 56 | 57 | if (R_FAILED(rc)) 58 | return rc; 59 | 60 | entry = &nacp->lang[g_nacpLanguageTable[Language]]; 61 | 62 | if (entry->name[0]==0 && entry->author[0]==0) { 63 | for(i=0; i<16; i++) { 64 | entry = &nacp->lang[i]; 65 | if (entry->name[0] || entry->author[0]) break; 66 | } 67 | } 68 | 69 | if (entry->name[0]==0 && entry->author[0]==0) 70 | return rc; 71 | 72 | *langentry = entry; 73 | 74 | return rc; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/kernel/uevent.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 plutoo 2 | #include "result.h" 3 | #include "kernel/svc.h" 4 | #include "kernel/mutex.h" 5 | #include "kernel/uevent.h" 6 | #include "wait.h" 7 | 8 | static bool _ueventBeginWait(Waitable* ww, WaiterNode* w, u64 cur_tick, u64* next_tick); 9 | static Result _ueventOnTimeout(Waitable* ww, u64 old_tick); 10 | static Result _ueventOnSignal(Waitable* ww); 11 | 12 | static const WaitableMethods g_ueventVt = { 13 | .beginWait = _ueventBeginWait, 14 | .onTimeout = _ueventOnTimeout, 15 | .onSignal = _ueventOnSignal, 16 | }; 17 | 18 | void ueventCreate(UEvent* e, bool auto_clear) 19 | { 20 | _waitableInitialize(&e->waitable, &g_ueventVt); 21 | 22 | e->signal = false; 23 | e->auto_clear = auto_clear; 24 | } 25 | 26 | void ueventClear(UEvent* e) 27 | { 28 | mutexLock(&e->waitable.mutex); 29 | e->signal = false; 30 | mutexUnlock(&e->waitable.mutex); 31 | } 32 | 33 | void ueventSignal(UEvent* e) 34 | { 35 | mutexLock(&e->waitable.mutex); 36 | e->signal = true; 37 | _waitableSignalAllListeners(&e->waitable); 38 | mutexUnlock(&e->waitable.mutex); 39 | } 40 | 41 | Result _ueventOnSignal(Waitable* ww) 42 | { 43 | UEvent* e = (UEvent*)ww; 44 | Result rc = 0; 45 | mutexLock(&e->waitable.mutex); 46 | 47 | // Try to auto-clear the event. If auto-clear is enabled but 48 | // the event is not signalled, that means the state of the 49 | // event has changed and thus we need to retry the wait. 50 | if (e->auto_clear) { 51 | if (e->signal) 52 | e->signal = false; 53 | else 54 | rc = KERNELRESULT(Cancelled); 55 | } 56 | 57 | mutexUnlock(&e->waitable.mutex); 58 | return rc; 59 | } 60 | 61 | bool _ueventBeginWait(Waitable* ww, WaiterNode* w, u64 cur_tick, u64* next_tick) 62 | { 63 | UEvent* e = (UEvent*)ww; 64 | mutexLock(&e->waitable.mutex); 65 | 66 | bool can_add = !e->signal; 67 | 68 | if (can_add) 69 | _waiterNodeAdd(w); 70 | else if (e->auto_clear) 71 | e->signal = false; 72 | 73 | mutexUnlock(&e->waitable.mutex); 74 | return can_add; 75 | } 76 | 77 | Result _ueventOnTimeout(Waitable* ww, u64 old_tick) 78 | { 79 | // This is not supposed to happen. 80 | return KERNELRESULT(Cancelled); 81 | } 82 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/runtime/devices/socket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../types.h" 3 | 4 | /// Configuration structure for socketInitalize 5 | typedef struct { 6 | u32 bsdsockets_version; ///< Observed 1 on 2.0 LibAppletWeb, 2 on 3.0. 7 | 8 | u32 tcp_tx_buf_size; ///< Size of the TCP transfer (send) buffer (initial or fixed). 9 | u32 tcp_rx_buf_size; ///< Size of the TCP recieve buffer (initial or fixed). 10 | u32 tcp_tx_buf_max_size; ///< Maximum size of the TCP transfer (send) buffer. If it is 0, the size of the buffer is fixed to its initial value. 11 | u32 tcp_rx_buf_max_size; ///< Maximum size of the TCP receive buffer. If it is 0, the size of the buffer is fixed to its initial value. 12 | 13 | u32 udp_tx_buf_size; ///< Size of the UDP transfer (send) buffer (typically 0x2400 bytes). 14 | u32 udp_rx_buf_size; ///< Size of the UDP receive buffer (typically 0xA500 bytes). 15 | 16 | u32 sb_efficiency; ///< Number of buffers for each socket (standard values range from 1 to 8). 17 | 18 | size_t serialized_out_addrinfos_max_size; ///< For getaddrinfo. 19 | size_t serialized_out_hostent_max_size; ///< For gethostbyname/gethostbyaddr. 20 | bool bypass_nsd; ///< For name gethostbyname/getaddrinfo: bypass the Name Server Daemon. 21 | int dns_timeout; ///< For DNS requests: timeout or 0. 22 | } SocketInitConfig; 23 | 24 | /// Fetch the default configuration for the socket driver. 25 | const SocketInitConfig *socketGetDefaultInitConfig(void); 26 | /// Initalize the socket driver. 27 | Result socketInitialize(const SocketInitConfig *config); 28 | /// Fetch the last bsd:u/s Switch result code (thread-local). 29 | Result socketGetLastBsdResult(void); 30 | /// Fetch the last sfdnsres Switch result code (thread-local). 31 | Result socketGetLastSfdnsresResult(void); 32 | /// Deinitialize the socket driver. 33 | void socketExit(void); 34 | 35 | /// Initalize the socket driver using the default configuration. 36 | static inline Result socketInitializeDefault(void) { 37 | return socketInitialize(socketGetDefaultInitConfig()); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/condvar.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file condvar.h 3 | * @brief Condition variable synchronization primitive. 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../kernel/svc.h" 10 | #include "../kernel/mutex.h" 11 | 12 | /// Condition variable. 13 | typedef u32 CondVar; 14 | 15 | /** 16 | * @brief Initializes a condition variable. 17 | * @param[in] c Condition variable object. 18 | */ 19 | static inline void condvarInit(CondVar* c) 20 | { 21 | *c = 0; 22 | } 23 | 24 | /** 25 | * @brief Waits on a condition variable with a timeout. 26 | * @param[in] c Condition variable object. 27 | * @param[in] m Mutex object to use inside the condition variable. 28 | * @param[in] timeout Timeout in nanoseconds. 29 | * @return Result code (0xEA01 on timeout). 30 | * @remark On function return, the underlying mutex is acquired. 31 | */ 32 | Result condvarWaitTimeout(CondVar* c, Mutex* m, u64 timeout); 33 | 34 | /** 35 | * @brief Waits on a condition variable. 36 | * @param[in] c Condition variable object. 37 | * @param[in] m Mutex object to use inside the condition variable. 38 | * @return Result code. 39 | * @remark On function return, the underlying mutex is acquired. 40 | */ 41 | static inline Result condvarWait(CondVar* c, Mutex* m) 42 | { 43 | return condvarWaitTimeout(c, m, U64_MAX); 44 | } 45 | 46 | /** 47 | * @brief Wakes up up to the specified number of threads waiting on a condition variable. 48 | * @param[in] c Condition variable object. 49 | * @param[in] num Maximum number of threads to wake up (or -1 to wake them all up). 50 | * @return Result code. 51 | */ 52 | static inline Result condvarWake(CondVar* c, int num) 53 | { 54 | return svcSignalProcessWideKey(c, num); 55 | } 56 | 57 | /** 58 | * @brief Wakes up a single thread waiting on a condition variable. 59 | * @param[in] c Condition variable object. 60 | * @return Result code. 61 | */ 62 | static inline Result condvarWakeOne(CondVar* c) 63 | { 64 | return condvarWake(c, 1); 65 | } 66 | 67 | /** 68 | * @brief Wakes up all thread waiting on a condition variable. 69 | * @param[in] c Condition variable object. 70 | * @return Result code. 71 | */ 72 | static inline Result condvarWakeAll(CondVar* c) 73 | { 74 | return condvarWake(c, -1); 75 | } 76 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/kernel/wait.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 plutoo 2 | #pragma once 3 | #include "kernel/svc.h" 4 | #include "kernel/mutex.h" 5 | #include "kernel/wait.h" 6 | 7 | typedef struct WaiterNode WaiterNode; 8 | 9 | struct WaiterNode { 10 | WaitableNode node; 11 | Waitable* parent; 12 | Handle thread; 13 | s32* idx_out; 14 | s32 idx; 15 | }; 16 | 17 | struct WaitableMethods { 18 | bool (* beginWait)(Waitable* ww, WaiterNode* w, u64 cur_tick, u64* next_tick); 19 | Result (* onTimeout)(Waitable* ww, u64 old_tick); 20 | Result (* onSignal)(Waitable* ww); 21 | }; 22 | 23 | static inline void _waitableInitialize(Waitable* ww, const WaitableMethods* vt) 24 | { 25 | mutexInit(&ww->mutex); 26 | ww->vt = vt; 27 | ww->list.next = &ww->list; 28 | ww->list.prev = &ww->list; 29 | } 30 | 31 | static inline void _waitableSignalAllListeners(Waitable* ww) 32 | { 33 | WaitableNode* node = &ww->list; 34 | WaitableNode* end = node; 35 | 36 | while (node->next != end) { 37 | node = node->next; 38 | WaiterNode* w = (WaiterNode*) node; 39 | 40 | // Try to swap -1 => idx on the waiter thread. 41 | // If another waitable signals simultaneously only one will win the race and insert its own idx. 42 | s32 minus_one = -1; 43 | bool sent_idx = __atomic_compare_exchange_n( 44 | w->idx_out, &minus_one, w->idx, true, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); 45 | 46 | if (sent_idx) 47 | svcCancelSynchronization(w->thread); 48 | } 49 | } 50 | 51 | static inline void _waiterNodeInitialize( 52 | WaiterNode* w, Waitable* parent, Handle thread, 53 | s32 idx, s32* idx_out) 54 | { 55 | // Initialize WaiterNode fields 56 | w->parent = parent; 57 | w->thread = thread; 58 | w->idx = idx; 59 | w->idx_out = idx_out; 60 | } 61 | 62 | static inline void _waiterNodeAdd(WaiterNode* w) 63 | { 64 | // Add WaiterNode to the parent's linked list 65 | w->node.next = w->parent->list.next; 66 | w->parent->list.next = &w->node; 67 | w->node.prev = &w->parent->list; 68 | } 69 | 70 | static inline void _waiterNodeRemove(WaiterNode* w) 71 | { 72 | mutexLock(&w->parent->mutex); 73 | w->node.prev->next = w->node.next; 74 | w->node.next->prev = w->node.prev; 75 | mutexUnlock(&w->parent->mutex); 76 | } 77 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/services/smm.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 SciresM 2 | #include 3 | #include "types.h" 4 | #include "result.h" 5 | #include "arm/atomics.h" 6 | #include "kernel/ipc.h" 7 | #include "services/fs.h" 8 | #include "services/sm.h" 9 | #include "services/smm.h" 10 | 11 | static Service g_smManagerSrv; 12 | static u64 g_smManagerRefcnt; 13 | 14 | Result smManagerInitialize(void) { 15 | atomicIncrement64(&g_smManagerRefcnt); 16 | 17 | if (serviceIsActive(&g_smManagerSrv)) 18 | return 0; 19 | 20 | return smGetService(&g_smManagerSrv, "sm:m"); 21 | } 22 | 23 | void smManagerExit(void) { 24 | if (atomicDecrement64(&g_smManagerRefcnt) == 0) 25 | serviceClose(&g_smManagerSrv); 26 | } 27 | 28 | Result smManagerRegisterProcess(u64 pid, const void *acid_sac, size_t acid_sac_size, const void *aci0_sac, size_t aci0_sac_size) { 29 | IpcCommand c; 30 | ipcInitialize(&c); 31 | ipcAddSendBuffer(&c, acid_sac, acid_sac_size, BufferType_Normal); 32 | ipcAddSendBuffer(&c, aci0_sac, aci0_sac_size, BufferType_Normal); 33 | 34 | struct { 35 | u64 magic; 36 | u64 cmd_id; 37 | u64 pid; 38 | } *raw; 39 | 40 | raw = ipcPrepareHeader(&c, sizeof(*raw)); 41 | raw->magic = SFCI_MAGIC; 42 | raw->cmd_id = 0; 43 | raw->pid = pid; 44 | 45 | Result rc = serviceIpcDispatch(&g_smManagerSrv); 46 | 47 | if (R_SUCCEEDED(rc)) { 48 | IpcParsedCommand r; 49 | ipcParse(&r); 50 | 51 | struct { 52 | u64 magic; 53 | u64 result; 54 | } *resp = r.Raw; 55 | 56 | rc = resp->result; 57 | } 58 | 59 | return rc; 60 | } 61 | 62 | Result smManagerUnregisterProcess(u64 pid) { 63 | IpcCommand c; 64 | ipcInitialize(&c); 65 | 66 | struct { 67 | u64 magic; 68 | u64 cmd_id; 69 | u64 pid; 70 | } *raw; 71 | 72 | raw = ipcPrepareHeader(&c, sizeof(*raw)); 73 | raw->magic = SFCI_MAGIC; 74 | raw->cmd_id = 1; 75 | raw->pid = pid; 76 | 77 | Result rc = serviceIpcDispatch(&g_smManagerSrv); 78 | 79 | if (R_SUCCEEDED(rc)) { 80 | IpcParsedCommand r; 81 | ipcParse(&r); 82 | 83 | struct { 84 | u64 magic; 85 | u64 result; 86 | } *resp = r.Raw; 87 | 88 | rc = resp->result; 89 | } 90 | 91 | return rc; 92 | } 93 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/runtime/switch_crt0.s: -------------------------------------------------------------------------------- 1 | .section ".crt0","ax" 2 | .global _start 3 | 4 | _start: 5 | b startup 6 | .word __nx_mod0 - _start 7 | .ascii "HOMEBREW" 8 | 9 | .org _start+0x80 10 | startup: 11 | // save lr 12 | mov x7, x30 13 | 14 | // get aslr base 15 | bl +4 16 | sub x6, x30, #0x88 17 | 18 | // context ptr and main thread handle 19 | mov x5, x0 20 | mov x4, x1 21 | 22 | // Handle the exception if needed. 23 | // if (ctx != NULL && main_thread != -1)__libnx_exception_entry(); 24 | cmp x5, #0 25 | ccmn x4, #1, #4, ne // 4 = Z 26 | beq bssclr_start 27 | b __libnx_exception_entry 28 | 29 | bssclr_start: 30 | mov x27, x7 31 | mov x25, x5 32 | mov x26, x4 33 | 34 | // clear .bss 35 | adrp x0, __bss_start__ 36 | adrp x1, __bss_end__ 37 | add x0, x0, #:lo12:__bss_start__ 38 | add x1, x1, #:lo12:__bss_end__ 39 | sub x1, x1, x0 // calculate size 40 | add x1, x1, #7 // round up to 8 41 | bic x1, x1, #7 42 | 43 | bss_loop: 44 | str xzr, [x0], #8 45 | subs x1, x1, #8 46 | bne bss_loop 47 | 48 | // store stack pointer 49 | mov x1, sp 50 | adrp x0, __stack_top 51 | str x1, [x0, #:lo12:__stack_top] 52 | 53 | // process .dynamic section 54 | mov x0, x6 55 | adrp x1, _DYNAMIC 56 | add x1, x1, #:lo12:_DYNAMIC 57 | bl __nx_dynamic 58 | 59 | // initialize system 60 | mov x0, x25 61 | mov x1, x26 62 | mov x2, x27 63 | bl __libnx_init 64 | 65 | // call entrypoint 66 | adrp x0, __system_argc // argc 67 | ldr w0, [x0, #:lo12:__system_argc] 68 | adrp x1, __system_argv // argv 69 | ldr x1, [x1, #:lo12:__system_argv] 70 | adrp x30, exit 71 | add x30, x30, #:lo12:exit 72 | b main 73 | 74 | .global __nx_exit 75 | .type __nx_exit, %function 76 | __nx_exit: 77 | // restore stack pointer 78 | adrp x8, __stack_top 79 | ldr x8, [x8, #:lo12:__stack_top] 80 | mov sp, x8 81 | 82 | // jump back to loader 83 | br x1 84 | 85 | .global __nx_mod0 86 | __nx_mod0: 87 | .ascii "MOD0" 88 | .word _DYNAMIC - __nx_mod0 89 | .word __bss_start__ - __nx_mod0 90 | .word __bss_end__ - __nx_mod0 91 | .word __eh_frame_hdr_start - __nx_mod0 92 | .word __eh_frame_hdr_end - __nx_mod0 93 | .word 0 // "offset to runtime-generated module object" (??) 94 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/kernel/mutex.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 plutoo 2 | #include "kernel/svc.h" 3 | #include "kernel/mutex.h" 4 | #include "../internal.h" 5 | 6 | #define HAS_LISTENERS 0x40000000 7 | 8 | static u32 _GetTag(void) { 9 | return getThreadVars()->handle; 10 | } 11 | 12 | void mutexLock(Mutex* m) { 13 | u32 self = _GetTag(); 14 | 15 | while (1) { 16 | u32 cur = __sync_val_compare_and_swap((u32*)m, 0, self); 17 | 18 | if (cur == 0) { 19 | // We won the race! 20 | return; 21 | } 22 | 23 | if ((cur &~ HAS_LISTENERS) == self) { 24 | // Kernel assigned it to us! 25 | return; 26 | } 27 | 28 | if (cur & HAS_LISTENERS) { 29 | // The flag is already set, we can use the syscall. 30 | svcArbitrateLock(cur &~ HAS_LISTENERS, (u32*)m, self); 31 | } 32 | else { 33 | // The flag is not set, we need to set it. 34 | u32 old = __sync_val_compare_and_swap((u32*)m, cur, cur | HAS_LISTENERS); 35 | 36 | if (old == cur) { 37 | // Flag was set successfully. 38 | svcArbitrateLock(cur, (u32*)m, self); 39 | } 40 | } 41 | } 42 | } 43 | 44 | bool mutexTryLock(Mutex* m) { 45 | u32 self = _GetTag(); 46 | u32 cur = __sync_val_compare_and_swap((u32*)m, 0, self); 47 | 48 | if (cur == 0) { 49 | // We won the race! 50 | return true; 51 | } 52 | 53 | if ((cur &~ HAS_LISTENERS) == self) { 54 | // Kernel assigned it to us! 55 | return true; 56 | } 57 | 58 | return 0; 59 | } 60 | 61 | void mutexUnlock(Mutex* m) { 62 | u32 old = __sync_val_compare_and_swap((u32*)m, _GetTag(), 0); 63 | 64 | if (old & HAS_LISTENERS) { 65 | svcArbitrateUnlock((u32*)m); 66 | } 67 | } 68 | 69 | void rmutexLock(RMutex* m) { 70 | if (m->thread_tag != _GetTag()) { 71 | mutexLock(&m->lock); 72 | m->thread_tag = _GetTag(); 73 | } 74 | 75 | m->counter++; 76 | } 77 | 78 | bool rmutexTryLock(RMutex* m) { 79 | if (m->thread_tag != _GetTag()) { 80 | if (!mutexTryLock(&m->lock)) { 81 | return false; 82 | } 83 | m->thread_tag = _GetTag(); 84 | } 85 | 86 | m->counter++; 87 | return true; 88 | } 89 | 90 | void rmutexUnlock(RMutex* m) { 91 | if (--m->counter == 0) { 92 | m->thread_tag = 0; 93 | mutexUnlock(&m->lock); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/switch_rules: -------------------------------------------------------------------------------- 1 | ifeq ($(strip $(DEVKITPRO)),) 2 | $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=devkitPro) 3 | endif 4 | 5 | include $(DEVKITPRO)/devkitA64/base_rules 6 | 7 | PORTLIBS := $(PORTLIBS_PATH)/switch 8 | PATH := $(PORTLIBS)/bin:$(PATH) 9 | 10 | LIBNX ?= $(DEVKITPRO)/libnx 11 | 12 | ifeq ($(strip $(APP_TITLE)),) 13 | APP_TITLE := $(notdir $(OUTPUT)) 14 | endif 15 | 16 | ifeq ($(strip $(APP_AUTHOR)),) 17 | APP_AUTHOR := Unspecified Author 18 | endif 19 | 20 | ifeq ($(strip $(APP_VERSION)),) 21 | APP_VERSION := 1.0.0 22 | endif 23 | 24 | ifeq ($(strip $(APP_ICON)),) 25 | APP_ICON := $(LIBNX)/default_icon.jpg 26 | endif 27 | 28 | #--------------------------------------------------------------------------------- 29 | %.nacp: $(MAKEFILE_LIST) 30 | @nacptool --create "$(APP_TITLE)" "$(APP_AUTHOR)" "$(APP_VERSION)" $@ $(NACPFLAGS) 31 | @echo built ... $(notdir $@) 32 | 33 | #--------------------------------------------------------------------------------- 34 | %.npdm: $(APP_JSON) 35 | @npdmtool $< $@ 36 | @echo built ... $(notdir $@) 37 | 38 | #--------------------------------------------------------------------------------- 39 | define make_pfs0 40 | @mkdir -p exefs 41 | @[ $(BUILD_EXEFS_SRC) ] && [ -d $(BUILD_EXEFS_SRC) ] && cp -R $(BUILD_EXEFS_SRC)/* exefs || echo > /dev/null 42 | @cp $*.nso exefs/main 43 | @[ $(APP_JSON) ] && cp $*.npdm exefs/main.npdm || echo > /dev/null 44 | @build_pfs0 exefs $@ 45 | @echo built ... $(notdir $@) 46 | endef 47 | 48 | ifeq ($(strip $(APP_JSON)),) 49 | %.pfs0: %.nso 50 | else 51 | %.pfs0: %.nso %.npdm 52 | endif 53 | $(make_pfs0) 54 | 55 | ifeq ($(strip $(APP_JSON)),) 56 | %.nsp: %.nso 57 | else 58 | %.nsp: %.nso %.npdm 59 | endif 60 | $(make_pfs0) 61 | 62 | #--------------------------------------------------------------------------------- 63 | %.nso: %.elf 64 | @elf2nso $< $@ 65 | @echo built ... $(notdir $@) 66 | 67 | #--------------------------------------------------------------------------------- 68 | %.nro: %.elf 69 | @elf2nro $< $@ $(NROFLAGS) 70 | @echo built ... $(notdir $@) 71 | 72 | #--------------------------------------------------------------------------------- 73 | %.kip: %.elf 74 | @elf2kip $< $(APP_JSON) $@ 75 | @echo built ... $(notdir $@) 76 | 77 | #--------------------------------------------------------------------------------- 78 | %.elf: 79 | @echo linking $(notdir $@) 80 | @$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@ 81 | @$(NM) -CSn $@ > $(notdir $*.lst) 82 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/external/bsd/include/sys/ioctl.h: -------------------------------------------------------------------------------- 1 | // TuxSH: removed definitions under _KERNEL ifdef block, modify the prototype of some functions, 2 | // some other changes 3 | 4 | /*- 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | * 7 | * Copyright (c) 1982, 1986, 1990, 1993, 1994 8 | * The Regents of the University of California. All rights reserved. 9 | * (c) UNIX System Laboratories, Inc. 10 | * All or some portions of this file are derived from material licensed 11 | * to the University of California by American Telephone and Telegraph 12 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with 13 | * the permission of UNIX System Laboratories, Inc. 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted provided that the following conditions 17 | * are met: 18 | * 1. Redistributions of source code must retain the above copyright 19 | * notice, this list of conditions and the following disclaimer. 20 | * 2. Redistributions in binary form must reproduce the above copyright 21 | * notice, this list of conditions and the following disclaimer in the 22 | * documentation and/or other materials provided with the distribution. 23 | * 3. Neither the name of the University nor the names of its contributors 24 | * may be used to endorse or promote products derived from this software 25 | * without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 | * SUCH DAMAGE. 38 | * 39 | * @(#)ioctl.h 8.6 (Berkeley) 3/28/94 40 | * $FreeBSD$ 41 | */ 42 | 43 | #ifndef _SYS_IOCTL_H_ 44 | #define _SYS_IOCTL_H_ 45 | 46 | #include 47 | 48 | #include 49 | #include 50 | //#include 51 | 52 | #endif /* !_SYS_IOCTL_H_ */ 53 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/services/fatal.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 plutoo 2 | #include "types.h" 3 | #include "result.h" 4 | #include "kernel/ipc.h" 5 | #include "kernel/detect.h" 6 | #include "kernel/svc.h" 7 | #include "services/fatal.h" 8 | #include "services/sm.h" 9 | 10 | static void _fatalImpl(u32 cmd_id, Result err, FatalType type, FatalContext *ctx) { 11 | Result rc = 0; 12 | 13 | //Only 3.0.0+ supports FatalType_ErrorScreen, when specified on pre-3.0.0 use FatalType_ErrorReportAndErrorScreen instead. 14 | if (type == FatalType_ErrorScreen && !kernelAbove300()) type = FatalType_ErrorReportAndErrorScreen; 15 | 16 | if (detectDebugger()) { 17 | svcBreak(0x80000000, err, 0); 18 | } 19 | 20 | if (!smHasInitialized()) { 21 | rc = smInitialize(); 22 | } 23 | 24 | if (R_SUCCEEDED(rc)) { 25 | Handle srv; 26 | rc = smGetServiceOriginal(&srv, smEncodeName("fatal:u")); 27 | 28 | if (R_SUCCEEDED(rc)) { 29 | IpcCommand c; 30 | ipcInitialize(&c); 31 | ipcSendPid(&c); 32 | if (ctx != NULL) { 33 | ipcAddSendBuffer(&c, ctx, sizeof(*ctx), BufferType_Normal); 34 | } 35 | 36 | struct { 37 | u64 magic; 38 | u64 cmd_id; 39 | u32 result; 40 | u32 type; 41 | u64 pid_placeholder; 42 | } *raw; 43 | 44 | raw = ipcPrepareHeader(&c, sizeof(*raw)); 45 | 46 | raw->magic = SFCI_MAGIC; 47 | raw->cmd_id = cmd_id; 48 | raw->result = err; 49 | raw->type = type; 50 | raw->pid_placeholder = 0; // Overwritten by fatal with PID descriptor. 51 | 52 | ipcDispatch(srv); 53 | } 54 | } 55 | 56 | switch (type) { 57 | case FatalType_ErrorReport: 58 | break; 59 | case FatalType_ErrorReportAndErrorScreen: 60 | case FatalType_ErrorScreen: 61 | default: 62 | svcExitProcess(); 63 | __builtin_unreachable(); 64 | } 65 | } 66 | 67 | void NORETURN fatalSimple(Result err) { 68 | /* By default, do not generate an error report. */ 69 | fatalWithType(err, FatalType_ErrorScreen); 70 | svcExitProcess(); 71 | __builtin_unreachable(); 72 | } 73 | 74 | void fatalWithType(Result err, FatalType type) { 75 | _fatalImpl(1, err, type, NULL); 76 | } 77 | 78 | void fatalWithContext(Result err, FatalType type, FatalContext *ctx) { 79 | _fatalImpl(2, err, type, ctx); 80 | } 81 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/nifm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file nifm.h 3 | * @brief Network interface service IPC wrapper. 4 | * @author shadowninja108, shibboleet, exelix 5 | * @copyright libnx Authors 6 | */ 7 | 8 | #pragma once 9 | #include "../kernel/ipc.h" 10 | #include "../services/sm.h" 11 | 12 | typedef enum { 13 | NifmServiceType_NotInitialized = 0, ///< Initializes nifm:u. 14 | NifmServiceType_User = 1, ///< Initializes nifm:u. 15 | NifmServiceType_System = 2, ///< Initializes nifm:s. 16 | NifmServiceType_Admin = 3, ///< Initializes nifm:a. 17 | } NifmServiceType; 18 | 19 | typedef enum { 20 | NifmInternetConnectionType_WiFi = 1, ///< Wi-Fi connection is used. 21 | NifmInternetConnectionType_Ethernet = 2, ///< Ethernet connection is used. 22 | } NifmInternetConnectionType; 23 | 24 | typedef enum { 25 | NifmInternetConnectionStatus_ConnectingUnknown1 = 0, ///< Unknown internet connection status 1. 26 | NifmInternetConnectionStatus_ConnectingUnknown2 = 1, ///< Unknown internet connection status 2. 27 | NifmInternetConnectionStatus_ConnectingUnknown3 = 2, ///< Unknown internet connection status 3 (conntest?). 28 | NifmInternetConnectionStatus_ConnectingUnknown4 = 3, ///< Unknown internet connection status 4. 29 | NifmInternetConnectionStatus_Connected = 4, ///< Internet is connected. 30 | } NifmInternetConnectionStatus; 31 | 32 | /** 33 | * @brief Sets the \ref NifmServiceType for initialization. Call this function before \ref nifmInitialize. 34 | * @note By default nifm:u will be used. 35 | */ 36 | void nifmSetServiceType(NifmServiceType serviceType); 37 | 38 | Result nifmInitialize(void); 39 | void nifmExit(void); 40 | 41 | Result nifmGetCurrentIpAddress(u32* out); 42 | 43 | Result nifmIsWirelessCommunicationEnabled(bool* out); 44 | 45 | /** 46 | * @note Works only if called from nifm:a or nifm:s. 47 | */ 48 | Result nifmSetWirelessCommunicationEnabled(bool enable); 49 | 50 | /** 51 | * @note Will fail with 0xd46ed if Internet is neither connecting or connected (airplane mode or no known network in reach). 52 | * @param wifiStrength Strength of the Wi-Fi signal in number of bars from 0 to 3. 53 | */ 54 | Result nifmGetInternetConnectionStatus(NifmInternetConnectionType* connectionType, u32* wifiStrength, NifmInternetConnectionStatus* connectionStatus); 55 | 56 | Result nifmIsEthernetCommunicationEnabled(bool* out); 57 | Result nifmIsAnyForegroundRequestAccepted(bool* out); 58 | Result nifmPutToSleep(void); 59 | Result nifmWakeUp(void); 60 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/services/wlaninf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file wlaninf.c 3 | * @brief WLAN InfraManager service IPC wrapper. 4 | * @author natinusala 5 | * @copyright libnx Authors 6 | */ 7 | 8 | #include "types.h" 9 | #include "result.h" 10 | #include "services/sm.h" 11 | #include "services/wlaninf.h" 12 | #include "arm/atomics.h" 13 | 14 | static Service g_wlaninfSrv; 15 | static u64 g_refCnt; 16 | 17 | Result wlaninfInitialize(void) { 18 | Result rc; 19 | 20 | atomicIncrement64(&g_refCnt); 21 | 22 | if (serviceIsActive(&g_wlaninfSrv)) 23 | return 0; 24 | 25 | rc = smGetService(&g_wlaninfSrv, "wlan:inf"); 26 | 27 | if (R_FAILED(rc)) 28 | wlaninfExit(); 29 | 30 | return rc; 31 | } 32 | 33 | void wlaninfExit(void) { 34 | if (atomicDecrement64(&g_refCnt) == 0) { 35 | serviceClose(&g_wlaninfSrv); 36 | } 37 | } 38 | 39 | Result wlaninfGetState(WlanInfState* out) { 40 | IpcCommand c; 41 | ipcInitialize(&c); 42 | 43 | struct { 44 | u64 magic; 45 | u64 cmd_id; 46 | } *raw; 47 | 48 | raw = serviceIpcPrepareHeader(&g_wlaninfSrv, &c, sizeof(*raw)); 49 | 50 | raw->magic = SFCI_MAGIC; 51 | raw->cmd_id = 10; 52 | 53 | Result rc = serviceIpcDispatch(&g_wlaninfSrv); 54 | 55 | if (R_SUCCEEDED(rc)) { 56 | IpcParsedCommand r; 57 | 58 | struct { 59 | u64 magic; 60 | u64 result; 61 | u32 out; 62 | } *resp; 63 | 64 | serviceIpcParse(&g_wlaninfSrv, &r, sizeof(*resp)); 65 | resp = r.Raw; 66 | 67 | rc = resp->result; 68 | *out = resp->out; 69 | } 70 | 71 | return rc; 72 | } 73 | 74 | Result wlaninfGetRSSI(s32* out) { 75 | IpcCommand c; 76 | ipcInitialize(&c); 77 | 78 | struct { 79 | u64 magic; 80 | u64 cmd_id; 81 | } *raw; 82 | 83 | raw = serviceIpcPrepareHeader(&g_wlaninfSrv, &c, sizeof(*raw)); 84 | 85 | raw->magic = SFCI_MAGIC; 86 | raw->cmd_id = 12; 87 | 88 | Result rc = serviceIpcDispatch(&g_wlaninfSrv); 89 | 90 | if (R_SUCCEEDED(rc)) { 91 | IpcParsedCommand r; 92 | 93 | struct { 94 | u64 magic; 95 | u64 result; 96 | s32 out; 97 | } *resp; 98 | 99 | serviceIpcParse(&g_wlaninfSrv, &r, sizeof(*resp)); 100 | resp = r.Raw; 101 | 102 | rc = resp->result; 103 | *out = resp->out; 104 | } 105 | 106 | return rc; 107 | } 108 | -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/TcpLogger.cpp: -------------------------------------------------------------------------------- 1 | #include "TcpLogger.hpp" 2 | 3 | 4 | #define IP "192.168.0.10" 5 | #define PORT 6969 6 | 7 | int g_tcpSocket; 8 | int g_loggerInit = 0; 9 | 10 | 11 | std::list* g_msgQueue = nullptr; 12 | 13 | void SendRaw(void* data, size_t size) 14 | { 15 | nn::socket::Send(g_tcpSocket, data, size, 0); 16 | } 17 | 18 | 19 | void AddToQueue(u8* data) 20 | { 21 | if(!g_msgQueue) 22 | g_msgQueue = new std::list(); 23 | 24 | g_msgQueue->push_back(data); 25 | } 26 | 27 | void ClearQueue() 28 | { 29 | if(!g_msgQueue) 30 | return; 31 | 32 | while (!g_msgQueue->empty()) 33 | { 34 | auto data = g_msgQueue->front(); 35 | SendRaw(data, strlen((char*)data)); 36 | delete[] data; 37 | g_msgQueue->pop_front(); 38 | } 39 | 40 | } 41 | 42 | 43 | void TcpLogger::Initialize() 44 | { 45 | struct sockaddr_in serverAddr; 46 | g_tcpSocket = nn::socket::Socket(AF_INET, SOCK_STREAM, 0); 47 | if(g_tcpSocket & 0x80000000) 48 | nn::err::ShowError((u32)Sp2Error::nnSocket); 49 | 50 | serverAddr.sin_addr.s_addr = inet_addr(IP); 51 | serverAddr.sin_family = AF_INET; 52 | serverAddr.sin_port = nn::socket::InetHtons(PORT); 53 | 54 | int rval = nn::socket::Connect(g_tcpSocket, (struct sockaddr*)&serverAddr, sizeof(serverAddr)); 55 | if (rval < 0) 56 | nn::err::ShowError((u32)Sp2Error::nnSocketConnect); 57 | 58 | 59 | g_loggerInit = 1; 60 | 61 | TcpLogger::LogFormat("socket initialized!"); 62 | ClearQueue(); 63 | } 64 | 65 | void TcpLogger::Log(u8* data, size_t size) 66 | { 67 | u8* ptr = new u8[size+2]; 68 | memset(ptr, 0, size+2); 69 | ptr[size] = (u8)'\n'; 70 | memcpy(ptr, data, size); 71 | 72 | if (!g_loggerInit) 73 | { 74 | AddToQueue(ptr); 75 | return; 76 | } 77 | 78 | SendRaw(ptr, size+1); 79 | } 80 | 81 | void TcpLogger::Log(std::string str) 82 | { 83 | TcpLogger::Log((u8*)str.data(), str.size()); 84 | } 85 | 86 | void TcpLogger::Log(std::vector vec) 87 | { 88 | TcpLogger::Log(vec.data(), vec.size()); 89 | } 90 | 91 | void TcpLogger::LogFormat(const char* format, ...) 92 | { 93 | va_list args; 94 | char buff[0x1000]; 95 | memset(buff, 0, sizeof(buff)); 96 | va_start(args, format); 97 | 98 | int len = vsnprintf(buff, sizeof(buff), format, args); 99 | 100 | TcpLogger::Log((u8*)buff, len); 101 | 102 | va_end (args); 103 | } -------------------------------------------------------------------------------- /sp2Module/sp2Module/source/FsLogger.cpp: -------------------------------------------------------------------------------- 1 | #include "FsLogger.hpp" 2 | 3 | FsFileSystem g_fsHandle; 4 | FsFile g_fileHandle; 5 | 6 | int g_fsInit = 0; 7 | 8 | 9 | void LogRaw(void* data, size_t size) 10 | { 11 | if (!g_fsInit) 12 | return; 13 | 14 | u64 filesize = 0; 15 | 16 | Result rc = fsFileGetSize(&g_fileHandle, &filesize); 17 | if (R_SUCCEEDED(rc)) 18 | { 19 | fsFileWrite(&g_fileHandle, filesize, data, size); 20 | fsFileFlush(&g_fileHandle); 21 | } 22 | } 23 | 24 | void FsLogger::Initialize() 25 | { 26 | if (g_fsInit) 27 | return; 28 | 29 | const char* path = "/sp2Module/logs.txt"; 30 | Result rc; 31 | 32 | rc = fsInitialize(); 33 | if (R_FAILED(rc)) 34 | goto error_fs; 35 | 36 | if (R_FAILED(rc = fsMountSdcard(&g_fsHandle))) 37 | goto error_fs; 38 | 39 | if (R_FAILED(rc = fsFsCreateDirectory(&g_fsHandle, "/sp2Module")) && rc != 0x402) 40 | goto error_fs; 41 | 42 | if (R_FAILED(rc = fsFsCreateFile(&g_fsHandle, path, 0, 0))) 43 | { 44 | if (rc == 0x402) //path already exist 45 | { 46 | if (R_FAILED(rc = fsFsDeleteFile(&g_fsHandle, path))) 47 | goto error_fs; 48 | rc = fsFsCreateFile(&g_fsHandle, path, 0, 0); 49 | } 50 | if (R_FAILED(rc)) 51 | goto error_fs; 52 | } 53 | 54 | if (R_FAILED(rc = fsFsOpenFile(&g_fsHandle, path, FS_OPEN_READ | FS_OPEN_APPEND | FS_OPEN_WRITE, &g_fileHandle))) 55 | goto error_fs; 56 | 57 | if (R_FAILED(rc = fsFileSetSize(&g_fileHandle, 0))) 58 | goto error_fs; 59 | 60 | g_fsInit = 1; 61 | 62 | FsLogger::LogFormat("fs initialized!"); 63 | return; 64 | 65 | error_fs: 66 | fatalSimple((u32)Sp2Error::fsInitialize); 67 | } 68 | 69 | void FsLogger::Log(u8* data, size_t size) 70 | { 71 | u8* ptr = new u8[size+2]; 72 | memset(ptr, 0, size+2); 73 | ptr[size] = (u8)'\n'; 74 | memcpy(ptr, data, size); 75 | 76 | LogRaw(ptr, size+1); 77 | } 78 | 79 | void FsLogger::Log(std::string str) 80 | { 81 | FsLogger::Log((u8*)str.data(), str.size()); 82 | } 83 | 84 | void FsLogger::Log(std::vector vec) 85 | { 86 | FsLogger::Log(vec.data(), vec.size()); 87 | } 88 | 89 | void FsLogger::LogFormat(const char* format, ...) 90 | { 91 | va_list args; 92 | char buff[0x1000]; 93 | memset(buff, 0, sizeof(buff)); 94 | va_start(args, format); 95 | 96 | int len = vsnprintf(buff, sizeof(buff), format, args); 97 | 98 | FsLogger::Log((u8*)buff, len); 99 | 100 | va_end (args); 101 | } -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/sfdnsres.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file sfdnsres.h 3 | * @brief Domain name resolution service IPC wrapper. Please use socket.c instead. 4 | * @author TuxSH 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | 10 | #include // For socklen_t, etc. 11 | 12 | /// Configuration structure for sfdnsres. 13 | typedef struct { 14 | size_t serialized_out_addrinfos_max_size; ///< For getaddrinfo. 15 | size_t serialized_out_hostent_max_size; ///< For gethostbyname/gethostbyaddr. 16 | bool bypass_nsd; ///< For name gethostbyname/getaddrinfo: bypass the Name Server Daemon. 17 | int timeout; ///< For DNS requests: timeout or 0. 18 | } SfdnsresConfig; 19 | 20 | /// Result values returned by the DNS request commands. 21 | typedef struct { 22 | int ret; ///< Return value (error code). 23 | int errno_; ///< Errno. 24 | ssize_t out_serialized_size; ///< Size of the serialized output buffer or -1 (?). 25 | } SfdnsresRequestResults; 26 | 27 | // SetDnsAddressesPrivate & GetDnsAddressPrivate are stubbed 28 | 29 | Result sfdnsresGetHostByName(SfdnsresRequestResults *ret, const SfdnsresConfig *config, void *out_he_serialized, const char *name); 30 | Result sfdnsresGetHostByAddr(SfdnsresRequestResults *ret, const SfdnsresConfig *config, void *out_he_serialized, const void *addr, socklen_t len, int type); 31 | 32 | Result sfdnsresGetHostStringError(int err, char *str, size_t str_size); 33 | Result sfdnsresGetGaiStringError(int err, char *str, size_t str_size); 34 | 35 | Result sfdnsresGetAddrInfo(SfdnsresRequestResults *ret, const SfdnsresConfig *config, const char *node, const char *service, 36 | const void *hints_serialized, size_t hints_serialized_size, void *res_serialized); 37 | Result sfdnsresGetNameInfo(SfdnsresRequestResults *ret, const SfdnsresConfig *config, 38 | const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, 39 | char *serv, size_t servlen, int flags); 40 | 41 | /// Requests an handle for use with @ref sfdnsresCancelSocketCall. 42 | Result sfdnsresRequestCancelHandle(u32 *out_handle); 43 | /// Cancels a DNS request (how? which requests?). Bug: always sets errno? 44 | Result sfdnsresCancelSocketCall(SfdnsresRequestResults *ret, u32 handle); 45 | /// Cancels all DNS requests made by the current process (how? which requests?). Bug: always sets errno? 46 | Result sfdnsresCancelAllSocketCalls(SfdnsresRequestResults *ret); 47 | /// Clears up to 4 DNS server IPs registered by bsdcfg (DHCP client, etc.). 48 | Result sfdnsresClearDnsIpServerAddressArray(void); 49 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/external/bsd/include/sys/_sockaddr_storage.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * @(#)socket.h 8.4 (Berkeley) 2/21/94 32 | * $FreeBSD$ 33 | */ 34 | 35 | #ifndef _SYS__SOCKADDR_STORAGE_H_ 36 | #define _SYS__SOCKADDR_STORAGE_H_ 37 | 38 | #include // changed 39 | #include 40 | 41 | /* 42 | * RFC 2553: protocol-independent placeholder for socket addresses 43 | */ 44 | #define _SS_MAXSIZE 128U 45 | #define _SS_ALIGNSIZE (sizeof(__int64_t)) 46 | #define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned char) - \ 47 | sizeof(sa_family_t)) 48 | #define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(unsigned char) - \ 49 | sizeof(sa_family_t) - _SS_PAD1SIZE - _SS_ALIGNSIZE) 50 | 51 | struct sockaddr_storage { 52 | unsigned char ss_len; /* address length */ 53 | sa_family_t ss_family; /* address family */ 54 | char __ss_pad1[_SS_PAD1SIZE]; 55 | int64_t __ss_align; /* force desired struct alignment */ // changed 56 | char __ss_pad2[_SS_PAD2SIZE]; 57 | }; 58 | 59 | #endif /* !_SYS__SOCKADDR_STORAGE_H_ */ 60 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/audio/mempool.c: -------------------------------------------------------------------------------- 1 | #include "driver_internal.h" 2 | 3 | int audrvMemPoolAdd(AudioDriver* d, void* buffer, size_t size) 4 | { 5 | if (!buffer || ((uintptr_t)buffer & (AUDREN_MEMPOOL_ALIGNMENT-1))) 6 | return -1; 7 | if (size & (AUDREN_MEMPOOL_ALIGNMENT-1)) 8 | return -1; 9 | 10 | int id = d->etc->first_free_mempool; 11 | if (id < 0) 12 | return -1; 13 | 14 | d->etc->first_free_mempool = d->etc->mempools[id].next_free; 15 | d->in_mempools[id].address = buffer; 16 | d->in_mempools[id].size = size; 17 | d->in_mempools[id].state = AudioRendererMemPoolState_New; 18 | 19 | return id; 20 | } 21 | 22 | bool audrvMemPoolRemove(AudioDriver* d, int id) 23 | { 24 | if (id < 0) 25 | return false; 26 | if (d->in_mempools[id].state == AudioRendererMemPoolState_Attached || d->in_mempools[id].state == AudioRendererMemPoolState_RequestDetach) 27 | return false; 28 | 29 | d->etc->mempools[id].next_free = d->etc->first_free_mempool; 30 | d->etc->first_free_mempool = id; 31 | d->in_mempools[id].address = NULL; 32 | d->in_mempools[id].size = 0; 33 | d->in_mempools[id].state = AudioRendererMemPoolState_Released; 34 | 35 | return true; 36 | } 37 | 38 | bool audrvMemPoolAttach(AudioDriver* d, int id) 39 | { 40 | if (id < 0 || id >= d->etc->mempool_count) 41 | return false; 42 | 43 | switch (d->in_mempools[id].state) { 44 | case AudioRendererMemPoolState_New: 45 | case AudioRendererMemPoolState_RequestAttach: 46 | case AudioRendererMemPoolState_Detached: 47 | d->in_mempools[id].state = AudioRendererMemPoolState_RequestAttach; 48 | return true; 49 | case AudioRendererMemPoolState_RequestDetach: 50 | case AudioRendererMemPoolState_Attached: 51 | d->in_mempools[id].state = AudioRendererMemPoolState_Attached; 52 | return true; 53 | default: 54 | return false; 55 | } 56 | } 57 | 58 | bool audrvMemPoolDetach(AudioDriver* d, int id) 59 | { 60 | if (id < 0 || id >= d->etc->mempool_count) 61 | return false; 62 | 63 | switch (d->in_mempools[id].state) { 64 | case AudioRendererMemPoolState_New: 65 | return true; 66 | case AudioRendererMemPoolState_RequestAttach: 67 | case AudioRendererMemPoolState_Detached: 68 | d->in_mempools[id].state = AudioRendererMemPoolState_Detached; 69 | return true; 70 | case AudioRendererMemPoolState_RequestDetach: 71 | case AudioRendererMemPoolState_Attached: 72 | d->in_mempools[id].state = AudioRendererMemPoolState_RequestDetach; 73 | return true; 74 | default: 75 | return false; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/nvidia/ioctl/nvhost-ctrl-gpu.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "types.h" 3 | #include "result.h" 4 | #include "services/nv.h" 5 | #include "nvidia/ioctl.h" 6 | 7 | Result nvioctlNvhostCtrlGpu_ZCullGetCtxSize(u32 fd, u32 *out) { 8 | Result rc = 0; 9 | 10 | struct { 11 | __nv_out u32 out; 12 | } data; 13 | 14 | memset(&data, 0, sizeof(data)); 15 | 16 | rc = nvIoctl(fd, _NV_IOR(0x47, 0x01, data), &data); 17 | 18 | if (R_SUCCEEDED(rc)) { 19 | *out = data.out; 20 | } 21 | 22 | return rc; 23 | } 24 | 25 | Result nvioctlNvhostCtrlGpu_ZCullGetInfo(u32 fd, u32 out[40>>2]) { 26 | Result rc = 0; 27 | 28 | struct { 29 | __nv_out u32 out[40>>2]; 30 | } data; 31 | 32 | memset(&data, 0, sizeof(data)); 33 | 34 | rc = nvIoctl(fd, _NV_IOR(0x47, 0x02, data), &data); 35 | 36 | if (R_SUCCEEDED(rc)) { 37 | memcpy(out, data.out, sizeof(data.out)); 38 | } 39 | 40 | return rc; 41 | } 42 | 43 | Result nvioctlNvhostCtrlGpu_GetCharacteristics(u32 fd, nvioctl_gpu_characteristics *out) { 44 | Result rc = 0; 45 | 46 | struct { 47 | __nv_in u64 gc_buf_size; // must not be NULL, but gets overwritten with 0xA0=max_size 48 | __nv_in u64 gc_buf_addr; // ignored, but must not be NULL 49 | __nv_out nvioctl_gpu_characteristics gc; 50 | } data; 51 | 52 | memset(&data, 0, sizeof(data)); 53 | data.gc_buf_size = sizeof(nvioctl_gpu_characteristics); 54 | data.gc_buf_addr = 1; 55 | 56 | rc = nvIoctl(fd, _NV_IOWR(0x47, 0x05, data), &data); 57 | 58 | if (R_SUCCEEDED(rc)) { 59 | memcpy(out, &data.gc, sizeof(nvioctl_gpu_characteristics)); 60 | } 61 | 62 | return rc; 63 | } 64 | 65 | Result nvioctlNvhostCtrlGpu_GetTpcMasks(u32 fd, u32 inval, u32 out[24>>2]) { 66 | Result rc = 0; 67 | 68 | // Fixme: This one is wrong. 69 | struct { 70 | __nv_inout u32 unk[24>>2]; 71 | } data; 72 | 73 | memset(&data, 0, sizeof(data)); 74 | data.unk[0] = inval; 75 | data.unk[2] = 1; //addr? 76 | 77 | rc = nvIoctl(fd, _NV_IOWR(0x47, 0x06, data), &data); 78 | if (R_FAILED(rc)) return rc; 79 | 80 | memcpy(out, &data.unk, sizeof(data.unk)); 81 | 82 | return rc; 83 | } 84 | 85 | Result nvioctlNvhostCtrlGpu_GetL2State(u32 fd, nvioctl_l2_state *out) { 86 | Result rc = 0; 87 | 88 | struct { 89 | __nv_out nvioctl_l2_state out; 90 | } data; 91 | 92 | memset(&data, 0, sizeof(data)); 93 | 94 | rc = nvIoctl(fd, _NV_IOR(0x47, 0x14, data), &data); 95 | 96 | if (R_SUCCEEDED(rc)) { 97 | memcpy(out, &data.out, sizeof(data.out)); 98 | } 99 | 100 | return rc; 101 | } 102 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/shmem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file shmem.h 3 | * @brief Shared memory object handling 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | * @remark Shared memory differs from transfer memory in the fact that the kernel (as opposed to the user process) allocates and owns its backing memory. 7 | */ 8 | #pragma once 9 | #include "../types.h" 10 | 11 | /// Shared memory information structure. 12 | typedef struct { 13 | Handle handle; ///< Kernel object handle. 14 | size_t size; ///< Size of the shared memory object. 15 | Permission perm; ///< Permissions. 16 | void* map_addr; ///< Address to which the shared memory object is mapped. 17 | } SharedMemory; 18 | 19 | /** 20 | * @brief Creates a shared memory object. 21 | * @param s Shared memory information structure which will be filled in. 22 | * @param size Size of the shared memory object to create. 23 | * @param local_perm Permissions with which the shared memory object will be mapped in the local process. 24 | * @param remote_perm Permissions with which the shared memory object will be mapped in the remote process (can be Perm_DontCare). 25 | * @return Result code. 26 | * @warning This is a privileged operation; in normal circumstances applications cannot use this function. 27 | */ 28 | Result shmemCreate(SharedMemory* s, size_t size, Permission local_perm, Permission remote_perm); 29 | 30 | /** 31 | * @brief Loads a shared memory object coming from a remote process. 32 | * @param s Shared memory information structure which will be filled in. 33 | * @param handle Handle of the shared memory object. 34 | * @param size Size of the shared memory object that is being loaded. 35 | * @param perm Permissions with which the shared memory object will be mapped in the local process. 36 | */ 37 | void shmemLoadRemote(SharedMemory* s, Handle handle, size_t size, Permission perm); 38 | 39 | /** 40 | * @brief Maps a shared memory object. 41 | * @param s Shared memory information structure. 42 | * @return Result code. 43 | */ 44 | Result shmemMap(SharedMemory* s); 45 | 46 | /** 47 | * @brief Unmaps a shared memory object. 48 | * @param s Shared memory information structure. 49 | * @return Result code. 50 | */ 51 | Result shmemUnmap(SharedMemory* s); 52 | 53 | /** 54 | * @brief Retrieves the mapped address of a shared memory object. 55 | * @param s Shared memory information structure. 56 | * @return Mapped address of the shared memory object. 57 | */ 58 | static inline void* shmemGetAddr(SharedMemory* s) { 59 | return s->map_addr; 60 | } 61 | 62 | /** 63 | * @brief Frees up resources used by a shared memory object, unmapping and closing handles, etc. 64 | * @param s Shared memory information structure. 65 | * @return Result code. 66 | */ 67 | Result shmemClose(SharedMemory* s); 68 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/services/i2c.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "result.h" 3 | #include "arm/atomics.h" 4 | #include "kernel/ipc.h" 5 | #include "services/i2c.h" 6 | #include "services/sm.h" 7 | 8 | static Service g_i2cSrv; 9 | static size_t g_i2cSrvPtrBufSize; 10 | static u64 g_refCnt; 11 | 12 | Result i2cInitialize(void) { 13 | Result rc = 0; 14 | 15 | atomicIncrement64(&g_refCnt); 16 | 17 | if (serviceIsActive(&g_i2cSrv)) 18 | return 0; 19 | 20 | rc = smGetService(&g_i2cSrv, "i2c"); 21 | 22 | if (R_SUCCEEDED(rc)) rc = ipcQueryPointerBufferSize(g_i2cSrv.handle, &g_i2cSrvPtrBufSize); 23 | 24 | if (R_FAILED(rc)) i2cExit(); 25 | 26 | return rc; 27 | } 28 | 29 | void i2cExit(void) { 30 | if (atomicDecrement64(&g_refCnt) == 0) { 31 | g_i2cSrvPtrBufSize = 0; 32 | serviceClose(&g_i2cSrv); 33 | } 34 | } 35 | 36 | Result i2cOpenSession(I2cSession *out, I2cDevice dev) { 37 | IpcCommand c; 38 | ipcInitialize(&c); 39 | 40 | struct { 41 | u64 magic; 42 | u64 cmd_id; 43 | u32 device; 44 | } *raw; 45 | 46 | raw = serviceIpcPrepareHeader(&g_i2cSrv, &c, sizeof(*raw)); 47 | 48 | raw->magic = SFCI_MAGIC; 49 | raw->cmd_id = 1; 50 | raw->device = dev; 51 | 52 | Result rc = serviceIpcDispatch(&g_i2cSrv); 53 | 54 | if (R_SUCCEEDED(rc)) { 55 | IpcParsedCommand r; 56 | struct { 57 | u64 magic; 58 | u64 result; 59 | } *resp; 60 | 61 | serviceIpcParse(&g_i2cSrv, &r, sizeof(*resp)); 62 | resp = r.Raw; 63 | 64 | rc = resp->result; 65 | 66 | if (R_SUCCEEDED(rc)) { 67 | serviceCreateSubservice(&out->s, &g_i2cSrv, &r, 0); 68 | } 69 | } 70 | 71 | return rc; 72 | } 73 | 74 | Result i2csessionSendAuto(I2cSession *s, void *buf, size_t size, I2cTransactionOption option) { 75 | IpcCommand c; 76 | ipcInitialize(&c); 77 | ipcAddSendSmart(&c, g_i2cSrvPtrBufSize, buf, size, 0); 78 | 79 | struct { 80 | u64 magic; 81 | u64 cmd_id; 82 | u32 option; 83 | } *raw; 84 | 85 | raw = serviceIpcPrepareHeader(&s->s, &c, sizeof(*raw)); 86 | 87 | raw->magic = SFCI_MAGIC; 88 | raw->cmd_id = 10; 89 | raw->option = option; 90 | 91 | Result rc = serviceIpcDispatch(&s->s); 92 | 93 | if (R_SUCCEEDED(rc)) { 94 | IpcParsedCommand r; 95 | struct { 96 | u64 magic; 97 | u64 result; 98 | } *resp; 99 | 100 | serviceIpcParse(&s->s, &r, sizeof(*resp)); 101 | resp = r.Raw; 102 | 103 | rc = resp->result; 104 | } 105 | 106 | return rc; 107 | } 108 | 109 | void i2csessionClose(I2cSession *s) { 110 | serviceClose(&s->s); 111 | } 112 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/services/capssu.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "types.h" 3 | #include "result.h" 4 | #include "arm/atomics.h" 5 | #include "kernel/ipc.h" 6 | #include "runtime/hosversion.h" 7 | #include "services/applet.h" 8 | #include "services/caps.h" 9 | #include "services/capssu.h" 10 | #include "services/sm.h" 11 | 12 | static Service g_capssuSrv; 13 | static u64 g_capssuRefCnt; 14 | 15 | Result capssuInitialize(void) { 16 | Result rc=0; 17 | 18 | atomicIncrement64(&g_capssuRefCnt); 19 | 20 | if (serviceIsActive(&g_capssuSrv)) 21 | return 0; 22 | 23 | if (hosversionBefore(4,0,0)) 24 | rc = MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); 25 | 26 | if (R_SUCCEEDED(rc)) rc = smGetService(&g_capssuSrv, "caps:su"); 27 | 28 | if (R_FAILED(rc)) capssuExit(); 29 | 30 | return rc; 31 | } 32 | 33 | void capssuExit(void) { 34 | if (atomicDecrement64(&g_capssuRefCnt) == 0) 35 | serviceClose(&g_capssuSrv); 36 | } 37 | 38 | static Result _capssuSaveScreenShotEx0(const void* buffer, size_t size, CapsScreenShotAttribute *attr, u32 unk, CapsApplicationAlbumEntry *out) { 39 | u64 AppletResourceUserId = 0; 40 | appletGetAppletResourceUserId(&AppletResourceUserId); 41 | 42 | IpcCommand c; 43 | ipcInitialize(&c); 44 | 45 | struct { 46 | u64 magic; 47 | u64 cmd_id; 48 | CapsScreenShotAttribute attr; 49 | u32 unk; 50 | u64 AppletResourceUserId; 51 | } *raw; 52 | 53 | ipcSendPid(&c); 54 | ipcAddSendBuffer(&c, buffer, size, 1); 55 | 56 | raw = serviceIpcPrepareHeader(&g_capssuSrv, &c, sizeof(*raw)); 57 | 58 | raw->magic = SFCI_MAGIC; 59 | raw->cmd_id = 203; 60 | raw->attr = *attr; 61 | raw->unk = unk; 62 | raw->AppletResourceUserId = AppletResourceUserId; 63 | 64 | Result rc = serviceIpcDispatch(&g_capssuSrv); 65 | 66 | if (R_SUCCEEDED(rc)) { 67 | IpcParsedCommand r; 68 | struct { 69 | u64 magic; 70 | u64 result; 71 | CapsApplicationAlbumEntry out; 72 | } *resp; 73 | 74 | serviceIpcParse(&g_capssuSrv, &r, sizeof(*resp)); 75 | resp = r.Raw; 76 | 77 | rc = resp->result; 78 | 79 | if (R_SUCCEEDED(rc) && out) *out = resp->out; 80 | } 81 | 82 | return rc; 83 | } 84 | 85 | Result capssuSaveScreenShot(const void* buffer, size_t size, u32 unk, u32 attr_val, CapsApplicationAlbumEntry *out) { 86 | CapsScreenShotAttribute attr; 87 | 88 | memset(&attr, 0, sizeof(attr)); 89 | attr.unk_x0 = attr_val; 90 | 91 | return _capssuSaveScreenShotEx0(buffer, size, &attr, unk, out); 92 | } 93 | 94 | Result capssuSaveScreenShotEx0(const void* buffer, size_t size, CapsScreenShotAttribute *attr, u32 unk, CapsApplicationAlbumEntry *out) { 95 | return _capssuSaveScreenShotEx0(buffer, size, attr, unk, out); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/pm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pm.h 3 | * @brief Process management (pm*) service IPC wrapper. 4 | * @author plutoo 5 | * @author yellows8 6 | * @author mdbell 7 | * @copyright libnx Authors 8 | */ 9 | #pragma once 10 | #include "../types.h" 11 | #include "../kernel/event.h" 12 | #include "../services/sm.h" 13 | 14 | typedef enum { 15 | PmLaunchFlag_None = 0, 16 | 17 | ///< PmLaunchFlag_* should be used on 5.0.0+. 18 | PmLaunchFlag_SignalOnExit = (1 << 0), 19 | PmLaunchFlag_SignalOnStart = (1 << 1), 20 | PmLaunchFlag_SignalOnCrash = (1 << 2), 21 | PmLaunchFlag_SignalOnDebug = (1 << 3), 22 | PmLaunchFlag_StartSuspended = (1 << 4), 23 | PmLaunchFlag_DisableAslr = (1 << 5), 24 | 25 | ///< PmLaunchFlagOld_* should be used on 1.0.0-4.1.0. 26 | PmLaunchFlagOld_SignalOnExit = (1 << 0), 27 | PmLaunchFlagOld_StartSuspended = (1 << 1), 28 | PmLaunchFlagOld_SignalOnCrash = (1 << 2), 29 | PmLaunchFlagOld_DisableAslr = (1 << 3), 30 | PmLaunchFlagOld_SignalOnDebug = (1 << 4), 31 | ///< PmLaunchFlagOld_SignalOnStart was added in 2.0.0. 32 | PmLaunchFlagOld_SignalOnStart = (1 << 5), 33 | } PmLaunchFlag; 34 | 35 | typedef enum { 36 | PmProcessEvent_None = 0, 37 | PmProcessEvent_Exit = 1, 38 | PmProcessEvent_Start = 2, 39 | PmProcessEvent_Crash = 3, 40 | PmProcessEvent_DebugStart = 4, 41 | PmProcessEvent_DebugBreak = 5, 42 | } PmProcessEvent; 43 | 44 | typedef struct { 45 | PmProcessEvent event; 46 | u64 process_id; 47 | } PmProcessEventInfo; 48 | 49 | Result pmdmntInitialize(void); 50 | void pmdmntExit(void); 51 | 52 | Service* pmdmntGetServiceSession(void); 53 | 54 | Result pminfoInitialize(void); 55 | void pminfoExit(void); 56 | 57 | Result pmshellInitialize(void); 58 | void pmshellExit(void); 59 | 60 | Result pmdmntGetDebugProcesses(u32* out_count, u64* out_pids, size_t max_pids); 61 | Result pmdmntStartProcess(u64 pid); 62 | Result pmdmntGetTitlePid(u64* pid_out, u64 title_id); 63 | Result pmdmntEnableDebugForTitleId(Handle* handle_out, u64 title_id); 64 | Result pmdmntGetApplicationPid(u64* pid_out); 65 | Result pmdmntEnableDebugForApplication(Handle* handle_out); 66 | Result pmdmntDisableDebug(void); 67 | 68 | Result pminfoGetTitleId(u64* title_id_out, u64 pid); 69 | 70 | Result pmshellLaunchProcess(u32 launch_flags, u64 titleID, u64 storageID, u64 *pid); 71 | Result pmshellTerminateProcessByProcessId(u64 processID); 72 | Result pmshellTerminateProcessByTitleId(u64 titleID); 73 | Result pmshellGetProcessEvent(Event* out); // Autoclear for pmshellProcessEvent is always true. 74 | Result pmshellGetProcessEventInfo(PmProcessEventInfo* out); 75 | Result pmshellFinalizeDeadProcess(u64 pid); 76 | Result pmshellClearProcessExceptionOccurred(u64 pid); 77 | Result pmshellNotifyBootFinished(void); 78 | Result pmshellGetApplicationPid(u64* pid_out); 79 | Result pmshellBoostSystemMemoryResourceLimit(u64 boost_size); 80 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/audin.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file audin.h 3 | * @brief Audio input service. 4 | * @author hexkyz 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | 9 | #include "../audio/audio.h" 10 | 11 | typedef enum { 12 | AudioInState_Started = 0, 13 | AudioInState_Stopped = 1, 14 | } AudioInState; 15 | 16 | /// Audio input buffer format 17 | typedef struct AudioInBuffer AudioInBuffer; 18 | 19 | struct AudioInBuffer 20 | { 21 | AudioInBuffer* next; ///< Next buffer. (Unused) 22 | void* buffer; ///< Sample buffer (aligned to 0x1000 bytes). 23 | u64 buffer_size; ///< Sample buffer size (aligned to 0x1000 bytes). 24 | u64 data_size; ///< Size of data inside the buffer. 25 | u64 data_offset; ///< Offset of data inside the buffer. (Unused?) 26 | }; 27 | 28 | Result audinInitialize(void); 29 | void audinExit(void); 30 | 31 | Result audinListAudioIns(char *DeviceNames, u32 *DeviceNamesCount); 32 | Result audinOpenAudioIn(const char *DeviceNameIn, char *DeviceNameOut, u32 SampleRateIn, u32 ChannelCountIn, u32 *SampleRateOut, u32 *ChannelCountOut, PcmFormat *Format, AudioInState *State); 33 | Result audinGetAudioInState(AudioInState *State); 34 | Result audinStartAudioIn(void); 35 | Result audinStopAudioIn(void); 36 | 37 | /// Submits an \ref AudioInBuffer for capturing. 38 | Result audinAppendAudioInBuffer(AudioInBuffer *Buffer); 39 | 40 | Result audinGetReleasedAudioInBuffer(AudioInBuffer **Buffer, u32 *ReleasedBuffersCount); 41 | Result audinContainsAudioInBuffer(AudioInBuffer *Buffer, bool *ContainsBuffer); 42 | 43 | /** 44 | * @brief Submits an audio sample data buffer for capturing and waits for it to finish capturing. 45 | * @brief Uses \ref audinAppendAudioInBuffer and \ref audinWaitCaptureFinish internally. 46 | * @param source AudioInBuffer containing the buffer to hold the captured sample data. 47 | * @param released AudioInBuffer to receive the captured buffer after being released. 48 | */ 49 | Result audinCaptureBuffer(AudioInBuffer *source, AudioInBuffer **released); 50 | 51 | /** 52 | * @brief Waits for audio capture to finish. 53 | * @param released AudioInBuffer to receive the first captured buffer after being released. 54 | * @param released_count Pointer to receive the number of captured buffers. 55 | * @param timeout Timeout value, use U64_MAX to wait until all finished. 56 | */ 57 | Result audinWaitCaptureFinish(AudioInBuffer **released, u32* released_count, u64 timeout); 58 | 59 | /// These return the state associated with the currently active audio input device. 60 | u32 audinGetSampleRate(void); ///< Supported sample rate (48000Hz). 61 | u32 audinGetChannelCount(void); ///< Supported channel count (2 channels). 62 | PcmFormat audinGetPcmFormat(void); ///< Supported PCM format (Int16). 63 | AudioInState audinGetDeviceState(void); ///< Initial device state (stopped). 64 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/audout.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file audout.h 3 | * @brief Audio output service. 4 | * @author hexkyz 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | 9 | #include "../audio/audio.h" 10 | 11 | typedef enum { 12 | AudioOutState_Started = 0, 13 | AudioOutState_Stopped = 1, 14 | } AudioOutState; 15 | 16 | /// Audio output buffer format 17 | typedef struct AudioOutBuffer AudioOutBuffer; 18 | 19 | struct AudioOutBuffer 20 | { 21 | AudioOutBuffer* next; ///< Next buffer. (Unused) 22 | void* buffer; ///< Sample buffer (aligned to 0x1000 bytes). 23 | u64 buffer_size; ///< Sample buffer size (aligned to 0x1000 bytes). 24 | u64 data_size; ///< Size of data inside the buffer. 25 | u64 data_offset; ///< Offset of data inside the buffer. (Unused?) 26 | }; 27 | 28 | Result audoutInitialize(void); 29 | void audoutExit(void); 30 | 31 | Result audoutListAudioOuts(char *DeviceNames, u32 *DeviceNamesCount); 32 | Result audoutOpenAudioOut(const char *DeviceNameIn, char *DeviceNameOut, u32 SampleRateIn, u32 ChannelCountIn, u32 *SampleRateOut, u32 *ChannelCountOut, PcmFormat *Format, AudioOutState *State); 33 | Result audoutGetAudioOutState(AudioOutState *State); 34 | Result audoutStartAudioOut(void); 35 | Result audoutStopAudioOut(void); 36 | 37 | /// Submits an \ref AudioOutBuffer for playing. 38 | Result audoutAppendAudioOutBuffer(AudioOutBuffer *Buffer); 39 | 40 | Result audoutGetReleasedAudioOutBuffer(AudioOutBuffer **Buffer, u32 *ReleasedBuffersCount); 41 | Result audoutContainsAudioOutBuffer(AudioOutBuffer *Buffer, bool *ContainsBuffer); 42 | 43 | /** 44 | * @brief Submits an audio sample data buffer for playing and waits for it to finish playing. 45 | * @brief Uses \ref audoutAppendAudioOutBuffer and \ref audoutWaitPlayFinish internally. 46 | * @param source AudioOutBuffer containing the source sample data to be played. 47 | * @param released AudioOutBuffer to receive the played buffer after being released. 48 | */ 49 | Result audoutPlayBuffer(AudioOutBuffer *source, AudioOutBuffer **released); 50 | 51 | /** 52 | * @brief Waits for audio playback to finish. 53 | * @param released AudioOutBuffer to receive the first played buffer after being released. 54 | * @param released_count Pointer to receive the number of played buffers. 55 | * @param timeout Timeout value, use U64_MAX to wait until all finished. 56 | */ 57 | Result audoutWaitPlayFinish(AudioOutBuffer **released, u32* released_count, u64 timeout); 58 | 59 | /// These return the state associated with the currently active audio output device. 60 | u32 audoutGetSampleRate(void); ///< Supported sample rate (48000Hz). 61 | u32 audoutGetChannelCount(void); ///< Supported channel count (2 channels). 62 | PcmFormat audoutGetPcmFormat(void); ///< Supported PCM format (Int16). 63 | AudioOutState audoutGetDeviceState(void); ///< Initial device state (stopped). 64 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file switch/types.h 3 | * @brief Various system types. 4 | * @copyright libnx Authors 5 | */ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | /// The maximum value of a u64. 14 | #define U64_MAX UINT64_MAX 15 | 16 | #ifndef SSIZE_MAX 17 | #ifdef SIZE_MAX 18 | #define SSIZE_MAX ((SIZE_MAX) >> 1) 19 | #endif 20 | #endif 21 | 22 | typedef uint8_t u8; ///< 8-bit unsigned integer. 23 | typedef uint16_t u16; ///< 16-bit unsigned integer. 24 | typedef uint32_t u32; ///< 32-bit unsigned integer. 25 | typedef uint64_t u64; ///< 64-bit unsigned integer. 26 | typedef __uint128_t u128; ///< 128-bit unsigned integer. 27 | 28 | typedef int8_t s8; ///< 8-bit signed integer. 29 | typedef int16_t s16; ///< 16-bit signed integer. 30 | typedef int32_t s32; ///< 32-bit signed integer. 31 | typedef int64_t s64; ///< 64-bit signed integer. 32 | typedef __int128_t s128; ///< 128-bit unsigned integer. 33 | 34 | typedef volatile u8 vu8; ///< 8-bit volatile unsigned integer. 35 | typedef volatile u16 vu16; ///< 16-bit volatile unsigned integer. 36 | typedef volatile u32 vu32; ///< 32-bit volatile unsigned integer. 37 | typedef volatile u64 vu64; ///< 64-bit volatile unsigned integer. 38 | typedef volatile u128 vu128; ///< 128-bit volatile unsigned integer. 39 | 40 | typedef volatile s8 vs8; ///< 8-bit volatile signed integer. 41 | typedef volatile s16 vs16; ///< 16-bit volatile signed integer. 42 | typedef volatile s32 vs32; ///< 32-bit volatile signed integer. 43 | typedef volatile s64 vs64; ///< 64-bit volatile signed integer. 44 | typedef volatile s128 vs128; ///< 128-bit volatile signed integer. 45 | 46 | typedef u32 Handle; ///< Kernel object handle. 47 | typedef u32 Result; ///< Function error code result type. 48 | typedef void (*ThreadFunc)(void *); ///< Thread entrypoint function. 49 | typedef void (*VoidFn)(void); ///< Function without arguments nor return value. 50 | 51 | /// Creates a bitmask from a bit number. 52 | #ifndef BIT 53 | #define BIT(n) (1U<<(n)) 54 | #endif 55 | 56 | /// Packs a struct so that it won't include padding bytes. 57 | #ifndef PACKED 58 | #define PACKED __attribute__((packed)) 59 | #endif 60 | 61 | /// Marks a function as not returning, for the purposes of compiler optimization. 62 | #ifndef NORETURN 63 | #define NORETURN __attribute__((noreturn)) 64 | #endif 65 | 66 | /// Performs a dummy operation on the specified argument in order to silence compiler warnings about unused arguments. 67 | #ifndef IGNORE_ARG 68 | #define IGNORE_ARG(x) (void)(x) 69 | #endif 70 | 71 | /// Flags a function as deprecated. 72 | #ifndef DEPRECATED 73 | #ifndef LIBNX_NO_DEPRECATION 74 | #define DEPRECATED __attribute__ ((deprecated)) 75 | #else 76 | #define DEPRECATED 77 | #endif 78 | #endif 79 | 80 | /// Invalid handle. 81 | #define INVALID_HANDLE ((Handle) 0) 82 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/kernel/thread.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file thread.h 3 | * @brief Multi-threading support 4 | * @author plutoo 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "../arm/thread_context.h" 10 | #include "wait.h" 11 | 12 | /// Thread information structure. 13 | typedef struct { 14 | Handle handle; ///< Thread handle. 15 | void* stack_mem; ///< Pointer to stack memory. 16 | void* stack_mirror; ///< Pointer to stack memory mirror. 17 | size_t stack_sz; ///< Stack size. 18 | } Thread; 19 | 20 | /// Creates a \ref Waiter for a \ref Thread. 21 | static inline Waiter waiterForThread(Thread* t) 22 | { 23 | return waiterForHandle(t->handle); 24 | } 25 | 26 | /** 27 | * @brief Creates a thread. 28 | * @param t Thread information structure which will be filled in. 29 | * @param entry Entrypoint of the thread. 30 | * @param arg Argument to pass to the entrypoint. 31 | * @param stack_sz Stack size (rounded up to page alignment). 32 | * @param prio Thread priority (0x00~0x3F); 0x2C is the usual priority of the main thread, 0x3B is a special priority on cores 0..2 that enables preemptive multithreading (0x3F on core 3). 33 | * @param cpuid ID of the core on which to create the thread (0~3); or -2 to use the default core for the current process. 34 | * @return Result code. 35 | */ 36 | Result threadCreate( 37 | Thread* t, ThreadFunc entry, void* arg, size_t stack_sz, int prio, 38 | int cpuid); 39 | 40 | /** 41 | * @brief Starts the execution of a thread. 42 | * @param t Thread information structure. 43 | * @return Result code. 44 | */ 45 | Result threadStart(Thread* t); 46 | 47 | /** 48 | * @brief Waits for a thread to finish executing. 49 | * @param t Thread information structure. 50 | * @return Result code. 51 | */ 52 | Result threadWaitForExit(Thread* t); 53 | 54 | /** 55 | * @brief Frees up resources associated with a thread. 56 | * @param t Thread information structure. 57 | * @return Result code. 58 | */ 59 | Result threadClose(Thread* t); 60 | 61 | /** 62 | * @brief Pauses the execution of a thread. 63 | * @param t Thread information structure. 64 | * @return Result code. 65 | */ 66 | Result threadPause(Thread* t); 67 | 68 | /** 69 | * @brief Resumes the execution of a thread, after having been paused. 70 | * @param t Thread information structure. 71 | * @return Result code. 72 | */ 73 | Result threadResume(Thread* t); 74 | 75 | /** 76 | * @brief Dumps the registers of a thread paused by @ref threadPause (register groups: all). 77 | * @param[out] ctx Output thread context (register dump). 78 | * @param t Thread information structure. 79 | * @return Result code. 80 | * @warning Official kernel will not dump x0..x18 if the thread is currently executing a system call, and prior to 6.0.0 doesn't dump TPIDR_EL0. 81 | */ 82 | Result threadDumpContext(ThreadContext* ctx, Thread* t); 83 | 84 | /** 85 | * @brief Gets the raw handle to the current thread. 86 | * @return The current thread's handle. 87 | */ 88 | Handle threadGetCurHandle(void); 89 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/include/switch/services/acc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file acc.h 3 | * @brief Account (acc:*) service IPC wrapper. 4 | * @author yellows8 5 | * @copyright libnx Authors 6 | */ 7 | #pragma once 8 | #include "../types.h" 9 | #include "sm.h" 10 | 11 | #define ACC_USER_LIST_SIZE 8 12 | 13 | typedef struct { 14 | Service s; 15 | } AccountProfile; 16 | 17 | typedef struct 18 | { 19 | u32 unk_x0; 20 | u32 iconID; ///< Icon ID. 0 = Mii, the rest are character icon IDs. 21 | u8 iconBackgroundColorID; ///< Profile icon background color ID 22 | u8 unk_x9[0x7]; 23 | u8 miiID[0x10]; ///< Some ID related to the Mii? All zeros when a character icon is used. 24 | u8 unk_x20[0x60]; ///< Usually zeros? 25 | } PACKED AccountUserData; 26 | 27 | typedef struct 28 | { 29 | u128 userID; 30 | u64 lastEditTimestamp; ///< POSIX UTC timestamp, for the last account edit. 31 | char username[0x20]; ///< UTF-8 Username. 32 | } PACKED AccountProfileBase; 33 | 34 | Result accountInitialize(void); 35 | void accountExit(void); 36 | Service* accountGetService(void); 37 | 38 | /// Get the total number of user profiles 39 | Result accountGetUserCount(s32* user_count); 40 | 41 | /** 42 | * @brief Get a list of all user IDs. The returned list will never be larger than ACC_USER_LIST_SIZE. 43 | * @param userIDs Pointer to array of user IDs. 44 | * @param max_userIDs Maximum number of user IDs to return. 45 | * @param actual_total The actual total number of user IDs found. 46 | */ 47 | Result accountListAllUsers(u128* userIDs, size_t max_userIDs, size_t *actual_total); 48 | 49 | /// Get the userID for the currently active user. The output userID is only valid when the output account_selected==1, otherwise no user is currently selected. 50 | /// An user is only selected when the user-account selection applet was used to select an user at least once before. 51 | Result accountGetActiveUser(u128 *userID, bool *account_selected); 52 | 53 | /// Get an AccountProfile for the specified userID. 54 | Result accountGetProfile(AccountProfile* out, u128 userID); 55 | 56 | /// Get \ref AccountUserData and \ref AccountProfileBase for the specified profile, userdata is optional (can be NULL). 57 | Result accountProfileGet(AccountProfile* profile, AccountUserData* userdata, AccountProfileBase* profilebase); 58 | 59 | /// Get the icon image size. 60 | Result accountProfileGetImageSize(AccountProfile* profile, size_t* image_size); 61 | 62 | /// Load the JPEG profile icon, valid for both Miis and character icons. The output image_size is the same as the one from \ref accountProfileGetImageSize. 63 | Result accountProfileLoadImage(AccountProfile* profile, void* buf, size_t len, size_t* image_size); 64 | 65 | void accountProfileClose(AccountProfile* profile); 66 | 67 | /// Gets the userID which was selected by the profile-selector applet (if any), prior to launching the currently running Application title. This can only be used once under the current process, under an Application title. 68 | Result accountGetPreselectedUser(u128 *userID); 69 | 70 | -------------------------------------------------------------------------------- /Sp2Patcher/Sp2Patcher/Sp2Patcher.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {44043CE0-FBAB-491D-87F0-E2BFEDE77983} 8 | Exe 9 | Sp2Patcher 10 | Sp2Patcher 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\packages\lz4net.1.0.15.93\lib\net4-client\LZ4.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/source/services/bpc.c: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "result.h" 3 | #include "arm/atomics.h" 4 | #include "kernel/ipc.h" 5 | #include "runtime/hosversion.h" 6 | #include "services/bpc.h" 7 | #include "services/sm.h" 8 | 9 | static Service g_bpcSrv; 10 | static u64 g_refCnt; 11 | 12 | Result bpcInitialize(void) 13 | { 14 | Result rc = 0; 15 | 16 | atomicIncrement64(&g_refCnt); 17 | 18 | if (serviceIsActive(&g_bpcSrv)) 19 | return 0; 20 | 21 | rc = smGetService(&g_bpcSrv, hosversionAtLeast(2,0,0) ? "bpc" : "bpc:c"); 22 | 23 | return rc; 24 | } 25 | 26 | void bpcExit(void) 27 | { 28 | if (atomicDecrement64(&g_refCnt) == 0) 29 | serviceClose(&g_bpcSrv); 30 | } 31 | 32 | Result bpcShutdownSystem(void) 33 | { 34 | IpcCommand c; 35 | ipcInitialize(&c); 36 | 37 | struct { 38 | u64 magic; 39 | u64 cmd_id; 40 | } *raw; 41 | 42 | raw = serviceIpcPrepareHeader(&g_bpcSrv, &c, sizeof(*raw)); 43 | raw->magic = SFCI_MAGIC; 44 | raw->cmd_id = 0; 45 | 46 | Result rc = serviceIpcDispatch(&g_bpcSrv); 47 | 48 | if(R_SUCCEEDED(rc)) { 49 | IpcParsedCommand r; 50 | struct { 51 | u64 magic; 52 | u64 result; 53 | } *resp; 54 | 55 | serviceIpcParse(&g_bpcSrv, &r, sizeof(*resp)); 56 | resp = r.Raw; 57 | 58 | rc = resp->result; 59 | } 60 | 61 | return rc; 62 | } 63 | 64 | Result bpcRebootSystem(void) 65 | { 66 | IpcCommand c; 67 | ipcInitialize(&c); 68 | 69 | struct { 70 | u64 magic; 71 | u64 cmd_id; 72 | } *raw; 73 | 74 | raw = serviceIpcPrepareHeader(&g_bpcSrv, &c, sizeof(*raw)); 75 | raw->magic = SFCI_MAGIC; 76 | raw->cmd_id = 1; 77 | 78 | Result rc = serviceIpcDispatch(&g_bpcSrv); 79 | 80 | if(R_SUCCEEDED(rc)) { 81 | IpcParsedCommand r; 82 | struct { 83 | u64 magic; 84 | u64 result; 85 | } *resp; 86 | 87 | serviceIpcParse(&g_bpcSrv, &r, sizeof(*resp)); 88 | resp = r.Raw; 89 | 90 | rc = resp->result; 91 | } 92 | 93 | return rc; 94 | } 95 | 96 | Result bpcGetSleepButtonState(BpcSleepButtonState *out) { 97 | IpcCommand c; 98 | ipcInitialize(&c); 99 | 100 | struct { 101 | u64 magic; 102 | u64 cmd_id; 103 | } *raw; 104 | 105 | raw = serviceIpcPrepareHeader(&g_bpcSrv, &c, sizeof(*raw)); 106 | raw->magic = SFCI_MAGIC; 107 | raw->cmd_id = 6; 108 | 109 | Result rc = serviceIpcDispatch(&g_bpcSrv); 110 | 111 | if(R_SUCCEEDED(rc)) { 112 | IpcParsedCommand r; 113 | struct { 114 | u64 magic; 115 | u64 result; 116 | u8 state; 117 | } *resp; 118 | 119 | serviceIpcParse(&g_bpcSrv, &r, sizeof(*resp)); 120 | resp = r.Raw; 121 | 122 | rc = resp->result; 123 | 124 | if (R_SUCCEEDED(rc)) { 125 | *out = (BpcSleepButtonState)resp->state; 126 | } 127 | } 128 | 129 | return rc; 130 | } 131 | -------------------------------------------------------------------------------- /sp2Module/libnx/nx/external/bsd/include/netinet/udp.h: -------------------------------------------------------------------------------- 1 | // TuxSH: removed definitions under _KERNEL ifdef blocks, modify the prototype of some functions, some other cleanup, etc. 2 | #ifndef __BSD_VISIBLE 3 | #define __BSD_VISIBLE 1 4 | #endif 5 | 6 | /*- 7 | * SPDX-License-Identifier: BSD-3-Clause 8 | * 9 | * Copyright (c) 1982, 1986, 1993 10 | * The Regents of the University of California. 11 | * All rights reserved. 12 | * 13 | * Redistribution and use in source and binary forms, with or without 14 | * modification, are permitted provided that the following conditions 15 | * are met: 16 | * 1. Redistributions of source code must retain the above copyright 17 | * notice, this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright 19 | * notice, this list of conditions and the following disclaimer in the 20 | * documentation and/or other materials provided with the distribution. 21 | * 3. Neither the name of the University nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | * 37 | * @(#)udp.h 8.1 (Berkeley) 6/10/93 38 | * $FreeBSD$ 39 | */ 40 | 41 | #ifndef _NETINET_UDP_H_ 42 | #define _NETINET_UDP_H_ 43 | 44 | // Added: 45 | #include 46 | #include 47 | #include 48 | 49 | /* 50 | * UDP protocol header. 51 | * Per RFC 768, September, 1981. 52 | */ 53 | struct udphdr { 54 | u_short uh_sport; /* source port */ 55 | u_short uh_dport; /* destination port */ 56 | u_short uh_ulen; /* udp length */ 57 | u_short uh_sum; /* udp checksum */ 58 | }; 59 | 60 | /* 61 | * User-settable options (used with setsockopt). 62 | */ 63 | #define UDP_ENCAP 1 64 | 65 | /* Start of reserved space for third-party user-settable options. */ 66 | #define UDP_VENDOR SO_VENDOR 67 | 68 | /* 69 | * UDP Encapsulation of IPsec Packets options. 70 | */ 71 | /* Encapsulation types. */ 72 | #define UDP_ENCAP_ESPINUDP_NON_IKE 1 /* draft-ietf-ipsec-nat-t-ike-00/01 */ 73 | #define UDP_ENCAP_ESPINUDP 2 /* RFC3948 */ 74 | 75 | /* Default ESP in UDP encapsulation port. */ 76 | #define UDP_ENCAP_ESPINUDP_PORT 500 77 | 78 | /* Maximum UDP fragment size for ESP over UDP. */ 79 | #define UDP_ENCAP_ESPINUDP_MAXFRAGLEN 552 80 | 81 | #endif 82 | --------------------------------------------------------------------------------