[Fix] (P11 A1): settle MOBILEGL_IPC_ADOPT_TIER at the handshake from the data plane - a stream refuses T0/T1 by name and runs T2 on either side, a client over shared segments dies by name before any record, the at-use check trusts the settlement; unit gates on a real tcp session and a real inproc handshake

This commit is contained in:
2026-09-29 07:23:41 -04:00
parent 1797db0070
commit 3c72e5c637
16 changed files with 500 additions and 73 deletions
@@ -0,0 +1,70 @@
// MobileGL - MobileGL/MG_Remote/Transport/AdoptTier.cpp
// Copyright (c) 2025-2026 MobileGL-Dev
// Licensed under the GNU Lesser General Public License v3.0:
// https://www.gnu.org/licenses/gpl-3.0.txt
// https://www.gnu.org/licenses/lgpl-3.0.txt
// SPDX-License-Identifier: LGPL-3.0-only
// End of Source File Header
#include "AdoptTier.h"
#include <Config.h>
#include <MG_Remote/FatalFunnel.h>
#include <MG_Util/Debug/Log.h>
#include <atomic>
namespace MobileGL::MG_Remote::Transport {
namespace {
std::atomic<bool> g_settled{false};
const char* SideName(AdoptTierSide side) { return side == AdoptTierSide::Client ? "client" : "server"; }
} // namespace
std::uint32_t SettleAdoptTierAtHandshake(bool streamDataPlane, AdoptTierSide side) {
const std::uint32_t knob = MG_Config::Ipc.AdoptTier;
if (knob > 2) {
// Unreachable through ConfigLoader (it admits 0..2); a direct assignment is the only
// way here, and "P11 implements it" of a 7 would be a lie.
SessionFail(MGFatalFamily::UnimplementedAdoptTier,
"MGPipe: Fatal{UnimplementedAdoptTier, \"%u\"} - MOBILEGL_IPC_ADOPT_TIER=%u is not an "
"adoption tier; the values are 0 and 1 (not implemented) and 2 (emulate, the default)",
static_cast<unsigned>(knob), static_cast<unsigned>(knob));
}
if (knob == 2) {
g_settled.store(true, std::memory_order_release);
return 2;
}
if (streamDataPlane) {
// ONE LINE PER SESSION, on the side that holds the knob. The tcp lane's server is a
// shared fixture that never sees the client's environment, so each side says it for
// itself; neither side dies, because T2 is the only tier a stream can carry.
MGLOG_W("MG_Remote %s: Refuse{AdoptTierOnStream, \"T%u\"} - MOBILEGL_IPC_ADOPT_TIER=%u names a "
"shared-mapping adoption tier and this session's data plane is a stream (tcp): the two "
"sides share no memory to map, so the session runs T2 (emulate: the client keeps the "
"shadow and pushes)",
SideName(side), static_cast<unsigned>(knob), static_cast<unsigned>(knob));
g_settled.store(true, std::memory_order_release);
return 2;
}
if (side == AdoptTierSide::Server) {
MGLOG_W("MG_Remote server: MOBILEGL_IPC_ADOPT_TIER=%u is the client's to settle on a shared-segment "
"link (a client naming T0/T1 dies by name at its own handshake); this server serves T2",
static_cast<unsigned>(knob));
g_settled.store(true, std::memory_order_release);
return 2;
}
SessionFail(MGFatalFamily::UnimplementedAdoptTier,
"MGPipe: Fatal{UnimplementedAdoptTier, \"T%u\"} - MOBILEGL_IPC_ADOPT_TIER=%u names a "
"shared-mapping adoption tier no package implements yet (T0 is P11 package B's, T1 is "
"closed); refused at the handshake over shared segments, before any record is emitted. "
"Unset it or set 2 (emulate)",
static_cast<unsigned>(knob), static_cast<unsigned>(knob));
}
bool AdoptTierSettledAtHandshake() { return g_settled.load(std::memory_order_acquire); }
void ForgetAdoptTierSettlementForTest() { g_settled.store(false, std::memory_order_release); }
} // namespace MobileGL::MG_Remote::Transport
+53
View File
@@ -0,0 +1,53 @@
// MobileGL - MobileGL/MG_Remote/Transport/AdoptTier.h
// Copyright (c) 2025-2026 MobileGL-Dev
// Licensed under the GNU Lesser General Public License v3.0:
// https://www.gnu.org/licenses/gpl-3.0.txt
// https://www.gnu.org/licenses/lgpl-3.0.txt
// SPDX-License-Identifier: LGPL-3.0-only
// End of Source File Header
// P11 A1 (MG_Remote/CONTRACT-P11.md §1): THE PERSISTENT-MAP ADOPTION TIER IS SETTLED AT THE
// HANDSHAKE, BY THE SIDE THAT KNOWS THE DATA PLANE, BEFORE THE FIRST map_persistent.
//
// Tier names follow docs/Disaggregated/design/07: T0 = the client allocates an AHardwareBuffer
// and the server imports it; T1 = the server exports an opaque fd; T2 = the resource owner
// declines and the client keeps the shadow and pushes. Only T2 is implemented (T0 is P11
// package B's, T1 is closed), so MOBILEGL_IPC_ADOPT_TIER=0/1 is either refused by name or
// fatal - never a silent T2, and never discovered at the first map_persistent:
//
// data plane side knob 0 / 1
// Stream (tcp) either one line `Refuse{AdoptTierOnStream, "T<n>"}`, then T2. Never Fatal:
// a stream has no memory the two sides share, so no tier but T2
// can exist on it.
// SharedSegments client Fatal{UnimplementedAdoptTier, "T<n>"} at the handshake, before any
// record is emitted.
// SharedSegments server one warning that the client settles the tier on this plane, then
// T2. (inproc and fork share the client's environment, so the client
// dies by name right after; a unix-socket server launched on its own
// serves the T2 its client settled.)
//
// In MG_Remote/Transport (the link-ratchet's SERVER partition) because both roles call it:
// ServerSession::Accept and ClientSession's two Start halves. The at-use check the server's
// applier and codec ask (Client::AdoptTierIsEmulate) reads the settlement back.
#pragma once
#include <cstdint>
namespace MobileGL::MG_Remote::Transport {
enum class AdoptTierSide : std::uint8_t { Client, Server };
// Settles this session's tier from MOBILEGL_IPC_ADOPT_TIER and the negotiated data plane,
// on `side`, and returns the tier the session runs (2 until package B). Logs at most one
// line per call; aborts (SessionFail) only on the client over shared segments.
std::uint32_t SettleAdoptTierAtHandshake(bool streamDataPlane, AdoptTierSide side);
// True once a handshake in this process has settled the tier. The at-use check trusts a
// settled session and still refuses by name a map_persistent no handshake settled.
bool AdoptTierSettledAtHandshake();
// Test seam: forget the settlement, so one process can drive both answers.
void ForgetAdoptTierSettlementForTest();
} // namespace MobileGL::MG_Remote::Transport