diff --git a/Dockerfile b/Dockerfile index c2284d6..f37c721 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,13 @@ -FROM devkitpro/devkita64_devkitarm:20190720 +FROM devkitpro/devkita64_devkitarm:20200405 -# RUN git clone -b master https://github.com/switchbrew/libnx.git --depth=1 \ -# && cd libnx \ -# && make -j8 \ -# && make install \ -# && cd .. \ -# && rm -rf libnx RUN dkp-pacman -Syyu --noconfirm switch-dev libnx \ && dkp-pacman -Scc --noconfirm +RUN git clone -b master https://github.com/switchbrew/libnx.git --depth=1 \ + && cd libnx \ + && make -j8 \ + && make install \ + && cd .. \ + && rm -rf libnx VOLUME [ "/code" ] WORKDIR /code diff --git a/ldn_mitm/source/ipinfo.cpp b/ldn_mitm/source/ipinfo.cpp index e8a8107..19ade88 100644 --- a/ldn_mitm/source/ipinfo.cpp +++ b/ldn_mitm/source/ipinfo.cpp @@ -16,7 +16,7 @@ Result _nifmSetConnectionConfirmationOption(s8 option); Result _nifmSubmitRequest(); Result ipinfoInit() { - atomicIncrement64(&g_nifmRefCount); + g_nifmRefCount++; if (serviceIsActive(&g_nifmSrv)) return 0; @@ -39,7 +39,7 @@ Result ipinfoInit() { } void ipinfoExit() { - if (atomicDecrement64(&g_nifmRefCount) == 0) { + if (--g_nifmRefCount == 0) { serviceClose(&g_nifmIReq); serviceClose(&g_nifmIGS); serviceClose(&g_nifmSrv); diff --git a/ldn_mitm/source/lan_discovery.cpp b/ldn_mitm/source/lan_discovery.cpp index 48a0b71..fb66512 100644 --- a/ldn_mitm/source/lan_discovery.cpp +++ b/ldn_mitm/source/lan_discovery.cpp @@ -704,10 +704,7 @@ namespace ams::mitm::ldn { if (this->inited) { this->stop = true; - rc = this->workerThread.Join(); - if (R_FAILED(rc)) { - LogFormat("thread.join %d", rc); - } + os::WaitThread(&this->workerThread); this->udp.reset(); this->tcp.reset(); this->resetStations(); @@ -751,17 +748,13 @@ namespace ams::mitm::ldn { return rc; } - rc = this->workerThread.Initialize(&Worker, this, 0x4000, 0x15, 2); + rc = os::CreateThread(&this->workerThread, &Worker, this, stack.get(), StackSize, 0x15, 2); if (R_FAILED(rc)) { LogFormat("LANDiscovery Failed to threadCreate: %x", rc); return 0xF601; } - rc = this->workerThread.Start(); - if (R_FAILED(rc)) { - LogFormat("LANDiscovery Failed to threadStart %x", rc); - return 0xF601; - } + os::StartThread(&this->workerThread); this->setState(CommState::Initialized); this->inited = true; diff --git a/ldn_mitm/source/lan_discovery.hpp b/ldn_mitm/source/lan_discovery.hpp index b9e2ed6..e1254a7 100644 --- a/ldn_mitm/source/lan_discovery.hpp +++ b/ldn_mitm/source/lan_discovery.hpp @@ -13,6 +13,7 @@ #include "lan_protocol.hpp" namespace ams::mitm::ldn { + const size_t StackSize = 0x4000; enum class NodeStatus : u8 { Disconnected, Connect, @@ -137,7 +138,7 @@ namespace ams::mitm::ldn { bool inited; NetworkInfo networkInfo; u16 listenPort; - os::Thread workerThread; + os::ThreadType workerThread; CommState state; void worker(); int loopPoll(); @@ -151,6 +152,7 @@ namespace ams::mitm::ldn { Result getFakeMac(MacAddress *mac); Result getNodeInfo(NodeInfo *node, const UserConfig *userConfig, u16 localCommunicationVersion); LanEventFunc lanEvent; + std::unique_ptr stack; public: Result initialize(LanEventFunc lanEvent = EmptyFunc, bool listening = true); Result finalize(); @@ -170,6 +172,7 @@ namespace ams::mitm::ldn { public: LANDiscovery(u16 port = DefaultPort) : disconnect_reason(DisconnectReason::None), + pollMutex(false), stations({{{1, this}, {2, this}, {3, this}, {4, this}, {5, this}, {6, this}, {7, this}}}), stop(false), inited(false), networkInfo({}), listenPort(port), diff --git a/ldn_mitm/source/ldn_icommunication.cpp b/ldn_mitm/source/ldn_icommunication.cpp index 954df01..f280837 100644 --- a/ldn_mitm/source/ldn_icommunication.cpp +++ b/ldn_mitm/source/ldn_icommunication.cpp @@ -11,7 +11,8 @@ namespace ams::mitm::ldn { LogFormat("ICommunicationInterface::Initialize pid: %" PRIu64, client_process_id); if (this->state_event == nullptr) { - this->state_event = new os::SystemEvent(true); + // ClearMode, inter_process + this->state_event = new os::SystemEvent(ams::os::EventClearMode_AutoClear, true); } R_TRY(lanDiscovery.initialize([&](){ @@ -30,7 +31,6 @@ namespace ams::mitm::ldn { Result ICommunicationInterface::Finalize() { Result rc = lanDiscovery.finalize(); if (this->state_event) { - this->state_event->Finalize(); delete this->state_event; this->state_event = nullptr; }