Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions src/libpthreadglue/osal.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ pte_osResult pte_osThreadCreate(pte_osThreadEntryPoint entryPoint,
int pspAttr;
void *pTls;
SceUID threadId;
pte_osResult result;
pspThreadData *pThreadData;

if (threadNum++ > MAX_PSP_UID) {
Expand All @@ -215,8 +214,7 @@ pte_osResult pte_osThreadCreate(pte_osThreadEntryPoint entryPoint,
pTls = pteTlsThreadInit();
if (pTls == NULL) {
PSP_DEBUG("pteTlsThreadInit: PTE_OS_NO_RESOURCES\n");
result = PTE_OS_NO_RESOURCES;
goto FAIL0;
return PTE_OS_NO_RESOURCES;
}

/* Allocate some memory for our per-thread control data. We use this for:
Expand All @@ -227,10 +225,8 @@ pte_osResult pte_osThreadCreate(pte_osThreadEntryPoint entryPoint,

if (pThreadData == NULL) {
pteTlsThreadDestroy(pTls);

PSP_DEBUG("malloc(pspThreadData): PTE_OS_NO_RESOURCES\n");
result = PTE_OS_NO_RESOURCES;
goto FAIL0;
return PTE_OS_NO_RESOURCES;
}

/* Save a pointer to our per-thread control data as a TLS value */
Expand All @@ -248,6 +244,12 @@ pte_osResult pte_osThreadCreate(pte_osThreadEntryPoint entryPoint,
255, /* maximum value */
0); /* options (default) */

if (pThreadData->cancelSem < 0) {
free(pThreadData);
pteTlsThreadDestroy(pTls);
PSP_DEBUG("sceKernelCreateSema(cancelSem): PTE_OS_NO_RESOURCES\n");
return PTE_OS_NO_RESOURCES;
}

/* In order to emulate TLS functionality, we append the address of the TLS structure that we
* allocated above to the thread's name. To set or get TLS values for this thread, the user
Expand All @@ -267,24 +269,23 @@ pte_osResult pte_osThreadCreate(pte_osThreadEntryPoint entryPoint,
NULL);

if (threadId == (SceUID) SCE_KERNEL_ERROR_NO_MEMORY) {
sceKernelDeleteSema(pThreadData->cancelSem);
free(pThreadData);
pteTlsThreadDestroy(pTls);

PSP_DEBUG("sceKernelCreateThread: PTE_OS_NO_RESOURCES\n");
result = PTE_OS_NO_RESOURCES;
} else if (threadId < 0) {
return PTE_OS_NO_RESOURCES;
}

if (threadId < 0) {
sceKernelDeleteSema(pThreadData->cancelSem);
free(pThreadData);
pteTlsThreadDestroy(pTls);

PSP_DEBUG("sceKernelCreateThread: PTE_OS_GENERAL_FAILURE\n");
result = PTE_OS_GENERAL_FAILURE;
} else {
*ppte_osThreadHandle = threadId;
result = PTE_OS_OK;
return PTE_OS_GENERAL_FAILURE;
}

FAIL0:
return result;
*ppte_osThreadHandle = threadId;
return PTE_OS_OK;
}
#endif

Expand Down Expand Up @@ -529,6 +530,10 @@ pte_osResult pte_osMutexCreate(pte_osMutexHandle *pHandle)
1, /* maximum value */
0); /* options (default) */

if (handle < 0) {
return PTE_OS_NO_RESOURCES;
}

*pHandle = handle;
return PTE_OS_OK;
}
Expand Down Expand Up @@ -601,6 +606,10 @@ pte_osResult pte_osSemaphoreCreate(int initialValue, pte_osSemaphoreHandle *pHan
SEM_VALUE_MAX, /* maximum value */
0); /* options (default) */

if (handle < 0) {
return PTE_OS_NO_RESOURCES;
}

*pHandle = handle;
return PTE_OS_OK;
}
Expand Down
Loading