Hello Orna.

What I would do, is to write a small function which returns the value of the stack pointer, when it was called. It's not very accurate, but it can give a good indication of how heavily the stack is consumed.

I process is more or less: Write a dummy function, which does nothing interesting, but returns a pointer (be sure it's not optimized out). Compile the function into a separate .o file. Then hack the .o file with a disassembler, so that the returned value is the stack pointer, and not the previous value.

This is an ugly, but rather fast solution. Then you link your code with the hacked .o file, thus getting the values you need.

As for Nadav's you're-wrong remark -- my hunch is that Orna *knows* that this is wrong, and she's trying to prove the point to someone else...

Good luck,
  Eli

Orna Agmon wrote:

Hello eveyone,

I was wondering if there was anything that detected C stack overflow in a nice way (i.e., not by having to cut down my program until I stop getting a segmentation fault on the first line of main).

In details:

I have a program that looks somewhat like that:

typedef struct{
/*a huge struct definition*/
} a_t;

int main(int argc, char *argv){
 a_t a;
 return 0;
}

and I want to get something politer than a segmentation fault.
I found some info on preventing attacks on the stack, so it seems to me that it should be possible to do this in a non- hostile manner.


BTW, it is not a problem of lack of memory- the same struct can be allocated on the heap.


Thanks,
Orna.





-------------------------------------------------------------------------- Haifa Linux Club Mailing List (http://www.haifux.org) To unsub send an empty message to [EMAIL PROTECTED]




Reply via email to