Prev: error
Next: Automake Conditional and ARG_VAR Question
From: Nicolas George on 28 Apr 2010 07:32 Noob wrote in message <hr95v3$52f$1(a)speranza.aioe.org>: > .text > .globl _get_current_stack_pointer > _get_current_stack_pointer: > movl %esp, %eax > ret void *get_approx_stack_pointer(void) { int a; return(&a); }
From: boltar2003 on 28 Apr 2010 07:46 On 28 Apr 2010 11:32:18 GMT Nicolas George <nicolas$george(a)salle-s.org> wrote: >Noob wrote in message <hr95v3$52f$1(a)speranza.aioe.org>: >> .text >> .globl _get_current_stack_pointer >> _get_current_stack_pointer: >> movl %esp, %eax >> ret > >void *get_approx_stack_pointer(void) >{ > int a; > return(&a); >} Ah , very elegant and so obvious when you see it, but of course thinking it up is always harder! Of course it doesn't tell me when I'll hit the limit but its certainly more useful than guessing. Is there a way of knowing where stack bottom will be or this is an unfixed quantity that simply varies depending on how much free memory the OS has? Thanks B2003
From: Noob on 28 Apr 2010 07:47 Nicolas George wrote: > Noob wrote: > >> .text >> .globl _get_current_stack_pointer >> _get_current_stack_pointer: >> movl %esp, %eax >> ret > > void *get_approx_stack_pointer(void) > { > int a; > return(&a); > } 3.1.2.4 Storage durations of objects The value of a pointer that referred to an object with automatic storage duration that is no longer guaranteed to be reserved is indeterminate. AFAIU, a conforming compiler is free to change the function to void *get_approx_stack_pointer(void) { return NULL; } However, gcc 4.3.2 does not perform this optimization. $ cat bar.c void *get_approx_stack_pointer(void) { int a; return(&a); } $ gcc -O3 -fomit-frame-pointer -Wall -S bar.c bar.c: In function 'get_approx_stack_pointer': bar.c:4: warning: function returns address of local variable _get_approx_stack_pointer: subl $16, %esp leal 12(%esp), %eax addl $16, %esp ret Regards.
From: Öö Tiib on 28 Apr 2010 07:53 On Apr 28, 1:01 pm, boltar2...(a)boltar.world wrote: > This crashes too: > > $ cat t.c > void func() > { > func(); > > } > > int main() > { > func();} > > $ cc t.c > $ a.out > Segmentation fault (core dumped) Yes. Like i said in other thread you have to do some undefined by standard things that are usually defined by platform or implementation documentation. Microsoft for example throws seh (microsoft term) exceptions and for restoring the damaged stack there is some sort of: int _resetstkoflw(); I do not use such techniques, instead i avoid deep recursion. To avoid deep recursion i avoid deep trees.
From: Nicolas George on 28 Apr 2010 08:12
Noob wrote in message <hr977p$78u$1(a)speranza.aioe.org>: > AFAIU, a conforming compiler is free to change the function to > > void *get_approx_stack_pointer(void) > { > return NULL; > } Of course, there is nothing portable in examining the stack pointer; the very notion of stack is not portable. This is just a debugging trick. |