os_result os_threadProtect(void) { os_result result; os_threadProtectInfo *pi; pi = os_threadMemGet(OS_THREAD_PROTECT); if (pi == NULL) { pi = os_threadMemMalloc(OS_THREAD_PROTECT, sizeof(os_threadProtectInfo), NULL, NULL); if (pi) { pi->protectCount = 1; result = os_resultSuccess; } else { result = os_resultFail; } } else { pi->protectCount++; result = os_resultSuccess; } #ifndef INTEGRITY if ((result == os_resultSuccess) && (pi->protectCount == 1)) { if (pthread_sigmask(SIG_SETMASK, &os_threadBlockAllMask, &pi->oldMask) != 0) { result = os_resultFail; } } #endif return result; }
void DJA_UtilityBridge_us_doThreadAttach( DLRL_Exception* exception, void* userData) { JavaVM *jvm; JNIEnv *env = NULL; void* threadData; jint jresult; DLRL_INFO(INF_ENTER); assert(exception); assert(userData); jvm = (JavaVM*)userData; jresult = (*jvm)->AttachCurrentThread(jvm, (void**)&env, NULL); if(jresult != 0){ DLRL_Exception_THROW(exception, DLRL_OUT_OF_MEMORY, "Unable to complete operation. Out of resources."); } threadData = os_threadMemMalloc(OS_THREAD_JVM, sizeof(env)); *(JNIEnv**)threadData = env; DLRL_Exception_EXIT(exception); DLRL_INFO(INF_EXIT); }
static void os_reportSetApiInfoRec( const char *reportContext, const char *sourceLine, const char *callStack, os_int32 reportCode, const char *description, va_list args) { os_reportInfo *report; char * descriptionCopy = NULL; /* since description may point to report->description*/ if (description) { descriptionCopy = os_strdup(description); } report = (os_reportInfo *)os_threadMemGet(OS_THREAD_API_INFO); if (report == NULL) { report = (os_reportInfo *)os_threadMemMalloc(OS_THREAD_API_INFO, sizeof(os_reportInfo)); if (report) memset(report, 0, sizeof(os_reportInfo)); } if (report) { if (report->reportContext) { os_free(report->reportContext); report->reportContext = NULL; } if (reportContext) { report->reportContext = os_strdup(reportContext); } if (report->sourceLine) { os_free(report->sourceLine); report->sourceLine = NULL; } if (sourceLine) { report->sourceLine = os_strdup(sourceLine); } if (report->callStack) { os_free(report->callStack); report->callStack = NULL; } if (callStack) { report->callStack = os_strdup(callStack); } report->reportCode = reportCode; if (report->description) { os_free(report->description); report->description = NULL; } if (descriptionCopy) { report->description = (char*) os_malloc(OS_MAX_DESCRIPTIONSIZE); if (report->description) { os_vsnprintf(report->description, OS_MAX_DESCRIPTIONSIZE-1, descriptionCopy, args); } } } os_free(descriptionCopy); }
void saj_listenerAttach( void* listener_data) { JavaVM *jvm; JNIEnv *env; void* threadData; jint jresult; jvm = (JavaVM*)listener_data; jresult = (*jvm)->AttachCurrentThread(jvm, (void**)&env, NULL); assert(jresult == 0); threadData = os_threadMemMalloc(OS_THREAD_JVM, sizeof(env)); *(JNIEnv**)threadData = env; }
c_bool saj_setThreadEnv( JNIEnv *env) { void *threadData; c_bool result; threadData = os_threadMemGet(OS_THREAD_JVM); if (threadData) { *(JNIEnv**)threadData = env; result = FALSE; } else { threadData = os_threadMemMalloc(OS_THREAD_JVM, sizeof(env)); if (threadData) { *(JNIEnv**)threadData = env; result = TRUE; } else { result = FALSE; assert(0); } } return result; }