From 2cb979ed294aed2c6c8c4b1a971818475c8fb8b3 Mon Sep 17 00:00:00 2001 From: Nguyen Dac Nam Date: Tue, 21 Aug 2018 13:38:14 +0700 Subject: [PATCH 1/5] add header RecvFromOther --- src/core/hle/service/soc_u.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/hle/service/soc_u.h b/src/core/hle/service/soc_u.h index 9b12e5462..b1fa7751d 100644 --- a/src/core/hle/service/soc_u.h +++ b/src/core/hle/service/soc_u.h @@ -30,6 +30,7 @@ private: void GetHostId(Kernel::HLERequestContext& ctx); void Close(Kernel::HLERequestContext& ctx); void SendTo(Kernel::HLERequestContext& ctx); + void RecvFromOther(Kernel::HLERequestContext& ctx); void RecvFrom(Kernel::HLERequestContext& ctx); void Poll(Kernel::HLERequestContext& ctx); void GetSockName(Kernel::HLERequestContext& ctx); From c5eec5656dab8be94b1625bea3e79dfb0dc61870 Mon Sep 17 00:00:00 2001 From: Nguyen Dac Nam Date: Tue, 21 Aug 2018 13:40:11 +0700 Subject: [PATCH 2/5] add RecvFromOther cmd --- src/core/hle/service/soc_u.cpp | 39 +++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp index cfb1af110..f084a4a1f 100644 --- a/src/core/hle/service/soc_u.cpp +++ b/src/core/hle/service/soc_u.cpp @@ -565,6 +565,43 @@ void SOC_U::SendTo(Kernel::HLERequestContext& ctx) { rb.Push(ret); } +void SOC_U::RecvFromOther(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp(ctx, 0x7, 4, 4); + u32 socket_handle = rp.Pop(); + u32 len = rp.Pop(); + u32 flags = rp.Pop(); + u32 addr_len = rp.Pop(); + rp.PopPID(); + auto& buffer = rp.PopMappedBuffer(); + + CTRSockAddr ctr_src_addr; + std::vector output_buff(len); + std::vector addr_buff(sizeof(ctr_src_addr)); + sockaddr src_addr; + socklen_t src_addr_len = sizeof(src_addr); + s32 ret = ::recvfrom(socket_handle, reinterpret_cast(output_buff.data()), len, flags, + &src_addr, &src_addr_len); + + if (ret >= 0 && src_addr_len > 0) { + ctr_src_addr = CTRSockAddr::FromPlatform(src_addr); + std::memcpy(addr_buff.data(), &ctr_src_addr, sizeof(ctr_src_addr)); + } else { + addr_buff.resize(0); + } + + if (ret == SOCKET_ERROR_VALUE) { + ret = TranslateError(GET_ERRNO); + } else { + buffer.Write(output_buff.data(), 0, ret); + } + + IPC::RequestBuilder rb = rp.MakeBuilder(2, 4); + rb.Push(RESULT_SUCCESS); + rb.Push(ret); + rb.PushStaticBuffer(addr_buff, 1); + rb.PushMappedBuffer(buffer); +} + void SOC_U::RecvFrom(Kernel::HLERequestContext& ctx) { // TODO(Subv): Calling this function on a blocking socket will block the emu thread, // preventing graceful shutdown when closing the emulator, this can be fixed by always @@ -816,7 +853,7 @@ SOC_U::SOC_U() : ServiceFramework("soc:U") { {0x00040082, &SOC_U::Accept, "Accept"}, {0x00050084, &SOC_U::Bind, "Bind"}, {0x00060084, &SOC_U::Connect, "Connect"}, - {0x00070104, nullptr, "recvfrom_other"}, + {0x00070104, &SOC_U::RecvFromOther, "recvfrom_other"}, {0x00080102, &SOC_U::RecvFrom, "RecvFrom"}, {0x00090106, nullptr, "sendto_other"}, {0x000A0106, &SOC_U::SendTo, "SendTo"}, From 8d98a387ac570c7f3ee77f8659e13bc12e33ed50 Mon Sep 17 00:00:00 2001 From: Nguyen Dac Nam Date: Tue, 21 Aug 2018 21:39:45 +0700 Subject: [PATCH 3/5] only get src_adr if input_adr available --- src/core/hle/service/soc_u.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp index f084a4a1f..30b19c254 100644 --- a/src/core/hle/service/soc_u.cpp +++ b/src/core/hle/service/soc_u.cpp @@ -579,13 +579,18 @@ void SOC_U::RecvFromOther(Kernel::HLERequestContext& ctx) { std::vector addr_buff(sizeof(ctr_src_addr)); sockaddr src_addr; socklen_t src_addr_len = sizeof(src_addr); - s32 ret = ::recvfrom(socket_handle, reinterpret_cast(output_buff.data()), len, flags, + + s32 ret = -1; + if (addr_len > 0) { + ret = ::recvfrom(socket_handle, reinterpret_cast(output_buff.data()), len, flags, &src_addr, &src_addr_len); - - if (ret >= 0 && src_addr_len > 0) { - ctr_src_addr = CTRSockAddr::FromPlatform(src_addr); - std::memcpy(addr_buff.data(), &ctr_src_addr, sizeof(ctr_src_addr)); + if (ret >= 0 && src_addr_len > 0) { + ctr_src_addr = CTRSockAddr::FromPlatform(src_addr); + std::memcpy(addr_buff.data(), &ctr_src_addr, sizeof(ctr_src_addr)); + } } else { + ret = ::recvfrom(socket_handle, reinterpret_cast(output_buff.data()), len, flags, + NULL, 0); addr_buff.resize(0); } From 41f256f3cd5bd8a361e96aee38aed582c8582af3 Mon Sep 17 00:00:00 2001 From: Nguyen Dac Nam Date: Tue, 21 Aug 2018 22:22:50 +0700 Subject: [PATCH 4/5] fix clang-format --- src/core/hle/service/soc_u.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp index 30b19c254..bf9578d5d 100644 --- a/src/core/hle/service/soc_u.cpp +++ b/src/core/hle/service/soc_u.cpp @@ -579,7 +579,7 @@ void SOC_U::RecvFromOther(Kernel::HLERequestContext& ctx) { std::vector addr_buff(sizeof(ctr_src_addr)); sockaddr src_addr; socklen_t src_addr_len = sizeof(src_addr); - + s32 ret = -1; if (addr_len > 0) { ret = ::recvfrom(socket_handle, reinterpret_cast(output_buff.data()), len, flags, From a8af14ad124b075420d1a862b594f9fe69fd3be7 Mon Sep 17 00:00:00 2001 From: Nguyen Dac Nam Date: Tue, 4 Sep 2018 09:41:34 +0700 Subject: [PATCH 5/5] change buffer index from 1 to 0. --- src/core/hle/service/soc_u.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp index bf9578d5d..663597f1f 100644 --- a/src/core/hle/service/soc_u.cpp +++ b/src/core/hle/service/soc_u.cpp @@ -603,7 +603,7 @@ void SOC_U::RecvFromOther(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb = rp.MakeBuilder(2, 4); rb.Push(RESULT_SUCCESS); rb.Push(ret); - rb.PushStaticBuffer(addr_buff, 1); + rb.PushStaticBuffer(addr_buff, 0); rb.PushMappedBuffer(buffer); }