kopia lustrzana https://github.com/micropython/micropython
embed: Improve stack top estimation.
Obtaining the stack-top via a few function calls may yield a pointer which is too deep within the stack. So require the user to obtain it from a higher level (or via some other means). Fixes issue #11781. Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>pull/13653/head
rodzic
be8d660fc2
commit
d2a3cd7ac4
|
@ -31,7 +31,14 @@ static char heap[8 * 1024];
|
|||
|
||||
int main() {
|
||||
// Initialise MicroPython.
|
||||
mp_embed_init(&heap[0], sizeof(heap));
|
||||
//
|
||||
// Note: &stack_top below should be good enough for many cases.
|
||||
// However, depending on environment, there might be more appropriate
|
||||
// ways to get the stack top value.
|
||||
// eg. pthread_get_stackaddr_np, pthread_getattr_np,
|
||||
// __builtin_frame_address/__builtin_stack_address, etc.
|
||||
int stack_top;
|
||||
mp_embed_init(&heap[0], sizeof(heap), &stack_top);
|
||||
|
||||
// Run the example scripts (they will be compiled first).
|
||||
mp_embed_exec_str(example_1);
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
#include "port/micropython_embed.h"
|
||||
|
||||
// Initialise the runtime.
|
||||
void mp_embed_init(void *gc_heap, size_t gc_heap_size) {
|
||||
mp_stack_ctrl_init();
|
||||
void mp_embed_init(void *gc_heap, size_t gc_heap_size, void *stack_top) {
|
||||
mp_stack_set_top(stack_top);
|
||||
gc_init(gc_heap, (uint8_t *)gc_heap + gc_heap_size);
|
||||
mp_init();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void mp_embed_init(void *gc_heap, size_t gc_heap_size);
|
||||
void mp_embed_init(void *gc_heap, size_t gc_heap_size, void *stack_top);
|
||||
void mp_embed_deinit(void);
|
||||
|
||||
// Only available if MICROPY_ENABLE_COMPILER is enabled.
|
||||
|
|
Ładowanie…
Reference in New Issue