private void InitOnce()
        {
            if (AudioStream == null)
            {
                //AudioContext = new AudioContext(AudioContext.DefaultDevice, 44100, 4410);
                //AudioContext = new AudioContext();
                //XRam = new XRamExtension();

                device = AL.alcOpenDevice(AL.alcGetString(null, AL.ALC_DEFAULT_DEVICE_SPECIFIER));
                context = AL.alcCreateContext(device, null);
                AL.alcMakeContextCurrent(context);

                AL.alListener3f(AL.AL_POSITION, 0f, 0f, 0f);
                AL.alListener3f(AL.AL_VELOCITY, 0f, 0f, 0f);

                AudioStream = new AudioStream();
            }
        }
Exemple #2
0
 public unsafe IntPtr ImportMemory([Flow(FlowDirection.In)] int context, [Flow(FlowDirection.In)] ARM flags, [Flow(FlowDirection.In)] IntPtr *properties, [Flow(FlowDirection.Out)] void *memory, [Flow(FlowDirection.In)] uint size, [Flow(FlowDirection.Out)] int *errcode_ret)
 {
     // IntPtrOverloader
     return(ImportMemory(new IntPtr(context), flags, properties, memory, new UIntPtr(size), errcode_ret));
 }
Exemple #3
0
        unsafe HRESULT Ole32.IOleContainer.ParseDisplayName(IntPtr pbc, string pszDisplayName, uint *pchEaten, IntPtr *ppmkOut)
        {
            if (ppmkOut != null)
            {
                *ppmkOut = IntPtr.Zero;
            }

            return(HRESULT.E_NOTIMPL);
        }
Exemple #4
0
 internal static extern unsafe int WindowsDuplicateString(IntPtr sourceString,
                                                          IntPtr *hstring);
Exemple #5
0
 internal static extern unsafe int WindowsCreateString([MarshalAs(UnmanagedType.LPWStr)] string sourceString,
                                                       int length,
                                                       IntPtr *hstring);
Exemple #6
0
 internal static extern unsafe int CoIncrementMTAUsage(IntPtr *cookie);
Exemple #7
0
 public static extern int WindowsReplaceString([NativeTypeName("HSTRING")] IntPtr @string, [NativeTypeName("HSTRING")] IntPtr stringReplaced, [NativeTypeName("HSTRING")] IntPtr stringReplaceWith, [NativeTypeName("HSTRING *")] IntPtr *newString);
Exemple #8
0
        internal bool Grow()
        {
            int newCapacity = m_capacity * 2;

            // NOTE: Call must be used instead of StdCall to avoid deadlock
            IntPtr* pNewHandles = (IntPtr*)ExternalInterop.MemReAlloc((IntPtr)m_pHandles,
                                                                      new UIntPtr( (uint) (sizeof(IntPtr) * newCapacity)),
                                                                      HEAP_ZERO_MEMORY);

            if (pNewHandles == null)
                return false;

            m_pHandles = pNewHandles;
            m_capacity = newCapacity;

            return true;
        }
Exemple #9
0
 private unsafe static extern int OleCreatePictureIndirectRaw(PICTDESC *pictdesc, Guid *refiid, BOOL fOwn, IntPtr *lplpvObj);
Exemple #10
0
 /// <summary>
 /// Frees a device list.  Decrements the reference count for each device by 1
 /// if the unref_devices parameter is set.
 /// </summary>
 internal static unsafe extern void libusbFreeDeviceList(IntPtr *list, int unref_devices);
Exemple #11
0
 /// <summary>
 /// gets a list of device pointers - must be freed with libusbFreeDeviceList
 /// </summary>
 /// <returns>number of devices OR an error code</returns>
 internal static unsafe extern int libusbGetDeviceList(LibusbContext ctx, out IntPtr *list);
Exemple #12
0
 public static extern int WindowsPromoteStringBuffer([NativeTypeName("HSTRING_BUFFER")] IntPtr bufferHandle, [NativeTypeName("HSTRING *")] IntPtr * @string);
Exemple #13
0
 public static extern int WindowsPreallocateStringBuffer([NativeTypeName("UINT32")] uint length, [NativeTypeName("WCHAR **")] ushort **charBuffer, [NativeTypeName("HSTRING_BUFFER *")] IntPtr *bufferHandle);
