]> Chaos Git - corbenik/ctrulib.git/commitdiff
fix thread static buffers usage (save+restore)
authorLectem <lectem@gmail.com>
Sun, 10 Jan 2016 18:06:32 +0000 (13:06 -0500)
committerLectem <lectem@gmail.com>
Sun, 10 Jan 2016 18:41:28 +0000 (13:41 -0500)
libctru/source/services/apt.c
libctru/source/services/dsp.c
libctru/source/services/soc/soc_accept.c
libctru/source/services/soc/soc_gethostbyname.c
libctru/source/services/soc/soc_getpeername.c
libctru/source/services/soc/soc_getsockname.c
libctru/source/services/soc/soc_getsockopt.c
libctru/source/services/soc/soc_poll.c
libctru/source/services/soc/soc_recvfrom.c

index ab3a17befd8ca5754986d341d8e3d80ea0741306..21ed31e051da0540730ce3306fb224900e15d0e1 100644 (file)
@@ -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];
index 1a66441c0afa4b807823245e43e708467f90b2f8..0a8aba662840e592c085453b355ab63a1db18990 100644 (file)
@@ -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];
index a5a39e304ca1375d405d2ac0c16e916de0492f76..2c62040ee863f7684a2e0f3c483fb15a34083fde 100644 (file)
@@ -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]);
index 50c44aa88f60cd4beabac62c7494c06afd9ae075..43c436e5ff9dfeb1f0eb7a9dba8fed343e11f1cd 100644 (file)
@@ -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]);
index b0aedab1b1fdf6201fa53b9fe175fd6b3b36c221..11f3d60815e98728a71b9a51031cdc648bace507 100644 (file)
@@ -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]);
index 9b9f0c39debab8618b2cf3a1d5726372d0fd2afb..8a2b3c5eb098bab3350da1a2a6111ad87bf88c01 100644 (file)
@@ -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]);
index 52d0f6e785b7796c2c9801444be6d901ce6d9200..d2409c69b0476ee1d508476c711c56fe94200d04 100644 (file)
@@ -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]);
index 2d6f3bca649f414815c15b81af44684e2ed3226b..a458e69f7c66e46febea535a810e0dbb29aca124 100644 (file)
@@ -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]);
index 03365f452244118d9b674fc7d809a250b9538a04..207df99907974420338ed5107682c3a16ed3ca29 100644 (file)
@@ -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]);