Example #1
0
 public HandleInfoTest()
 {
     Current     = Process.GetCurrentProcess();
     LocalHandle = new HandleInfo(Current.Id, HandleType.Process, Current.Handle.DangerousGetHandle(),
                                  (uint)ProcessRights.QueryInformation);
     InvalidHandle = new HandleInfo(0, HandleType.None, IntPtr.Zero, (uint)ProcessRights.None);
 }
Example #2
0
        /// <summary>Writes a handle to a <see cref="CsWriter"/>.</summary>
        /// <param name="csWriter">The <see cref="CsWriter"/> to write the handle to.</param>
        /// <param name="handleInfo">The handle to write to <paramref name="csWriter"/>.</param>
        private static void WriteHandle(CsWriter csWriter, HandleInfo handleInfo)
        {
            var handleType = handleInfo.Dispatchable ? "UIntPtr" : "ulong";
            var nullValue  = handleInfo.Dispatchable ? "UIntPtr.Zero" : "0";

            csWriter.WriteLine($"public struct {handleInfo.Name}");
            csWriter.WriteScope(() =>
            {
                // fields
                csWriter.WriteLine($"public readonly {handleType} Handle;");

                // accessors
                csWriter.WriteLine($"public bool IsNull => Handle == {nullValue};");
                csWriter.WriteLine($"public static {handleInfo.Name} Null => new({nullValue});");

                // public methods
                csWriter.WriteLine($"public {handleInfo.Name}({handleType} handle)");
                csWriter.WriteScope(() =>
                {
                    csWriter.WriteLine("Handle = handle;");
                });
                csWriter.WriteLine($"public override bool Equals(object obj) => obj is {handleInfo.Name} handle && this == handle;");
                csWriter.WriteLine($"public override int GetHashCode() => Handle.GetHashCode();");

                // operators
                csWriter.WriteLine($"public static bool operator ==({handleInfo.Name} left, {handleInfo.Name} right) => left.Handle == right.Handle;");
                csWriter.WriteLine($"public static bool operator !=({handleInfo.Name} left, {handleInfo.Name} right) => left.Handle != right.Handle;");
                csWriter.WriteLine($"public static bool operator ==({handleInfo.Name} left, {handleType} right) => left.Handle == right;");
                csWriter.WriteLine($"public static bool operator !=({handleInfo.Name} left, {handleType} right) => left.Handle != right;");
                csWriter.WriteLine($"public static bool operator ==({handleType} left, {handleInfo.Name} right) => left == right.Handle;");
                csWriter.WriteLine($"public static bool operator !=({handleType} left, {handleInfo.Name} right) => left != right.Handle;");
            });
        }
Example #3
0
 public virtual void GetHandle(BaseObject op, int i, HandleInfo info)
 {
     C4dApiPINVOKE.ObjectData_GetHandle(swigCPtr, BaseObject.getCPtr(op), i, HandleInfo.getCPtr(info));
     if (C4dApiPINVOKE.SWIGPendingException.Pending)
     {
         throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
     }
 }
        public static IEnumerable <HandleInfo> GetFileHandles()
        {
            SystemHandleEntry[] systemHandleEntries = GetSystemHandles();

            foreach (SystemHandleEntry struc in systemHandleEntries)
            {
                HandleInfo hi = new HandleInfo(struc.OwnerProcessId, struc.Handle, struc.GrantedAccess, struc.ObjectTypeNumber, struc.Flags);
                if (hi.Type == HandleType.File && hi.Name != null)
                {
                    yield return(hi);
                }
            }
        }
