aboutsummaryrefslogtreecommitdiffstats
path: root/os/rt
diff options
context:
space:
mode:
Diffstat (limited to 'os/rt')
-rw-r--r--os/rt/include/chschd.h10
-rw-r--r--os/rt/include/chthreads.h11
-rw-r--r--os/rt/src/chregistry.c9
-rw-r--r--os/rt/src/chsys.c13
-rw-r--r--os/rt/src/chthreads.c12
5 files changed, 38 insertions, 17 deletions
diff --git a/os/rt/include/chschd.h b/os/rt/include/chschd.h
index aa49adcff..a00b2fa5a 100644
--- a/os/rt/include/chschd.h
+++ b/os/rt/include/chschd.h
@@ -169,11 +169,15 @@ struct ch_thread {
*/
const char *name;
#endif
+#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) || \
+ defined(__DOXYGEN__)
/**
- * @brief Thread stack boundary.
- * @note This pointer matches with the working area base address.
+ * @brief Working area base address.
+ * @note This pointer is used for stack overflow checks and for
+ * dynamic threading.
*/
- stkalign_t *stklimit;
+ stkalign_t *wabase;
+#endif
/**
* @brief Current thread state.
*/
diff --git a/os/rt/include/chthreads.h b/os/rt/include/chthreads.h
index 47d7c2672..1b29260ed 100644
--- a/os/rt/include/chthreads.h
+++ b/os/rt/include/chthreads.h
@@ -307,18 +307,21 @@ static inline systime_t chThdGetTicksX(thread_t *tp) {
}
#endif
+#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) || \
+ defined(__DOXYGEN__)
/**
- * @brief Returns the stack limit of the specified thread.
+ * @brief Returns the working area base of the specified thread.
*
* @param[in] tp pointer to the thread
- * @return The stack limit pointer.
+ * @return The working area base pointer.
*
* @xclass
*/
-static inline stkalign_t *chthdGetStackLimitX(thread_t *tp) {
+static inline stkalign_t *chThdGetWorkingAreaX(thread_t *tp) {
- return tp->stklimit;
+ return tp->wabase;
}
+#endif /* CH_DBG_ENABLE_STACK_CHECK == TRUE */
/**
* @brief Verifies if the specified thread is in the @p CH_STATE_FINAL state.
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: