Ships with a deliberately broken function (bad_compute()) that will
segfault when called. Connects to the hotpatch server, receives a
replacement function as raw bytes, writes them into an executable page,
installs a detour over bad_compute, then calls it successfully.
- Call
bad_compute()- crashes intentionally (writes to null)
- (we skip the first call and just show what WOULD happen)
- Connect to hotpatch server on HOTPATCH_PORT
- Receive PatchHeader (16 bytes)
- Validate magic
- Receive payload (patch_size bytes) into RWX page
- Install detour:
bad_compute()-> patch page - Call
bad_compute()again - now routed through the fix - Send
ACKto server
Holds the CORRECT implementation of compute() as compiled Flux.
- Serializes the fix function's machine code bytes by reading from its own text segment via a function pointer
- Sends a PatchHeader followed by the raw bytes
- Waits for the client ACK
The "fix" is just good_compute — the same logic bad_compute was
supposed to implement but without the null-write bug:
good_compute(x) = x * 3;The server reads its OWN compiledgood_compute()bytes out of memory and ships them to the client. The client receives real, already-compiled machine code and executes it directly - no interpretation, no JIT.
Wire format (all fields little-endian):
// struct PatchPacket
// {
// u32 magic, // 0x48505458 "HPTX" — sanity check
// patch_size; // number of bytes in the payload
// u64 target_rva; // RVA from client image base to patch site
// // (0 = use target_addr directly, for demo)
// byte payload[]; // raw machine code bytes, patch_size long
// };
The client reads the header first (16 bytes), allocates a page, // receives exactly patch_size bytes into it, then installs the detour.
Uses HMAC SHA256 to verify the server's signature before applying the patch.