Skip to content

Commit

Permalink
Revert "fix: misaligned pointer dereference."
Browse files Browse the repository at this point in the history
This reverts commit d53ef6b.
  • Loading branch information
cloudwebrtc committed Jun 14, 2024
1 parent d53ef6b commit de68f2c
Show file tree
Hide file tree
Showing 5 changed files with 1,416 additions and 2,694 deletions.
12 changes: 6 additions & 6 deletions Runtime/Scripts/Internal/FFIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,17 @@ public FfiResponse SendRequest(FfiRequest request)
using var memory = memoryPool.Memory(request);
var data = memory.Span();
request.WriteTo(data);
UIntPtr dataInLen = new UIntPtr((UInt64)data.Length);

fixed (byte* requestDataPtr = data)
{
var handle = NativeMethods.FfiNewRequest(
requestDataPtr,
dataInLen,
data.Length,
out byte* dataPtr,
out UIntPtr dataLen
out int dataLen
);

var dataSpan = new Span<byte>(dataPtr, (int)dataLen.ToUInt32());
var dataSpan = new Span<byte>(dataPtr, dataLen);
var response = responseParser.ParseFrom(dataSpan)!;
NativeMethods.FfiDropHandle(handle);
return response;
Expand All @@ -198,15 +198,15 @@ out UIntPtr dataLen


[AOT.MonoPInvokeCallback(typeof(FFICallbackDelegate))]
static unsafe void FFICallback(IntPtr data, UIntPtr size)
static unsafe void FFICallback(IntPtr data, int size)
{
#if NO_LIVEKIT_MODE
return;
#endif

if (_isDisposed) return;

var respData = new Span<byte>(data.ToPointer()!, (int)size.ToUInt32());
var respData = new Span<byte>(data.ToPointer()!, size);
var response = FfiEvent.Parser!.ParseFrom(respData);

// Run on the main thread, the order of execution is guaranteed by Unity
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/Internal/FFIClients/FFIEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace LiveKit.Internal
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void FFICallbackDelegate(IntPtr data, UIntPtr size);
internal delegate void FFICallbackDelegate(IntPtr data, int size);

// Callbacks
internal delegate void PublishTrackDelegate(PublishTrackCallback e);
Expand Down
4 changes: 1 addition & 3 deletions Runtime/Scripts/Internal/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;

using FfiHandleId = System.UInt64;

namespace LiveKit.Internal
{
[SuppressUnmanagedCodeSecurity]
Expand All @@ -21,7 +19,7 @@ internal static class NativeMethods
internal extern static bool FfiDropHandle(IntPtr handleId);

[DllImport(Lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "livekit_ffi_request")]
internal extern static unsafe IntPtr FfiNewRequest(byte* data, UIntPtr len, out byte* dataPtr, out UIntPtr dataLen);
internal extern static unsafe IntPtr FfiNewRequest(byte* data, int len, out byte* dataPtr, out int dataLen);

//TODO optimise FfiHandle, can be replaced by FfiHandleId = uint64_t
[DllImport(Lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "livekit_ffi_initialize")]
Expand Down
Loading

0 comments on commit de68f2c

Please sign in to comment.