about stackmap intrinsic

Dear All

My MSc was about implementing some kind of On stack replacement in LLVM to enhance security by obfuscating running code periodically.

I’ve tried to implement this job in JIT, but I couldn’t. So I implemented it in interpreter, as an initial step.

However, now I’m trying to make it in JIT.

My first step is to extract function state at an arbitrary point. So, I interrupt function at any point (from within JIT) and pause to extract state. My problem now is with state.

By searching I found about stackmap new intrinsic. I got idea about what it does and I think it may help greatly in my task. However, I could not find any source about how to use it exactly, specially, how to retrieve information stored in a stackmap. I’m not understanding the concept of intrinsics very well.​ Again, I tried to find any source that explains how intrinsic work, but I couldn’t.

So, any help will be greatly appreciated.

Regards,
Marwa Yusuf
Teaching Assistant - Computer Engineering Department
Faculty of Engineering - Benha University
E-JUST MSc Student
Computer Science & Engineering Dept.

Dear All

My MSc was about implementing some kind of On stack replacement in LLVM to enhance security by obfuscating running code periodically.

I’ve tried to implement this job in JIT, but I couldn’t. So I implemented it in interpreter, as an initial step.

However, now I’m trying to make it in JIT.

My first step is to extract function state at an arbitrary point. So, I interrupt function at any point (from within JIT) and pause to extract state. My problem now is with state.

By searching I found about stackmap new intrinsic. I got idea about what it does and I think it may help greatly in my task. However, I could not find any source about how to use it exactly, specially, how to retrieve information stored in a stackmap. I’m not understanding the concept of intrinsics very well.​ Again, I tried to find any source that explains how intrinsic work, but I couldn’t.

So, any help will be greatly appreciated.

http://llvm.org/docs/StackMaps.html

The format of the stackmap section is defined in include/CodeGen/StackMaps.h. You currently have to intercept calls to RTDyldMemoryManager to find the stackmap section.

The intrinsics and stackmap format will probably change again before the next LLVM release.

You cannot arbitrarily stop a thread running compiled code and extract the state. You have to patch the code so that it calls back to your runtime at a known location. The stackmap intrinsic can be useful if you want to destrcutively patch the code and don’t want control to resume in the JITed function. The patchpoint intrinsic works if you want to patch into the runtime and return back to the JIT function.

-Andy

​Sorry for naiive question but I could not understand the shadow bytes required in the stackmaps.