Exemple #14
0
 public static extern int WindowsTrimStringEnd([NativeTypeName("HSTRING")] IntPtr @string, [NativeTypeName("HSTRING")] IntPtr trimString, [NativeTypeName("HSTRING *")] IntPtr *newString);
Exemple #15
0
        // Backup the original native virtual function table and overwrite the pointer to it with our own (which is a copy of the original).
        private void InitializeVFTable()
        {
            // Save off the original VFTable (only if it really is the original).
            if (OriginalVFTable == null)
            {
                OriginalVFTable = NativeIDirect3D9->VFTable;
            }

            // IDirect3D9 has 17 members.
            const uint VFTableLength = 17;
            // Allocate space for our new VFTable.
            var NewVFTable =
                (IntPtr*) Kernel32.HeapAlloc(Kernel32.GetProcessHeap(), 0, (UIntPtr) (VFTableLength*sizeof (IntPtr)));

            // Copy all of the original function pointers into our new VFTable.
            for (int i = 0; i < VFTableLength; i++)
            {
                NewVFTable[i] = OriginalVFTable[i];
            }

            // Set the Real IDirect3D9 implementation's VFTable to point at our custom one.
            NativeIDirect3D9->VFTable = NewVFTable;
        }
Exemple #16
0
            private unsafe void HandleInvokeFunctionFromBP(IntPtr obj, FFrame stack, IntPtr result,
                                                           UFunction.FuncInvokerManaged managedFunctionInvoker)
            {
                // NOTE: ScriptCore.cpp uses PropertiesSize instead of ParamsSize. Is it ever any different? (it says alignment
                // may make them different) If it is different we should probably use PropertiesSize (including in generated code /
                // IL) as ScriptCore.cpp uses a memcpy of our memory.
                Debug.Assert(Native_UStruct.Get_PropertiesSize(stack.CurrentNativeFunction) ==
                             Native_UFunction.Get_ParmsSize(stack.CurrentNativeFunction));

                IntPtr function     = stack.CurrentNativeFunction;
                int    paramsSize   = Native_UFunction.Get_ParmsSize(function);
                int    numParams    = Native_UFunction.Get_NumParms(function);
                bool   hasOutParams = Native_UFunction.HasAnyFunctionFlags(function, EFunctionFlags.HasOutParms);

                IntPtr *outParamsBufferPtr = stackalloc IntPtr[numParams];

                byte * paramsBufferPtr = stackalloc byte[paramsSize];
                IntPtr paramsBuffer    = (IntPtr)paramsBufferPtr;

                // We could skip this memzero as stackalloc will (always?) zero memory even though the spec states
                // "The content of the newly allocated memory is undefined."
                // https://github.com/dotnet/coreclr/issues/1279
                FMemory.Memzero(paramsBuffer, paramsSize);

                if (hasOutParams)
                {
                    int paramIndex = 0;
                    foreach (IntPtr param in new NativeReflection.NativeFieldIterator(Runtime.Classes.UProperty, function, false))
                    {
                        // Not required but using for Debug.Assert() when getting the value
                        stack.MostRecentPropertyAddress = IntPtr.Zero;

                        stack.Step(stack.Object, paramsBuffer + Native_UProperty.GetOffset_ForUFunction(param));
                        outParamsBufferPtr[paramIndex] = stack.MostRecentPropertyAddress;

                        if (Native_UProperty.HasAnyPropertyFlags(param, EPropertyFlags.ReturnParm))
                        {
                            // This should be UObject::execEndFunctionParms which will just do "stack->Code--;" for allowing
                            // the caller to use PFINISH aftwards
                            outParamsBufferPtr[paramIndex] = result;
                        }

                        paramIndex++;
                    }
                }
                else
                {
                    foreach (IntPtr param in new NativeReflection.NativeFieldIterator(Runtime.Classes.UProperty, function, false))
                    {
                        stack.Step(stack.Object, paramsBuffer + Native_UProperty.GetOffset_ForUFunction(param));
                    }
                }
                stack.PFinish();// Skip EX_EndFunctionParms

                // Call the managed function invoker which will marshal the params from the native params buffer and then call the
                // target managed function
                managedFunctionInvoker(paramsBuffer, obj);

                // Copy out params from the temp buffer
                //if (hasOutParams) // 4.20 DestructorLink change (see below)
                {
                    int paramIndex = 0;
                    foreach (IntPtr paramProp in new NativeReflection.NativeFieldIterator(Runtime.Classes.UProperty, function, false))
                    {
                        EPropertyFlags paramFlags = Native_UProperty.GetPropertyFlags(paramProp);

                        if ((paramFlags & EPropertyFlags.OutParm) == EPropertyFlags.OutParm &&
                            (paramFlags & EPropertyFlags.ConstParm) != EPropertyFlags.ConstParm)
                        {
                            Debug.Assert(outParamsBufferPtr[paramIndex] != IntPtr.Zero);

                            // - See "REMOVING the DestroyValue call" below.
                            // Destroy the existing memory (this assumed the existing memory is valid or at least memzerod)
                            //Native_UProperty.DestroyValue(paramProp, outParamsBufferPtr[paramIndex]);

                            // A raw memcpy should be OK since the managed invoker should have set this memory appropriately.
                            FMemory.Memcpy(outParamsBufferPtr[paramIndex],
                                           paramsBuffer + Native_UProperty.GetOffset_ForUFunction(paramProp),
                                           Native_UProperty.Get_ElementSize(paramProp));// Should be ArrayDim*ElementSize but ArrayDim should always be 1 for params
                        }
                        else
                        {
                            // 4.20 the original DestructorLink code doesn't work as expected (did it ever work?). DestructorLink seems to only be
                            // used on delegate functions (e.g. /Script/Engine.ActorOnClickedSignature__DelegateSignature).
                            // - For now call destroy everything other than out params (is this safe?)
                            // - TODO: Replace this with custom Stack.Code stepping as described above?
                            Native_UProperty.DestroyValue_InContainer(paramProp, paramsBuffer);
                        }

                        paramIndex++;
                    }
                }

                // Parameters are copied when calling stack->Step(). We are responsible for destroying non-blittable types
                // which were copied (FString, TArray, etc). For C++ this works out well due to the copy constructors etc.
                //
                // Example where an FString is constructed from stack->Step():
                // UObject::execStringConst(...) { *(FString*)RESULT_PARAM = (ANSICHAR*)Stack.Code; }
                //
                // For C# it might be better if we reimplemented all of the IMPLEMENT_VM_FUNCTION functions to reduce the amount
                // of copying as we currently need ANOTHER copy to get it from the temp buffer into a C# type (which is done
                // inside the managedFunctionInvoker function)

                /*foreach (IntPtr paramProp in new NativeReflection.NativeFieldIterator(Runtime.Classes.UProperty, function,
                 *  EFieldIteratorType.Destructor, false))
                 * {
                 *  // When is this ever false? It seems to be checked in UObject::ProcessEvent()
                 *  // "Destroy local variables except function parameters." - used for BP locals?
                 *  Debug.Assert(Native_UProperty.IsInContainer(paramProp, paramsSize));
                 *
                 *  // Out params are copied to the memory maintained by the caller so only destroy "by value" parameters.
                 *  if (!Native_UProperty.HasAnyPropertyFlags(paramProp, EPropertyFlags.OutParm))
                 *  {
                 *      Native_UProperty.DestroyValue_InContainer(paramProp, paramsBuffer);
                 *  }
                 * }*/
            }
