-
Notifications
You must be signed in to change notification settings - Fork 8
Add support for NativeAot #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I conducted manual testing based on the FIDOUI program and it looks good. I think it's necessary to enable Github Action for PR |
|
Consider upgrade to net10 for IsAotCompatible assembly metadata support.
|
|
Thanks for the PR, @wu-yafeng . I suspect that migration from |
|
I am not good at the P/Invoke, but I have reviewed some articles and complied some work that needs tobe done to migrate from
Example: [LibraryImport(WebAuthn, EntryPoint = "WebAuthNAuthenticatorMakeCredential")]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static partial HResult AuthenticatorMakeCredential(
WindowHandle windowHandle,
[MarshalUsing(typeof(ReplyingPartyInformationMarshaler))] RelyingPartyInformation rpInformation,
... // other parameter with MarshalUsing
);
[CustomMarshaller(typeof(RelyingPartyInformation), MarshalMode.Default, typeof(ReplyingPartyInformationMarshaler))]
internal static unsafe class ReplyingPartyInformationMarshaler
{
internal static IntPtr ConvertToUnmanaged(RelyingPartyInformation rpInfo)
{
var structure = new WEBAUTHN_RP_ENTITY_INFORMATION()
{
dwVersion = (uint)rpInfo.Version,
pwszIcon = Utf16StringMarshaller.ConvertToUnmanaged(rpInfo.Icon),
pwszId = Utf16StringMarshaller.ConvertToUnmanaged(rpInfo.Id),
pwszName = Utf16StringMarshaller.ConvertToUnmanaged(rpInfo.Name),
};
IntPtr result = Marshal.AllocHGlobal(Marshal.SizeOf<WEBAUTHN_RP_ENTITY_INFORMATION>());
Marshal.StructureToPtr(structure, result, false);
return result;
}
public static void Free(IntPtr ptr)
{
Marshal.FreeHGlobal(ptr);
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
partial struct WEBAUTHN_RP_ENTITY_INFORMATION
{
internal uint dwVersion;
internal ushort* pwszIcon;
internal ushort* pwszId;
internal ushort* pwszName;
}
} |
|
@wu-yafeng You are right. P/Invoke without memory leaks was the hardest thing to implement. Duplicate method signatures are needed as well, see a code snippet from a different project of mine: #if NET7_0_OR_GREATER
[LibraryImport("Advapi.dll", SetLastError = true)]
internal static partial NtStatus LsaClose(IntPtr handle);
#else
[DllImport("Advapi.dll", SetLastError = true)]
internal static extern NtStatus LsaClose(IntPtr handle);
#endif |
NativeAot support #34