diff options
Diffstat (limited to 'os/rt/src')
| -rw-r--r-- | os/rt/src/chregistry.c | 9 | ||||
| -rw-r--r-- | os/rt/src/chsys.c | 13 | ||||
| -rw-r--r-- | os/rt/src/chthreads.c | 12 | 
3 files changed, 24 insertions, 10 deletions
| diff --git a/os/rt/src/chregistry.c b/os/rt/src/chregistry.c index c20909cd0..7be0939c8 100644 --- a/os/rt/src/chregistry.c +++ b/os/rt/src/chregistry.c @@ -95,8 +95,8 @@ ROMCONST chdebug_t ch_debug = {    (uint8_t)_offsetof(thread_t, newer),
    (uint8_t)_offsetof(thread_t, older),
    (uint8_t)_offsetof(thread_t, name),
 -#if CH_DBG_ENABLE_STACK_CHECK == TRUE
 -  (uint8_t)_offsetof(thread_t, stklimit),
 +#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
 +  (uint8_t)_offsetof(thread_t, wabase),
  #else
    (uint8_t)0,
  #endif
 @@ -233,6 +233,8 @@ thread_t *chRegFindThreadByPointer(thread_t *tp) {    return NULL;
  }
 +#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) ||  \
 +    defined(__DOXYGEN__)
  /**
   * @brief   Confirms that a working area is being used by some active thread.
   * @note    The reference counter of the found thread is increased by one so
 @@ -251,7 +253,7 @@ thread_t *chRegFindThreadByWorkingArea(stkalign_t *wa) {    /* Scanning registry.*/
    ctp = chRegFirstThread();
    do {
 -    if (ctp->stklimit == wa) {
 +    if (chThdGetWorkingAreaX(ctp) == wa) {
        return ctp;
      }
      ctp = chRegNextThread(ctp);
 @@ -259,6 +261,7 @@ thread_t *chRegFindThreadByWorkingArea(stkalign_t *wa) {    return NULL;
  }
 +#endif
  #endif /* CH_CFG_USE_REGISTRY == TRUE */
 diff --git a/os/rt/src/chsys.c b/os/rt/src/chsys.c index 82a9e78d6..f4dbbb4e2 100644 --- a/os/rt/src/chsys.c +++ b/os/rt/src/chsys.c @@ -98,7 +98,6 @@ static void _idle_thread(void *p) {   * @special
   */
  void chSysInit(void) {
 -  extern stkalign_t __main_thread_stack_base__;
    _scheduler_init();
    _vt_init();
 @@ -135,8 +134,16 @@ void chSysInit(void) {    currp = _thread_init(&ch.mainthread, "idle", IDLEPRIO);
  #endif
 -  /* Setting up the base address of the static main thread stack.*/
 -  currp->stklimit = &__main_thread_stack_base__;
 +#if CH_DBG_ENABLE_STACK_CHECK == TRUE
 +  {
 +    /* Setting up the base address of the static main thread stack, the
 +       symbol must be provided externally.*/
 +    extern stkalign_t __main_thread_stack_base__;
 +    currp->wabase = &__main_thread_stack_base__;
 +  }
 +#elif CH_CFG_USE_DYNAMIC == TRUE
 +  currp->wabase = NULL;
 +#endif
    /* Setting up the caller as current thread.*/
    currp->state = CH_STATE_CURRENT;
 diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c index 8566aaa11..74c41fa7b 100644 --- a/os/rt/src/chthreads.c +++ b/os/rt/src/chthreads.c @@ -182,8 +182,10 @@ thread_t *chThdCreateSuspendedI(const thread_descriptor_t *tdp) {    tp = (thread_t *)((uint8_t *)tdp->wend -
                      MEM_ALIGN_NEXT(sizeof (thread_t), PORT_STACK_ALIGN));
 +#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
    /* Stack boundary.*/
 -  tp->stklimit = tdp->wbase;
 +  tp->wabase = tdp->wbase;
 +#endif
    /* Setting up the port-dependent part of the working area.*/
    PORT_SETUP_CONTEXT(tp, tdp->wbase, tp, tdp->funcp, tdp->arg);
 @@ -348,8 +350,10 @@ thread_t *chThdCreateStatic(void *wsp, size_t size,    tp = (thread_t *)((uint8_t *)wsp + size -
                      MEM_ALIGN_NEXT(sizeof (thread_t), PORT_STACK_ALIGN));
 +#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
    /* Stack boundary.*/
 -  tp->stklimit = (stkalign_t *)wsp;
 +  tp->wabase = (stkalign_t *)wsp;
 +#endif
    /* Setting up the port-dependent part of the working area.*/
    PORT_SETUP_CONTEXT(tp, wsp, tp, pf, arg);
 @@ -436,12 +440,12 @@ void chThdRelease(thread_t *tp) {      switch (tp->flags & CH_FLAG_MODE_MASK) {
  #if CH_CFG_USE_HEAP == TRUE
      case CH_FLAG_MODE_HEAP:
 -      chHeapFree(chthdGetStackLimitX(tp));
 +      chHeapFree(chThdGetWorkingAreaX(tp));
        break;
  #endif
  #if CH_CFG_USE_MEMPOOLS == TRUE
      case CH_FLAG_MODE_MPOOL:
 -      chPoolFree(tp->mpool, chthdGetStackLimitX(tp));
 +      chPoolFree(tp->mpool, chThdGetWorkingAreaX(tp));
        break;
  #endif
      default:
 | 
