__stack_size__, __stack_end__ characters in 'C'

Is there a direct method in which the values ​​of the stack_start and stack_end characters can reference the 'C' function? I can do this using a little assembler to read each character and put it in a variable that has the attribute "used" assigned to it. For instance.

static __attribute__((used)) UI_32 StkStart; __asm__ ( "LDR R0, =__stack_start__ \n" "LDR R1, =StkStart\n" "STMIA.W R1, {R0}\n" ); 

Is there any way to avoid using the information here?

The reason I need to do this is because my stack area is initialized with a specific template in the launcher and to determine which part of the stack was used. I can go through the memory stack by checking the changes to the original drawing.

+4
source share
2 answers

Perhaps you can get a rough idea of ​​the use of the stack:

 #include <stdio.h> char *stack_top; void f() { int stack; char tab[1 << 20]; char stack_end; stack = stack_top - &stack_end; printf("%d.\n", stack); } void main() { char dummy; stack_top = &dummy; f(); exit(0); } 

sample run:

 $ gcc stack.c -o stack $ ./stack 1048624. 
+2
source

There is no direct path in C to access the symbols stack_start and stack_en d. To access the stack memory, you need to use the assembly code.

+1
source

Source: https://habr.com/ru/post/1482324/


All Articles