-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathSafeProjFsHandle.cs
More file actions
37 lines (35 loc) · 1.51 KB
/
SafeProjFsHandle.cs
File metadata and controls
37 lines (35 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
namespace Microsoft.Windows.ProjFS
{
/// <summary>
/// SafeHandle wrapper for the PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT returned
/// by PrjStartVirtualizing. Guarantees PrjStopVirtualizing is called even
/// during rude app domain unloads, Environment.Exit, or finalizer-only cleanup.
/// </summary>
/// <remarks>
/// <para>
/// SafeHandle is a CriticalFinalizerObject — the CLR guarantees its
/// ReleaseHandle runs after all normal finalizers and during constrained
/// execution regions. This provides the strongest possible guarantee that
/// the ProjFS virtualization root is released, preventing zombie processes.
/// </para>
/// </remarks>
internal sealed class SafeProjFsHandle : SafeHandleZeroOrMinusOneIsInvalid
{
/// <summary>
/// Parameterless constructor required by P/Invoke marshaler for out-parameter usage.
/// </summary>
public SafeProjFsHandle() : base(ownsHandle: true) { }
protected override bool ReleaseHandle()
{
// Must use the raw 'handle' field (IntPtr) here, not 'this'.
// Inside ReleaseHandle, the SafeHandle is already marked as closed —
// passing 'this' to a P/Invoke taking SafeProjFsHandle would fail
// because the marshaler refuses to marshal a closed SafeHandle.
ProjFSNative.PrjStopVirtualizing(handle);
return true;
}
}
}