Link to home
Start Free TrialLog in
Avatar of mark-rev
mark-rev

asked on

How can I "hot-patch" a hotpatchable C++ service exe on Windows Server?

I'm looking into making our C++ Windows service application hotpatchable... I see in Visual Studio 2010 the ability to add the compile and link flags to embed the appropriate assembly instructions in front of and at function entry points.  But how do I go to a running system on the machine and tell Windows "take SERVICE.EXE version 6 and replace the appropriate functions in the in-memory and actively running SERVICE.EXE version 5?"... and "oh by the way, update the one on the disk too so that if/when the service or OS restarts, it's the new one".  Is this a function of WIX?
Avatar of JimBeveridge
JimBeveridge
Flag of United States of America image

I have run this question through some Microsoft forums and only received a pointer this this article that discusses the hotpatching process:

http://www.openrce.org/articles/full_view/22

I cannot find any discussion of how to create a .hp file for Windows installer.
Avatar of mark-rev
mark-rev

ASKER

@Jim thanks for the link... I reviewed it and it seems like this article is basically managing its own hot swapping of the functions.  The OS already has the ability to do it to itself, however, so I just need to figure out how (or if?) Microsoft exposes that to application developers to do to their own applications...
ASKER CERTIFIED SOLUTION
Avatar of JimBeveridge
JimBeveridge
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Jim I see your point... I looked over the Divide.hp.c in the example and I saw what appeared to be HOTPATCH_HOOKS with x86 JMP instructions and immediately punted. It does appear worth a closer look... although I was certainly looking for an "easier out".  The problem I'm trying to solve is simple to define... hosted services with lots and lots of customers, many with few service windows... we have a problem and need to make a small patch, but can't because of service disruption... one could argue we need a better design or better testing but that's life in the fast lane.  Of course it also occurs to me the ability to patch things will be limited... e.g. clearly can't make a change to a c++ object's storage, although should be able to change member functions, unless they're virtual?  Perhaps this is just a pipe dream...
Hotpatching and simple are mutually exclusive even under the best of circumstances. You aren't going to be able to create a new executable and just tell Windows Installer to "figure it out", particularly with C++. My guess is that hotpatches are always handcrafted to a certain, even at Microsoft.

I certainly sympathize with the problem you are trying to solve, I've run into it myself many times. Most of the recommendations that I've seen for solving this involve running a cluster and taking individual nodes of the cluster down for maintenance while the rest of the cluster carries the load.
One other interesting note - I built hotpatches for Unix somewhere around 1988. These were for 911 emergency call systems, where the systems could not be shut down under any circumstances. All of that work was done in assembly language and the patch was published as a set of hex codes.

Doesn't look like much has changed since then.
Funny, we're along the same lines... full Unified Communications (voice video desktop-sharing chat presence file-transfer etc.)... with call centers, banks, and hospitals... including 911 services.  Anyway, you're right, sounds like it hasn't changed...