os_iter os_iterAppend( os_iter iter, void *object) { os_iterNode n; if (iter == NULL) return os_iterNew(object); if (object == NULL) { return iter; } n = (os_iterNode)os_malloc(OS_SIZEOF(os_iterNode)); n->object = object; n->next = NULL; if(iter->tail){ iter->tail->next = n; iter->tail = n; } else { iter->head = n; iter->tail = n; } iter->length++; return iter; }
ut_fileOut ut_fileOutNew( const os_char *name, const os_char *mode) { ut_fileOut stream; os_char *fname; os_char * filename; stream = os_malloc((size_t)OS_SIZEOF(ut_fileOut)); if (ut_outputdir) { fname = os_malloc(strlen(ut_outputdir) + strlen(os_fileSep()) + strlen(name) + 1); os_sprintf(fname, "%s%s%s", ut_outputdir, os_fileSep(), name); } else { fname = os_strdup(name); } filename = os_fileNormalize(fname); stream->file = fopen(filename, mode); os_free(fname); os_free(filename); if (stream->file == NULL) { os_free(stream); stream = NULL; } return stream; }
/* Initialize for programs not started with os_procCreate*/ void os_procInitialize() { os_procContextData process_procContextData; os_int32 status = os_resultSuccess; os_int32 taskid; if ( readTLSVarSelf(procContextData) == NULL) { taskid = taskIdSelf(); process_procContextData = (os_procContextData )os_malloc((size_t)OS_SIZEOF(os_procContextData)); if (process_procContextData == (os_procContextData) NULL) { OS_REPORT(OS_WARNING, "os_procCreate", 1, "malloc failed with error %d (%s)", os_getErrno(), taskName(taskIdSelf())); } else { os_procInit(process_procContextData, taskName((int)taskid), "program" , "none"); os_procSetTaskId(process_procContextData, (int)taskid); process_procContextData->procAttrPrio = VXWORKS_PRIORITY_DEFAULT; /* create & set context variable for the task */ status = os_procAddTaskVar((int)taskid, "none", process_procContextData, 0); if (status == os_resultSuccess) { status = os_threadNew(process_procContextData->procName); } else { printf("os_procApplAddContext os_threadNew ERROR\n"); } process_procContextData->procStartWithProcCreate = 1; /* not started with procCreate*/ } } }
/** \brief constructor */ in_transportReceiverIBasic in_transportReceiverIBasicNew(in_configChannel config) { os_boolean supportsControl = in_configChannelSupportsControl(config); in_transportReceiverIBasic result = (in_transportReceiverIBasic) os_malloc(OS_SIZEOF(in_transportReceiverIBasic)); in_socket sock = in_socketReceiveNew( config, supportsControl); if (!result || !sock) { if (result) { os_free(result); } if (sock) { in_socketFree(sock); } } else { if (!in_transportReceiverIBasicInit(result, config, sock)) { os_free(result); result = NULL; } /* decrement refcount */ in_socketFree(sock); } IN_TRACE_1(Construction,2,"in_transportReceiverIBasic created = %x",result); return result; }
/** \brief constructor */ in_transportReceiverIBasic in_transportReceiverIBasicNewDuplex( in_configChannel config, in_socket duplexSocket) { in_transportReceiverIBasic result = (in_transportReceiverIBasic) os_malloc(OS_SIZEOF(in_transportReceiverIBasic)); assert(duplexSocket); if (result) { if (!in_transportReceiverIBasicInit( result, config, duplexSocket)) { os_free(result); result = NULL; } } IN_TRACE_1(Construction,2,"in_transportReceiverIBasic created = %x",result); return result; }
ut_tmplExp ut_tmplExpNew ( const ut_macroSet macroSet) { ut_tmplExp tmplExp = os_malloc((size_t)OS_SIZEOF(ut_tmplExp)); tmplExp->macroSet = macroSet; return tmplExp; }
ut_macroSet ut_macroSetNew( void) { ut_macroSet macroSet = os_malloc((size_t)OS_SIZEOF(ut_macroSet)); macroSet->macroSet = os_iterNew(NULL); return macroSet; }
ut_streamOut ut_streamOutNew ( os_uint32 max_length) { ut_streamOut stream; stream = os_malloc((size_t)OS_SIZEOF(ut_streamOut)); ut_streamInit(ut_stream(stream), ""); stream->max_length = max_length; return stream; }
ut_macro ut_macroNew ( const os_char *name, const os_char *value) { ut_macro macro = os_malloc((size_t)OS_SIZEOF(ut_macro)); macro->name = os_strdup(name); macro->value = os_strdup(value); return macro; }
os_iter os_iterNew( void *object) { os_iter l; l = (os_iter)os_malloc(OS_SIZEOF(os_iter)); if (object == NULL) { l->length = 0; l->head = NULL; l->tail = NULL; } else { l->length = 1; l->head = (os_iterNode)os_malloc(OS_SIZEOF(os_iterNode)); l->head->next = NULL; l->head->object = object; l->tail = l->head; } return l; }
ut_macroAttrib ut_macroAttribNew( os_char startToken, os_char openToken, os_char closeToken) { ut_macroAttrib macroAttrib = os_malloc((size_t)OS_SIZEOF(ut_macroAttrib)); macroAttrib->startToken = startToken; macroAttrib->openToken = openToken; macroAttrib->closeToken = closeToken; return macroAttrib; }
ut_streamIn ut_streamInNew ( const os_char *stream_val, const ut_macroAttrib macroAttrib) { ut_streamIn stream; assert(stream_val); assert(macroAttrib); stream = os_malloc((size_t)OS_SIZEOF(ut_streamIn)); ut_streamInit(ut_stream(stream), stream_val); stream->macroAttrib = macroAttrib; return stream; }
/* *************************************************************************** * FUNCTION DECLARATIONS * ***************************************************************************/ static ut_tableNode ut_newTableNode( void *key, void *value) { ut_tableNode node; node = NULL; node = os_malloc((os_uint32)OS_SIZEOF(ut_tableNode)); assert(node); node->key = key; node->value = value; return node; }
void os_procDDSHook( WIND_TCB *pNewTcb) { os_procContextData process_procContextData; os_int32 status = os_resultSuccess; os_int32 taskid; os_int32 init_process = 0; if (getenv("SPLICE_NEW_PROCESS") != NULL) { if (strncmp(getenv("SPLICE_NEW_PROCESS"),"no",2) == 0) { init_process = 1; } } if (init_process == 1) { /* task Started with os_proCreate */ } else { if (readTLSVarSelf(procContextData) == NULL) { /* main thread */ taskid = (int)pNewTcb; process_procContextData = (os_procContextData )os_malloc((size_t)OS_SIZEOF(os_procContextData)); if (process_procContextData == (os_procContextData) NULL) { OS_REPORT(OS_WARNING, "os_procCreate", 1, "malloc failed with error %d (%s)", os_getErrno(), taskName(taskid)); } else { os_procInit(process_procContextData, taskName((int)taskid), "program" , "none"); os_procSetTaskId(process_procContextData, (int)taskid); process_procContextData->procAttrPrio = VXWORKS_PRIORITY_DEFAULT; /* create & set context variable for the task */ status = os_procAddTaskVar((int)taskid, "none", process_procContextData, 0); if (status == os_resultSuccess) { status = os_hookthreadNew(process_procContextData->procName, process_procContextData, taskid); } else { printf("os_procApplAddContext os_threadNew ERROR\n"); } /* process_procContextData->procStartWithProcCreate = 1; not started with procCreate*/ } } else { /* extra threads */ os_threadHookThreadInit(readTLSVarSelf(procContextData), pNewTcb); } } }
in_ddsiDiscoveredReaderData in_ddsiDiscoveredReaderDataNew(void) { os_boolean success; in_ddsiDiscoveredReaderData _this; _this = in_ddsiDiscoveredReaderData(os_malloc(OS_SIZEOF(in_ddsiDiscoveredReaderData))); if(_this) { success = in_ddsiDiscoveredReaderDataInit(_this); if(!success) { os_free(_this); _this = NULL; } } return _this; }
void os_procInit( os_procContextData process_procContextData, const char *name, const char *executable_file, const char *arguments) { bzero((char *)process_procContextData, (size_t)OS_SIZEOF(os_procContextData)); process_procContextData->procName = (char *)os_malloc(strlen(name) + 1); os_strncpy(process_procContextData->procName, name, strlen(name) + 1); os_procSetExitStatus(process_procContextData, -1); process_procContextData->procId = (os_int32)process_procContextData; os_procSetValidity(process_procContextData, proc_ValRunning); process_procContextData->procCallbackList = os_iterNew(NULL); process_procContextData->procThreadList = os_iterNew(NULL); process_procContextData->procDataSem = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE); process_procContextData->procGlobalVarList = os_iterNew(NULL); process_procContextData->arguments = (char *)os_malloc(strlen(arguments) + 1); os_strncpy(process_procContextData->arguments, arguments, strlen(arguments) + 1); process_procContextData->executable = (char *)os_malloc(strlen(executable_file) + 1); os_strncpy(process_procContextData->executable, executable_file, strlen(executable_file) + 1); }
ut_collection ut_tableNew( const ut_compareElementsFunc cmpFunc, void *arg) { ut_table table; ut_avlTree tree; table = NULL; tree = NULL; table = (ut_table)os_malloc((os_uint32)OS_SIZEOF(ut_table)); ut_collection(table)->type = UT_TABLE; ut_collection(table)->cmpFunc = cmpFunc; ut_collection(table)->args = arg; tree = ut_avlTreeNew(0); table->tree = tree; return ut_collection(table); }
os_result os_procCreate( const char *executable_file, const char *name, const char *arguments, os_procAttr *procAttr, os_procId *procId) { int procTaskId; int sched_policy; os_result rv = os_resultSuccess; os_procContextData process_procContextData; os_int32 startRoutine = 0; os_int32 pOptions,privateSet; os_int32 len,i=0,n=0; char *converted = NULL; assert(executable_file != NULL); assert(name != NULL); assert(arguments != NULL); assert(procAttr != NULL); assert(procId != NULL); len = strlen(arguments); converted = (char*)os_malloc(len+1); for (; i < len ; i++) { if (arguments[i] != '\"') { converted[n] = arguments[i]; n++; } } converted[n] = '\0'; pOptions = 0; privateSet = 0; taskOptionsGet(taskIdSelf(),&pOptions); if ((pOptions & VX_PRIVATE_ENV) == 0) { envPrivateCreate(taskIdSelf(), 0); privateSet = 1; } putenv("SPLICE_NEW_PROCESS=no"); if (procAttr->schedClass == OS_SCHED_REALTIME) { sched_policy = SCHED_FIFO; } else if (procAttr->schedClass == OS_SCHED_TIMESHARE) { return os_resultInvalid; } else if (procAttr->schedClass == OS_SCHED_DEFAULT) { sched_policy = SCHED_OTHER; } else { return os_resultInvalid; } if ((procAttr->schedPriority > VXWORKS_PRIORITY_MIN) || (procAttr->schedPriority < VXWORKS_PRIORITY_MAX) ) { return os_resultInvalid; } { os_library binlib; os_libraryAttr attr; os_libraryAttrInit(&attr); /* Dynamic load of services is a special case, so try just static via os_libraryOpen */ attr.staticLibOnly=1; binlib = os_libraryOpen( executable_file, &attr); /* FIXME existing use of os_int32 for pointer is CRAZY!! */ if ( binlib != NULL ) { startRoutine = (os_int32)os_libraryGetSymbol( binlib, executable_file ); } if ( startRoutine == 0 && os_dynamicLibPlugin != NULL ) { startRoutine = (os_uint32)os_dynamicLibPlugin->dlp_loadLib( executable_file ); } if ( startRoutine == 0 ) { OS_REPORT(OS_ERROR, "os_procCreate", 1, "Unable to load %s (%s)", executable_file, name); rv = os_resultInvalid; } } if (rv == os_resultSuccess) { process_procContextData = (os_procContextData )os_malloc((size_t)OS_SIZEOF(os_procContextData)); if (process_procContextData == (os_procContextData) NULL) { OS_REPORT(OS_WARNING, "os_procCreate", 1, "malloc failed with error %d (%s, %s)", os_getErrno(), executable_file, name); rv = os_resultInvalid; } else { #if defined ( _WRS_VXWORKS_MAJOR ) && ( _WRS_VXWORKS_MAJOR > 6 ) || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR > 8 ) /* the blockParent semaphore is used to prevent this task exiting before the spawned task has completed copying its environ. */ os_sem_t blockParent; os_sem_init( &blockParent, 0); #endif os_procInit(process_procContextData, name, executable_file, converted); process_procContextData->procAttrPrio = procAttr->schedPriority; procTaskId = taskSpawn((char *)name, procAttr->schedPriority, VX_FP_TASK #if ! defined ( _WRS_VXWORKS_MAJOR ) || _WRS_VXWORKS_MAJOR < 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR < 9 ) /* VX_PRIVATE_ENV flag is no longer functional in vxworks 6.9 */ | VX_PRIVATE_ENV #endif #if defined ( VXWORKS_55 ) || defined ( VXWORKS_54 ) | VX_STDIO | VX_DEALLOC_STACK #endif , VXWORKS_PROC_DEFAULT_STACK, (FUNCPTR)os_procWrapper, (int)process_procContextData, (int)process_procContextData->executable, (int)startRoutine, (int)process_procContextData->arguments, taskIdSelf(), #if ! defined ( _WRS_VXWORKS_MAJOR ) || _WRS_VXWORKS_MAJOR < 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR < 9 ) 0, #else &blockParent, #endif 0, 0, 0, 0); #if defined ( _WRS_VXWORKS_MAJOR ) && ( _WRS_VXWORKS_MAJOR > 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR > 8 ) ) os_sem_wait(&blockParent); os_sem_destroy(&blockParent); #endif if (procTaskId == ERROR) { os_free(process_procContextData); rv = os_resultInvalid; } else { *procId = *(os_procId *)&process_procContextData; rv = os_resultSuccess; } } } putenv("SPLICE_NEW_PROCESS=empty"); if ( privateSet == 1) { envPrivateDestroy(taskIdSelf()); } os_free(converted); return rv; }
os_result idl_genJavaHelperAddPackageRedirect ( const os_char *optarg) { idl_packageRedirect exists, redirect = NULL; os_char *colon; os_char *module = NULL; os_char *package = NULL; os_char *trim = NULL; os_result result = os_resultSuccess; assert (optarg != NULL); colon = os_index (optarg, ':'); if (colon != NULL) { if (colon == optarg) { module = NULL; } else { module = os_strndup (optarg, (size_t) (colon - optarg)); if (module != NULL) { if ((trim = os_str_trim (module, "./:")) != module) { os_free (module); } module = trim; } if (module == NULL) { result = os_resultFail; } else if (strlen (module) == 0) { os_free (module); module = NULL; } } package = os_strdup (colon + 1); if ((trim = os_str_trim (package, "./:")) != package) { os_free (package); } package = trim; if (strlen (package) == 0) { result = os_resultInvalid; } redirect = os_malloc (OS_SIZEOF (idl_packageRedirect)); if (result == os_resultSuccess) { redirect->module = module; redirect->package = package; exists = os_iterResolve ( idl_genJavaHelperPackageRedirects, &idl_genJavaHelperComparePackageRedirect, redirect); if (exists != NULL) { result = os_resultInvalid; } else { idl_genJavaHelperPackageRedirects = os_iterAppend ( idl_genJavaHelperPackageRedirects, redirect); /* idl_genJavaHelperPackageRedirect must be sorted */ os_iterSort ( idl_genJavaHelperPackageRedirects, &idl_genJavaHelperComparePackageRedirect, OS_FALSE); } } if (result != os_resultSuccess) { os_free (module); os_free (package); os_free (redirect); } } else { result = os_resultInvalid; } return result; }