src: dotnet: fix UnmanagedFunctionPointer delegate lifetime

This commit is contained in:
Bill Zissimopoulos 2017-04-09 21:37:04 -07:00
parent c4b73c8eda
commit aa53b1e5ef
3 changed files with 35 additions and 33 deletions

View File

@ -158,7 +158,7 @@ namespace Fsp
Int32 Result; Int32 Result;
Result = Api.FspFileSystemCreate( Result = Api.FspFileSystemCreate(
_VolumeParams.IsPrefixEmpty() ? "WinFsp.Disk" : "WinFsp.Net", _VolumeParams.IsPrefixEmpty() ? "WinFsp.Disk" : "WinFsp.Net",
ref _VolumeParams, _FileSystemInterface, out _FileSystem); ref _VolumeParams, _FileSystemInterfacePtr, out _FileSystem);
if (0 <= Result) if (0 <= Result)
{ {
Api.SetUserContext(_FileSystem, this); Api.SetUserContext(_FileSystem, this);
@ -1192,38 +1192,37 @@ namespace Fsp
static FileSystem() static FileSystem()
{ {
FileSystemInterface FileSystemInterface; _FileSystemInterface.GetVolumeInfo = GetVolumeInfo;
FileSystemInterface = default(FileSystemInterface); _FileSystemInterface.SetVolumeLabel = SetVolumeLabel;
FileSystemInterface.GetVolumeInfo = GetVolumeInfo; _FileSystemInterface.GetSecurityByName = GetSecurityByName;
FileSystemInterface.SetVolumeLabel = SetVolumeLabel; _FileSystemInterface.Create = Create;
FileSystemInterface.GetSecurityByName = GetSecurityByName; _FileSystemInterface.Open = Open;
FileSystemInterface.Create = Create; _FileSystemInterface.Overwrite = Overwrite;
FileSystemInterface.Open = Open; _FileSystemInterface.Cleanup = Cleanup;
FileSystemInterface.Overwrite = Overwrite; _FileSystemInterface.Close = Close;
FileSystemInterface.Cleanup = Cleanup; _FileSystemInterface.Read = Read;
FileSystemInterface.Close = Close; _FileSystemInterface.Write = Write;
FileSystemInterface.Read = Read; _FileSystemInterface.Flush = Flush;
FileSystemInterface.Write = Write; _FileSystemInterface.GetFileInfo = GetFileInfo;
FileSystemInterface.Flush = Flush; _FileSystemInterface.SetBasicInfo = SetBasicInfo;
FileSystemInterface.GetFileInfo = GetFileInfo; _FileSystemInterface.SetFileSize = SetFileSize;
FileSystemInterface.SetBasicInfo = SetBasicInfo; _FileSystemInterface.CanDelete = CanDelete;
FileSystemInterface.SetFileSize = SetFileSize; _FileSystemInterface.Rename = Rename;
FileSystemInterface.CanDelete = CanDelete; _FileSystemInterface.GetSecurity = GetSecurity;
FileSystemInterface.Rename = Rename; _FileSystemInterface.SetSecurity = SetSecurity;
FileSystemInterface.GetSecurity = GetSecurity; _FileSystemInterface.ReadDirectory = ReadDirectory;
FileSystemInterface.SetSecurity = SetSecurity; _FileSystemInterface.ResolveReparsePoints = ResolveReparsePoints;
FileSystemInterface.ReadDirectory = ReadDirectory; _FileSystemInterface.GetReparsePoint = GetReparsePoint;
FileSystemInterface.ResolveReparsePoints = ResolveReparsePoints; _FileSystemInterface.SetReparsePoint = SetReparsePoint;
FileSystemInterface.GetReparsePoint = GetReparsePoint; _FileSystemInterface.DeleteReparsePoint = DeleteReparsePoint;
FileSystemInterface.SetReparsePoint = SetReparsePoint; _FileSystemInterface.GetStreamInfo = GetStreamInfo;
FileSystemInterface.DeleteReparsePoint = DeleteReparsePoint;
FileSystemInterface.GetStreamInfo = GetStreamInfo;
_FileSystemInterface = Marshal.AllocHGlobal(Marshal.SizeOf(FileSystemInterface)); _FileSystemInterfacePtr = Marshal.AllocHGlobal(FileSystemInterface.Size);
Marshal.StructureToPtr(FileSystemInterface, _FileSystemInterface, false); Marshal.StructureToPtr(_FileSystemInterface, _FileSystemInterfacePtr, false);
} }
private static IntPtr _FileSystemInterface; private static FileSystemInterface _FileSystemInterface;
private static IntPtr _FileSystemInterfacePtr;
private VolumeParams _VolumeParams; private VolumeParams _VolumeParams;
private IntPtr _FileSystem; private IntPtr _FileSystem;
} }

View File

@ -374,6 +374,8 @@ namespace Fsp.Interop
out UInt32 PBytesTransferred); out UInt32 PBytesTransferred);
} }
internal static int Size = IntPtr.Size * 64;
internal Proto.GetVolumeInfo GetVolumeInfo; internal Proto.GetVolumeInfo GetVolumeInfo;
internal Proto.SetVolumeLabel SetVolumeLabel; internal Proto.SetVolumeLabel SetVolumeLabel;
internal Proto.GetSecurityByName GetSecurityByName; internal Proto.GetSecurityByName GetSecurityByName;
@ -398,7 +400,6 @@ namespace Fsp.Interop
internal Proto.SetReparsePoint SetReparsePoint; internal Proto.SetReparsePoint SetReparsePoint;
internal Proto.DeleteReparsePoint DeleteReparsePoint; internal Proto.DeleteReparsePoint DeleteReparsePoint;
internal Proto.GetStreamInfo GetStreamInfo; internal Proto.GetStreamInfo GetStreamInfo;
internal unsafe fixed long/*IntPtr*/ Reserved[40];
/* NTSTATUS (*Reserved[40])(); */ /* NTSTATUS (*Reserved[40])(); */
} }

View File

@ -33,7 +33,7 @@ namespace Fsp
/* ctor/dtor */ /* ctor/dtor */
public Service(String ServiceName) public Service(String ServiceName)
{ {
Api.FspServiceCreate(ServiceName, OnStart, OnStop, null, out _Service); Api.FspServiceCreate(ServiceName, _OnStart, _OnStop, null, out _Service);
if (IntPtr.Zero != _Service) if (IntPtr.Zero != _Service)
Api.SetUserContext(_Service, this); Api.SetUserContext(_Service, this);
} }
@ -150,6 +150,8 @@ namespace Fsp
} }
} }
private static Api.Proto.ServiceStart _OnStart = OnStart;
private static Api.Proto.ServiceStop _OnStop = OnStop;
private IntPtr _Service; private IntPtr _Service;
} }