diff --git a/src/AudioUnit/AUGraph.cs b/src/AudioUnit/AUGraph.cs index 494789b5985f..2f5ae9b8300c 100644 --- a/src/AudioUnit/AUGraph.cs +++ b/src/AudioUnit/AUGraph.cs @@ -362,7 +362,7 @@ public AUGraphError SetNodeInputCallback (int destNode, uint destInputNumber, Re cb.Proc = &RenderCallbackImpl; } #else - cb.Proc = CreateRenderCallback; + cb.Proc = Marshal.GetFunctionPointerForDelegate (CreateRenderCallback); #endif cb.ProcRefCon = GCHandle.ToIntPtr (gcHandle); return AUGraphSetNodeInputCallback (Handle, destNode, destInputNumber, ref cb); diff --git a/src/AudioUnit/AUScheduledAudioFileRegion.cs b/src/AudioUnit/AUScheduledAudioFileRegion.cs index 84bf85320021..78d1ae5c285d 100644 --- a/src/AudioUnit/AUScheduledAudioFileRegion.cs +++ b/src/AudioUnit/AUScheduledAudioFileRegion.cs @@ -35,7 +35,7 @@ internal struct ScheduledAudioFileRegion { #if NET public unsafe delegate* unmanaged CompletionHandler; #else - public ScheduledAudioFileRegionCompletionHandler CompletionHandler; + public IntPtr CompletionHandler; #endif public /* void * */ IntPtr CompletionHandlerUserData; public IntPtr AudioFile; @@ -113,7 +113,7 @@ internal ScheduledAudioFileRegion GetAudioFileRegion () #if NET ret.CompletionHandler = &ScheduledAudioFileRegionCallback; #else - ret.CompletionHandler = static_ScheduledAudioFileRegionCompletionHandler; + ret.CompletionHandler = Marshal.GetFunctionPointerForDelegate (static_ScheduledAudioFileRegionCompletionHandler); #endif } } diff --git a/src/AudioUnit/AudioUnit.cs b/src/AudioUnit/AudioUnit.cs index c34ab013c01d..cd9fe298d635 100644 --- a/src/AudioUnit/AudioUnit.cs +++ b/src/AudioUnit/AudioUnit.cs @@ -39,6 +39,7 @@ using System.Collections; using System.Collections.Generic; using System.Text; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; using AudioToolbox; @@ -147,7 +148,7 @@ unsafe struct AURenderCallbackStruct #else [StructLayout (LayoutKind.Sequential)] struct AURenderCallbackStruct { - public Delegate Proc; + public IntPtr Proc; public IntPtr ProcRefCon; } #endif @@ -371,7 +372,11 @@ static IntPtr Create (AudioComponent component) if (component is null) ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (component)); - var err = AudioComponentInstanceNew (component.GetCheckedHandle (), out var handle); + IntPtr handle; + AudioUnitStatus err; + unsafe { + err = AudioComponentInstanceNew (component.GetCheckedHandle (), &handle); + } if (err != 0) throw new AudioUnitException (err); @@ -394,26 +399,26 @@ public AudioComponent Component { #if !XAMCORE_3_0 [Obsolete ("Use 'SetFormat' instead as it has the ability of returning a status code.")] - public void SetAudioFormat (AudioToolbox.AudioStreamBasicDescription audioFormat, AudioUnitScopeType scope, uint audioUnitElement = 0) + public unsafe void SetAudioFormat (AudioToolbox.AudioStreamBasicDescription audioFormat, AudioUnitScopeType scope, uint audioUnitElement = 0) { var err = AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.StreamFormat, scope, audioUnitElement, - ref audioFormat, + &audioFormat, (uint) Marshal.SizeOf ()); if (err != 0) throw new AudioUnitException (err); } #endif - public AudioUnitStatus SetFormat (AudioToolbox.AudioStreamBasicDescription audioFormat, AudioUnitScopeType scope, uint audioUnitElement = 0) + public unsafe AudioUnitStatus SetFormat (AudioToolbox.AudioStreamBasicDescription audioFormat, AudioUnitScopeType scope, uint audioUnitElement = 0) { return (AudioUnitStatus) AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.StreamFormat, scope, audioUnitElement, - ref audioFormat, + &audioFormat, (uint) Marshal.SizeOf ()); } @@ -421,12 +426,15 @@ public uint GetCurrentDevice (AudioUnitScopeType scope, uint audioUnitElement = { uint device = 0; int size = sizeof (uint); - var err = AudioUnitGetProperty (Handle, + AudioUnitStatus err; + unsafe { + err = AudioUnitGetProperty (Handle, AudioUnitPropertyIDType.CurrentDevice, scope, audioUnitElement, - ref device, - ref size); + &device, + &size); + } if (err != 0) throw new AudioUnitException ((int) err); return device; @@ -452,7 +460,7 @@ public static uint GetCurrentInputDevice () // See Listing 4 New - Getting the default input device. // https://developer.apple.com/library/mac/technotes/tn2223/_index.html - uint inputDevice; + uint inputDevice = 0; uint size = (uint) sizeof (uint); var theAddress = new AudioObjectPropertyAddress ( AudioObjectPropertySelector.DefaultInputDevice, @@ -461,7 +469,10 @@ public static uint GetCurrentInputDevice () uint inQualifierDataSize = 0; IntPtr inQualifierData = IntPtr.Zero; - var err = AudioObjectGetPropertyData (1, ref theAddress, ref inQualifierDataSize, ref inQualifierData, ref size, out inputDevice); + int err; + unsafe { + err = AudioObjectGetPropertyData (1, &theAddress, &inQualifierDataSize, &inQualifierData, &size, &inputDevice); + } if (err != 0) throw new AudioUnitException ((int) err); @@ -471,13 +482,13 @@ public static uint GetCurrentInputDevice () #endif } #endif - public AudioUnitStatus SetCurrentDevice (uint inputDevice, AudioUnitScopeType scope, uint audioUnitElement = 0) + public unsafe AudioUnitStatus SetCurrentDevice (uint inputDevice, AudioUnitScopeType scope, uint audioUnitElement = 0) { return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.CurrentDevice, scope, audioUnitElement, - ref inputDevice, + &inputDevice, (uint) sizeof (uint)); } @@ -486,12 +497,15 @@ public AudioStreamBasicDescription GetAudioFormat (AudioUnitScopeType scope, uin var audioFormat = new AudioStreamBasicDescription (); uint size = (uint) Marshal.SizeOf (); - var err = AudioUnitGetProperty (Handle, + AudioUnitStatus err; + unsafe { + err = AudioUnitGetProperty (Handle, AudioUnitPropertyIDType.StreamFormat, scope, audioUnitElement, - ref audioFormat, - ref size); + &audioFormat, + &size); + } if (err != 0) throw new AudioUnitException ((int) err); @@ -502,8 +516,15 @@ public AudioStreamBasicDescription GetAudioFormat (AudioUnitScopeType scope, uin { IntPtr ptr = new IntPtr (); int size = IntPtr.Size; - var res = AudioUnitGetProperty (Handle, AudioUnitPropertyIDType.ClassInfo, scope, audioUnitElement, - ref ptr, ref size); + AudioUnitStatus res; + unsafe { + res = AudioUnitGetProperty (Handle, + AudioUnitPropertyIDType.ClassInfo, + scope, + audioUnitElement, + &ptr, + &size); + } if (res != 0) return null; @@ -514,21 +535,23 @@ public AudioStreamBasicDescription GetAudioFormat (AudioUnitScopeType scope, uin public AudioUnitStatus SetClassInfo (ClassInfoDictionary preset, AudioUnitScopeType scope = AudioUnitScopeType.Global, uint audioUnitElement = 0) { var ptr = preset.Dictionary.Handle; - return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.ClassInfo, scope, audioUnitElement, - ref ptr, IntPtr.Size); + unsafe { + return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.ClassInfo, scope, audioUnitElement, + &ptr, IntPtr.Size); + } } public unsafe AudioUnitParameterInfo []? GetParameterList (AudioUnitScopeType scope = AudioUnitScopeType.Global, uint audioUnitElement = 0) { uint size; - bool writable; - if (AudioUnitGetPropertyInfo (Handle, AudioUnitPropertyIDType.ParameterList, scope, audioUnitElement, out size, out writable) != 0) + byte writable; + if (AudioUnitGetPropertyInfo (Handle, AudioUnitPropertyIDType.ParameterList, scope, audioUnitElement, &size, &writable) != 0) return null; // Array of AudioUnitParameterID = UInt32 var data = new uint [size / sizeof (uint)]; fixed (uint* ptr = data) { - if (AudioUnitGetProperty (Handle, AudioUnitPropertyIDType.ParameterList, scope, audioUnitElement, ptr, ref size) != 0) + if (AudioUnitGetProperty (Handle, AudioUnitPropertyIDType.ParameterList, scope, audioUnitElement, ptr, &size) != 0) return null; } @@ -537,7 +560,7 @@ public AudioUnitStatus SetClassInfo (ClassInfoDictionary preset, AudioUnitScopeT for (int i = 0; i < data.Length; ++i) { var native = new AudioUnitParameterInfoNative (); - if (AudioUnitGetProperty (Handle, AudioUnitPropertyIDType.ParameterInfo, scope, data [i], ref native, ref size) != 0) + if (AudioUnitGetProperty (Handle, AudioUnitPropertyIDType.ParameterInfo, scope, data [i], &native, &size) != 0) return null; info [i] = AudioUnitParameterInfo.Create (native, (AudioUnitParameterType) data [i]); @@ -552,8 +575,10 @@ public AudioUnitStatus LoadInstrument (SamplerInstrumentData instrumentData, Aud ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (instrumentData)); var data = instrumentData.ToStruct (); - return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.LoadInstrument, scope, audioUnitElement, - ref data, Marshal.SizeOf ()); + unsafe { + return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.LoadInstrument, scope, audioUnitElement, + &data, Marshal.SizeOf ()); + } } public AudioUnitStatus MakeConnection (AudioUnit sourceAudioUnit, uint sourceOutputNumber, uint destInputNumber) @@ -564,20 +589,26 @@ public AudioUnitStatus MakeConnection (AudioUnit sourceAudioUnit, uint sourceOut DestInputNumber = destInputNumber }; - return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.MakeConnection, AudioUnitScopeType.Input, 0, ref auc, Marshal.SizeOf ()); + unsafe { + return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.MakeConnection, AudioUnitScopeType.Input, 0, &auc, Marshal.SizeOf ()); + } } public AudioUnitStatus SetEnableIO (bool enableIO, AudioUnitScopeType scope, uint audioUnitElement = 0) { // EnableIO: UInt32 uint flag = enableIO ? (uint) 1 : 0; - return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.EnableIO, scope, audioUnitElement, ref flag, sizeof (uint)); + unsafe { + return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.EnableIO, scope, audioUnitElement, &flag, sizeof (uint)); + } } public AudioUnitStatus SetMaximumFramesPerSlice (uint value, AudioUnitScopeType scope, uint audioUnitElement = 0) { // MaximumFramesPerSlice: UInt32 - return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.MaximumFramesPerSlice, scope, audioUnitElement, ref value, sizeof (uint)); + unsafe { + return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.MaximumFramesPerSlice, scope, audioUnitElement, &value, sizeof (uint)); + } } public uint GetMaximumFramesPerSlice (AudioUnitScopeType scope = AudioUnitScopeType.Global, uint audioUnitElement = 0) @@ -585,8 +616,15 @@ public uint GetMaximumFramesPerSlice (AudioUnitScopeType scope = AudioUnitScopeT // MaximumFramesPerSlice: UInt32 uint value = 0; uint size = sizeof (uint); - var res = AudioUnitGetProperty (Handle, AudioUnitPropertyIDType.MaximumFramesPerSlice, scope, - audioUnitElement, ref value, ref size); + AudioUnitStatus res; + unsafe { + res = AudioUnitGetProperty (Handle, + AudioUnitPropertyIDType.MaximumFramesPerSlice, + scope, + audioUnitElement, + &value, + &size); + } if (res != 0) throw new AudioUnitException ((int) res); @@ -597,7 +635,9 @@ public uint GetMaximumFramesPerSlice (AudioUnitScopeType scope = AudioUnitScopeT public AudioUnitStatus SetElementCount (AudioUnitScopeType scope, uint count) { // ElementCount: UInt32 - return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.ElementCount, scope, 0, ref count, sizeof (uint)); + unsafe { + return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.ElementCount, scope, 0, &count, sizeof (uint)); + } } public uint GetElementCount (AudioUnitScopeType scope) @@ -605,8 +645,15 @@ public uint GetElementCount (AudioUnitScopeType scope) // ElementCount: UInt32 uint value = 0; uint size = sizeof (uint); - var res = AudioUnitGetProperty (Handle, AudioUnitPropertyIDType.ElementCount, scope, - 0, ref value, ref size); + AudioUnitStatus res; + unsafe { + res = AudioUnitGetProperty (Handle, + AudioUnitPropertyIDType.ElementCount, + scope, + 0, + &value, + &size); + } if (res != 0) throw new AudioUnitException ((int) res); @@ -617,7 +664,9 @@ public uint GetElementCount (AudioUnitScopeType scope) public AudioUnitStatus SetSampleRate (double sampleRate, AudioUnitScopeType scope = AudioUnitScopeType.Output, uint audioUnitElement = 0) { // ElementCount: Float64 - return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.SampleRate, scope, 0, ref sampleRate, sizeof (double)); + unsafe { + return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.SampleRate, scope, 0, &sampleRate, sizeof (double)); + } } public AudioUnitStatus MusicDeviceMIDIEvent (uint status, uint data1, uint data2, uint offsetSampleFrame = 0) @@ -634,13 +683,16 @@ public AudioUnitStatus SetLatency (double latency) #endif [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitGetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, ref double outData, ref uint ioDataSize); + unsafe static extern AudioUnitStatus AudioUnitGetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, double* outData, uint* ioDataSize); public double GetLatency () { uint size = sizeof (double); double latency = 0; - var err = AudioUnitGetProperty (Handle, AudioUnitPropertyIDType.Latency, AudioUnitScopeType.Global, 0, ref latency, ref size); + AudioUnitStatus err; + unsafe { + err = AudioUnitGetProperty (Handle, AudioUnitPropertyIDType.Latency, AudioUnitScopeType.Global, 0, &latency, &size); + } if (err != 0) throw new AudioUnitException ((int) err); return latency; @@ -659,15 +711,15 @@ public AudioUnitStatus SetRenderCallback (RenderDelegate renderDelegate, AudioUn gcHandle = GCHandle.Alloc (this); var cb = new AURenderCallbackStruct (); -#if NET unsafe { +#if NET cb.Proc = &RenderCallbackImpl; - } #else - cb.Proc = CreateRenderCallback; + cb.Proc = Marshal.GetFunctionPointerForDelegate (CreateRenderCallback); #endif - cb.ProcRefCon = GCHandle.ToIntPtr (gcHandle); - return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.SetRenderCallback, scope, audioUnitElement, ref cb, Marshal.SizeOf ()); + cb.ProcRefCon = GCHandle.ToIntPtr (gcHandle); + return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.SetRenderCallback, scope, audioUnitElement, &cb, Marshal.SizeOf ()); + } } #if NET @@ -713,15 +765,15 @@ public AudioUnitStatus SetInputCallback (InputDelegate inputDelegate, AudioUnitS gcHandle = GCHandle.Alloc (this); var cb = new AURenderCallbackStruct (); -#if NET unsafe { +#if NET cb.Proc = &InputCallbackImpl; - } #else - cb.Proc = CreateInputCallback; + cb.Proc = Marshal.GetFunctionPointerForDelegate (CreateInputCallback); #endif - cb.ProcRefCon = GCHandle.ToIntPtr (gcHandle); - return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.SetInputCallback, scope, audioUnitElement, ref cb, Marshal.SizeOf ()); + cb.ProcRefCon = GCHandle.ToIntPtr (gcHandle); + return AudioUnitSetProperty (Handle, AudioUnitPropertyIDType.SetInputCallback, scope, audioUnitElement, &cb, Marshal.SizeOf ()); + } } #if NET [UnmanagedCallersOnly] @@ -897,7 +949,15 @@ public AudioUnitStatus Render (ref AudioUnitRenderActionFlags actionFlags, Audio { if ((IntPtr) data == IntPtr.Zero) ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (data)); - return AudioUnitRender (Handle, ref actionFlags, ref timeStamp, busNumber, numberFrames, (IntPtr) data); + unsafe { + return AudioUnitRender ( + Handle, + (AudioUnitRenderActionFlags*) Unsafe.AsPointer (ref actionFlags), + &timeStamp, + busNumber, + numberFrames, + (IntPtr) data); + } } #endregion @@ -927,8 +987,8 @@ protected override void Dispose (bool disposing) base.Dispose (disposing); } - [DllImport (Constants.AudioUnitLibrary, EntryPoint = "AudioComponentInstanceNew")] - static extern AudioUnitStatus AudioComponentInstanceNew (IntPtr inComponent, out IntPtr inDesc); + [DllImport (Constants.AudioUnitLibrary)] + unsafe static extern AudioUnitStatus AudioComponentInstanceNew (IntPtr inComponent, IntPtr* inDesc); [DllImport (Constants.AudioUnitLibrary)] static extern IntPtr AudioComponentInstanceGetComponent (IntPtr inComponent); @@ -946,82 +1006,72 @@ protected override void Dispose (bool disposing) static extern AudioUnitStatus AudioOutputUnitStop (IntPtr ci); [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitRender (IntPtr inUnit, ref AudioUnitRenderActionFlags ioActionFlags, ref AudioTimeStamp inTimeStamp, + unsafe static extern AudioUnitStatus AudioUnitRender (IntPtr inUnit, AudioUnitRenderActionFlags* ioActionFlags, AudioTimeStamp* inTimeStamp, uint inOutputBusNumber, uint inNumberFrames, IntPtr ioData); [DllImport (Constants.AudioUnitLibrary)] - static extern int AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref AudioStreamBasicDescription inData, + unsafe static extern int AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + AudioStreamBasicDescription* inData, uint inDataSize); [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref uint inData, uint inDataSize); + unsafe static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + uint* inData, uint inDataSize); [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref double inData, uint inDataSize); + unsafe static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + double* inData, uint inDataSize); [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref IntPtr inData, int inDataSize); + unsafe static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + IntPtr* inData, int inDataSize); #if NET [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref NativeHandle inData, int inDataSize); + unsafe static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + NativeHandle* inData, int inDataSize); #endif [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref AURenderCallbackStruct inData, int inDataSize); + unsafe static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + AURenderCallbackStruct* inData, int inDataSize); [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref AudioUnitConnection inData, int inDataSize); + unsafe static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + AudioUnitConnection* inData, int inDataSize); [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref AUSamplerInstrumentData inData, int inDataSize); + unsafe static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + AUSamplerInstrumentData* inData, int inDataSize); [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitGetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref AudioStreamBasicDescription outData, - ref uint ioDataSize); + unsafe static extern AudioUnitStatus AudioUnitGetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + AudioStreamBasicDescription* outData, + uint* ioDataSize); [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitGetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref IntPtr outData, - ref int ioDataSize); + unsafe static extern AudioUnitStatus AudioUnitGetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + IntPtr* outData, + int* ioDataSize); [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitGetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref uint outData, - ref int ioDataSize); + unsafe static extern AudioUnitStatus AudioUnitGetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + uint* outData, + int* ioDataSize); [DllImport (Constants.AudioUnitLibrary)] static extern unsafe AudioUnitStatus AudioUnitGetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, uint* outData, - ref uint ioDataSize); + uint* ioDataSize); [DllImport (Constants.AudioUnitLibrary)] static extern unsafe AudioUnitStatus AudioUnitGetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref AudioUnitParameterInfoNative outData, - ref uint ioDataSize); - - [DllImport (Constants.AudioUnitLibrary)] - static extern int AudioUnitGetProperty (IntPtr inUnit, - [MarshalAs (UnmanagedType.U4)] AudioUnitPropertyIDType inID, - [MarshalAs (UnmanagedType.U4)] AudioUnitScopeType inScope, - [MarshalAs (UnmanagedType.U4)] uint inElement, - ref uint flag, - ref uint ioDataSize - ); - + AudioUnitParameterInfoNative* outData, + uint* ioDataSize); [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitGetPropertyInfo (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - out uint outDataSize, [MarshalAs (UnmanagedType.I1)] out bool outWritable); + unsafe static extern AudioUnitStatus AudioUnitGetPropertyInfo (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + uint* outDataSize, byte* outWritable); [DllImport (Constants.AudioUnitLibrary)] static extern AudioUnitStatus AudioUnitSetParameter (IntPtr inUnit, AudioUnitParameterType inID, AudioUnitScopeType inScope, @@ -1038,13 +1088,13 @@ static extern AudioUnitStatus AudioUnitSetParameter (IntPtr inUnit, AudioUnitPar [MacCatalyst (15,0)] #endif [DllImport (Constants.CoreAudioLibrary)] - static extern int AudioObjectGetPropertyData ( + unsafe static extern int AudioObjectGetPropertyData ( uint inObjectID, - ref AudioObjectPropertyAddress inAddress, - ref uint inQualifierDataSize, - ref IntPtr inQualifierData, - ref uint ioDataSize, - out uint outData + AudioObjectPropertyAddress* inAddress, + uint* inQualifierDataSize, + IntPtr* inQualifierData, + uint* ioDataSize, + uint* outData ); #endif // MONOMAC [DllImport (Constants.AudioUnitLibrary)] @@ -1056,8 +1106,8 @@ out uint outData // static extern MusicDeviceMIDIEvent[] MusicDeviceMIDIEventList (IntPtr /* MusicDeviceComponent = void* */ inUnit, uint /* UInt32 */ inOffsetSampleFrame, MIDIEventList eventList); [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref AUScheduledAudioFileRegion.ScheduledAudioFileRegion inData, int inDataSize); + unsafe static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + AUScheduledAudioFileRegion.ScheduledAudioFileRegion* inData, int inDataSize); public AudioUnitStatus SetScheduledFileRegion (AUScheduledAudioFileRegion region) { @@ -1065,16 +1115,20 @@ public AudioUnitStatus SetScheduledFileRegion (AUScheduledAudioFileRegion region ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (region)); var safr = region.GetAudioFileRegion (); - return AudioUnitSetProperty (GetCheckedHandle (), AudioUnitPropertyIDType.ScheduledFileRegion, AudioUnitScopeType.Global, 0, ref safr, Marshal.SizeOf ()); + unsafe { + return AudioUnitSetProperty (GetCheckedHandle (), AudioUnitPropertyIDType.ScheduledFileRegion, AudioUnitScopeType.Global, 0, &safr, Marshal.SizeOf ()); + } } [DllImport (Constants.AudioUnitLibrary)] - static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, - ref AudioTimeStamp inData, int inDataSize); + unsafe static extern AudioUnitStatus AudioUnitSetProperty (IntPtr inUnit, AudioUnitPropertyIDType inID, AudioUnitScopeType inScope, uint inElement, + AudioTimeStamp* inData, int inDataSize); public AudioUnitStatus SetScheduleStartTimeStamp (AudioTimeStamp timeStamp) { - return AudioUnitSetProperty (GetCheckedHandle (), AudioUnitPropertyIDType.ScheduleStartTimeStamp, AudioUnitScopeType.Global, 0, ref timeStamp, Marshal.SizeOf ()); + unsafe { + return AudioUnitSetProperty (GetCheckedHandle (), AudioUnitPropertyIDType.ScheduleStartTimeStamp, AudioUnitScopeType.Global, 0, &timeStamp, Marshal.SizeOf ()); + } } public AudioUnitStatus SetScheduledFiles (AudioFile audioFile) @@ -1083,7 +1137,9 @@ public AudioUnitStatus SetScheduledFiles (AudioFile audioFile) ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (audioFile)); var audioFilehandle = audioFile.Handle; - return AudioUnitSetProperty (GetCheckedHandle (), AudioUnitPropertyIDType.ScheduledFileIDs, AudioUnitScopeType.Global, 0, ref audioFilehandle, Marshal.SizeOf ()); + unsafe { + return AudioUnitSetProperty (GetCheckedHandle (), AudioUnitPropertyIDType.ScheduledFileIDs, AudioUnitScopeType.Global, 0, &audioFilehandle, Marshal.SizeOf ()); + } } [DllImport (Constants.AudioUnitLibrary)] diff --git a/src/Security/Authorization.cs b/src/Security/Authorization.cs index 3bf7bd6791ec..bbf35e7f7305 100644 --- a/src/Security/Authorization.cs +++ b/src/Security/Authorization.cs @@ -151,7 +151,7 @@ unsafe struct AuthorizationItemSet { #endif public unsafe class Authorization : DisposableObject { [DllImport (Constants.SecurityLibrary)] - extern static int /* OSStatus = int */ AuthorizationCreate (AuthorizationItemSet *rights, AuthorizationItemSet *environment, AuthorizationFlags flags, out IntPtr auth); + unsafe extern static int /* OSStatus = int */ AuthorizationCreate (AuthorizationItemSet *rights, AuthorizationItemSet *environment, AuthorizationFlags flags, IntPtr* auth); #if NET [SupportedOSPlatform ("maccatalyst15.0")] @@ -272,7 +272,7 @@ static void EncodeString (ref AuthorizationItem item, string key, string? value) EncodeString (ref env.ptrToAuthorization [env.count++], "prompt", parameters.Prompt); } } - code = AuthorizationCreate (ppars, penv, flags, out auth); + code = AuthorizationCreate (ppars, penv, flags, &auth); if (code != 0) return null; return new Authorization (auth, true); diff --git a/src/Security/ImportExport.cs b/src/Security/ImportExport.cs index 3110eeccaa94..c0af9ae4f19c 100644 --- a/src/Security/ImportExport.cs +++ b/src/Security/ImportExport.cs @@ -39,7 +39,7 @@ namespace Security { public partial class SecImportExport { [DllImport (Constants.SecurityLibrary)] - extern static SecStatusCode SecPKCS12Import (IntPtr pkcs12_data, IntPtr options, out IntPtr items); + unsafe extern static SecStatusCode SecPKCS12Import (IntPtr pkcs12_data, IntPtr options, IntPtr* items); static public SecStatusCode ImportPkcs12 (byte [] buffer, NSDictionary options, out NSDictionary [] array) { @@ -54,7 +54,10 @@ static public SecStatusCode ImportPkcs12 (NSData data, NSDictionary options, out ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (options)); IntPtr handle; - SecStatusCode code = SecPKCS12Import (data.Handle, options.Handle, out handle); + SecStatusCode code; + unsafe { + code = SecPKCS12Import (data.Handle, options.Handle, &handle); + } array = NSArray.ArrayFromHandle (handle); NSObject.DangerousRelease (handle); return code; diff --git a/src/Security/Items.cs b/src/Security/Items.cs index e98d9a6b8865..61313d88bb4c 100644 --- a/src/Security/Items.cs +++ b/src/Security/Items.cs @@ -35,6 +35,7 @@ using System; using System.Collections; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using CoreFoundation; using Foundation; @@ -322,14 +323,14 @@ extern static SecStatusCode SecKeychainAddGenericPassword ( [Deprecated (PlatformName.MacOSX, 10,10)] #endif [DllImport (Constants.SecurityLibrary)] - extern static SecStatusCode SecKeychainFindGenericPassword ( + unsafe extern static SecStatusCode SecKeychainFindGenericPassword ( IntPtr keychainOrArray, int serviceNameLength, - byte[]? serviceName, + byte* serviceName, int accountNameLength, - byte[]? accountName, - out int passwordLength, - out IntPtr passwordData, + byte* accountName, + int* passwordLength, + IntPtr* passwordData, IntPtr itemRef); #if NET @@ -361,21 +362,21 @@ extern static SecStatusCode SecKeychainAddInternetPassword ( [Deprecated (PlatformName.MacOSX, 10,10)] #endif [DllImport (Constants.SecurityLibrary)] - extern static SecStatusCode SecKeychainFindInternetPassword ( + unsafe extern static SecStatusCode SecKeychainFindInternetPassword ( IntPtr keychain, int serverNameLength, - byte[]? serverName, + byte* serverName, int securityDomainLength, - byte[]? securityDomain, + byte* securityDomain, int accountNameLength, - byte[]? accountName, + byte* accountName, int pathLength, - byte[]? path, + byte* path, short port, IntPtr protocol, IntPtr authenticationType, - out int passwordLength, - out IntPtr passwordData, + int* passwordLength, + IntPtr* passwordData, IntPtr itemRef); #if NET @@ -466,22 +467,33 @@ public static SecStatusCode FindInternetPassword( int passwordLength = 0; - SecStatusCode code = SecKeychainFindInternetPassword( - IntPtr.Zero, - serverBytes?.Length ?? 0, - serverBytes, - securityDomainBytes?.Length ?? 0, - securityDomainBytes, - accountNameBytes?.Length ?? 0, - accountNameBytes, - pathBytes?.Length ?? 0, - pathBytes, - port, - SecProtocolKeys.FromSecProtocol(protocolType), - KeysAuthenticationType.FromSecAuthenticationType(authenticationType), - out passwordLength, - out passwordPtr, - IntPtr.Zero); + SecStatusCode code; + unsafe { + fixed (byte* serverBytesPtr = serverBytes) { + fixed (byte* securityDomainBytesPtr = securityDomainBytes) { + fixed (byte* accountNameBytesPtr = accountNameBytes) { + fixed (byte* pathBytesPtr = pathBytes) { + code = SecKeychainFindInternetPassword( + IntPtr.Zero, + serverBytes?.Length ?? 0, + serverBytesPtr, + securityDomainBytes?.Length ?? 0, + securityDomainBytesPtr, + accountNameBytes?.Length ?? 0, + accountNameBytesPtr, + pathBytes?.Length ?? 0, + pathBytesPtr, + port, + SecProtocolKeys.FromSecProtocol(protocolType), + KeysAuthenticationType.FromSecAuthenticationType(authenticationType), + &passwordLength, + &passwordPtr, + IntPtr.Zero); + } + } + } + } + } if (code == SecStatusCode.Success && passwordLength > 0) { password = new byte[passwordLength]; @@ -538,16 +550,23 @@ public static SecStatusCode FindGenericPassword (string serviceName, string acco int passwordLength = 0; - var code = SecKeychainFindGenericPassword( - IntPtr.Zero, - serviceNameBytes?.Length ?? 0, - serviceNameBytes, - accountNameBytes?.Length ?? 0, - accountNameBytes, - out passwordLength, - out passwordPtr, - IntPtr.Zero - ); + SecStatusCode code; + unsafe { + fixed (byte* serviceNameBytesPtr = serviceNameBytes) { + fixed (byte* accountNameBytesPtr = accountNameBytes) { + code = SecKeychainFindGenericPassword( + IntPtr.Zero, + serviceNameBytes?.Length ?? 0, + serviceNameBytesPtr, + accountNameBytes?.Length ?? 0, + accountNameBytesPtr, + &passwordLength, + &passwordPtr, + IntPtr.Zero + ); + } + } + } if (code == SecStatusCode.Success && passwordLength > 0){ password = new byte[passwordLength]; @@ -1556,7 +1575,15 @@ public void SetValueRef (INativeObject value) internal partial class SecItem { [DllImport (Constants.SecurityLibrary)] - internal extern static SecStatusCode SecItemCopyMatching (/* CFDictionaryRef */ IntPtr query, /* CFTypeRef* */ out IntPtr result); + unsafe extern static SecStatusCode SecItemCopyMatching (/* CFDictionaryRef */ IntPtr query, /* CFTypeRef* */ IntPtr* result); + + internal static SecStatusCode SecItemCopyMatching (/* CFDictionaryRef */ IntPtr query, /* CFTypeRef* */ out IntPtr result) + { + result = default; + unsafe { + return SecItemCopyMatching (query, (IntPtr*) Unsafe.AsPointer (ref result)); + } + } [DllImport (Constants.SecurityLibrary)] internal extern static SecStatusCode SecItemAdd (/* CFDictionaryRef */ IntPtr attributes, /* CFTypeRef* */ IntPtr result); diff --git a/src/Security/Policy.cs b/src/Security/Policy.cs index 6b691b4e7225..969601aabe00 100644 --- a/src/Security/Policy.cs +++ b/src/Security/Policy.cs @@ -57,13 +57,13 @@ internal SecPolicy (NativeHandle handle, bool owns) } [DllImport (Constants.SecurityLibrary)] - extern static IntPtr /* SecPolicyRef */ SecPolicyCreateSSL ([MarshalAs (UnmanagedType.I1)] bool server, IntPtr /* CFStringRef */ hostname); + extern static IntPtr /* SecPolicyRef */ SecPolicyCreateSSL (byte server, IntPtr /* CFStringRef */ hostname); static public SecPolicy CreateSslPolicy (bool server, string hostName) { var handle = CFString.CreateNative (hostName); try { - return new SecPolicy (SecPolicyCreateSSL (server, handle), true); + return new SecPolicy (SecPolicyCreateSSL (server.AsByte (), handle), true); } finally { CFString.ReleaseNative (handle); } diff --git a/src/Security/SecAccessControl.cs b/src/Security/SecAccessControl.cs index cc323615aa78..322cb9774312 100644 --- a/src/Security/SecAccessControl.cs +++ b/src/Security/SecAccessControl.cs @@ -15,6 +15,7 @@ #nullable enable using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ObjCRuntime; using CoreFoundation; @@ -157,7 +158,13 @@ public SecAccessControl (SecAccessible accessible, SecAccessControlCreateFlags f public SecAccessControlCreateFlags Flags { get; private set; } [DllImport (Constants.SecurityLibrary)] - extern static IntPtr SecAccessControlCreateWithFlags (IntPtr allocator, /* CFTypeRef */ IntPtr protection, /* SecAccessControlCreateFlags */ nint flags, out IntPtr error); + unsafe extern static IntPtr SecAccessControlCreateWithFlags (IntPtr allocator, /* CFTypeRef */ IntPtr protection, /* SecAccessControlCreateFlags */ nint flags, IntPtr* error); + + unsafe static IntPtr SecAccessControlCreateWithFlags (IntPtr allocator, /* CFTypeRef */ IntPtr protection, /* SecAccessControlCreateFlags */ nint flags, out IntPtr error) + { + error = default; + return SecAccessControlCreateWithFlags (allocator, protection, flags, (IntPtr*) Unsafe.AsPointer (ref error)); + } #endif } } diff --git a/src/Security/SecIdentity.cs b/src/Security/SecIdentity.cs index ce71f7103b24..7928e0aa18f5 100644 --- a/src/Security/SecIdentity.cs +++ b/src/Security/SecIdentity.cs @@ -20,12 +20,15 @@ namespace Security { public partial class SecIdentity { [DllImport (Constants.SecurityLibrary)] - extern static SecStatusCode /* OSStatus */ SecIdentityCopyPrivateKey (IntPtr /* SecIdentityRef */ identity, out IntPtr /* SecKeyRef* */ privatekey); + unsafe extern static SecStatusCode /* OSStatus */ SecIdentityCopyPrivateKey (IntPtr /* SecIdentityRef */ identity, IntPtr* /* SecKeyRef* */ privatekey); public SecKey PrivateKey { get { IntPtr p; - SecStatusCode result = SecIdentityCopyPrivateKey (Handle, out p); + SecStatusCode result; + unsafe { + result = SecIdentityCopyPrivateKey (Handle, &p); + } if (result != SecStatusCode.Success) throw new InvalidOperationException (result.ToString ()); return new SecKey (p, true); diff --git a/src/Security/SecIdentity2.cs b/src/Security/SecIdentity2.cs index a9bfe58db772..5e5d739002c0 100644 --- a/src/Security/SecIdentity2.cs +++ b/src/Security/SecIdentity2.cs @@ -102,8 +102,7 @@ public SecCertificate [] Certificates { [iOS (13, 0)] #endif [DllImport (Constants.SecurityLibrary)] - [return: MarshalAs (UnmanagedType.I1)] - unsafe static extern bool sec_identity_access_certificates (IntPtr identity, BlockLiteral* block); + unsafe static extern byte sec_identity_access_certificates (IntPtr identity, BlockLiteral* block); #if !NET internal delegate void AccessCertificatesHandler (IntPtr block, IntPtr cert); @@ -145,7 +144,7 @@ public bool AccessCertificates (Action hand using var block = new BlockLiteral (); block.SetupBlockUnsafe (access, handler); #endif - return sec_identity_access_certificates (GetCheckedHandle (), &block); + return sec_identity_access_certificates (GetCheckedHandle (), &block) != 0; } } #endif diff --git a/src/Security/SecProtocolMetadata.cs b/src/Security/SecProtocolMetadata.cs index 71c42935c227..4fbd910192cd 100644 --- a/src/Security/SecProtocolMetadata.cs +++ b/src/Security/SecProtocolMetadata.cs @@ -161,8 +161,7 @@ internal SecProtocolMetadata (NativeHandle handle, bool owns) : base (handle, ow public bool EarlyDataAccepted => sec_protocol_metadata_get_early_data_accepted (GetCheckedHandle ()) != 0; [DllImport (Constants.SecurityLibrary)] - [return: MarshalAs (UnmanagedType.I1)] - extern static bool sec_protocol_metadata_challenge_parameters_are_equal (IntPtr metadataA, IntPtr metadataB); + extern static byte sec_protocol_metadata_challenge_parameters_are_equal (IntPtr metadataA, IntPtr metadataB); public static bool ChallengeParametersAreEqual (SecProtocolMetadata metadataA, SecProtocolMetadata metadataB) { @@ -170,12 +169,11 @@ public static bool ChallengeParametersAreEqual (SecProtocolMetadata metadataA, S return metadataB is null; else if (metadataB is null) return false; // This was tested in a native app. We do copy the behaviour. - return sec_protocol_metadata_challenge_parameters_are_equal (metadataA.GetCheckedHandle (), metadataB.GetCheckedHandle ()); + return sec_protocol_metadata_challenge_parameters_are_equal (metadataA.GetCheckedHandle (), metadataB.GetCheckedHandle ()) != 0; } [DllImport (Constants.SecurityLibrary)] - [return: MarshalAs (UnmanagedType.I1)] - extern static bool sec_protocol_metadata_peers_are_equal (IntPtr metadataA, IntPtr metadataB); + extern static byte sec_protocol_metadata_peers_are_equal (IntPtr metadataA, IntPtr metadataB); public static bool PeersAreEqual (SecProtocolMetadata metadataA, SecProtocolMetadata metadataB) { @@ -183,7 +181,7 @@ public static bool PeersAreEqual (SecProtocolMetadata metadataA, SecProtocolMeta return metadataB is null; else if (metadataB is null) return false; // This was tested in a native app. We do copy the behaviour. - return sec_protocol_metadata_peers_are_equal (metadataA.GetCheckedHandle (), metadataB.GetCheckedHandle ()); + return sec_protocol_metadata_peers_are_equal (metadataA.GetCheckedHandle (), metadataB.GetCheckedHandle ()) != 0; } #if !NET @@ -204,8 +202,7 @@ static void TrampolineDistinguishedNamesForPeer (IntPtr block, IntPtr data) } [DllImport (Constants.SecurityLibrary)] - [return: MarshalAs (UnmanagedType.I1)] - unsafe static extern bool sec_protocol_metadata_access_distinguished_names (IntPtr handle, BlockLiteral* callback); + unsafe static extern byte sec_protocol_metadata_access_distinguished_names (IntPtr handle, BlockLiteral* callback); [BindingImpl (BindingImplOptions.Optimizable)] public void SetDistinguishedNamesForPeerHandler (Action callback) @@ -221,7 +218,7 @@ public void SetDistinguishedNamesForPeerHandler (Action callback) using var block = new BlockLiteral (); block.SetupBlockUnsafe (static_DistinguishedNamesForPeer, callback); #endif - if (!sec_protocol_metadata_access_distinguished_names (GetCheckedHandle (), &block)) + if (sec_protocol_metadata_access_distinguished_names (GetCheckedHandle (), &block) == 0) throw new InvalidOperationException ("Distinguished names are not accessible."); } } @@ -244,8 +241,7 @@ static void TrampolineOcspReposeForPeer (IntPtr block, IntPtr data) } [DllImport (Constants.SecurityLibrary)] - [return: MarshalAs (UnmanagedType.I1)] - unsafe static extern bool sec_protocol_metadata_access_ocsp_response (IntPtr handle, BlockLiteral* callback); + unsafe static extern byte sec_protocol_metadata_access_ocsp_response (IntPtr handle, BlockLiteral* callback); [BindingImpl (BindingImplOptions.Optimizable)] public void SetOcspResponseForPeerHandler (Action callback) @@ -261,7 +257,7 @@ public void SetOcspResponseForPeerHandler (Action callback) using var block = new BlockLiteral (); block.SetupBlockUnsafe (static_OcspReposeForPeer, callback); #endif - if (!sec_protocol_metadata_access_ocsp_response (GetCheckedHandle (), &block)) + if (sec_protocol_metadata_access_ocsp_response (GetCheckedHandle (), &block) == 0) throw new InvalidOperationException ("The OSCP response is not accessible."); } } @@ -284,8 +280,7 @@ static void TrampolineCertificateChainForPeer (IntPtr block, IntPtr certificate) } [DllImport (Constants.SecurityLibrary)] - [return: MarshalAs (UnmanagedType.I1)] - unsafe static extern bool sec_protocol_metadata_access_peer_certificate_chain (IntPtr handle, BlockLiteral* callback); + unsafe static extern byte sec_protocol_metadata_access_peer_certificate_chain (IntPtr handle, BlockLiteral* callback); [BindingImpl (BindingImplOptions.Optimizable)] public void SetCertificateChainForPeerHandler (Action callback) @@ -301,7 +296,7 @@ public void SetCertificateChainForPeerHandler (Action callback) using var block = new BlockLiteral (); block.SetupBlockUnsafe (static_CertificateChainForPeer, callback); #endif - if (!sec_protocol_metadata_access_peer_certificate_chain (GetCheckedHandle (), &block)) + if (sec_protocol_metadata_access_peer_certificate_chain (GetCheckedHandle (), &block) == 0) throw new InvalidOperationException ("The peer certificates are not accessible."); } } @@ -323,7 +318,6 @@ static void TrampolineSignatureAlgorithmsForPeer (IntPtr block, ushort signature } [DllImport (Constants.SecurityLibrary)] - [return: MarshalAs (UnmanagedType.I1)] unsafe static extern byte sec_protocol_metadata_access_supported_signature_algorithms (IntPtr handle, BlockLiteral* callback); [BindingImpl (BindingImplOptions.Optimizable)] @@ -413,8 +407,7 @@ public void SetSignatureAlgorithmsForPeerHandler (Action callback) [iOS (13, 0)] #endif [DllImport (Constants.SecurityLibrary)] - [return: MarshalAs (UnmanagedType.U1)] - unsafe static extern bool sec_protocol_metadata_access_pre_shared_keys (IntPtr /* sec_protocol_metadata_t */ handle, BlockLiteral* block); + unsafe static extern byte sec_protocol_metadata_access_pre_shared_keys (IntPtr /* sec_protocol_metadata_t */ handle, BlockLiteral* block); public delegate void SecAccessPreSharedKeysHandler (DispatchData psk, DispatchData pskIdentity); @@ -458,7 +451,7 @@ public bool AccessPreSharedKeys (SecAccessPreSharedKeysHandler handler) using var block = new BlockLiteral (); block.SetupBlockUnsafe (presharedkeys, handler); #endif - return sec_protocol_metadata_access_pre_shared_keys (GetCheckedHandle (), &block); + return sec_protocol_metadata_access_pre_shared_keys (GetCheckedHandle (), &block) != 0; } } #endif diff --git a/src/Security/SecProtocolOptions.cs b/src/Security/SecProtocolOptions.cs index 8135111e1535..499e1d9969b7 100644 --- a/src/Security/SecProtocolOptions.cs +++ b/src/Security/SecProtocolOptions.cs @@ -523,8 +523,7 @@ public void SetKeyUpdateCallback (SecProtocolKeyUpdate keyUpdate, DispatchQueue [iOS (13, 0)] #endif [DllImport (Constants.SecurityLibrary)] - [return: MarshalAs (UnmanagedType.I1)] - static extern bool sec_protocol_options_are_equal (sec_protocol_options_t optionsA, sec_protocol_options_t optionsB); + static extern byte sec_protocol_options_are_equal (sec_protocol_options_t optionsA, sec_protocol_options_t optionsB); // Equatable would be nice but would fail on earlier OS versions #if NET @@ -541,7 +540,7 @@ public bool IsEqual (SecProtocolOptions other) { if (other is null) return false; - return sec_protocol_options_are_equal (GetCheckedHandle (), other.Handle); + return sec_protocol_options_are_equal (GetCheckedHandle (), other.Handle) != 0; } #if NET @@ -560,7 +559,7 @@ static public bool IsEqual (SecProtocolOptions optionsA, SecProtocolOptions opti return (optionsB is null); else if (optionsB is null) return false; - return sec_protocol_options_are_equal (optionsA.Handle, optionsB.Handle); + return sec_protocol_options_are_equal (optionsA.Handle, optionsB.Handle) != 0; } #if NET diff --git a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs index e4758c3969cd..7962081fef5f 100644 --- a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs +++ b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs @@ -17,24 +17,6 @@ namespace Cecil.Tests { public partial class BlittablePInvokes { static HashSet knownFailuresPInvokes = new HashSet { - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioComponentInstanceNew(System.IntPtr,System.IntPtr&)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitGetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,AudioToolbox.AudioStreamBasicDescription&,System.UInt32&)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitGetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,AudioUnit.AudioUnitParameterInfoNative&,System.UInt32&)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitGetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.Double&,System.UInt32&)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitGetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.IntPtr&,System.Int32&)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitGetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.UInt32*,System.UInt32&)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitGetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.UInt32&,System.Int32&)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitGetPropertyInfo(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.UInt32&,System.Boolean&)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitRender(System.IntPtr,AudioUnit.AudioUnitRenderActionFlags&,AudioToolbox.AudioTimeStamp&,System.UInt32,System.UInt32,System.IntPtr)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,AudioToolbox.AudioTimeStamp&,System.Int32)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,AudioUnit.AudioUnitConnection&,System.Int32)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,AudioUnit.AURenderCallbackStruct&,System.Int32)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,AudioUnit.AUSamplerInstrumentData&,System.Int32)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,AudioUnit.AUScheduledAudioFileRegion/ScheduledAudioFileRegion&,System.Int32)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,ObjCRuntime.NativeHandle&,System.Int32)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.Double&,System.UInt32)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.IntPtr&,System.Int32)", - "AudioUnit.AudioUnitStatus AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.UInt32&,System.UInt32)", "AudioUnit.AUGraphError AudioUnit.AUGraph::AUGraphAddNode(System.IntPtr,AudioUnit.AudioComponentDescription&,System.Int32&)", "AudioUnit.AUGraphError AudioUnit.AUGraph::AUGraphCountNodeInteractions(System.IntPtr,System.Int32,System.UInt32&)", "AudioUnit.AUGraphError AudioUnit.AUGraph::AUGraphGetCPULoad(System.IntPtr,System.Single&)", @@ -61,11 +43,6 @@ public partial class BlittablePInvokes { "AVFoundation.AVSampleCursorSyncInfo ObjCRuntime.Messaging::AVSampleCursorSyncInfo_objc_msgSendSuper(System.IntPtr,System.IntPtr)", "MediaToolbox.MTAudioProcessingTapError MediaToolbox.MTAudioProcessingTap::MTAudioProcessingTapCreate(System.IntPtr,MediaToolbox.MTAudioProcessingTap/Callbacks&,MediaToolbox.MTAudioProcessingTapCreationFlags,System.IntPtr&)", "MediaToolbox.MTAudioProcessingTapError MediaToolbox.MTAudioProcessingTap::MTAudioProcessingTapGetSourceAudio(System.IntPtr,System.IntPtr,System.IntPtr,MediaToolbox.MTAudioProcessingTapFlags&,CoreMedia.CMTimeRange&,System.IntPtr&)", - "Security.SecStatusCode Security.SecIdentity::SecIdentityCopyPrivateKey(System.IntPtr,System.IntPtr&)", - "Security.SecStatusCode Security.SecImportExport::SecPKCS12Import(System.IntPtr,System.IntPtr,System.IntPtr&)", - "Security.SecStatusCode Security.SecItem::SecItemCopyMatching(System.IntPtr,System.IntPtr&)", - "Security.SecStatusCode Security.SecKeyChain::SecKeychainFindGenericPassword(System.IntPtr,System.Int32,System.Byte[],System.Int32,System.Byte[],System.Int32&,System.IntPtr&,System.IntPtr)", - "Security.SecStatusCode Security.SecKeyChain::SecKeychainFindInternetPassword(System.IntPtr,System.Int32,System.Byte[],System.Int32,System.Byte[],System.Int32,System.Byte[],System.Int32,System.Byte[],System.Int16,System.IntPtr,System.IntPtr,System.Int32&,System.IntPtr&,System.IntPtr)", "System.Boolean Network.NWAdvertiseDescriptor::nw_advertise_descriptor_get_no_auto_rename(System.IntPtr)", "System.Boolean Network.NWBrowserDescriptor::nw_browse_descriptor_get_include_txt_record(System.IntPtr)", "System.Boolean Network.NWConnectionGroup::nw_connection_group_reinsert_extracted_connection(System.IntPtr,System.IntPtr)", @@ -113,25 +90,10 @@ public partial class BlittablePInvokes { "System.Boolean Network.NWWebSocketRequest::nw_ws_request_enumerate_additional_headers(System.IntPtr,ObjCRuntime.BlockLiteral*)", "System.Boolean Network.NWWebSocketRequest::nw_ws_request_enumerate_subprotocols(System.IntPtr,ObjCRuntime.BlockLiteral*)", "System.Boolean Network.NWWebSocketResponse::nw_ws_response_enumerate_additional_headers(System.IntPtr,ObjCRuntime.BlockLiteral*)", - "System.Boolean Security.SecIdentity2::sec_identity_access_certificates(System.IntPtr,ObjCRuntime.BlockLiteral*)", - "System.Boolean Security.SecProtocolMetadata::sec_protocol_metadata_access_distinguished_names(System.IntPtr,ObjCRuntime.BlockLiteral*)", - "System.Boolean Security.SecProtocolMetadata::sec_protocol_metadata_access_ocsp_response(System.IntPtr,ObjCRuntime.BlockLiteral*)", - "System.Boolean Security.SecProtocolMetadata::sec_protocol_metadata_access_peer_certificate_chain(System.IntPtr,ObjCRuntime.BlockLiteral*)", - "System.Boolean Security.SecProtocolMetadata::sec_protocol_metadata_access_pre_shared_keys(System.IntPtr,ObjCRuntime.BlockLiteral*)", - "System.Boolean Security.SecProtocolMetadata::sec_protocol_metadata_challenge_parameters_are_equal(System.IntPtr,System.IntPtr)", - "System.Boolean Security.SecProtocolMetadata::sec_protocol_metadata_peers_are_equal(System.IntPtr,System.IntPtr)", - "System.Boolean Security.SecProtocolOptions::sec_protocol_options_are_equal(System.IntPtr,System.IntPtr)", - "System.Byte Security.SecProtocolMetadata::sec_protocol_metadata_access_supported_signature_algorithms(System.IntPtr,ObjCRuntime.BlockLiteral*)", "System.Byte* Network.NWEndpoint::nw_endpoint_get_signature(System.IntPtr,System.UIntPtr&)", - "System.Int32 AudioUnit.AudioUnit::AudioObjectGetPropertyData(System.UInt32,AudioUnit.AudioObjectPropertyAddress&,System.UInt32&,System.IntPtr&,System.UInt32&,System.UInt32&)", - "System.Int32 AudioUnit.AudioUnit::AudioUnitGetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.UInt32&,System.UInt32&)", - "System.Int32 AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,AudioToolbox.AudioStreamBasicDescription&,System.UInt32)", "System.Int32 AudioUnit.AUGraph::NewAUGraph(System.IntPtr&)", - "System.Int32 Security.Authorization::AuthorizationCreate(Security.AuthorizationItemSet*,Security.AuthorizationItemSet*,Security.AuthorizationFlags,System.IntPtr&)", "System.IntPtr ObjCRuntime.Selector::GetHandle(System.String)", - "System.IntPtr Security.SecAccessControl::SecAccessControlCreateWithFlags(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr&)", "System.IntPtr Security.SecKey::SecKeyCreateEncryptedData(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr&)", - "System.IntPtr Security.SecPolicy::SecPolicyCreateSSL(System.Boolean,System.IntPtr)", "System.Void Network.NWAdvertiseDescriptor::nw_advertise_descriptor_set_no_auto_rename(System.IntPtr,System.Boolean)", "System.Void Network.NWBrowserDescriptor::nw_browse_descriptor_set_include_txt_record(System.IntPtr,System.Boolean)", "System.Void Network.NWConnection::nw_connection_send(System.IntPtr,System.IntPtr,System.IntPtr,System.Boolean,ObjCRuntime.BlockLiteral*)", diff --git a/tools/devops/automation/templates/build/api-diff-process-results.yml b/tools/devops/automation/templates/build/api-diff-process-results.yml index 4f65536d2b3a..eeb4b050db0f 100644 --- a/tools/devops/automation/templates/build/api-diff-process-results.yml +++ b/tools/devops/automation/templates/build/api-diff-process-results.yml @@ -69,7 +69,7 @@ steps: Import-Module $Env:SYSTEM_DEFAULTWORKINGDIRECTORY\xamarin-macios\tools\devops\automation\scripts\MaciosCI.psd1 $vsdropsChangeDetectionPrefix = "https://vsdrop.corp.microsoft.com/file/v1/xamarin-macios/detected-changes/$Env:BUILD_BUILDNUMBER/$Env:BUILD_BUILDID-$Env:SYSTEM_JOBATTEMPT/;/" - $rootDirectory = Join-Path "$Env:BUILD_ARTIFACTSTAGINGDIRECTORY" "change-detection" "results" + $rootDirectory = Join-Path "$Env:SYSTEM_DEFAULTWORKINGDIRECTORY" "change-detection" "results" $inputContentsPath = Join-Path -Path $rootDirectory -ChildPath "gh-comment.md" if (Test-Path $inputContentsPath -PathType leaf) {