Skip to content

Commit fd01e6f

Browse files
committed
Correct stack base calculation on Mac and NuttX
VELAPLATFO-1343 Signed-off-by: Huang Qi <huangqi3@xiaomi.com> Change-Id: I3b69cd1c4819e494f16e32582c6764bcfb0075fe
1 parent ee97e30 commit fd01e6f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

core/shared/platform/common/posix/posix_thread.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,16 @@ os_thread_get_stack_boundary()
326326
#elif defined(__APPLE__) || defined(__NuttX__)
327327
if ((addr = (uint8 *)pthread_get_stackaddr_np(self))) {
328328
stack_size = pthread_get_stacksize_np(self);
329+
330+
/* Check whether stack_addr is the base or end of the stack,
331+
change it to the base if it is the end of stack */
332+
if (addr <= (uint8 *)&stack_size)
333+
addr = addr + stack_size;
334+
329335
if (stack_size > max_stack_size)
330-
addr -= max_stack_size;
331-
else
332-
addr -= stack_size;
336+
stack_size = max_stack_size;
337+
338+
addr -= stack_size;
333339
/* Reserved 1 guard page at least for safety */
334340
addr += page_size;
335341
}

0 commit comments

Comments
 (0)