Exemple #17
0
 public int GetRuntimeClassName([NativeTypeName("HSTRING *")] IntPtr *className)
 {
     return(((delegate * unmanaged <IProtectionPolicyManagerInterop *, IntPtr *, int>)(lpVtbl[4]))((IProtectionPolicyManagerInterop *)Unsafe.AsPointer(ref this), className));
 }
Exemple #18
0
 public HandleTable()
 {
     size = 0x10;
     baseAdr = (IntPtr*)Marshal.AllocHGlobal(size * IntPtr.Size);
     current = baseAdr;
     currentIdx = 0;
 }
 internal static extern unsafe TypeManagerHandle RhpCreateTypeManager(IntPtr osModule, IntPtr moduleHeader, IntPtr *pClasslibFunctions, int nClasslibFunctions);
Exemple #20
0
 internal extern static unsafe Result vkAllocateCommandBuffers(IntPtr device, VkCommandBufferAllocateInfo *pAllocateInfo, IntPtr *pCommandBuffers);
Exemple #21
0
 public abstract unsafe int QueryStreamConsumerEvent([Flow(FlowDirection.In)] IntPtr dpy, [Flow(FlowDirection.In)] IntPtr stream, [Flow(FlowDirection.In)] ulong timeout, [Flow(FlowDirection.Out)] NV * @event, [Flow(FlowDirection.Out)] IntPtr *aux);
