[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
+40
View File
@@ -34,6 +34,7 @@
// the boundary before the data plane needs it.
#include <MG_Remote/Client/ClientSession.h>
#include <MG_Remote/Server/ServerLoop.h>
#include <MG_Remote/Server/ServerSpawn.h>
#include <MG_Remote/Transport/Doorbell.h>
#include <MG_Remote/Transport/FdPassing.h>
@@ -151,6 +152,45 @@ TEST(ServerSpawnTest, StartsAServerProcessAndHandshakesAcrossIt) {
EXPECT_EQ(Server::CountOwnChildren(), before) << "a zombie would still be counted here";
}
TEST(ServerSpawnTest, AnEglControlOpCrossesToTheOtherProcessAndAnswers) {
// `cp`. All twelve Server* EGL forwarders funnel through
// ServerLoop::RunSurfaceControlFrame, so this exercises the ONE seam that
// sends them: encode -> control socket -> the server's pump ->
// ServerApplyWireSurfaceOp -> its one-slot mailbox -> the apply thread ->
// SurfaceReply -> back here.
//
// Under inproc this same call posts into a mailbox in THIS process. The
// assertion that it is not doing that here is the server's pid in the
// handshake plus the fact that ServerLoopInstance() in this process was
// never started - a local post would find no apply thread and time out.
Session session;
ASSERT_TRUE(Bring("eglop", &session));
ASSERT_EQ(Handshake(session), MOBILEGL_OK);
// eglInitialize's forwarder: the simplest op that has a real answer.
EGLint major = -1;
EGLint minor = -1;
const bool ok = Server::ServerInitializeEGLDisplay(EGL_NO_DISPLAY, &major, &minor);
// WHAT IS ASSERTED IS THE ROUND TRIP, not the EGL result. A headless CI
// machine has no display to initialise, so `ok` is expected to be false -
// and that is fine, because `cp` is done when the op reaches the other
// process and an answer comes back.
//
// THE OUT-PARAMETERS ARE THE PROOF. ServerInitializeEGLDisplay writes them
// "whenever the dispatch ran, success or not" (ServerLoop.cpp's own comment
// at the forwarder), so they move off -1 if and only if a SurfaceReply came
// back from the other process. A transport failure returns before the
// write-back and leaves both at -1; that is the difference this asserts.
EXPECT_NE(major, -1) << "no SurfaceReply came back: the op never reached the other process";
EXPECT_NE(minor, -1) << "no SurfaceReply came back: the op never reached the other process";
(void)ok;
Client::ClientSessionInstance().Stop();
int exitCode = -1;
ASSERT_EQ(Server::ReapServer(session.server, 5000, &exitCode), MOBILEGL_OK);
}
TEST(ServerSpawnTest, AnUnresolvableImageIsANamedRefusalAndStartsNothing) {
const int before = Server::CountOwnChildren();