diff --git a/libctru/source/services/apt.c b/libctru/source/services/apt.c index ab3a17b..21ed31e 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -940,6 +940,8 @@ Result APT_NotifyToWait(NS_APPID appID) Result APT_AppletUtility(u32* out, u32 a, u32 size1, u8* buf1, u32 size2, u8* buf2) { + u32 saved_threadstorage[2]; + u32* cmdbuf=getThreadCommandBuffer(); cmdbuf[0]=IPC_MakeHeader(0x4B,3,2); // 0x4B00C2 cmdbuf[1]=a; @@ -949,12 +951,19 @@ Result APT_AppletUtility(u32* out, u32 a, u32 size1, u8* buf1, u32 size2, u8* bu cmdbuf[5]=(u32)buf1; u32 *staticbufs = getThreadStaticBuffers(); + saved_threadstorage[0]=staticbufs[0]; + saved_threadstorage[1]=staticbufs[1]; + staticbufs[0]=IPC_Desc_StaticBuffer(size2,0); staticbufs[1]=(u32)buf2; - Result ret=0; - if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret; - + Result ret=svcSendSyncRequest(aptuHandle); + + staticbufs[0]=saved_threadstorage[0]; + staticbufs[1]=saved_threadstorage[1]; + + if(R_FAILED(ret))return ret; + if(out)*out=cmdbuf[2]; return cmdbuf[1]; diff --git a/libctru/source/services/dsp.c b/libctru/source/services/dsp.c index 1a66441..0a8aba6 100644 --- a/libctru/source/services/dsp.c +++ b/libctru/source/services/dsp.c @@ -148,11 +148,13 @@ Result DSP_ReadPipeIfPossible(u32 channel, u32 peer, void* buffer, u16 length, u staticbufs[0] = IPC_Desc_StaticBuffer(length,0); staticbufs[1] = (u32)buffer; - if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret; + ret = svcSendSyncRequest(dspHandle); staticbufs[0] = saved1; staticbufs[1] = saved2; - + + if (R_FAILED(ret)) return ret; + if (length_read) *length_read = cmdbuf[2] & 0xFFFF; return cmdbuf[1]; diff --git a/libctru/source/services/soc/soc_accept.c b/libctru/source/services/soc/soc_accept.c index a5a39e3..2c62040 100644 --- a/libctru/source/services/soc/soc_accept.c +++ b/libctru/source/services/soc/soc_accept.c @@ -50,15 +50,16 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) staticbufs[1] = (u32)tmpaddr; ret = svcSendSyncRequest(SOCU_handle); + + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; + if(ret != 0) { __release_handle(fd); errno = SYNC_ERROR; return ret; } - staticbufs[0] = saved_threadstorage[0]; - staticbufs[1] = saved_threadstorage[1]; - ret = (int)cmdbuf[1]; if(ret == 0) ret = _net_convert_error(cmdbuf[2]); diff --git a/libctru/source/services/soc/soc_gethostbyname.c b/libctru/source/services/soc/soc_gethostbyname.c index 50c44aa..43c436e 100644 --- a/libctru/source/services/soc/soc_gethostbyname.c +++ b/libctru/source/services/soc/soc_gethostbyname.c @@ -30,14 +30,15 @@ struct hostent* gethostbyname(const char *name) staticbufs[1] = (u32)outbuf; ret = svcSendSyncRequest(SOCU_handle); + + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; + if(ret != 0) { h_errno = NO_RECOVERY; return NULL; } - staticbufs[0] = saved_threadstorage[0]; - staticbufs[1] = saved_threadstorage[1]; - ret = (int)cmdbuf[1]; if(ret == 0) ret = _net_convert_error(cmdbuf[2]); diff --git a/libctru/source/services/soc/soc_getpeername.c b/libctru/source/services/soc/soc_getpeername.c index b0aedab..11f3d60 100644 --- a/libctru/source/services/soc/soc_getpeername.c +++ b/libctru/source/services/soc/soc_getpeername.c @@ -29,14 +29,15 @@ int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen) staticbufs[1] = (u32)tmpaddr; ret = svcSendSyncRequest(SOCU_handle); + + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; + if(ret != 0) { errno = SYNC_ERROR; return ret; } - staticbufs[0] = saved_threadstorage[0]; - staticbufs[1] = saved_threadstorage[1]; - ret = (int)cmdbuf[1]; if(ret == 0) ret = _net_convert_error(cmdbuf[2]); diff --git a/libctru/source/services/soc/soc_getsockname.c b/libctru/source/services/soc/soc_getsockname.c index 9b9f0c3..8a2b3c5 100644 --- a/libctru/source/services/soc/soc_getsockname.c +++ b/libctru/source/services/soc/soc_getsockname.c @@ -29,14 +29,15 @@ int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen) staticbufs[1] = (u32)tmpaddr; ret = svcSendSyncRequest(SOCU_handle); + + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; + if(ret != 0) { errno = SYNC_ERROR; return ret; } - staticbufs[0] = saved_threadstorage[0]; - staticbufs[1] = saved_threadstorage[1]; - ret = (int)cmdbuf[1]; if(ret == 0) ret = _net_convert_error(cmdbuf[2]); diff --git a/libctru/source/services/soc/soc_getsockopt.c b/libctru/source/services/soc/soc_getsockopt.c index 52d0f6e..d2409c6 100644 --- a/libctru/source/services/soc/soc_getsockopt.c +++ b/libctru/source/services/soc/soc_getsockopt.c @@ -30,14 +30,15 @@ int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optl staticbufs[1] = (u32)optval; ret = svcSendSyncRequest(SOCU_handle); + + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; + if(ret != 0) { errno = SYNC_ERROR; return ret; } - staticbufs[0] = saved_threadstorage[0]; - staticbufs[1] = saved_threadstorage[1]; - ret = (int)cmdbuf[1]; if(ret == 0) ret = _net_convert_error(cmdbuf[2]); diff --git a/libctru/source/services/soc/soc_poll.c b/libctru/source/services/soc/soc_poll.c index 2d6f3bc..a458e69 100644 --- a/libctru/source/services/soc/soc_poll.c +++ b/libctru/source/services/soc/soc_poll.c @@ -51,15 +51,16 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) staticbufs[1] = (u32)tmp_fds; ret = svcSendSyncRequest(SOCU_handle); + + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; + if(ret != 0) { free(tmp_fds); errno = SYNC_ERROR; return ret; } - staticbufs[0] = saved_threadstorage[0]; - staticbufs[1] = saved_threadstorage[1]; - ret = (int)cmdbuf[1]; if(ret == 0) ret = _net_convert_error(cmdbuf[2]); diff --git a/libctru/source/services/soc/soc_recvfrom.c b/libctru/source/services/soc/soc_recvfrom.c index 03365f4..207df99 100644 --- a/libctru/source/services/soc/soc_recvfrom.c +++ b/libctru/source/services/soc/soc_recvfrom.c @@ -33,14 +33,15 @@ ssize_t socuipc_cmd7(int sockfd, void *buf, size_t len, int flags, struct sockad staticbufs[1] = (u32)tmpaddr; ret = svcSendSyncRequest(SOCU_handle); + + staticbufs[0] = saved_threadstorage[0]; + staticbufs[1] = saved_threadstorage[1]; + if(ret != 0) { errno = SYNC_ERROR; return -1; } - staticbufs[0] = saved_threadstorage[0]; - staticbufs[1] = saved_threadstorage[1]; - ret = (int)cmdbuf[1]; if(ret == 0) ret = _net_convert_error(cmdbuf[2]);