NO

Author Topic: __pexit function  (Read 3766 times)

CommonTater

  • Guest
__pexit function
« on: May 23, 2012, 06:07:03 pm »
Hi Pelle...  Really liking this new version!
 
Is it possible to ad a __pexit hook similar to the __penter one already in place? 
 
MS has it and it would increase compatibility.
Of course it has other uses too...
 
 

czerny

  • Guest
Re: __pexit function
« Reply #1 on: May 23, 2012, 10:22:44 pm »
Quote
similar to the __penter one already in place?

I can not find this topic in the help file.

czerny

CommonTater

  • Guest
Re: __pexit function
« Reply #2 on: May 24, 2012, 04:07:12 am »
Quote
similar to the __penter one already in place?

I can not find this topic in the help file.

czerny

First read this thread...  http://forum.pellesc.de/index.php?topic=4229.0

It's in the help file under Command Line Tools --> POCC -> /Gh
 
Note that _penter is not a library call, it's a hook set at the beginning of every function call.
_pexit is it's mate, called just before returning from every function call.


 
« Last Edit: May 24, 2012, 04:10:50 am by CommonTater »

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 383
    • Alex's Link Sammlung
Re: __pexit function
« Reply #3 on: May 24, 2012, 03:32:35 pm »
Is it possible to ad a __pexit hook similar to the __penter one already in place? 
The original __penter function (for profiling) replaces the return adress on the stack with the adess of __pexit. Perhaps you can use the same trick. ;)
best regards
 Alex ;)

CommonTater

  • Guest
Re: __pexit function
« Reply #4 on: May 24, 2012, 06:15:09 pm »
Is it possible to ad a __pexit hook similar to the __penter one already in place? 
The original __penter function (for profiling) replaces the return adress on the stack with the adess of __pexit. Perhaps you can use the same trick. ;)

If you check my garbage collector experiment that is what I did.  However, it is horridly inelegant and not entirely reliable, at least in my limited experience...  Playing with it in MSVC made life a lot easier, since it has both hooks, and I was able to get it to work very nicely without having to mess with assembler (not that ASM is a bad thing). 


Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 383
    • Alex's Link Sammlung
Re: __pexit function
« Reply #5 on: May 24, 2012, 08:17:22 pm »
When I read your posting first, I thought you can avoid your problem by misusing the profiling functions. So I wanted to verify the profiling functions and was suprised that there was only a function at the function header.
So I looked with the debugger how the profiling works and saw how Pelle uses his __pexit function. I think that is the easiest way for him because every function has only one entry but it can have many exits (also no good coding style).
If Pelle decides to spend an extra call to __pexit at each return, you can be happy to have an easy way for your problem. If he decides that it is to much work, you can look how Pelle keep his stack clean  with __penter and __pexit and you can solve your probleme in the suggested way. ;)
I know this is no elegant way, but you need it only one time as a wrapper around the __penter and __pexit and there you can call any function you want.

PS: Perhaps Vortex, our Assembler guru will write such a wrapper and can take away some work from Pelle.
best regards
 Alex ;)

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 1976
    • http://www.smorgasbordet.com
Re: __pexit function
« Reply #6 on: May 27, 2012, 01:18:38 pm »
I know there is a __pexit function, but only for convenience AFAICT. The __penter function is enough to get the job done.
I will not add __pexit to version 7.0; maybe in the future, but I'm not sure there is enough demand for it...
/Pelle

CommonTater

  • Guest
Re: __pexit function
« Reply #7 on: May 27, 2012, 02:02:41 pm »
Hello Pelle.... 

I doubt there is much demand at all, since most people seem unaware of _penter and what it can be used for.  What I was hoping is that it wasn't a difficult thing to add and you wouldn't mind.  I have a rather extensive library project planned that is using the _penter as part of a garbage collector system for memory cleanups. 

Experimenting with it in MSVC++ where I have both _penter and _pexit shows that it has some potentially good uses and having both calls simplifies my code quite a bit.

Yes, the _pexit can be faked by replacing the return address during _penter but that seems rather kludgy. I'm thinking that with compiler support, the outcome would be a lot better.

If it is possible to add this, without too much trouble, I would definately appreciate it...