Exemple #22
0
 internal static extern unsafe int RoGetActivationFactory(IntPtr runtimeClassId, ref Guid iid, IntPtr *factory);
Exemple #23
0
 public abstract unsafe bool StreamAcquireImage([Flow(FlowDirection.In)] IntPtr dpy, [Flow(FlowDirection.In)] IntPtr stream, [Flow(FlowDirection.Out)] IntPtr *pImage, [Flow(FlowDirection.In)] IntPtr sync);
Exemple #24
0
 internal static extern unsafe int WindowsCreateStringReference(char *sourceString,
                                                                int length,
                                                                IntPtr *hstring_header,
                                                                IntPtr *hstring);
Exemple #25
0
 public abstract unsafe bool StreamImageConsumerConnect([Flow(FlowDirection.In)] IntPtr dpy, [Flow(FlowDirection.In)] IntPtr stream, [Flow(FlowDirection.In)] int num_modifiers, [Flow(FlowDirection.Out)] ulong *modifiers, [Flow(FlowDirection.Out)] IntPtr *attrib_list);
Exemple #26
0
 public virtual void GetMethodProps(uint mb, uint *pClass, [In] ushort *szMethod, uint cchMethod, uint *pchMethod, uint *pdwAttr, [Out] IntPtr *ppvSigBlob, [Out] uint *pcbSigBlob, [Out] uint *pulCodeRVA, [Out] uint *pdwImplFlags) => throw new NotImplementedException();
Exemple #27
0
 public unsafe int QueryStreamConsumerEvent([Flow(FlowDirection.In)] int dpy, [Flow(FlowDirection.In)] int stream, [Flow(FlowDirection.In)] ulong timeout, [Flow(FlowDirection.Out)] NV * @event, [Flow(FlowDirection.Out)] IntPtr *aux)
 {
     // IntPtrOverloader
     return(QueryStreamConsumerEvent(new IntPtr(dpy), new IntPtr(stream), timeout, @event, aux));
 }
Exemple #28
0
 public abstract unsafe IntPtr ImportMemory([Flow(FlowDirection.In)] IntPtr context, [Flow(FlowDirection.In)] ARM flags, [Flow(FlowDirection.In)] IntPtr *properties, [Flow(FlowDirection.Out)] void *memory, [Flow(FlowDirection.In)] UIntPtr size, [Flow(FlowDirection.Out)] int *errcode_ret);
Exemple #29
0
 public unsafe bool StreamAcquireImage([Flow(FlowDirection.In)] int dpy, [Flow(FlowDirection.In)] int stream, [Flow(FlowDirection.Out)] IntPtr *pImage, [Flow(FlowDirection.In)] int sync)
 {
     // IntPtrOverloader
     return(StreamAcquireImage(new IntPtr(dpy), new IntPtr(stream), pImage, new IntPtr(sync)));
 }
Exemple #30
0
 // Cleanup resources.  Destructing == true means we are getting garbage collected so don't reference any managed resources.
 private void Dispose(bool Destructing)
 {
     if (OriginalVFTable != null)
     {
         Kernel32.HeapFree(Kernel32.GetProcessHeap(), 0, *OriginalVFTable);
         OriginalVFTable = null;
     }
 }
Exemple #31
0
 public unsafe bool StreamImageConsumerConnect([Flow(FlowDirection.In)] int dpy, [Flow(FlowDirection.In)] int stream, [Flow(FlowDirection.In)] int num_modifiers, [Flow(FlowDirection.Out)] ulong *modifiers, [Flow(FlowDirection.Out)] IntPtr *attrib_list)
 {
     // IntPtrOverloader
     return(StreamImageConsumerConnect(new IntPtr(dpy), new IntPtr(stream), num_modifiers, modifiers, attrib_list));
 }
Exemple #32
0
 // Reset the native virtual function table to point back at the original.
 private void ResetVFTable()
 {
     // If the original table is not defined do nothing.
     if (OriginalVFTable == null)
     {
         return;
     }
     // If the original table points to the same place as the current one do nothing.
     if (OriginalVFTable == NativeIDirect3D9->VFTable)
     {
         return;
     }
     // Cleanup memory allocated for our custom VFTable.
     Kernel32.HeapFree(Kernel32.GetProcessHeap(), 0, *NativeIDirect3D9->VFTable);
     // Set the VFTable back to the original.
     NativeIDirect3D9->VFTable = OriginalVFTable;
     // Set the original VFTable back to null.
     OriginalVFTable = null;
 }
