Skip to content

Commit f463ac8

Browse files
committed
P2-08.03: fix Linux publication identity and verify both native platforms
1 parent d66ddc0 commit f463ac8

8 files changed

Lines changed: 656 additions & 24 deletions

File tree

‎docs/evidence/p2/documentation-stableidentity-v1.json‎

Lines changed: 514 additions & 0 deletions
Large diffs are not rendered by default.
1.14 MB
Binary file not shown.

‎docs/roadmap/P2-HANDOFF.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ English | [简体中文](P2-HANDOFF_zh.md) | [P2 contract](P2.md)
88
`01a13503-db0e-7be0-a50e-11ff85e5890c`, bound to the unique active 30-minute
99
heartbeat `rustsharp-p1-p2-30`. The deleted old `rustsharp-p2` is not restored.
1010
The persistent dispatch and acceptance checkpoint is
11-
`artifacts/p1-supervision/resume-root-v38/resumption.json`.
11+
`artifacts/p1-supervision/resume-root-v39/resumption.json`.
12+
13+
Round35 stable publication identity is ✅ Complete as a bounded component: strict full build0 warnings/errors on local SDK10.0.402; native Windows and Ubuntu each pass publication21/21, command API20/20 and actual workspace children8/8, with98/98 executed and0 failed/skipped/notRun. [Exact component proof](../evidence/p2/documentation-stableidentity-v1.json) binds10 source inputs,6 DLL/PDBs, all ordered reports and16 child identities, and retains the earlier Linux20/21 failure. Linux now uses held O_PATH descriptors plus native stable identity; the replacement oracle proves real moved/original and fresh empty directories without manipulating timestamps. Full leaf, runtime same-process FD leak proof, exact new-SHA CI on pinned SDK400 and original containment remain separate. Formatter v7 source closes a PID-identity handoff gap but awaits root strict/native acceptance. P1 target Drop case is absent from d2 source/backend matrices; current NativeV2 implementation exists and historical v5 raw evidence must be reconciled before new execution. Checkpoint v39; six P1 gates remain open, P2 stays8/101 and both full closures remain false.
1214

1315
Round34 remains 🚧 In progress. The exact63500 resource query component is ✅ Complete: independent native OpenProcess returns87 at12:02:22, agreeing with the absent single-PID lookup; historical UNKNOWN and Job5→0 remain separate, with no invented exit time/code or kill. [Scoped root review](../evidence/p1/conhost63500-root-review-v1.json) preserves both original receipts. Production stable-identity sources are integrated but uncommitted: strict full build0 warnings/errors on newly observed local SDK10.0.402, Windows publication21/API20/workspace8 all pass. Actual Linux publication executes all21 with20 passed/1 failed: the old replacement-directory test precondition compares .NET creation time, and fails before the product negative assertion. Linux API20/workspace8 are NOT_RUN; no acceptance or source commit follows. Earlier header timeout/automatic-variable error and malformed patch are retained. Formatter v5 proves HWND owner=self while its owned job contains a distinct conhost; v6 actual-job identity correction is source-only. P1 NativeV2 already has a Linux destructor cleanup branch; its exact profile/case execution remains unverified. Checkpoint v38; six P1 gates stay open, P2 stays8/101 and both full closures remain false.
1416

‎docs/roadmap/P2-HANDOFF_zh.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
`01a13503-db0e-7be0-a50e-11ff85e5890c`,绑定唯一 ACTIVE 的每30分钟
99
heartbeat `rustsharp-p1-p2-30`。已删除的旧 `rustsharp-p2` 不恢复。
1010
持久派单与验收检查点为
11-
`artifacts/p1-supervision/resume-root-v38/resumption.json`。
11+
`artifacts/p1-supervision/resume-root-v39/resumption.json`。
12+
13+
第35轮稳定发布身份限定组件为 ✅ 已完成:本机SDK10.0.402严格全构建零警告/零错误,原生Windows与Ubuntu各通过publication21/21、命令API20/20、真实workspace子进程8/8;98/98已执行,失败/跳过/未运行均为0。[精确组件证据](../evidence/p2/documentation-stableidentity-v1.json)绑定10项源码、6份DLL/PDB、全部有序报告和16个子进程身份,并保留此前Linux20/21失败。Linux采用持续持有O_PATH描述符与原生稳定身份;替换oracle通过真实搬移原件和新建空目录证明替换,不操作时间戳。完整叶子、同进程运行FD泄漏证明、固定SDK400的新精确SHA CI及原始containment仍分列。Formatter v7源码补齐PID身份交接缺口,待监督者严格构建/原生验收。P1目标Drop案例不在d2源码/后端矩阵中;NativeV2实现已存在,须先对账历史v5原始证据再决定新执行。检查点v39;P1六门禁仍开放,P2保持8/101,两个完整闭环标志仍为false。
1214

