From 0e4fd6d37f827303f10a83595ba131fd9d517131 Mon Sep 17 00:00:00 2001 From: Cpasjuste Date: Fri, 24 Aug 2018 15:04:41 +0200 Subject: [PATCH 1/5] Gfx: Potential mitigation for the Fuzz Gfx: Temporarily remove fatal Error (only happens on Threaded+Docked) to prevent Data loss --- nx/source/gfx/gfx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nx/source/gfx/gfx.c b/nx/source/gfx/gfx.c index 8bfa2208..aef615f4 100644 --- a/nx/source/gfx/gfx.c +++ b/nx/source/gfx/gfx.c @@ -141,7 +141,7 @@ static Result _gfxDequeueBuffer(void) { //Only run nvgfxEventWait when the fence is valid and the id is not NO_FENCE. if (R_SUCCEEDED(rc) && tmp_fence.is_valid && tmp_fence.nv_fences[0].id!=0xffffffff) rc = nvgfxEventWait(tmp_fence.nv_fences[0].id, tmp_fence.nv_fences[0].value, -1); - if (R_SUCCEEDED(rc)) g_gfxCurrentBuffer = (g_gfxCurrentBuffer + 1) & (g_nvgfx_totalframebufs-1); + g_gfxCurrentBuffer = (g_gfxCurrentBuffer + 1) & (g_nvgfx_totalframebufs-1); //if (R_SUCCEEDED(rc)) rc = nvgfxSubmitGpfifo(); @@ -514,7 +514,7 @@ void gfxSwapBuffers(void) { rc = _gfxDequeueBuffer(); - if (R_FAILED(rc)) fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGfxDequeueBuffer)); + //if (R_FAILED(rc)) fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadGfxDequeueBuffer)); } u8* gfxGetFramebuffer(u32* width, u32* height) { From fe87c52e572f3879315361cf7be1b7ea7b4e3dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Hern=C3=A1ndez=20C=C3=A1novas?= Date: Fri, 24 Aug 2018 16:20:01 +0200 Subject: [PATCH 2/5] Add rwlockInit (#155) --- nx/include/switch/kernel/rwlock.h | 6 ++++++ nx/source/kernel/rwlock.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/nx/include/switch/kernel/rwlock.h b/nx/include/switch/kernel/rwlock.h index eb70b43d..de594b81 100644 --- a/nx/include/switch/kernel/rwlock.h +++ b/nx/include/switch/kernel/rwlock.h @@ -14,6 +14,12 @@ typedef struct { u64 b; } RwLock; +/** + * @brief Initializes the read/write lock. + * @param r Read/write lock object. + */ +void rwlockInit(RwLock* r); + /** * @brief Locks the read/write lock for reading. * @param r Read/write lock object. diff --git a/nx/source/kernel/rwlock.c b/nx/source/kernel/rwlock.c index e0863716..962dd0ca 100644 --- a/nx/source/kernel/rwlock.c +++ b/nx/source/kernel/rwlock.c @@ -2,6 +2,12 @@ #include "kernel/mutex.h" #include "kernel/rwlock.h" +void rwlockInit(RwLock* r) { + rmutexInit(&r->r); + rmutexInit(&r->g); + r->b = 0; +} + void rwlockReadLock(RwLock* r) { rmutexLock(&r->r); From 28285cb60d99bc4471f23286126ce646b2b1bace Mon Sep 17 00:00:00 2001 From: XorTroll <33005497+XorTroll@users.noreply.github.com> Date: Fri, 24 Aug 2018 16:21:16 +0200 Subject: [PATCH 3/5] Add bpc service with ShutdownSystem and RebootSystem commands (#144) --- nx/include/switch/services/bpc.h | 14 +++++ nx/source/services/bpc.c | 93 ++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 nx/include/switch/services/bpc.h create mode 100644 nx/source/services/bpc.c diff --git a/nx/include/switch/services/bpc.h b/nx/include/switch/services/bpc.h new file mode 100644 index 00000000..96e6d870 --- /dev/null +++ b/nx/include/switch/services/bpc.h @@ -0,0 +1,14 @@ +/** + * @file bpc.h + * @brief Board power control (bpc) service IPC wrapper. + * @author XorTroll + * @copyright libnx Authors + */ +#pragma once +#include "../types.h" + +Result bpcInitialize(void); +void bpcExit(void); + +Result bpcShutdownSystem(void); +Result bpcRebootSystem(void); diff --git a/nx/source/services/bpc.c b/nx/source/services/bpc.c new file mode 100644 index 00000000..4be0c93c --- /dev/null +++ b/nx/source/services/bpc.c @@ -0,0 +1,93 @@ +#include "types.h" +#include "result.h" +#include "arm/atomics.h" +#include "kernel/ipc.h" +#include "kernel/detect.h" +#include "services/bpc.h" +#include "services/sm.h" + +static Service g_bpcSrv; +static u64 g_refCnt; + +Result bpcInitialize(void) +{ + Result rc = 0; + + atomicIncrement64(&g_refCnt); + + if (serviceIsActive(&g_bpcSrv)) + return 0; + + rc = smGetService(&g_bpcSrv, kernelAbove200() ? "bpc" : "bpc:c"); + + return rc; +} + +void bpcExit(void) +{ + if (atomicDecrement64(&g_refCnt) == 0) + serviceClose(&g_bpcSrv); +} + +Result bpcShutdownSystem(void) +{ + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 0; + + Result rc = serviceIpcDispatch(&g_bpcSrv); + + if(R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + +Result bpcRebootSystem(void) +{ + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + raw->magic = SFCI_MAGIC; + raw->cmd_id = 1; + + Result rc = serviceIpcDispatch(&g_bpcSrv); + + if(R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} From dbb0b66773ee2006c2532968adba9333f9822c8e Mon Sep 17 00:00:00 2001 From: fincs Date: Fri, 24 Aug 2018 16:24:24 +0200 Subject: [PATCH 4/5] Fix #154 --- nx/include/switch/services/set.h | 1 + 1 file changed, 1 insertion(+) diff --git a/nx/include/switch/services/set.h b/nx/include/switch/services/set.h index 2b40738e..8a64b8bc 100644 --- a/nx/include/switch/services/set.h +++ b/nx/include/switch/services/set.h @@ -5,6 +5,7 @@ * @author yellows8 * @copyright libnx Authors */ +#pragma once #include "../result.h" #define SET_MAX_NAME_SIZE 0x48 From 65587baca9c30d556b391ebb079f4a2ef646635a Mon Sep 17 00:00:00 2001 From: fincs Date: Fri, 24 Aug 2018 16:24:42 +0200 Subject: [PATCH 5/5] Add switch/services/bpc.h to switch.h --- nx/include/switch.h | 1 + 1 file changed, 1 insertion(+) diff --git a/nx/include/switch.h b/nx/include/switch.h index c3779377..b3ed59cc 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -45,6 +45,7 @@ extern "C" { #include "switch/services/audin.h" #include "switch/services/audout.h" #include "switch/services/csrng.h" +#include "switch/services/bpc.h" //#include "switch/services/bsd.h" Use switch/runtime/devices/socket.h instead #include "switch/services/fatal.h" #include "switch/services/time.h"