Exemple #33
0
 public int GetWindow([NativeTypeName("HWND *")] IntPtr *phwnd)
 {
     return(((delegate * unmanaged <IOleInPlaceSite *, IntPtr *, int>)(lpVtbl[3]))((IOleInPlaceSite *)Unsafe.AsPointer(ref this), phwnd));
 }
Exemple #34
0
        internal bool ResetHandles()
        {
            if (m_pHandles == null)
            {
                //
                // This is the first time we use this list
                // Initialize it
                // NOTE: Call must be used instead of StdCall to avoid deadlock
                //
                m_capacity = DefaultCapacity;
                uint newCapacity = (uint)(sizeof(IntPtr) * m_capacity);
                m_pHandles = (IntPtr*)ExternalInterop.MemAlloc(new UIntPtr(newCapacity) , HEAP_ZERO_MEMORY);

                if (m_pHandles == null)
                    return false;

                // Our job is done if we are allocating this for the first time
                return true;
            }


            if (m_freeIndex < m_capacity / 2 && m_capacity > DefaultCapacity)
            {
                m_shrinkHint++;
                if (m_shrinkHint > ShrinkHintThreshold)
                {
                    //
                    // If we ever seeing consistently (> 5 times) that free index is less than half of
                    // our current capacity, it is time to shrink the size
                    //
                    Shrink();

                    m_shrinkHint = 0;
                }
            }
            else
            {
                //
                // Reset shrink hint and start over the counting
                //
                m_shrinkHint = 0;
            }

            //
            // Clear all the handles that were used
            //
            for (int index = 0; index < m_freeIndex; ++index)
            {
                IntPtr handle = m_pHandles[index];
                if (handle != default(IntPtr))
                {
                    InteropExtensions.RuntimeHandleSet(handle, null);
                    InteropExtensions.RuntimeHandleSetDependentSecondary(handle, null);
                }
            }

            m_freeIndex = 0;

            return true;
        }
Exemple #35
0
 public unsafe partial IntPtr CreateSyncFromCLevent([Flow(FlowDirection.Out)] out IntPtr context, [Flow(FlowDirection.Out)] IntPtr * @event, [Flow(FlowDirection.In)] uint flags);
Exemple #36
0
        internal bool Shrink()
        {
            Debug.Assert(m_capacity > DefaultCapacity && m_capacity / 2 > 10);

            int newCapacity = m_capacity / 2;

            //
            // Free all handles that will go away
            //
            for (int index = newCapacity; index < m_capacity; ++index)
            {
                if (m_pHandles[index] != default(IntPtr))
                {
                    InteropExtensions.RuntimeHandleFree(m_pHandles[index]);

                    // Assign them back to null in case the reallocation fails
                    m_pHandles[index] = default(IntPtr);
                }
            }

            //
            // Shrink the size of the memory
            // If this fails, we don't really care (very unlikely to fail, though)
            // NOTE: Call must be used instead of StdCall to avoid deadlock
            //
            IntPtr* pNewHandles = (IntPtr*)ExternalInterop.MemReAlloc((IntPtr)m_pHandles, new UIntPtr((uint)(sizeof(IntPtr) * newCapacity) ) , HEAP_ZERO_MEMORY);

            if (pNewHandles == null)
                return false;

            m_pHandles = pNewHandles;
            m_capacity = newCapacity;

            return true;
        }
 public unsafe virtual int CreateEnumeratorFromKey(IntPtr factory, void *collectionKey, uint collectionKeySize, IntPtr *fontFileEnumerator)
 {
 }
Exemple #38
0
 public IntPtr AddHandle(IntPtr hnd)
 {
     if (currentIdx == size)
     {
         IntPtr* newAdr = (IntPtr*)Marshal.AllocHGlobal(size * 2 * IntPtr.Size);
         for (int i = 0; i < size; i++)
             *(newAdr + i) = *(baseAdr + i);
         current = newAdr + size;
         size *= 2;
     }
     *current = hnd;
     currentIdx++;
     return (IntPtr)(current++);
 }
Exemple #39
0
 public static extern int WindowsConcatString([NativeTypeName("HSTRING")] IntPtr string1, [NativeTypeName("HSTRING")] IntPtr string2, [NativeTypeName("HSTRING *")] IntPtr *newString);