taskInfo.c
上传用户:nvosite88
上传日期:2007-01-17
资源大小:4983k
文件大小:13k
- /* taskInfo.c - task information library */
- /* Copyright 1984-1993 Wind River Systems, Inc. */
- #include "copyright_wrs.h"
- /*
- modification history
- --------------------
- 01j,18dec00,pes Correct compiler warnings
- 01i,29may98,cym removed all ifdefs for SIMNT since the register set is now
- current.
- 01h,04mar98,jmb add dec'l
- 01g,06jan98,cym changed taskRegsGet for SIMNT to update TCB from
- windows context.
- 01g,10nov97,dbt modified taskBpHook() routine interface.
- 01f,29oct96,jdi doc: taskName() returns empty string of the task has no name.
- 01e,06oct95,jdi changed Debugging .pG's to .tG "Shell".
- 01d,25feb93,jdi doc: reinstated VX_UNBREAKABLE as publishable option, per kdl.
- 01c,04feb93,jdi documentation cleanup for 5.1.
- 01b,04jan04,wmd added check of calling task id before calling
- taskRegsStackToTcb() for the i960 in taskRegsGet().
- added predeclarations for i960 to get rid of warnings.
- 01a,23aug92,jcf extracted from v02y of taskLib.c.
- */
- /*
- DESCRIPTION
- This library provides a programmatic interface for obtaining task information.
- Task information is crucial as a debugging aid and user-interface
- convenience during the development cycle of an application.
- The routines taskOptionsGet(), taskRegsGet(), taskName(), taskNameToId(),
- taskIsReady(), taskIsSuspended(), and taskIdListGet() are used to obtain
- task information. Three routines -- taskOptionsSet(), taskRegsSet(), and
- taskIdDefault() -- provide programmatic access to debugging features.
- The chief drawback of using task information is that tasks may
- change their state between the time the information is gathered and the
- time it is utilized. Information provided by these routines should
- therefore be viewed as a snapshot of the system, and not relied upon
- unless the task is consigned to a known state, such as suspended.
- Task management and control routines are provided by taskLib. Higher-level
- task information display routines are provided by taskShow.
- INCLUDE FILES: taskLib.h
- SEE ALSO: taskLib, taskShow, taskHookLib, taskVarLib, semLib, kernelLib,
- .pG "Basic OS"
- */
- #include "vxWorks.h"
- #include "errno.h"
- #include "semLib.h"
- #include "string.h"
- #include "regs.h"
- #include "intLib.h"
- #include "taskArchLib.h"
- #include "stdio.h"
- #include "memLib.h"
- #include "private/sigLibP.h"
- #include "private/classLibP.h"
- #include "private/objLibP.h"
- #include "private/smObjLibP.h"
- #include "private/smFixBlkLibP.h"
- #include "private/taskLibP.h"
- #include "private/kernelLibP.h"
- #include "private/workQLibP.h"
- #include "private/windLibP.h"
- /* external function declarations */
- #if CPU_FAMILY==I960
- void taskRegsStackToTcb (WIND_TCB *pTcb);
- void taskRegsTcbToStack (WIND_TCB *pTcb);
- #endif
- /* forward static functions */
- static BOOL taskNameNoMatch (Q_NODE *pNode, char *name);
- /*******************************************************************************
- *
- * taskOptionsSet - change task options
- *
- * This routine changes the execution options of a task.
- * The only option that can be changed after a task has been created is:
- * .iP VX_UNBREAKABLE 21
- * do not allow breakpoint debugging.
- * .LP
- * For definitions, see taskLib.h.
- *
- * RETURNS: OK, or ERROR if the task ID is invalid.
- *
- * SEE ALSO: taskOptionsGet()
- */
- STATUS taskOptionsSet
- (
- int tid, /* task ID */
- int mask, /* bit mask of option bits to unset */
- int newOptions /* bit mask of option bits to set */
- )
- {
- FAST WIND_TCB *pTcb;
- if (INT_RESTRICT () != OK) /* restrict interrupt use */
- return (ERROR);
- taskLock (); /* LOCK PREEMPTION */
- if ((pTcb = taskTcb (tid)) == NULL) /* check task ID validity */
- {
- taskUnlock (); /* UNLOCK PREEMPTION */
- return (ERROR);
- }
- /* update the task options */
- pTcb->options = (pTcb->options & ~mask) | newOptions;
- /*
- * If we are setting/resetting unbreakable option for current task,
- * then call breakpoint callout.
- */
- if (((mask & VX_UNBREAKABLE) || (newOptions & VX_UNBREAKABLE)) &&
- ((tid == 0) || (tid == (int)taskIdCurrent)) &&
- (taskBpHook != NULL))
- {
- (* taskBpHook) (tid);
- }
- taskUnlock (); /* UNLOCK PREEMPTION */
- return (OK);
- }
- /*******************************************************************************
- *
- * taskOptionsGet - examine task options
- *
- * This routine gets the current execution options of the specified task.
- * The option bits returned by this routine indicate the following modes:
- * .iP VX_FP_TASK 22
- * execute with floating-point coprocessor support.
- * .iP VX_PRIVATE_ENV
- * include private environment support (see envLib).
- * .iP VX_NO_STACK_FILL
- * do not fill the stack for use by checkstack().
- * .iP VX_UNBREAKABLE
- * do not allow breakpoint debugging.
- * .LP
- * For definitions, see taskLib.h.
- *
- * RETURNS: OK, or ERROR if the task ID is invalid.
- *
- * SEE ALSO: taskOptionsSet()
- */
- STATUS taskOptionsGet
- (
- int tid, /* task ID */
- int *pOptions /* task's options */
- )
- {
- WIND_TCB *pTcb = taskTcb (tid); /* get pointer to tcb */
- if (pTcb == NULL) /* invalid task ID */
- return (ERROR);
- *pOptions = pTcb->options; /* fill in the options */
- return (OK);
- }
- /*******************************************************************************
- *
- * taskBpHookSet - set breakpoint hook for dbgLib
- *
- * This routine allows dbgLib to install its break-point install/remove routine
- * used by taskOptionsSet. It should only be called by dbgInit().
- *
- * NOMANUAL
- */
- void taskBpHookSet
- (
- FUNCPTR bpHook
- )
- {
- taskBpHook = bpHook;
- }
- /*******************************************************************************
- *
- * taskRegsGet - get a task's registers from the TCB
- *
- * This routine gathers task information kept in the TCB. It copies the
- * contents of the task's registers to the register structure <pRegs>.
- *
- * NOTE
- * This routine only works well if the task is known to be in a stable,
- * non-executing state. Self-examination, for instance, is not advisable,
- * as results are unpredictable.
- *
- * RETURNS: OK, or ERROR if the task ID is invalid.
- *
- * SEE ALSO: taskSuspend(), taskRegsSet()
- */
- STATUS taskRegsGet
- (
- int tid, /* task ID */
- REG_SET *pRegs /* put register contents here */
- )
- {
- FAST WIND_TCB *pTcb = taskTcb (tid);
- if (pTcb == NULL)
- return (ERROR);
- #if CPU_FAMILY==I960
- if (tid != taskIdSelf ())
- taskRegsStackToTcb (pTcb);
- #endif /* CPU_FAMILY==I960 */
- if (pTcb->pExcRegSet != NULL)
- {
- bcopy ((char *)pTcb->pExcRegSet, (char *)&pTcb->regs, sizeof (REG_SET));
- pTcb->pExcRegSet = NULL;
- }
- bcopy ((char *) &pTcb->regs, (char *) pRegs, sizeof (REG_SET));
- return (OK);
- }
- /*******************************************************************************
- *
- * taskRegsSet - set a task's registers
- *
- * This routine loads a specified register set <pRegs> into a specified
- * task's TCB.
- *
- * NOTE
- * This routine only works well if the task is known not to be in the ready
- * state. Suspending the task before changing the register set is
- * recommended.
- *
- * RETURNS: OK, or ERROR if the task ID is invalid.
- *
- * SEE ALSO: taskSuspend(), taskRegsGet()
- */
- STATUS taskRegsSet
- (
- int tid, /* task ID */
- REG_SET *pRegs /* get register contents from here */
- )
- {
- FAST WIND_TCB *pTcb = taskTcb (tid);
- if (pTcb == NULL)
- return (ERROR);
- bcopy ((char *) pRegs, (char *) &pTcb->regs, sizeof (REG_SET));
- #if CPU_FAMILY==I960
- taskRegsTcbToStack (pTcb);
- #endif /* CPU_FAMILY==I960 */
- return (OK);
- }
- /*******************************************************************************
- *
- * taskName - get the name associated with a task ID
- *
- * This routine returns a pointer to the name of a task of a specified ID, if
- * the task has a name. If the task has no name, it returns an empty string.
- *
- * RETURNS: A pointer to the task name, or NULL if the task ID is invalid.
- */
- char *taskName
- (
- int tid /* ID of task whose name is to be found */
- )
- {
- WIND_TCB *pTcb = taskTcb (tid);
- if (pTcb == NULL)
- return ((char *) NULL);
- if (pTcb->name == NULL)
- return ("