On Thu, 19 Jun 2003, Eli Billauer wrote:
> 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.
Actually I tried looking for somthing of the sort, already written.
Something like valgrind, which does develop-time checks on things like the
stack.
Guy, when using valgrind with --v, I remember
getting a warning saying the stack pointer has changed, asking me if I was
replacing the stack myself, and telling me valgrind does not support this
wel. This was valgrind 1.1 or before that. I am currently using
valgrind 1.95, and it did not give me this warning- it only warned me that
I was about to make illegal write (back then, when I had some code after
the definition of the struct).
Tal, this is C code, there is no constructor.
Eli, I am not trying to prove a point, but find something automatic that
will tell me when the struct is too large, and I should use the heap. I
only relized that that struct was too big, when I had a segmentation
fault. I want to be able to tell beore this happens, using an automatic
tool. (As I said, I thought valgrind would do that for me- since I am now
converting code from fortran to C, I realize every now and then that
another struct is too large for the stack)
I always set my stack size to unlimited, only until now I did not know how
much unlimited was. AFAIK, it is compiler dependant, and gcc is not the
only compiler in the world. (portability issues again...)
So-
Is there anything that protects the stack efficiently?
Is there any variable which holds the stack size, such that I can compare
sizeof(a_t) to that?
Thanks everyone,
Orna.
>
> 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]
>
>
--
Orna. | http://vipe.technion.ac.il/~ladypine/
I am not a number, I am a free person!
--------------------------------------------------------------------------
Haifa Linux Club Mailing List (http://www.haifux.org)
To unsub send an empty message to [EMAIL PROTECTED]