Merge pull request #241 from Lectem/TLSfix
fix thread static buffers usage (save+restore)
This commit is contained in:
commit
a75c01c302
@ -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)
|
Result APT_AppletUtility(u32* out, u32 a, u32 size1, u8* buf1, u32 size2, u8* buf2)
|
||||||
{
|
{
|
||||||
|
u32 saved_threadstorage[2];
|
||||||
|
|
||||||
u32* cmdbuf=getThreadCommandBuffer();
|
u32* cmdbuf=getThreadCommandBuffer();
|
||||||
cmdbuf[0]=IPC_MakeHeader(0x4B,3,2); // 0x4B00C2
|
cmdbuf[0]=IPC_MakeHeader(0x4B,3,2); // 0x4B00C2
|
||||||
cmdbuf[1]=a;
|
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;
|
cmdbuf[5]=(u32)buf1;
|
||||||
|
|
||||||
u32 *staticbufs = getThreadStaticBuffers();
|
u32 *staticbufs = getThreadStaticBuffers();
|
||||||
|
saved_threadstorage[0]=staticbufs[0];
|
||||||
|
saved_threadstorage[1]=staticbufs[1];
|
||||||
|
|
||||||
staticbufs[0]=IPC_Desc_StaticBuffer(size2,0);
|
staticbufs[0]=IPC_Desc_StaticBuffer(size2,0);
|
||||||
staticbufs[1]=(u32)buf2;
|
staticbufs[1]=(u32)buf2;
|
||||||
|
|
||||||
Result ret=0;
|
Result ret=svcSendSyncRequest(aptuHandle);
|
||||||
if(R_FAILED(ret=svcSendSyncRequest(aptuHandle)))return ret;
|
|
||||||
|
staticbufs[0]=saved_threadstorage[0];
|
||||||
|
staticbufs[1]=saved_threadstorage[1];
|
||||||
|
|
||||||
|
if(R_FAILED(ret))return ret;
|
||||||
|
|
||||||
if(out)*out=cmdbuf[2];
|
if(out)*out=cmdbuf[2];
|
||||||
|
|
||||||
return cmdbuf[1];
|
return cmdbuf[1];
|
||||||
|
@ -148,11 +148,13 @@ Result DSP_ReadPipeIfPossible(u32 channel, u32 peer, void* buffer, u16 length, u
|
|||||||
staticbufs[0] = IPC_Desc_StaticBuffer(length,0);
|
staticbufs[0] = IPC_Desc_StaticBuffer(length,0);
|
||||||
staticbufs[1] = (u32)buffer;
|
staticbufs[1] = (u32)buffer;
|
||||||
|
|
||||||
if (R_FAILED(ret = svcSendSyncRequest(dspHandle))) return ret;
|
ret = svcSendSyncRequest(dspHandle);
|
||||||
|
|
||||||
staticbufs[0] = saved1;
|
staticbufs[0] = saved1;
|
||||||
staticbufs[1] = saved2;
|
staticbufs[1] = saved2;
|
||||||
|
|
||||||
|
if (R_FAILED(ret)) return ret;
|
||||||
|
|
||||||
if (length_read)
|
if (length_read)
|
||||||
*length_read = cmdbuf[2] & 0xFFFF;
|
*length_read = cmdbuf[2] & 0xFFFF;
|
||||||
return cmdbuf[1];
|
return cmdbuf[1];
|
||||||
|
@ -50,15 +50,16 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
|||||||
staticbufs[1] = (u32)tmpaddr;
|
staticbufs[1] = (u32)tmpaddr;
|
||||||
|
|
||||||
ret = svcSendSyncRequest(SOCU_handle);
|
ret = svcSendSyncRequest(SOCU_handle);
|
||||||
|
|
||||||
|
staticbufs[0] = saved_threadstorage[0];
|
||||||
|
staticbufs[1] = saved_threadstorage[1];
|
||||||
|
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
__release_handle(fd);
|
__release_handle(fd);
|
||||||
errno = SYNC_ERROR;
|
errno = SYNC_ERROR;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
staticbufs[0] = saved_threadstorage[0];
|
|
||||||
staticbufs[1] = saved_threadstorage[1];
|
|
||||||
|
|
||||||
ret = (int)cmdbuf[1];
|
ret = (int)cmdbuf[1];
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
ret = _net_convert_error(cmdbuf[2]);
|
ret = _net_convert_error(cmdbuf[2]);
|
||||||
|
@ -30,14 +30,15 @@ struct hostent* gethostbyname(const char *name)
|
|||||||
staticbufs[1] = (u32)outbuf;
|
staticbufs[1] = (u32)outbuf;
|
||||||
|
|
||||||
ret = svcSendSyncRequest(SOCU_handle);
|
ret = svcSendSyncRequest(SOCU_handle);
|
||||||
|
|
||||||
|
staticbufs[0] = saved_threadstorage[0];
|
||||||
|
staticbufs[1] = saved_threadstorage[1];
|
||||||
|
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
h_errno = NO_RECOVERY;
|
h_errno = NO_RECOVERY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
staticbufs[0] = saved_threadstorage[0];
|
|
||||||
staticbufs[1] = saved_threadstorage[1];
|
|
||||||
|
|
||||||
ret = (int)cmdbuf[1];
|
ret = (int)cmdbuf[1];
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
ret = _net_convert_error(cmdbuf[2]);
|
ret = _net_convert_error(cmdbuf[2]);
|
||||||
|
@ -29,14 +29,15 @@ int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
|||||||
staticbufs[1] = (u32)tmpaddr;
|
staticbufs[1] = (u32)tmpaddr;
|
||||||
|
|
||||||
ret = svcSendSyncRequest(SOCU_handle);
|
ret = svcSendSyncRequest(SOCU_handle);
|
||||||
|
|
||||||
|
staticbufs[0] = saved_threadstorage[0];
|
||||||
|
staticbufs[1] = saved_threadstorage[1];
|
||||||
|
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
errno = SYNC_ERROR;
|
errno = SYNC_ERROR;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
staticbufs[0] = saved_threadstorage[0];
|
|
||||||
staticbufs[1] = saved_threadstorage[1];
|
|
||||||
|
|
||||||
ret = (int)cmdbuf[1];
|
ret = (int)cmdbuf[1];
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
ret = _net_convert_error(cmdbuf[2]);
|
ret = _net_convert_error(cmdbuf[2]);
|
||||||
|
@ -29,14 +29,15 @@ int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
|||||||
staticbufs[1] = (u32)tmpaddr;
|
staticbufs[1] = (u32)tmpaddr;
|
||||||
|
|
||||||
ret = svcSendSyncRequest(SOCU_handle);
|
ret = svcSendSyncRequest(SOCU_handle);
|
||||||
|
|
||||||
|
staticbufs[0] = saved_threadstorage[0];
|
||||||
|
staticbufs[1] = saved_threadstorage[1];
|
||||||
|
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
errno = SYNC_ERROR;
|
errno = SYNC_ERROR;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
staticbufs[0] = saved_threadstorage[0];
|
|
||||||
staticbufs[1] = saved_threadstorage[1];
|
|
||||||
|
|
||||||
ret = (int)cmdbuf[1];
|
ret = (int)cmdbuf[1];
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
ret = _net_convert_error(cmdbuf[2]);
|
ret = _net_convert_error(cmdbuf[2]);
|
||||||
|
@ -30,14 +30,15 @@ int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optl
|
|||||||
staticbufs[1] = (u32)optval;
|
staticbufs[1] = (u32)optval;
|
||||||
|
|
||||||
ret = svcSendSyncRequest(SOCU_handle);
|
ret = svcSendSyncRequest(SOCU_handle);
|
||||||
|
|
||||||
|
staticbufs[0] = saved_threadstorage[0];
|
||||||
|
staticbufs[1] = saved_threadstorage[1];
|
||||||
|
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
errno = SYNC_ERROR;
|
errno = SYNC_ERROR;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
staticbufs[0] = saved_threadstorage[0];
|
|
||||||
staticbufs[1] = saved_threadstorage[1];
|
|
||||||
|
|
||||||
ret = (int)cmdbuf[1];
|
ret = (int)cmdbuf[1];
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
ret = _net_convert_error(cmdbuf[2]);
|
ret = _net_convert_error(cmdbuf[2]);
|
||||||
|
@ -51,15 +51,16 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
|||||||
staticbufs[1] = (u32)tmp_fds;
|
staticbufs[1] = (u32)tmp_fds;
|
||||||
|
|
||||||
ret = svcSendSyncRequest(SOCU_handle);
|
ret = svcSendSyncRequest(SOCU_handle);
|
||||||
|
|
||||||
|
staticbufs[0] = saved_threadstorage[0];
|
||||||
|
staticbufs[1] = saved_threadstorage[1];
|
||||||
|
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
free(tmp_fds);
|
free(tmp_fds);
|
||||||
errno = SYNC_ERROR;
|
errno = SYNC_ERROR;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
staticbufs[0] = saved_threadstorage[0];
|
|
||||||
staticbufs[1] = saved_threadstorage[1];
|
|
||||||
|
|
||||||
ret = (int)cmdbuf[1];
|
ret = (int)cmdbuf[1];
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
ret = _net_convert_error(cmdbuf[2]);
|
ret = _net_convert_error(cmdbuf[2]);
|
||||||
|
@ -33,14 +33,15 @@ ssize_t socuipc_cmd7(int sockfd, void *buf, size_t len, int flags, struct sockad
|
|||||||
staticbufs[1] = (u32)tmpaddr;
|
staticbufs[1] = (u32)tmpaddr;
|
||||||
|
|
||||||
ret = svcSendSyncRequest(SOCU_handle);
|
ret = svcSendSyncRequest(SOCU_handle);
|
||||||
|
|
||||||
|
staticbufs[0] = saved_threadstorage[0];
|
||||||
|
staticbufs[1] = saved_threadstorage[1];
|
||||||
|
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
errno = SYNC_ERROR;
|
errno = SYNC_ERROR;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
staticbufs[0] = saved_threadstorage[0];
|
|
||||||
staticbufs[1] = saved_threadstorage[1];
|
|
||||||
|
|
||||||
ret = (int)cmdbuf[1];
|
ret = (int)cmdbuf[1];
|
||||||
if(ret == 0)
|
if(ret == 0)
|
||||||
ret = _net_convert_error(cmdbuf[2]);
|
ret = _net_convert_error(cmdbuf[2]);
|
||||||
|
Loading…
Reference in New Issue
Block a user