Merge pull request #241 from Lectem/TLSfix

fix thread static buffers usage (save+restore)
This commit is contained in:
fincs 2016-01-12 20:36:05 +01:00
commit a75c01c302
9 changed files with 44 additions and 26 deletions

View 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];

View 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];

View 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]);

View 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]);

View 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]);

View 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]);

View 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]);

View 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]);

View 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]);