HighTechTalks DotNet Forums  

Force Rejit of a method

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss Force Rejit of a method in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Dinis Cruz
 
Posts: n/a

Default Force Rejit of a method - 04-19-2006 , 07:21 PM






Hello, Is there a way to force the ReJit of a method?

One of the demos that I do in my 'Rooting the CLR' presentation is to do
real time MSIL patching.

The problem is that I need to apply the 'patches' before the JIT has
occurred, unless (hence my question) I am able to dynamically either:
- ReJit a method
- Mark a method as not Jitted (whereby it is Jitted the next time that
method is invoked)

Looking at the symbols of a CLR dll (can't remember the name now) I
know that there is a internal way to do this on the CLR (after all (if I
remember correctly) that is one of the methods available to the GC to
reclaim memory).

Thanks,

Dinis Cruz
Owasp .Net Project
www.owasp.net


Reply With Quote
  #2  
Old   
Laura T.
 
Posts: n/a

Default Re: Force Rejit of a method - 04-20-2006 , 10:42 AM






I don't know how you "patch" the methods, but I have used MethodRental class
from System.Reflection.Emit.
It has JitImmediate and JitOnDemand methods to recompile methods.

Laura.

"Dinis Cruz" <dinis.cruz (AT) owasp (DOT) net> ha scritto nel messaggio
news:%23qqAogAZGHA.3752 (AT) TK2MSFTNGP03 (DOT) phx.gbl...
Quote:
Hello, Is there a way to force the ReJit of a method?

One of the demos that I do in my 'Rooting the CLR' presentation is to do
real time MSIL patching.

The problem is that I need to apply the 'patches' before the JIT has
occurred, unless (hence my question) I am able to dynamically either:
- ReJit a method
- Mark a method as not Jitted (whereby it is Jitted the next time that
method is invoked)

Looking at the symbols of a CLR dll (can't remember the name now) I
know that there is a internal way to do this on the CLR (after all (if I
remember correctly) that is one of the methods available to the GC to
reclaim memory).

Thanks,

Dinis Cruz
Owasp .Net Project
www.owasp.net




Reply With Quote
  #3  
Old   
Dinis Cruz
 
Posts: n/a

Default Re: Force Rejit of a method - 04-24-2006 , 05:40 PM



Hello Laura,

There are two types of patches that I do in my demos (both using direct
memory writes (after unlocking the relevant memory pages)).

1) Unmanaged patch - Re-Writing Assembly code directly on the method's
code. Used for example to patch the CLR so that you can load 'corrupted
Strong Named Assemblies'

2) MSIL patch - Re-Write MSIL on .Net methods. If you know the exact
location of the method this is a simple case of replacing the existing
MSIL code with the new one (although at the moment I am limited to the
size of the original MSIL code (there are some guys who did a very
interesting research on 'self healing code' which had a solution for
this problem))


Regarding JitImmediate and JitOnDemand, I have not looked at them, but I
don't think they will allow me to do what I want to do (which is to
patch managed methods that are already loaded in memory)

Best Regards

Dinis Cruz
Owasp .Net Project
www.owasp.net

Laura T. wrote:
Quote:
I don't know how you "patch" the methods, but I have used MethodRental class
from System.Reflection.Emit.
It has JitImmediate and JitOnDemand methods to recompile methods.

Laura.

"Dinis Cruz" <dinis.cruz (AT) owasp (DOT) net> ha scritto nel messaggio
news:%23qqAogAZGHA.3752 (AT) TK2MSFTNGP03 (DOT) phx.gbl...
Hello, Is there a way to force the ReJit of a method?

One of the demos that I do in my 'Rooting the CLR' presentation is to do
real time MSIL patching.

The problem is that I need to apply the 'patches' before the JIT has
occurred, unless (hence my question) I am able to dynamically either:
- ReJit a method
- Mark a method as not Jitted (whereby it is Jitted the next time that
method is invoked)

Looking at the symbols of a CLR dll (can't remember the name now) I
know that there is a internal way to do this on the CLR (after all (if I
remember correctly) that is one of the methods available to the GC to
reclaim memory).

Thanks,

Dinis Cruz
Owasp .Net Project
www.owasp.net




Reply With Quote
  #4  
Old   
cody
 
Posts: n/a

Default Re: Force Rejit of a method - 04-25-2006 , 04:11 AM



IMO you cannot jit a method with is already loaded you first have to unload
the assembly where the code belongs to and then reload it with
assembly.load.


"Dinis Cruz" <dinis.cruz (AT) owasp (DOT) net> schrieb im Newsbeitrag
news:444D45C6.20506 (AT) owasp (DOT) net...
Quote:
Hello Laura,

There are two types of patches that I do in my demos (both using direct
memory writes (after unlocking the relevant memory pages)).

1) Unmanaged patch - Re-Writing Assembly code directly on the method's
code. Used for example to patch the CLR so that you can load 'corrupted
Strong Named Assemblies'

2) MSIL patch - Re-Write MSIL on .Net methods. If you know the exact
location of the method this is a simple case of replacing the existing
MSIL code with the new one (although at the moment I am limited to the
size of the original MSIL code (there are some guys who did a very
interesting research on 'self healing code' which had a solution for
this problem))


Regarding JitImmediate and JitOnDemand, I have not looked at them, but I
don't think they will allow me to do what I want to do (which is to
patch managed methods that are already loaded in memory)

Best Regards

Dinis Cruz
Owasp .Net Project
www.owasp.net

Laura T. wrote:
I don't know how you "patch" the methods, but I have used MethodRental
class
from System.Reflection.Emit.
It has JitImmediate and JitOnDemand methods to recompile methods.

Laura.

"Dinis Cruz" <dinis.cruz (AT) owasp (DOT) net> ha scritto nel messaggio
news:%23qqAogAZGHA.3752 (AT) TK2MSFTNGP03 (DOT) phx.gbl...
Hello, Is there a way to force the ReJit of a method?

One of the demos that I do in my 'Rooting the CLR' presentation is to do
real time MSIL patching.

The problem is that I need to apply the 'patches' before the JIT has
occurred, unless (hence my question) I am able to dynamically either:
- ReJit a method
- Mark a method as not Jitted (whereby it is Jitted the next time that
method is invoked)

Looking at the symbols of a CLR dll (can't remember the name now) I
know that there is a internal way to do this on the CLR (after all (if I
remember correctly) that is one of the methods available to the GC to
reclaim memory).

Thanks,

Dinis Cruz
Owasp .Net Project
www.owasp.net






Reply With Quote
  #5  
Old   
drjflam (AT) gmail (DOT) com
 
Posts: n/a

Default Re: Force Rejit of a method - 04-28-2006 , 08:26 PM



Use ICorProfilerInfo::SetFunctionReJIT().

-John
http://www.iunknown.com


Reply With Quote
  #6  
Old   
Dinis Cruz
 
Posts: n/a

Default Re: Force Rejit of a method - 04-29-2006 , 07:48 PM



Does this works on an application where the .Net Profiler is not activated?

I have used the .Net Profiler in the past (see the .NetMon tool I wrote
for Foundstone) and the biggest annoyance that I had, was the fact that
I could not use the Profiler functionality (for example the ability to
trace function flow execution) on projects that where not started with
the Profiler activated.

Dinis Cruz
Owasp .Net Project
www.owasp.net

drjflam (AT) gmail (DOT) com wrote:
Quote:
Use ICorProfilerInfo::SetFunctionReJIT().

-John
http://www.iunknown.com


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.