Re: [email] RE: Function to see if a pointer is on the stack

"Dan Thompson" <[email protected]>
Newsgroups gmane.games.devel.windows
Message-ID <055d01c486d7$ab9732c0$6500a8c0@gunvulture>
Dunno, I think (Since its debug code), I would chuck cycles at it and just
check against my stored list of strings. If I have it already I would point
to the old copy, otherwise make a new one. (may refcount?)

Okay... train of thought gone. My coworker thought he'd be funny and leave a
watch with an alarm set hidden on my desk.

..copy..stack...
Yeah. If you are just on windows machines, you can use the CONTEXT
structure. I think (not sure) all windows boxes grow down with the stack, so
that makes the is stack function trivial.(If not its fairly easy to see
which way it goes). If you have to run on too many machines, it may not be
worth all the crazy code, so I'd say stick with tracking anything you
haven't seen yet. This minor feature probably has already cost you enough in
terms of time spent.

-Dan


----- Original Message ----- 
From: "Jon Watte" <[email protected]>
To: <[email protected]>
Sent: Friday, August 20, 2004 8:49 AM
Subject: [email] RE: [GD-Windows] Function to see if a pointer is on the
stack


>
> You should be able to easily wrap the thread creation functions
> to initialize thread-local data for the "isonstack" call. You
> could also add a grep for thread creation to your checkin tests
> to make sure nobody breaks the rule (make sure to exempt the
> actual wrapper implementation, though :-)
>
> Sadly, the Platform SDK doesn't have a function to test whether
> something is on a stack or not -- in fact, there isn't even a
> function to query the stack extent of a specific thread, only
> the current stack pointer! (By getting the CONTEXT structure)
> This has annoyed me in the past, but if you're Windows specific,
> the creation wrapping and Tls / Fls stack base works pretty
> well.
>
> Cheers,
>
> / h+
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of
> Jacob Turner (Core Design Ltd)
> Sent: Friday, August 20, 2004 4:29 AM
> To: [email protected]
> Subject: RE: [GD-Windows] Function to see if a pointer is on the stack
>
>
> Unfortunately can't do the reliable method.  My example for copying
strings
> is just an example so can't use std::string<> or bare pointer technique.
>
> Bit scared about the other option because we are in a multi-threaded app
and
> this function would be common to all threads and we don't have explicit
> creation of common library stuff when a new thread is made.
>
> Isn't there a really PC specific code e.g. getting the stack ptr etc.
This
> is how I am doing the function on consoles.
>
> Mind you not a big hassle because on the PC we have so much memory that
> don't care if just always copy strings or whatever data i.e. can make is
> variable on stack function return TRUE all the time.
>
> Thanks
>
> Jake
>
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]]On Behalf Of
> > Jon Watte
> > Sent: 19 August 2004 18:19
> > To: [email protected]
> > Subject: RE: [GD-Windows] Function to see if a pointer is on the stack
> >
> >
> > The most reliable way of doing this is to use a class for
> > your argument rather than bare pointers, and have a
> > constructor from bare pointers, and use reference counting
> > in the class implementation -- this is almost exactly what
> > std::string<> already does for you!
> >
> > Else, you can register the stack pointer in main() (or the
> > entry function for each thread/fiber), and get the stack
> > pointer in the called function, and compare -- this is not
> > entirely portable, because the stack may grow up on some
> > architectures.
> >
> > // non-threaded version -- if you use threads or fibers,
> > // you need one gBase per thread/fiber
> >
> > char * gBase;
> >
> > void register_main( char * base ) {
> >   gBase = base;
> > }
> >
> > bool is_stack_pointer( char const * ptr ) {
> >   char top[10];
> >   assert( top < gBase ); // else stack grows up
> >   return (ptr < gBase) && (ptr > top);
> > }
> >
> > int main() {
> >   ...
> >   char junk[ 10 ];
> >   register_main( junk );
> >   ...
> > }
> >
> > void some_func( char * anArg ) {
> >   if( is_stack_pointer( anArg ) ) {
> >     ...
> >   }
> > }
> >
> >
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]]On Behalf Of
> > Jacob Turner (Core Design Ltd)
> > Sent: Thursday, August 19, 2004 9:30 AM
> > To: [email protected]
> > Subject: [GD-Windows] Function to see if a pointer is on the stack
> >
> >
> > Is there some simple and reliable code for a console or
> > windows app to test
> > if a pointer value is on the stack or not ?
> >
> > If the pointer is on the stack (e.g. a string) then we want
> > to copy the
> > string to heap memory for reuse later on.
> >
> > Cheers
> >
> > Jake
> >
> >
> > -------------------------------------------------------
> > SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
> > 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
> > Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
> > http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
> > _______________________________________________
> > Gamedevlists-windows mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
> > Archives:
> > http://sourceforge.net/mailarchive/forum.php?forum_idU5
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
> > 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
> > Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
> > http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
> > _______________________________________________
> > Gamedevlists-windows mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
> > Archives:
> > http://sourceforge.net/mailarchive/forum.php?forum_id=555
> >
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
> 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
> Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
> http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
> _______________________________________________
> Gamedevlists-windows mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
> Archives:
> http://sourceforge.net/mailarchive/forum.php?forum_idU5
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
> 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
> Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
> http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
> _______________________________________________
> Gamedevlists-windows mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
> Archives:
> http://sourceforge.net/mailarchive/forum.php?forum_id=555
>



-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=555
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.