1315
第34轮仍为 🚧 进行中。精确PID63500资源查询组件为 ✅ 已完成:12:02:22独立原生OpenProcess返回87,与单PID查询不存在一致;历史UNKNOWN与Job5→0分别保留,不编造退出时间/退出码,不执行kill。[限定范围的监督复核](../evidence/p1/conhost63500-root-review-v1.json)保留两份原始收据。生产稳定身份源码已集成但未提交:本机新观察到SDK10.0.402,严格全构建零警告/零错误,Windows publication21/API20/workspace8全部通过。真实Linux publication已执行全部21项,20通过/1失败:旧替换目录测试前置条件比较.NET创建时间,在产品负向断言前失败。Linux API20/workspace8为NOT_RUN;不验收、不提交生产源码。头文件首次超时/自动变量错误及无效patch均保留。Formatter v5证明HWND归driver,而其自有job有独立conhost;v6改从真实job核身份仍仅源码。P1 NativeV2已有Linux析构清理分支,精确profile/案例执行仍未核。检查点v38;P1六门禁仍开放,P2保持8/101,两个完整闭环标志仍为false。
1416

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using System.ComponentModel;
2+
using System.Runtime.InteropServices;
3+
using Microsoft.Win32.SafeHandles;
4+
5+
namespace RustSharp.Compiler.Documentation;
6+
7+
// statx layout and open/AT constants reconciled against actual Ubuntu headers; native production behavior remains subject to full regression.
8+
// An O_PATH descriptor pins the object, so unlink/recreate cannot recycle its inode during publication.
9+
internal sealed partial class DocumentationFileIdentity : IDisposable
10+
{
11+
private readonly DateTime portableBirth;
12+
private readonly SafeFileHandle? handle;
13+
private readonly LinuxSnapshot snapshot;
14+
private DocumentationFileIdentity(DateTime birth) => portableBirth = birth;
15+
private DocumentationFileIdentity(SafeFileHandle descriptor, LinuxSnapshot value) { handle = descriptor; snapshot = value; }
16+
17+
internal static DocumentationFileIdentity Capture(string path)
18+
{
19+
if (!OperatingSystem.IsLinux()) return new(File.GetCreationTimeUtc(path));
20+
SafeFileHandle? owned = null;
21+
try
22+
{
23+
// Linux UAPI: O_PATH | O_NOFOLLOW | O_CLOEXEC. Never follow the final symlink.
24+
int descriptor = Open(path, 0x200000 | 0x20000 | 0x80000);
25+
if (descriptor < 0) throw NativeError("open identity");
26+
owned = new SafeFileHandle((nint)descriptor, ownsHandle: true);
27+
LinuxSnapshot byHandle = Read(descriptor, "", 0x1000 | 0x100);
28+
LinuxSnapshot byPath = Read(-100, path, 0x100 | 0x800);
29+
if (byHandle != byPath) throw new IOException("Publication object changed during identity capture.");
30+
var result = new DocumentationFileIdentity(owned, byHandle);
31+
owned = null;
32+
return result;
33+
}
34+
catch (Exception error) when (error is DllNotFoundException or EntryPointNotFoundException)
35+
{ throw new IOException("Linux stable filesystem identity is unavailable; publication was retained.", error); }
36+
finally { owned?.Dispose(); }
37+
}
38+
39+
internal bool Matches(string path)
40+
{
41+
try
42+
{
43+
if (handle is null) return File.GetCreationTimeUtc(path) == portableBirth;
44+
if (handle.IsClosed || handle.IsInvalid) return false;
45+
bool added = false;
46+
try
47+
{
48+
handle.DangerousAddRef(ref added);
49+
return Read(checked((int)handle.DangerousGetHandle()), "", 0x1000 | 0x100) == snapshot
50+
&& Read(-100, path, 0x100 | 0x800) == snapshot;
51+
}
52+
finally { if (added) handle.DangerousRelease(); }
53+
}
54+
catch (Exception error) when (error is IOException or UnauthorizedAccessException or ObjectDisposedException) { return false; }
55+
}
56+
57+
public void Dispose() => handle?.Dispose();
58+
59+
private static LinuxSnapshot Read(int directory, string path, int flags)
60+
{
61+
const uint required = 0x101; // STATX_TYPE | STATX_INO; device is always returned.
62+
if (Statx(directory, path, flags, 0xFFF, out StatxBuffer data) != 0) throw NativeError("statx identity");
63+
ushort type = (ushort)(data.Mode & 0xF000);
64+
if ((data.Mask & required) != required || type is not (0x4000 or 0x8000)) throw new IOException("Unknown or reparse publication object.");
65+
bool hasBirth = (data.Mask & 0x800) != 0;
66+
// Ignore ctime/mtime: legitimate owned writes change them. Retain available immutable btime.
67+
return new(data.DeviceMajor, data.DeviceMinor, data.Inode, type, hasBirth, hasBirth ? data.BirthSeconds : 0, hasBirth ? data.BirthNanoseconds : 0);
68+
}
69+
70+
private static IOException NativeError(string operation)
71+
{
72+
int error = Marshal.GetLastPInvokeError();
73+
return new IOException(operation + " failed: " + new Win32Exception(error).Message, new Win32Exception(error));
74+
}
75+
76+
private readonly record struct LinuxSnapshot(uint DeviceMajor, uint DeviceMinor, ulong Inode, ushort Type, bool HasBirth, long BirthSeconds, uint BirthNanoseconds);
77+
78+
// Actual Ubuntu /usr/include/linux/stat.h SHA C20889137B96F2A0A3FF3A250842FE226426CB67DCE84A2354B50CAB2AB348E2: 0x100 bytes.
79+
[StructLayout(LayoutKind.Explicit, Size = 256)]
80+
private struct StatxBuffer
81+
{
82+
[FieldOffset(0)] internal uint Mask;
83+
[FieldOffset(28)] internal ushort Mode;
84+
[FieldOffset(32)] internal ulong Inode;
85+
[FieldOffset(80)] internal long BirthSeconds;
86+
[FieldOffset(88)] internal uint BirthNanoseconds;
87+
[FieldOffset(136)] internal uint DeviceMajor;
88+
[FieldOffset(140)] internal uint DeviceMinor;
89+
}
90+
91+
[LibraryImport("libc", EntryPoint = "open", StringMarshalling = StringMarshalling.Utf8, SetLastError = true)]
92+
private static partial int Open(string path, int flags);
93+
[LibraryImport("libc", EntryPoint = "statx", StringMarshalling = StringMarshalling.Utf8, SetLastError = true)]
94+
private static partial int Statx(int directory, string path, int flags, uint mask, out StatxBuffer buffer);
95+
}
96+
// One method scope owns every successful capture, including objects not yet added to the publisher inventory.
97+
// The using declaration disposes after publisher finally/retained-path calculation on every exit path.
98+
internal sealed class DocumentationIdentityScope : IDisposable
99+
{
100+
private readonly List<DocumentationFileIdentity> identities = [];
101+
internal DocumentationFileIdentity Capture(string path)
102+
{
103+
var identity = DocumentationFileIdentity.Capture(path);
104+
try { identities.Add(identity); return identity; }
105+
catch { identity.Dispose(); throw; }
106+
}
107+
public void Dispose()
108+
{
109+
for (int index = identities.Count - 1; index >= 0; index--) identities[index].Dispose();
110+
identities.Clear();
111+
}
112+
}

0 commit comments

Comments
 (0)