STATUS wdCancel ( WDOG_ID wdId /* ID of watchdog to cancel */ ) { int level = intLock (); /* LOCK INTERRUPTS */ if (OBJ_VERIFY (wdId, wdClassId) != OK) { intUnlock (level); /* UNLOCK INTERRUPTS */ return (ERROR); } #ifdef WV_INSTRUMENTATION /* windview - level 1 event logging */ EVT_OBJ_1 (OBJ, wdId, wdClassId, EVENT_WDCANCEL, wdId); #endif if (kernelState) { intUnlock (level); /* UNLOCK INTERRUPTS */ workQAdd1 ((FUNCPTR)windWdCancel, (int)wdId); } else { kernelState = TRUE; /* KERNEL_ENT */ intUnlock (level); /* UNLOCK INTERRUPTS */ windWdCancel (wdId); /* cancel watchdog */ windExit (); /* KERNEL EXIT */ } return (OK); }
STATUS msgQEvStart ( MSG_Q_ID msgQId, /* msg Q for which to register events */ UINT32 events, /* 32 possible events */ UINT8 options /* event-related msg Q options */ ) { if (events == 0x0) { errnoSet (S_eventLib_ZERO_EVENTS); return (ERROR); } if (INT_RESTRICT () != OK) return (ERROR); /* errno set by INT_RESTRICT() */ TASK_LOCK (); /* to prevent msg Q from being deleted */ if (OBJ_VERIFY(msgQId,msgQClassId) != OK) { TASK_UNLOCK (); return (ERROR); /* errno is set by OBJ_VERIFY */ } /* TASK_UNLOCK() will be done by eventStart() */ return (eventStart ((OBJ_ID)msgQId, &msgQId->events, &msgQEvIsFree, events, options)); }
STATUS semQFlush( SEM_ID semId ) { STATUS status; int level; INT_LOCK(level); if (OBJ_VERIFY (semId, semClassId) != OK) { INT_UNLOCK (level); status = ERROR; } else { /* Check next object */ if (Q_FIRST(&semId->qHead) == NULL) { INT_UNLOCK(level); status = OK; } else { /* Enter kernel and flush pending queue */ kernelState = TRUE; INT_UNLOCK(level); vmxPendQFlush(&semId->qHead); vmxExit(); status = OK; } } return status; }
HASH_NODE *hashTblFind ( FAST HASH_ID hashId, /* id of hash table from which to find node */ HASH_NODE *pMatchNode, /* pointer to hash node to match */ int keyCmpArg /* parameter to be passed to key comparator */ ) { FAST HASH_NODE *pHNode; int ix; if (OBJ_VERIFY (hashId, hashClassId) != OK) return (NULL); /* invalid hash node */ /* invoke hash table's hashing routine to get index into table */ ix = (* hashId->keyRtn) (hashId->elements, pMatchNode, hashId->keyArg); /* search linked list for above hash index and return matching hash node */ pHNode = (HASH_NODE *) SLL_FIRST (&hashId->pHashTbl [ix]); while ((pHNode != NULL) && !((* hashId->keyCmpRtn) (pMatchNode, pHNode, keyCmpArg))) pHNode = (HASH_NODE *) SLL_NEXT (pHNode); return (pHNode); }
STATUS vmContextDestroy( VM_CONTEXT_ID context ) { STATUS status; /* Verify object class */ if (OBJ_VERIFY(context, vmContextClassId) != OK) { status = ERROR; } else { semTake(&context->sem, WAIT_FOREVER); if (MMU_TRANS_TABLE_DESTROY(context->mmuTransTable) != OK) { status = ERROR; } else { /* Free datastructure */ objFree(vmContextClassId, context); status = OK; } } return status; }
STATUS vmTranslate( VM_CONTEXT_ID context, void *vAddr, void **pAddr ) { STATUS status; /* Check if context should be current */ if (context == NULL) { context = vmCurrContext; } else { /* Verify object class */ if (OBJ_VERIFY(context, vmContextClassId) != OK) { status = ERROR; } else { status = MMU_TRANSLATE(context->mmuTransTable, vAddr, pAddr); } } return status; }
STATUS vmStateGet( VM_CONTEXT_ID context, void *vAddr, unsigned *pState ) { STATUS status; unsigned mmuState; VM2MMU_STATE_TRANS *thisState; int i; unsigned mmuTMask; unsigned mmuTState; unsigned vmTState; /* Check if context should be current */ if (context == NULL) { context = vmCurrContext; } /* Verify object class */ if (OBJ_VERIFY(context, vmContextClassId) != OK) { status = ERROR; } else { *pState = 0; if (MMU_STATE_GET( context->mmuTransTable, vAddr, &mmuState ) != OK) { status = ERROR; } else { /* Translate state */ for (i = 0; i < mmuStateTransTableSize; i++) { thisState = &mmuStateTransTable[i]; mmuTMask = thisState->mmuMask; mmuTState = thisState->mmuState; vmTState = thisState->vmState; if ((mmuState & mmuTMask) == mmuTState) { *pState |= vmTState; } } status = OK; } } return status; }
STATUS wdDestroy( WDOG_ID wdId, BOOL dealloc ) { STATUS status; int level; /* Not callable from interrupts */ if (INT_RESTRICT() != OK) { status = ERROR; } else { /* Lock interrupts */ INT_LOCK(level); /* Verify object */ if (OBJ_VERIFY(wdId, wdClassId) != OK ) { INT_UNLOCK(level); status = ERROR; } else { /* Terminate object */ objCoreTerminate(&wdId->objCore); /* Enter kernel */ kernelState = TRUE; /* Unlock interrupts */ INT_UNLOCK(level); /* Cancel watchdog timer */ vmxWdCancel(wdId); wdId->status = WDOG_DEAD; taskSafe(); /* Exit kernel */ vmxExit(); /* Deallocate if requested */ if (dealloc == TRUE) { objFree(wdClassId, wdId); } taskUnsafe(); status = OK; } } return status; }
int fileno ( FILE * fp /* stream */ ) { if (OBJ_VERIFY (fp, fpClassId) != OK) return (ERROR); return (__sfileno(fp)); }
STATUS symTblLock ( SYMTAB_ID symTblId /* ID of symbol table to lock */ ) { if (OBJ_VERIFY (symTblId, symTblClassId) != OK) return (ERROR); /* invalid symbol table ID */ semTake (&symTblId->symMutex, WAIT_FOREVER); return (OK); }
STATUS symTblUnlock ( SYMTAB_ID symTblId /* ID of symbol table to unlock */ ) { if (OBJ_VERIFY (symTblId, symTblClassId) != OK) return (ERROR); /* invalid symbol table ID */ semGive (&symTblId->symMutex); /* release mutual exclusion */ return (OK); }
/*lint --e{78, 527,752 } */ void semQueueGiveDefer ( SEM_ID semId /* semaphore ID to give */ ) { #ifdef _WRS_CONFIG_SMP /* For SMP, we don't know if semId is still valid at this point */ if (OBJ_VERIFY (semId, semClassId) != OK) return; #endif /* _WRS_CONFIG_SMP */ if (Q_FIRST (&semId->qHead) == NULL) /* anyone blocked? */ { /*lint -save -e52*/ semId->semCount++; /* give semaphore */ /*lint -restore +e52*/ /* sem is free, send events if registered */ if (semId->events.taskId != (int)NULL) { /* * We will be here only if semId->events.taskId is non-null (i.e. * the event library has been configured). Hence we can eliminate * the null-check for _func_eventRsrcSend. */ /*lint -save -e119 -e533 */ if ((*_func_eventRsrcSend) (semId->events.taskId, semId->events.registered) != OK) { semId->events.taskId = (int)NULL; return; } /*lint -restore*/ if ((semId->events.options & EVENTS_SEND_ONCE) == EVENTS_SEND_ONCE) semId->events.taskId = (int)NULL; } } else { /*lint -save -e516*/ #ifdef _WRS_CONFIG_SV_INSTRUMENTATION /* system viewer - level 2 event logging */ EVT_TASK_1 (EVENT_OBJ_SEMGIVE, semId); #endif /* _WRS_CONFIG_SV_INSTRUMENTATION */ /*lint -restore +e516*/ windPendQGet (&semId->qHead); /* unblock a task */ } }
long ftell ( FAST FILE * fp /* stream */ ) { FAST fpos_t pos; if (OBJ_VERIFY (fp, fpClassId) != OK) return (ERROR); /* * Find offset of underlying I/O object, then * adjust for buffered bytes. */ if (fp->_flags & __SOFF) pos = fp->_offset; else { pos = __sseek (fp, (fpos_t)0, SEEK_CUR); if (pos == -1L) return (pos); } if (fp->_flags & __SRD) { /* * Reading. Any unread characters (including * those from ungetc) cause the position to be * smaller than that in the underlying object. */ pos -= fp->_r; if (HASUB(fp)) pos -= fp->_ur; } else if (fp->_flags & __SWR && fp->_p != NULL) { /* * Writing. Any buffered characters cause the * position to be greater than that in the * underlying object. */ pos += fp->_p - fp->_bf._base; } return (pos); }
STATUS wdStart ( WDOG_ID wdId, /* watchdog ID */ int delay, /* delay count, in ticks */ FUNCPTR pRoutine, /* routine to call on time-out */ int parameter /* parameter with which to call routine */ ) { int level = intLock (); /* LOCK INTERRUPTS */ if (OBJ_VERIFY (wdId, wdClassId) != OK) { intUnlock (level); /* UNLOCK INTERRUPTS */ return (ERROR); } #ifdef WV_INSTRUMENTATION /* windview - level 1 event logging */ EVT_OBJ_2 (OBJ, wdId, wdClassId, EVENT_WDSTART, wdId, delay); #endif if (kernelState) /* already in kernel? */ { wdId->deferStartCnt ++; /* bump the start count */ wdId->wdParameter = parameter; /* update w/ new parameter */ wdId->wdRoutine = pRoutine; /* update w/ new routine */ intUnlock (level); /* UNLOCK INTERRUPTS */ workQAdd2 (windWdStart, (int)wdId, delay); /* defer the wdStart */ } else { wdId->deferStartCnt = 1; /* initialize start count */ wdId->wdParameter = parameter; /* update w/ new parameter */ wdId->wdRoutine = pRoutine; /* update w/ new routine */ kernelState = TRUE; /* KERNEL ENTER */ intUnlock (level); /* UNLOCK INTERRUPTS */ if (windWdStart (wdId, delay) != OK) /* start the watchdog */ { windExit (); /* KERNEL EXIT */ return (ERROR); } windExit (); /* KERNEL EXIT */ } return (OK); }
int getc ( FILE * fp /* input stream */ ) { int ch; if (OBJ_VERIFY (fp, fpClassId) != OK) return (EOF); if ((ch = __sgetc(fp)) == EOF) fp->_flags |= __SEOF; return (ch); }
/*lint --e{533 } */ STATUS osl_waitqueue_wakeup ( wait_queue_head_t semId /* semaphore ID to give */ ) { #ifndef _WRS_CONFIG_SMP int level; #endif /* !_WRS_CONFIG_SMP */ Q_NODE * pQNode = NULL; #ifdef _WRS_CONFIG_SMP /* lock has been taken in the case of ISR before here */ if (!_WRS_INT_CONTEXT ()) #endif /* _WRS_CONFIG_SMP */ OBJ_LOCK (semClassId, level); if (OBJ_VERIFY (semId, semClassId) != OK) { OBJ_UNLOCK (semClassId, level); return (ERROR); } pQNode = Q_EACH(&semId->qHead, semQueueEventCheck, TRUE); if (pQNode == NULL) { OBJ_UNLOCK (semClassId, level);/*lint !e2 */ return (OK); } else { /*lint -save -e10*/ KERNEL_LOCK_OBJ_UNLOCK (semClassId, level);/*lint !e2 */ /*lint -restore +e10*/ /*lint -save -e722*/ #ifdef _WRS_CONFIG_SV_INSTRUMENTATION /* system viewer - level 2 event logging */ EVT_TASK_1 (EVENT_OBJ_SEMGIVE, semId);/*lint !e681 */ #endif /* _WRS_CONFIG_SV_INSTRUMENTATION */ /*lint -restore +e722*/ semQueuePendQGet(&semId->qHead, pQNode); /* unblock a task */ KERNEL_UNLOCK (); return (OK); } }
STATUS hashTblDestroy ( HASH_ID hashId, /* id of hash table to destroy */ BOOL dealloc /* deallocate associated memory */ ) { if (OBJ_VERIFY (hashId, hashClassId) != OK) return (ERROR); /* invalid hash id */ objCoreTerminate (&hashId->objCore); /* terminate core */ if (dealloc) return (objFree (hashClassId, (char *) hashId)); return (OK); }
STATUS rBuffInfoGet ( BUFFER_ID buffId, /* generic buffer identifier */ RBUFF_INFO_TYPE *pRBuffInfo /* rBuff info structure */ ) { RBUFF_ID rBuff; /* access to private members of this rBuff */ /* Get access to this buffer's private information. */ rBuff = (RBUFF_ID) buffId; /* Check validity of the arguments. */ if (rBuff == NULL) { printf ("No rBuffId specified.\n"); return (ERROR); } if (OBJ_VERIFY (rBuff, rBuffClassId) != OK) return (ERROR); RBUFF_LOCK (rBuff); pRBuffInfo->srcPart = rBuff->info.srcPart; pRBuffInfo->options = rBuff->info.options; pRBuffInfo->buffSize = rBuff->info.buffSize; pRBuffInfo->currBuffs = rBuff->info.currBuffs; pRBuffInfo->minBuffs = rBuff->info.minBuffs; pRBuffInfo->maxBuffs = rBuff->info.maxBuffs; pRBuffInfo->maxBuffsActual = rBuff->info.maxBuffsActual; pRBuffInfo->emptyBuffs = rBuff->info.emptyBuffs; pRBuffInfo->timesExtended = rBuff->info.timesExtended; pRBuffInfo->threshold = rBuff->info.threshold; pRBuffInfo->timesXThreshold = rBuff->info.timesXThreshold; pRBuffInfo->dataContent = rBuff->info.dataContent; pRBuffInfo->writesSinceReset = rBuff->info.writesSinceReset; pRBuffInfo->writesSinceReset = rBuff->info.readsSinceReset; pRBuffInfo->bytesWritten = rBuff->info.bytesWritten; pRBuffInfo->bytesRead = rBuff->info.bytesRead; RBUFF_UNLOCK(rBuff); return (OK); }
STATUS wdCancel( WDOG_ID wdId ) { STATUS status; int level; /* Lock interrupts */ INT_LOCK(level); /* Verify object */ if (OBJ_VERIFY(wdId, wdClassId) != OK) { INT_UNLOCK(level); status = ERROR; } else { /* If in kernel mode */ if (kernelState == TRUE) { /* Unlock interrupts */ INT_UNLOCK(level); /* Add to kernel queue */ workQAdd1((FUNCPTR) vmxWdCancel, (ARG) wdId); status = OK; } else { /* Enter kernel */ kernelState = TRUE; /* Unlock interrupts */ INT_UNLOCK(level); vmxWdCancel(wdId); /* Exit kernel */ vmxExit(); status = OK; } } return status; }
SYMTAB_ID posixNameTblInit ( int posixTblHashSize ) { /* This check is needed because symLibInit is not reentrant */ if (OBJ_VERIFY (&symTblClassId->objCore, classClassId) != OK) symLibInit (); /* initialize symbol table package */ if (posixTblHashSize == 0) posixTblHashSize = POSIX_TBL_HASH_SIZE_LOG2; posixNameTbl = symTblCreate (posixTblHashSize, FALSE, memSysPartId); return (posixNameTbl); }
STATUS semDestroy( SEM_ID semId, BOOL deallocate ) { STATUS status; int level; if (INT_RESTRICT() != OK) { errnoSet(S_intLib_NOT_ISR_CALLABLE); status = ERROR; } else { INT_LOCK(level); if (OBJ_VERIFY(semId, semClassId) != OK) { INT_UNLOCK(level); status = ERROR; } else { objCoreTerminate(&semId->objCore); /* Delete it */ kernelState = TRUE; INT_UNLOCK(level); vmxSemDelete(semId); taskSafe(); vmxExit(); if (deallocate == TRUE) { objFree(semClassId, semId); } taskUnsafe(); status = OK; } } return status; }
STATUS wdDestroy ( WDOG_ID wdId, /* ID of watchdog to terminate */ BOOL dealloc /* dealloc associated memory */ ) { int level; if (INT_RESTRICT () != OK) /* restrict isr use */ return (ERROR); level = intLock (); /* LOCK INTERRUPTS */ if (OBJ_VERIFY (wdId, wdClassId) != OK) /* validate watchdog ID */ { intUnlock (level); /* UNLOCK INTERRUPTS */ return (ERROR); } #ifdef WV_INSTRUMENTATION /* windview - level 1 event logging */ EVT_OBJ_1 (OBJ, wdId, wdClassId, EVENT_WDDELETE, wdId); #endif objCoreTerminate (&wdId->objCore); /* invalidate watchdog */ kernelState = TRUE; /* KERNEL ENTER */ intUnlock (level); /* UNLOCK INTERRUPTS */ windWdCancel (wdId); /* cancel watchdog */ wdId->status = WDOG_DEAD; /* dead dog */ TASK_SAFE (); /* TASK SAFE */ windExit (); /* EXIT KERNEL */ if (dealloc) objFree (wdClassId, (char *) wdId); /* deallocate watchdog */ TASK_UNSAFE (); /* TASK UNSAFE */ return (OK); }
HASH_NODE *hashTblEach ( HASH_ID hashId, /* hash table to call routine for */ FUNCPTR routine, /* the routine to call for each hash node */ int routineArg /* arbitrary user-supplied argument */ ) { FAST int ix; HASH_NODE *pNode = NULL; if (OBJ_VERIFY (hashId, hashClassId) != OK) return (NULL); /* invalid hash id */ for (ix = 0; (ix < hashId->elements) && (pNode == NULL); ix++) pNode = (HASH_NODE *)sllEach (&hashId->pHashTbl[ix],routine,routineArg); return (pNode); /* return node we ended with */ }
LOCAL STATUS semBGive( SEM_ID semId ) { STATUS status; int level; /* Lock interrupts */ INT_LOCK(level); /* Verify class */ if (OBJ_VERIFY(semId, semClassId) != OK) { INT_UNLOCK(level); status = ERROR; } else { /* Get next listening task from queue */ SEM_OWNER_SET(semId, Q_FIRST(&semId->qHead)); /* Check if no more tasks are waiting for this semaphore */ if (SEM_OWNER_GET(semId) == NULL) { INT_UNLOCK(level); status = OK; } else { /* Enter kernel mode */ kernelState = TRUE; INT_UNLOCK(level); /* Unblock next task waiting */ vmxPendQGet(&semId->qHead); /* Exit kernel mode */ vmxExit(); status = OK; } } return status; }
int fputs ( const char * s, /* string */ FILE * fp /* stream to write to */ ) { struct __suio uio; struct __siov iov; if (OBJ_VERIFY (fp, fpClassId) != OK) return (EOF); iov.iov_base = (void *)s; iov.iov_len = uio.uio_resid = strlen (s); uio.uio_iov = &iov; uio.uio_iovcnt = 1; return (__sfvwrite (fp, &uio)); }
LOCAL STATUS semFlushDefer( SEM_ID semId ) { STATUS status; /* Verify object */ if (OBJ_VERIFY(semId, semClassId) != OK) { status = ERROR; } else { /* A method is guaranteed to exist */ workQAdd1(semFlushDeferTable[semId->semType & SEM_TYPE_MASK], semId); status = OK; } return status; }
int __sflush ( FAST FILE *fp ) { FAST unsigned char *p; FAST int n; FAST int t; if (OBJ_VERIFY (fp, fpClassId) != OK) return (EOF); t = fp->_flags; if ((t & __SWR) == 0) return (0); if ((p = fp->_bf._base) == NULL) return (0); n = fp->_p - p; /* write this much */ /* Set these immediately to avoid problems with longjmp and to allow * exchange buffering (via setvbuf) in user write function. */ fp->_p = p; fp->_w = (t & (__SLBF|__SNBF)) ? (0) : (fp->_bf._size); for (; n > 0; n -= t, p += t) { t = __swrite (fp, (char *)p, n); if (t <= 0) { fp->_flags |= __SERR; return (EOF); } } return (0); }
int fprintf ( FILE * fp, /* stream to write to */ const char * fmt, /* format string */ ... /* optional arguments to format string */ ) { int ret; va_list vaList; if (OBJ_VERIFY (fp, fpClassId) != OK) return (ERROR); va_start (vaList, fmt); ret = vfprintf (fp, fmt, vaList); va_end (vaList); return (ret); }
STATUS hashTblPut ( HASH_ID hashId, /* id of hash table in which to put node */ HASH_NODE *pHashNode /* pointer to hash node to put in hash table */ ) { int index; if (OBJ_VERIFY (hashId, hashClassId) != OK) return (ERROR); /* invalid hash id */ /* invoke hash table's hashing routine to get index into table */ index = (* hashId->keyRtn) (hashId->elements, pHashNode, hashId->keyArg); /* add hash node to head of linked list */ sllPutAtHead (&hashId->pHashTbl [index], pHashNode); return (OK); }
STATUS vmCurrentSet( VM_CONTEXT_ID context ) { STATUS status; /* Verify object class */ if (OBJ_VERIFY(context, vmContextClassId) != OK) { status = ERROR; } else { /* Set as current */ vmCurrContext = context; MMU_CURRENT_SET(context->mmuTransTable); status = OK; } return status; }