Example #5
0
 public UnifiedBlockingObject(HandleInfo handle) : this(BlockingObjectOrigin.MiniDumpHandles)
 {
     KernelObjectName     = handle.ObjectName;
     KernelObjectTypeName = handle.TypeName;
     if (handle.Type != HandleInfo.HandleType.NONE)
     {
         Reason = ConvertToUnified(handle.Type);
     }
     else if (!String.IsNullOrEmpty(handle.TypeName))
     {
         Reason = ConvertToUnified(handle.TypeName);
     }
     Type   = UnifiedBlockingType.DumpHandle;
     Handle = handle.Handle;
     if (handle.OwnerThreadId != 0) // Note that this can be a thread in another process, too
     {
         OwnerOSThreadIds.Add(handle.OwnerThreadId);
     }
 }
        bool WriteHandle(XElement handleElement)
        {
            string     csName = GetTypeCsName(handleElement.Element("name").Value, "handle");
            HandleInfo info   = handles [csName];

            IndentWriteLine("public partial class {0}", csName);
            IndentWriteLine("{");
            IndentLevel++;

            //// todo: implement marshalling
            switch (info.type)
            {
            case "VK_DEFINE_NON_DISPATCHABLE_HANDLE":
                IndentWriteLine("internal UInt64 m;", csName);
                break;

            case "VK_DEFINE_HANDLE":
                IndentWriteLine("internal IntPtr m;", csName);
                break;

            default:
                throw new Exception("unknown handle type: " + info.type);
            }

            if (info.commands.Count > 0)
            {
                WriteLine();
                bool written = false;
                foreach (var element in info.commands)
                {
                    written = WriteCommand(element, written, true, csName);
                }
            }

            IndentLevel--;
            IndentWriteLine("}");

            return(true);
        }
        void WriteUnmanagedCommandParameters(XElement commandElement)
        {
            bool first    = true;
            bool previous = false;

            foreach (var param in commandElement.Elements("param"))
            {
                string type   = param.Element("type").Value;
                string name   = param.Element("name").Value;
                string csType = GetTypeCsName(type);

                bool       isPointer  = param.Value.Contains(type + "*");
                XAttribute optional   = param.Attribute("optional");
                bool       isOptional = (optional != null && optional.Value == "true");

                var isNullable = RequiresNullableIntPtr(csType, isOptional, isPointer);

                HandleInfo handle = null;
                if (handles.TryGetValue(csType, out handle))
                {
                    if (first && !isPointer)
                    {
                        handle.commands.Add(commandElement);
                    }
                    csType = handle.type == "VK_DEFINE_HANDLE" ? "IntPtr" : "UInt64";
                }
                if (isPointer)
                {
                    switch (csType)
                    {
                    case "void":
                        csType = "IntPtr";
                        break;

                    case "char":
                        csType    = "string";
                        isPointer = false;
                        break;

                    default:
                        if (isNullable)
                        {
                            csType = "IntPtr";
                        }
                        else
                        {
                            csType += "*";
                        }

                        break;
                    }
                }
                else if (first && handles.ContainsKey(csType))
                {
                    handles [csType].commands.Add(commandElement);
                }

                name = GetParamName(name, isPointer);

                if (previous)
                {
                    Write(", ");
                }
                else
                {
                    previous = true;
                }

                if (param.Value.Contains(type + "**"))
                {
                    csType += "*";
                }

                Write("{0} {1}", csType, keywords.Contains(name) ? "@" + name : name);
                first = false;
            }
        }
Example #8
0
 /// <summary>
 /// Converts HandleType enum value to UnifiedBlockingReason enum value.
 /// </summary>
 private UnifiedBlockingReason ConvertToUnified(HandleInfo.HandleType type)
 {
     UnifiedBlockingReason result = UnifiedBlockingReason.Unknown;
     switch (type)
     {
         case HandleInfo.HandleType.NONE: result = UnifiedBlockingReason.None; break;
         case HandleInfo.HandleType.THREAD: result = UnifiedBlockingReason.ThreadWait; break;
         case HandleInfo.HandleType.MUTEX: result = UnifiedBlockingReason.Mutex; break;
         case HandleInfo.HandleType.PROCESS: result = UnifiedBlockingReason.ProcessWait; break;
         case HandleInfo.HandleType.EVENT: result = UnifiedBlockingReason.Event; break;
         case HandleInfo.HandleType.SECTION: result = UnifiedBlockingReason.MemorySection; break;
     }
     return result;
 }
Example #9
0
 public UnifiedBlockingObject(HandleInfo handle) : this(BlockingObjectOrigin.MiniDumpHandles)
 {
     KernelObjectName = handle.ObjectName;
     KernelObjectTypeName = handle.TypeName;
     if (handle.Type != HandleInfo.HandleType.NONE)
     {
         Reason = ConvertToUnified(handle.Type);
     }
     else if (!String.IsNullOrEmpty(handle.TypeName))
     {
         Reason = ConvertToUnified(handle.TypeName);
     }
     Type = UnifiedBlockingType.DumpHandle;
     Handle = handle.Handle;
     if (handle.OwnerThreadId != 0) // Note that this can be a thread in another process, too
     {
         OwnerOSThreadIds.Add(handle.OwnerThreadId);
     }
 }
Example #10
0
 public virtual void SetHandle(BaseObject op, int i, Fusee.Math.Core.double3 /* Vector_cstype */ p, HandleInfo info)
 {
     C4dApiPINVOKE.ObjectData_SetHandle(swigCPtr, BaseObject.getCPtr(op), i, p /* Vector_csin */, HandleInfo.getCPtr(info));
     if (C4dApiPINVOKE.SWIGPendingException.Pending)
     {
         throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Example #11
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(HandleInfo obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }