[MG_Remote] (P6/cp): EGL control frames cross to the other process, and answer

An eglInitialize issued in one process is dispatched in another and its answer
comes back. That is the last thing standing between the session and a native
context, because the server creates its context on the apply thread when the
client's first eglMakeCurrent crosses - and until now nothing crossed.

ONE SEAM, NOT TWELVE. a6 row A4-13 counted twelve Server* forwarders, each
ending in ServerLoopInstance().RunSurfaceControlFrame(frame) with no role
branch, and concluded twelve edits. They all funnel through that one function,
so the branch goes there and the forwarders are untouched.

A HOOK, NOT A CALL. ServerLoop::SetRemoteControlSink takes a function pointer
the client installs at handshake. The obvious alternative - the server half
asking ClientSession::Active() - would have added a fifth symbol to the six
MG_Remote already owes itself (a6-link-experiment §5), in the one file with a
clean reason not to.

The branch is BEFORE the local seq mint, deliberately. RunSurfaceControlFrame
numbers unnumbered local posts; a wire request must keep the CLIENT's number all
the way through dispatch and reply or its answer cannot be correlated
(CONTRACT-P6 §6.3, which says the client mints, always).

The client sink encodes with EncodeSurfaceOpFrame, sends, and waits for the
SurfaceReply carrying its own seq - under one mutex, because the twelve
forwarders are already caller-serialised on the server's m_callerMutex under
inproc and two replies racing for one correlation is the same bug on either
side. A CapsSnapshot arriving while it waits is ADOPTED rather than dropped:
the server republishes caps from inside its MakeCurrent dispatch (a6 row A4-30)
so a snapshot legitimately precedes the reply to the op that produced it. The
wait is bounded and its expiry is NOT fatal - a peer that is gone is a different
fact from a peer that is slow, and only the doorbell's death latch may say which.

The server's pump decodes and applies through ServerApplyWireSurfaceOp, which
a6 found had no production caller anywhere. It runs on ServerMain's own thread -
NOT the apply thread - which is what §6.2 asks for: a control arrival must not
wake the applier, and frame decode must not happen on the thread holding the
native context. A frame that is not a verifiable SurfaceOp ends the session
rather than being ignored, because a silent drop is the failure mode this
project refuses everywhere else.

THE TEST'S ASSERTION IS THE OUT-PARAMETERS, not the EGL result. A headless
machine has no display to initialise, so the op is expected to be refused - and
ServerInitializeEGLDisplay writes major/minor "whenever the dispatch ran,
success or not" (the forwarder's own comment). They move off -1 if and only if
a SurfaceReply came back from the other process; a transport failure returns
before the write-back. I got this backwards first and the test said so.

Gates: ServerSpawnTest 5/5; unit suite 2345 with the same two pre-existing
environmental failures; G1 pull 0 added / 0 removed, .text 10822147 unchanged.

Not TCP. It was considered and dropped for now: TCP has no SCM_RIGHTS, so the
four segments cannot cross it, and a TCP control plane would have to refuse a
data plane by name until StreamLink exists (P6.5). Recorded here so the reason
is on file rather than re-derived.
This commit is contained in:
2026-09-21 10:50:28 -04:00
parent 11807ac7d0
commit 5239ae0c19
6 changed files with 210 additions and 7 deletions
+18
View File
@@ -223,6 +223,21 @@ namespace MobileGL::MG_Remote::Server {
// What did NOT move: the blocking handshake, the one slot, and the apply-thread
// ownership. Under spawn the same frame is what SurfaceOpCodec encodes into a
// Wire::SurfaceOp - this signature is the seam both transports share.
// P6 `cp`: where a control frame goes when the server is ANOTHER PROCESS.
//
// All twelve Server* forwarders funnel through RunSurfaceControlFrame, so
// this is ONE seam rather than twelve (a6 row A4-13 counted them). The
// client installs a sink at handshake; with none installed the behaviour
// is exactly what it was - post into the one-slot mailbox, or run inline
// when we are already on the apply thread.
//
// A HOOK RATHER THAN A CALL INTO ClientSession, deliberately: the server
// half calling the client half is four of the six symbols a6 found
// MG_Remote owes itself (a6-link-experiment §5), and this is the one
// place that would have added a fifth.
using RemoteControlSink = MobileGLResult (*)(void* user, SurfaceControlFrame& frame);
void SetRemoteControlSink(RemoteControlSink sink, void* user);
MobileGLResult RunSurfaceControlFrame(SurfaceControlFrame& frame);
// The TEST seam through the same channel: posts a ProbeForTesting frame whose dispatch
@@ -364,6 +379,9 @@ namespace MobileGL::MG_Remote::Server {
Bool ControlIsPending() const;
private:
RemoteControlSink m_remoteSink = nullptr;
void* m_remoteSinkUser = nullptr;
void ApplyThreadMain();
// Runs a posted control frame, if there is one. Returns true if it ran one.
Bool PumpControlRequest();