src: dotnet: WIP

This commit is contained in:
Bill Zissimopoulos
2017-04-02 22:40:43 -07:00
parent fa9ff37de9
commit f2391d99d5
2 changed files with 35 additions and 6 deletions

View File

@ -16,6 +16,7 @@
*/
using System;
using System.Diagnostics;
using System.Security.AccessControl;
using System.Runtime.InteropServices;
using System.Security;
@ -409,6 +410,32 @@ namespace Fsp.Interop
else
return FspFileSystemSetMountPointEx(FileSystem, MountPoint, IntPtr.Zero);
}
internal unsafe static Object FspFileSystemGetUserContext(
IntPtr FileSystem)
{
IntPtr UserContext = Marshal.ReadIntPtr(FileSystem, sizeof(IntPtr));
return IntPtr.Zero != UserContext ? ((GCHandle)UserContext).Target : null;
}
internal unsafe static void FspFileSystemSetUserContext(
IntPtr FileSystem,
Object Obj)
{
if (null != Obj)
{
Debug.Assert(IntPtr.Zero == Marshal.ReadIntPtr(FileSystem, sizeof(IntPtr)));
GCHandle Handle = GCHandle.Alloc(Obj, GCHandleType.Weak);
Marshal.WriteIntPtr(FileSystem, sizeof(IntPtr), (IntPtr)Handle);
}
else
{
IntPtr UserContext = Marshal.ReadIntPtr(FileSystem, sizeof(IntPtr));
if (IntPtr.Zero != UserContext)
{
((GCHandle)UserContext).Free();
Marshal.WriteIntPtr(FileSystem, sizeof(IntPtr), IntPtr.Zero);
}
}
}
/* initialization */
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]