Exemplo n.º 1
0
        /// <summary>
        /// Checks if the given entry points can be paired.
        /// </summary>
        /// <returns>Boolean value</returns>
        /// <param name="ep1">first entry point</param>
        /// <param name="ep2">second entry point</param>
        private static bool CanBePaired(EntryPoint ep1, EntryPoint ep2)
        {
            if (ep1.IsCalledWithNetworkDisabled && DeviceDriver.IsNetworkAPI(ep2.API))
            {
                if (ep1.IsClone)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (ep2.IsCalledWithNetworkDisabled && DeviceDriver.IsNetworkAPI(ep1.API))
            {
                if (ep2.IsClone)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (ep1.IsGoingToDisableNetwork && DeviceDriver.IsNetworkAPI(ep2.API))
            {
                if (ep1.IsClone)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (ep2.IsGoingToDisableNetwork && DeviceDriver.IsNetworkAPI(ep1.API))
            {
                if (ep2.IsClone)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (ep1.IsClone || ep2.IsClone)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if it is a network entry point.
        /// </summary>
        /// <returns>Boolean value</returns>
        /// <param name="ep">Name of entry point</param>
        internal static bool IsNetworkAPI(string ep)
        {
            if (DeviceDriver.HasKernelImposedRTNL(ep))
            {
                return(true);
            }
            if (ep.Equals("ndo_tx_timeout"))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        public EntryPoint(string name, string api, string kernelFunc, Module module,
                          bool whoopInit, bool isClone = false)
        {
            this.Id = kernelFunc.Equals("") ? name : name + "$" + kernelFunc;

            this.Name       = name;
            this.API        = api;
            this.KernelFunc = kernelFunc;

            this.Module = module;

            if ((api.Equals("probe") || api.Equals("port_probe")) &&
                ((whoopInit && module.API.Equals("whoop_driver_ops")) ||
                 module.API.Equals("test_driver") ||
                 module.API.Equals("pci_driver") ||
                 module.API.Equals("usb_driver") ||
                 module.API.Equals("usb_serial_driver") ||
                 module.API.Equals("platform_driver") ||
                 module.API.Equals("ps3_system_bus_driver") ||
                 module.API.Equals("cx_drv")))
            {
                this.IsInit = true;
                DeviceDriver.SetInitEntryPoint(name);
            }
            else
            {
                this.IsInit = false;
            }

            if ((api.Equals("remove") || api.Equals("port_remove")) &&
                ((whoopInit && module.API.Equals("whoop_driver_ops")) ||
                 module.API.Equals("test_driver") ||
                 module.API.Equals("pci_driver") ||
                 module.API.Equals("usb_driver") ||
                 module.API.Equals("usb_serial_driver") ||
                 module.API.Equals("platform_driver") ||
                 module.API.Equals("ps3_system_bus_driver") ||
                 module.API.Equals("cx_drv")))
            {
                this.IsExit = true;
            }
            else
            {
                this.IsExit = false;
            }

            this.IsClone = isClone;

            if (DeviceDriver.HasKernelImposedDeviceLock(api, module))
            {
                this.IsDeviceLocked = true;
            }
            else
            {
                this.IsDeviceLocked = false;
            }

            if (DeviceDriver.HasKernelImposedPowerLock(api))
            {
                this.IsPowerLocked = true;
            }
            else
            {
                this.IsPowerLocked = false;
            }

            if (DeviceDriver.HasKernelImposedRTNL(api))
            {
                this.IsRtnlLocked = true;
            }
            else
            {
                this.IsRtnlLocked = false;
            }

            if (DeviceDriver.IsNetworkAPI(api))
            {
                this.IsNetLocked = true;
            }
            else
            {
                this.IsNetLocked = false;
            }

            if (DeviceDriver.HasKernelImposedTxLock(api))
            {
                this.IsTxLocked = true;
            }
            else
            {
                this.IsTxLocked = false;
            }

            if (DeviceDriver.IsGoingToDisableNetwork(api))
            {
                this.IsGoingToDisableNetwork = true;
            }
            else
            {
                this.IsGoingToDisableNetwork = false;
            }

            if (DeviceDriver.IsCalledWithNetworkDisabled(api))
            {
                this.IsCalledWithNetworkDisabled = true;
            }
            else
            {
                this.IsCalledWithNetworkDisabled = false;
            }

            this.IsInlined          = false;
            this.IsCallingPowerLock = false;
            this.IsCallingRtnlLock  = false;
            this.IsCallingNetLock   = false;
            this.IsCallingTxLock    = false;

            this.HasWriteAccess = new Dictionary <string, int>();
            this.HasReadAccess  = new Dictionary <string, int>();

            this.ForceWriteResource = new HashSet <string>();
            this.ForceReadResource  = new HashSet <string>();

            this.IsHoldingLock     = false;
            this.IsEnablingDevice  = false;
            this.IsDisablingDevice = false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parses and initializes device driver specific information.
        /// </summary>
        /// <param name="files">List of file names</param>
        public static void ParseAndInitialize(List <string> files)
        {
            string driverInfoFile = files[files.Count - 1].Substring(0,
                                                                     files[files.Count - 1].LastIndexOf(".")) + ".info";

            DeviceDriver.EntryPoints = new List <EntryPoint>();
            DeviceDriver.Modules     = new List <Module>();
            DeviceDriver.SharedStructInitialiseFunc = "";

            bool whoopInit = true;

            using (StreamReader file = new StreamReader(driverInfoFile))
            {
                string line;

                while ((line = file.ReadLine()) != null)
                {
                    string type       = line.Trim(new char[] { '<', '>' });
                    string api        = "";
                    string kernelFunc = "";

                    if (type.Contains("$"))
                    {
                        var moduleSplit = type.Split(new string[] { "$" }, StringSplitOptions.None);
                        api        = moduleSplit[0];
                        kernelFunc = moduleSplit[1];
                    }
                    else
                    {
                        api = type;
                    }

                    Module module = new Module(api, kernelFunc);
                    DeviceDriver.Modules.Add(module);

                    if (api.Equals("test_driver") ||
                        api.Equals("pci_driver") ||
                        api.Equals("usb_driver") ||
                        api.Equals("usb_serial_driver") ||
                        api.Equals("platform_driver") ||
                        api.Equals("ps3_system_bus_driver") ||
                        api.Equals("cx_drv"))
                    {
                        whoopInit = false;
                    }

                    while ((line = file.ReadLine()) != null)
                    {
                        if (line.Equals("</>"))
                        {
                            break;
                        }
                    }
                }
            }

            using (StreamReader file = new StreamReader(driverInfoFile))
            {
                string line;

                while ((line = file.ReadLine()) != null)
                {
                    string type       = line.Trim(new char[] { '<', '>' });
                    string api        = "";
                    string kernelFunc = "";

                    if (type.Contains("$"))
                    {
                        var moduleSplit = type.Split(new string[] { "$" }, StringSplitOptions.None);
                        api        = moduleSplit[0];
                        kernelFunc = moduleSplit[1];
                    }
                    else
                    {
                        api = type;
                    }

                    if (api.Equals("whoop_network_shared_struct"))
                    {
                        var info = file.ReadLine();
                        DeviceDriver.SharedStructInitialiseFunc = info.Remove(0, 2);
                    }

                    Module module = DeviceDriver.Modules.First(val => val.API.Equals(api));

                    while ((line = file.ReadLine()) != null)
                    {
                        if (line.Equals("</>"))
                        {
                            break;
                        }
                        string[] pair = line.Split(new string[] { "::" }, StringSplitOptions.None);

                        var ep = new EntryPoint(pair[1], pair[0], kernelFunc, module, whoopInit);
                        module.EntryPoints.Add(ep);

                        if (DeviceDriver.EntryPoints.Any(val => val.Name.Equals(ep.Name)))
                        {
                            continue;
                        }

                        DeviceDriver.EntryPoints.Add(ep);

                        if (ep.IsCalledWithNetworkDisabled || ep.IsGoingToDisableNetwork)
                        {
                            var epClone = new EntryPoint(pair[1] + "#net", pair[0], kernelFunc, module, whoopInit, true);
                            module.EntryPoints.Add(epClone);
                            DeviceDriver.EntryPoints.Add(epClone);
                        }
                    }
                }
            }

            DeviceDriver.EntryPointPairs = new List <EntryPointPair>();

            foreach (var ep1 in DeviceDriver.EntryPoints)
            {
                foreach (var ep2 in DeviceDriver.EntryPoints)
                {
                    if (!DeviceDriver.CanBePaired(ep1, ep2))
                    {
                        continue;
                    }
                    if (!DeviceDriver.IsNewPair(ep1.Name, ep2.Name))
                    {
                        continue;
                    }
                    if (!DeviceDriver.CanRunConcurrently(ep1, ep2))
                    {
                        continue;
                    }
                    DeviceDriver.EntryPointPairs.Add(new EntryPointPair(ep1, ep2));
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Checks if the given entry points can run concurrently.
        /// </summary>
        /// <returns>Boolean value</returns>
        /// <param name="ep1">First entry point</param>
        /// <param name="ep2">Second entry point</param>
        private static bool CanRunConcurrently(EntryPoint ep1, EntryPoint ep2)
        {
            if (ep1.IsInit && ep2.IsInit)
            {
                return(false);
            }
            if (ep1.IsExit || ep2.IsExit)
            {
                return(false);
            }

            if (DeviceDriver.HasKernelImposedDeviceLock(ep1.API, ep1.Module) &&
                DeviceDriver.HasKernelImposedDeviceLock(ep2.API, ep2.Module))
            {
                return(false);
            }
            if (DeviceDriver.HasKernelImposedPowerLock(ep1.API) &&
                DeviceDriver.HasKernelImposedPowerLock(ep2.API))
            {
                return(false);
            }
            if (DeviceDriver.HasKernelImposedRTNL(ep1.API) &&
                DeviceDriver.HasKernelImposedRTNL(ep2.API))
            {
                return(false);
            }
            if (DeviceDriver.HasKernelImposedTxLock(ep1.API) &&
                DeviceDriver.HasKernelImposedTxLock(ep2.API))
            {
                return(false);
            }

            if (DeviceDriver.IsPowerManagementAPI(ep1.API) &&
                DeviceDriver.IsPowerManagementAPI(ep2.API))
            {
                return(false);
            }
            if (DeviceDriver.IsCalledWithNetpollDisabled(ep1.API) &&
                DeviceDriver.IsCalledWithNetpollDisabled(ep2.API))
            {
                return(false);
            }

            if (DeviceDriver.IsFileOperationsSerialised(ep1, ep2))
            {
                return(false);
            }
            if (DeviceDriver.IsBlockOperationsSerialised(ep1, ep2))
            {
                return(false);
            }
            if (DeviceDriver.IsUSBOperationsSerialised(ep1, ep2))
            {
                return(false);
            }
            if (DeviceDriver.IsNFCOperationsSerialised(ep1, ep2))
            {
                return(false);
            }

            return(true);
        }