pussuw commented on code in PR #10856: URL: https://github.com/apache/nuttx/pull/10856#discussion_r1346185129
########## arch/risc-v/src/common/riscv_addrenv.c: ########## @@ -421,6 +422,12 @@ int up_addrenv_create(size_t textsize, size_t datasize, size_t heapsize, heapsize = heapsize + MM_PGALIGNUP(CONFIG_DEFAULT_TASK_STACKSIZE); +#ifdef CONFIG_TLS_ALIGNED Review Comment: Good question, what is a good way to handle this ? As far as I can tell there are several kconfig variables that affect this: - CONFIG_ARCH_HEAP_NPAGES; I don't want to use this, the heap requirement for a process cannot be known in advance, let the heap grow naturally via sbrk until memory runs out - CONFIG_DEFAULT_TASK_STACKSIZE; This amount of _initial_ heap is needed for the task stack, this is just a guess, and if not enough initial heap is available, the system crashes due to stack corruption - CONFIG_ELF_STACKSIZE; This is what is given to up_addrenv_create if (when) the new process is loaded from a (elf) file - CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE; No idea actually what this is ? Now, TLS requires that the stack is properly aligned. If I don't add this here, the system crashes because there is not enough initial stack to house the aligned TLS. There are so many variables here that I don't know how to fix this in a good way, if you have a suggestion I can try and implement it. This is exactly the same problem as I described in #5811 . There is no way of knowing how much initial heap is required for the process's stack, so we are left with two options: - Do patches like this, that try to guess how much is enough - Implement a dynamic stack (which is more work than I'm willing to do atm) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org