Questions about stack_ctrl and GC

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Posts: 4
Joined: Sun May 05, 2019 3:22 pm

Questions about stack_ctrl and GC

Post by quark » Sun May 05, 2019 5:18 pm

Hi, I just started playing with MicroPython for a day and am already quite impressed. We have short-lived Rust programs that embeds CPython now. I'm thinking about replacing CPython with MicroPython to reduce startup time overhead.

I noticed mp_stack_ctrl_init() is designed to be called at the beginning of a program so:
- gc_collect can do a C stack scan.
- STACK_CHECK can work, if mp_stack_set_limit is also called.
- (I didn't notice other use cases of stack_ctrl_init, but I can miss something)

I'd like to make `mp_stack_ctrl_init` optional in the Rust land, since there is no way to make the compiler enforce it's called when a thread is created.

My main question is about the GC. Suppose I have strict stackless mode and pystack turned on, is it okay to assume the native C stack scan is then unnecessary. So gc_collect() can just be { gc_collect_start() /* scans pystack */; gc_collect_end(); } ?

Another minor question is about the rest of stack_ctrl uses. The Rust stdlib has mprotect-ed both ends of its stack, and has a SIGSEGV handler to deal with stack overflow, I think it's okay to turn off STACK_CHECK then?

Post Reply