示例#1
0
        public async Task <IActionResult> Post([FromBody] PanicViewModel panicViewModel)
        {
            try
            {
                var user = await GetUser();

                var panic = new Panic
                {
                    ApplicationUserId = user.Id,

                    Id = panicViewModel.Id,

                    DateCreated = DateTime.UtcNow
                };

                await _panicRepository.CreatePanic(panic);

                await PanickingService.SendPanicAlarm(_locationActionEventsRepository, _messagingService, _locationRepository, user);

                return(Ok(panicViewModel));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);

                return(BadRequest(new ErrorResponse(ex)));
            }
        }
示例#2
0
        public CombatHelperBehavior()
        {
            //_arm = new Arm();
            //_combat = new Combat();
            //_drones = new Drones();
            _panic = new Panic();
            //_salvage = new Salvage();
            //_slave = new Slave();
            _unloadLoot = new UnloadLoot();
            _watch      = new Stopwatch();

            //
            // this is combat mission specific and needs to be generalized
            //
            Settings.Instance.SettingsLoaded += SettingsLoaded;

            //Settings.Instance.UseFittingManager = false;

            // States.CurrentCombatHelperBehaviorState fixed on ExecuteMission
            _States.CurrentCombatHelperBehaviorState = CombatHelperBehaviorState.UnloadLoot;
            _States.CurrentArmState = ArmState.Idle;

            //_States.CurrentCombatState = CombatState.Idle;
            //_States.CurrentDroneState = DroneState.Idle;
            _States.CurrentUnloadLootState = UnloadLootState.Idle;
            _States.CurrentTravelerState   = TravelerState.Idle;

            Interlocked.Increment(ref CombatHelperBehaviorInstances);
        }
示例#3
0
        private static void AssertError(string message, uint arg1 = 0, uint arg2 = 0, uint arg3 = 0)
        {
            var sb = new StringBuffer();

            sb.Append(message, arg1, arg2, arg3);
            Panic.Error(sb.CreateString());
        }
示例#4
0
        /// <summary>
        /// Adds an IRQ to the table
        /// </summary>
        /// <param name="slot">The slot</param>
        /// <param name="pin">The pin</param>
        /// <param name="irq">The IRQ</param>
        private static void addIRQ(uint slot, uint pin, uint irq, uint polarity, uint trigger)
        {
            if (slot >= PCI_BUS_DEV_MAX || pin > PCI_PINS)
            {
                Panic.DoPanic("[PCI] Invalid IRQ added");
            }

            PciIRQEntry entry = new PciIRQEntry();

            entry.Irq = irq;

            entry.Flags = 0;
            if (polarity == 0 || polarity == 3)
            {
                entry.Flags |= IOApic.IOAPIC_REDIR_POLARITY_LOW;
            }
            else
            {
                entry.Flags |= IOApic.IOAPIC_REDIR_POLARITY_HIGH;
            }

            if (trigger == 0 || trigger == 3)
            {
                entry.Flags |= IOApic.IOAPIC_REDIR_TRIGGER_LEVEL;
            }
            else
            {
                entry.Flags |= IOApic.IOAPIC_REDIR_TRIGGER_EDGE;
            }

            m_irqTable[(slot * PCI_PINS) + pin] = entry;
        }
示例#5
0
        /// <summary>
        /// Starts a new process based on the given path and arguments
        /// </summary>
        /// <param name="path">The path</param>
        /// <param name="argv">The arguments</param>
        /// <param name="flags">Spawn flags</param>
        /// <returns>Errorcode or PID</returns>
        public static int StartProcess(string path, string[] argv, Task.SpawnFlags flags)
        {
            if (argv == null)
            {
                Panic.DoPanic("argv == null");
            }

            Node node = VFS.GetByAbsolutePath(path);

            if (node == null)
            {
                return(-(int)ErrorCode.ENOENT);
            }

            // Open and create buffer
            VFS.Open(node, (int)FileMode.O_RDONLY);
            byte[] buffer = new byte[node.Size];
            if (buffer == null)
            {
                Heap.Free(node);
                VFS.Close(node);
                return(-(int)ErrorCode.ENOMEM);
            }

            // Fill buffer contents
            VFS.Read(node, 0, node.Size, buffer);
            VFS.Close(node);

            // Pass execution to ELF loader
            int status = ELFLoader.Execute(buffer, node.Size, argv, flags);

            Heap.Free(buffer);
            Heap.Free(node);
            return(status);
        }
示例#6
0
文件: Questor.cs 项目: vega87/questor
        public Questor()
        {
            _lastPulse = DateTime.MinValue;

            _random = new Random();

            _salvage = new Salvage();
            _defense = new Defense();
            _combat = new Combat();
            _traveler = new Traveler();
            _unloadLoot = new UnloadLoot();
            _agentInteraction = new AgentInteraction();
            _arm = new Arm();
            _missionController = new MissionController();
            _drones = new Drones();
            _panic = new Panic();
            _storyline = new Storyline();

            Settings.Instance.SettingsLoaded += SettingsLoaded;

            // State fixed on ExecuteMission
            State = QuestorState.Idle;

            _directEve = new DirectEve();
            Cache.Instance.DirectEve = _directEve;

            _directEve.OnFrame += OnFrame;
        }
示例#7
0
        public unsafe Page *AllocatePages(uint pages, AllocatePageOptions options = default)
        {
            if (pages > _FreePages)
            {
                Panic.Error("Out of Memory");
                return(null);
            }

            Page *page;

            if (AddressSpaceKind == AddressSpaceKind.Virtual || options.Continuous)
            {
                page = AllocatePagesContinuous(pages, options);
            }
            else
            {
                page = AllocatePagesNormal(pages, options);
            }

            if (page == null)
            {
                KernelMessage.WriteLine("DebugName: {0}", DebugName);
                KernelMessage.WriteLine("Free pages: {0:X8}, Requested: {1:X8}", FreePages, pages);
                Panic.Error("Out of Memory");
            }

            KernelMessage.Path(DebugName, "SimpleAlloc: Request {0} Pages, Addr {1:X8}", pages, GetAddress(page));

            return(page);
        }
示例#8
0
        public Questor(frmMain form1)
        {
            m_Parent   = form1;
            _lastPulse = DateTime.MinValue;

            _random = new Random();

            _salvage          = new Salvage();
            _defense          = new Defense();
            _combat           = new Combat();
            _traveler         = new Traveler();
            _unloadLoot       = new UnloadLoot();
            _agentInteraction = new AgentInteraction();
            _arm = new Arm();
            _missionController = new MissionController();
            _drones            = new Drones();
            _panic             = new Panic();
            _storyline         = new Storyline();

            Settings.Instance.SettingsLoaded += SettingsLoaded;

            // State fixed on ExecuteMission
            State = QuestorState.Idle;

            _directEve = new DirectEve();
            Cache.Instance.DirectEve = _directEve;

            Cache.Instance.StopTimeSpecified = Program.stopTimeSpecified;

            _directEve.OnFrame += OnFrame;
        }
示例#9
0
        /// <summary>
        /// Do identify and read needed shizzle
        /// </summary>
        private void DoIdentify()
        {
            void *adr = Heap.Alloc(0x1000);

            int status = Identify(0, 1, adr);

            int statusCode = (status >> COMP_STATUS_SC_SHIFT) & COMP_STATUS_SC_MASK;

            if (statusCode != COMP_STATUS_SC_SUC)
            {
                Panic.DoPanic("[NVMe] Couldn't identifiy");
            }

            NVMe_ID_Ctrl *idCtrl = (NVMe_ID_Ctrl *)adr;

            mFirmwareRevision = new char[8];
            mSerialNumber     = new char[20];
            mModel            = new char[40];
            nNumNamespaces    = (int)idCtrl->Nn;

            Memory.Memcpy(Util.ObjectToVoidPtr(mFirmwareRevision), idCtrl->FirmwareRevision, 8);
            Memory.Memcpy(Util.ObjectToVoidPtr(mSerialNumber), idCtrl->SerialNumber, 20);
            Memory.Memcpy(Util.ObjectToVoidPtr(mModel), idCtrl->ModelNumber, 40);

            Heap.Free(adr);
        }
示例#10
0
        /// <summary>
        /// Temporary kernel memory allocation before a real heap is set up
        /// </summary>
        /// <param name="size">The size</param>
        /// <param name="align">If the block should be aligned</param>
        /// <returns>A block of memory</returns>
        public static unsafe void *KAlloc(int size, bool align)
        {
#if HEAP_DEBUG
            if (useRealHeap)
            {
                Panic.DoPanic("[HEAP] KAlloc has been called after real heap started!");
            }
#endif

            if (PhysicalMemoryManager.IsInitialized)
            {
                return(PhysicalMemoryManager.AllocRange(size));
            }
            else
            {
                uint address = (uint)CurrentEnd;
                if (align)
                {
                    address = Paging.AlignUp(address);
                }

                // At least 4byte align
                if ((address & 3) != 0)
                {
                    address &= 3;
                    address += 4;
                }

                CurrentEnd = (void *)(address + size);

                return((void *)address);
            }
        }
示例#11
0
        /// <summary>
        /// Creates a new page directory using only physical memory (used in Init)
        /// </summary>
        /// <param name="flags">The flags</param>
        /// <returns>The page directory</returns>
        public static PageDirectory *CreateNewDirectoryPhysically(PageFlags flags)
        {
            // Allocate a new block of physical memory to store our physical page in
            PageDirectory *directory = (PageDirectory *)Heap.AlignedAlloc(0x1000, sizeof(PageDirectory));

            directory->PhysicalDirectory = directory;
            if (directory == null)
            {
                Panic.DoPanic("directory == null");
            }

            // Allocate the tables
            for (int i = 0; i < 1024; i++)
            {
                PageTable *table = (PageTable *)PhysicalMemoryManager.Alloc();
                if (table == null)
                {
                    Panic.DoPanic("table == null");
                }

                Memory.Memclear(table, sizeof(PageTable));

                // Note: At this point, virtual address == physical address due to identity mapping
                directory->PhysicalTables[i] = (int)table | (int)flags;
                directory->VirtualTables[i]  = (int)table;
            }

            return(directory);
        }
示例#12
0
        /// <summary>
        /// Wait for drive to be finished
        /// </summary>
        /// <param name="port">Port IO base</param>
        private static void poll(uint port)
        {
            wait400ns(port);

            byte status;

            do
            {
                status = PortIO.In8((ushort)(port + ATA_REG_STATUS));
            }while ((status & ATA_STATUS_BSY) > 0);

            while ((status & ATA_STATUS_DRQ) == 0)
            {
                status = PortIO.In8((ushort)(port + ATA_REG_STATUS));

                if ((status & ATA_STATUS_DF) > 0)
                {
                    Panic.DoPanic("Device fault!");
                }

                if ((status & ATA_STATUS_ERR) > 0)
                {
                    Panic.DoPanic("ERR IN ATA!!");
                }
            }
        }
示例#13
0
        private async void OnPanic()
        {
            _canPanic = false;
            Panic.ChangeCanExecute();
            await Task.Delay(1000);

            _canPanic = true;
            Panic.ChangeCanExecute();
        }
示例#14
0
        /// <summary>
        /// Translate ISA IRQ to a redirection entry
        /// </summary>
        /// <param name="irq">The ISA IRQ number</param>
        /// <returns>The override</returns>
        public static ISAOverride GetISARedirection(uint irq)
        {
            if (irq >= 16)
            {
                Panic.DoPanic("Requested an ISA redirection for IRQ >= 16");
            }

            return(m_intSourceOverrides[irq]);
        }
示例#15
0
        public static unsafe ElfSections FromSectionName(string name)
        {
            bool success;
            var  elf = FromSectionName(name, out success);

            if (!success)
            {
                Panic.Error("Could not find section " + name);
            }
            return(elf);
        }
示例#16
0
        public async Task CreatePanic(Panic panic)
        {
            panic.Id = Guid.NewGuid();

            using (DataContext = new SimplySecureDataContext())
            {
                DataContext.Panics.Add(panic);

                await DataContext.SaveChangesAsync();
            }
        }
示例#17
0
        /// <summary>
        /// Gets the block from the pointer
        /// </summary>
        /// <param name="ptr">The pointer</param>
        /// <returns>The block</returns>
        private static unsafe Block *getBlockFromPtr(void *ptr)
        {
            Block *block = (Block *)((int)ptr - sizeof(Block));

#if HEAP_USE_MAGIC
            if (block->Magic != HEAP_MAGIC)
            {
                Panic.DoPanic("[HEAP] block->Magic != HEAP_MAGIC");
            }
#endif
            return(block);
        }
示例#18
0
        /// <summary>
        /// Create queues (for now just 1..)
        /// </summary>
        private void CreateQueues()
        {
            var queue = CreateQueue(1);

            if (queue == null)
            {
                Panic.DoPanic("[NVMe] Couldn't make queue");
            }


            mIOQueue = queue;
        }
示例#19
0
        /// <summary>
        /// Sets the IRQ routing
        /// </summary>
        private static void setIRQRouting()
        {
            m_irqTable = new PciIRQEntry[PCI_BUS_DEV_MAX * PCI_PINS];

            // Find root PCI device and handle it
            int status = Acpica.AcpiGetDevices("PNP0A03", onRootDevice, null, null);

            if (status != Acpica.AE_OK)
            {
                Panic.DoPanic("[PCI] Couldn't get root device");
            }
        }
示例#20
0
        private static void Setup()
        {
            IDT.SetInterruptHandler(null);
            Panic.Setup();
            Debugger.Setup(Serial.COM1);

            // Initialize interrupts
            PIC.Setup();
            IDT.Setup();
            GDT.Setup();

            //Runtime.Internal.Setup();
        }
示例#21
0
 public void SavePanic(Panic panic)
 {
     this.SaveUser(panic.User);
     if (panic.Id == 0)
     {
         this.Panics.Add(panic);
     }
     else
     {
         this.Panics.Attach(panic);
     }
     this.SaveChanges();
 }
示例#22
0
        protected async Task PanicExecute()
        {
            try {
                IsBusy = true;
                Panic panic = new Panic(cid, BackendAuthManager.Instance.User);
                await api.Backend.SavePanicAsync(panic);

                Status = "Sent Panic";
                IsBusy = false;
            } catch (Exception ex) {
                Status = "Failed: " + ex.Message;
            }
        }
示例#23
0
        public MiningBehavior()
        {
            //_arm = new Arm();
            _panic = new Panic();
            //_combat = new Combat();
            _unloadLoot = new UnloadLoot();
            //_drones = new Drones();

            _lastPulse = DateTime.MinValue;

            MiningToolGroupIDs.Add((int)Group.Miners);               //miners
            MiningToolGroupIDs.Add((int)Group.StripMiners);          //strip miners
            MiningToolGroupIDs.Add((int)Group.ModulatedStripMiners); //modulated strip miners
        }
示例#24
0
        /// <summary>
        /// Syscall interrupt handler. Dispatcher for every SysCall.
        /// </summary>
        private static void InterruptHandler(ref IDTStack stack, SysCallCallingType callingMethod)
        {
            var args = new SystemMessage
            {
                Target = (SysCallTarget)stack.EAX,
                Arg1   = stack.EBX,
                Arg2   = stack.ECX,
                Arg3   = stack.EDX,
                Arg4   = stack.ESI,
                Arg5   = stack.EDI,
                Arg6   = stack.EBP,
            };

            var commandNum = GetCommandNum(args.Target);

            if (KConfig.Log.SysCall)
            {
                KernelMessage.WriteLine("Got SysCall cmd={0} arg1={1:X8} arg2={2:X8} arg3={3:X8} arg4={4:X8} arg5={5:X8} arg6={6:X8}", (uint)args.Target, args.Arg1, args.Arg2, args.Arg3, args.Arg4, args.Arg5, args.Arg6);
            }

            Scheduler.SaveThreadState(Scheduler.GetCurrentThread().ThreadID, ref stack);

            var info = Commands[commandNum];

            if (info == null)
            {
                Panic.Error("Undefined SysCall");
            }

            var ctx = new SysCallContext
            {
                CallingType = callingMethod,
                Debug       = info.Debug,
            };

            if (info.Debug)
            {
                KDebug.DumpStats();
                Debug.Nop();
            }

            var result = info.Handler(ref ctx, ref args);

            if (KConfig.Log.SysCall)
            {
                KernelMessage.WriteLine("Result of Syscall cmd={0}: {1:X8}", (uint)args.Target, result);
            }

            stack.EAX = result;
        }
示例#25
0
文件: Scheduler.cs 项目: arakis/abanu
        public static unsafe void Start()
        {
            SetThreadID(0);
            Enabled = true;

            KernelMessage.WriteLine("Enable Scheduler");
            IDTManager.SetPrivilegeLevel((uint)KnownInterrupt.TerminateCurrentThread, 0x03);
            GDT.Tss->ESP0 = Threads[0].KernelStackBottom;
            GDT.LoadTaskRegister();
            TriggerScheduler();

            // Normally, you should never get here
            Panic.Error("Main-Thread still alive");
        }
示例#26
0
        public void TestSavePanic()
        {
            User  u  = User.GenerateNewUser();
            Panic p  = new Panic("testCourse", u);
            Panic p2 = new Panic("testCourse", u);

            using (var db = new TestSurveyContext())
            {
                db.SaveUser(u);
                db.SavePanic(p);
                db.SavePanic(p2);
                db.SaveChanges();
            }
        }
示例#27
0
        private static void Setup()
        {
            Logger.Log("Initialize Kernel");

            IDT.SetInterruptHandler(null);
            Panic.Setup();
            Debugger.Setup(Serial.COM2);

            // Initialize interrupts
            PIC.Setup();
            IDT.Setup();
            GDT.Setup();

            Logger.Log("Kernel initialized");
        }
示例#28
0
        /// <summary>
        /// Creates a block descriptor with given minimal size
        /// </summary>
        /// <param name="size">The minimal size</param>
        /// <returns>The block descriptor</returns>
        private static unsafe BlockDescriptor *createBlockDescriptor(int size)
        {
#if HEAP_DEBUG_DESCRIPTOR
            Console.WriteLine("[HEAP] Creating a new block descriptor");
#endif

            // Add size of Block and BlockDescriptor
            size += sizeof(Block) + sizeof(BlockDescriptor);

            // Allocate descriptor
            size = getRequiredPageCount(size) * 0x1000;
            BlockDescriptor *descriptor = (BlockDescriptor *)Paging.AllocateVirtual(size);

#if HEAP_DEBUG_DESCRIPTOR
            Console.Write("[HEAP] New descriptor is at 0x");
            Console.WriteHex((int)descriptor);
            Console.Write(", physical: 0x");
            Console.WriteHex((int)Paging.GetPhysicalFromVirtual(descriptor));
            Console.Write('\n');
#endif

            if (descriptor == null)
            {
                Panic.DoPanic("descriptor == null");
            }

            // Setup block
            Block *first = (Block *)((int)descriptor + sizeof(BlockDescriptor));
            first->Prev       = null;
            first->Next       = null;
            first->Size       = size - sizeof(BlockDescriptor);
            first->Used       = false;
            first->Descriptor = descriptor;
#if HEAP_USE_MAGIC
            first->Magic = HEAP_MAGIC;
#endif

            // Setup descriptor
            descriptor->FreeSpace = size - sizeof(BlockDescriptor);
            descriptor->First     = first;
            descriptor->FirstFree = first;
            descriptor->Next      = null;
#if HEAP_USE_MAGIC
            descriptor->Magic = HEAP_MAGIC;
#endif

            return(descriptor);
        }
示例#29
0
        /// <summary>
        /// Called as callback when a root device is found
        /// </summary>
        /// <param name="Object">The object</param>
        /// <param name="NestingLevel">Nesting level</param>
        /// <param name="Context">User context</param>
        /// <param name="ReturnValue">Return value if early returned</param>
        /// <returns>Status</returns>
        private static int onRootDevice(void *Object, uint NestingLevel, void *Context, void **ReturnValue)
        {
            // Get routing table
            AcpiObjects.Buffer buffer;
            buffer.Length = Acpica.ACPI_ALLOCATE_BUFFER;
            int status = Acpica.AcpiGetIrqRoutingTable(Object, &buffer);

            if (status != Acpica.AE_OK)
            {
                Panic.DoPanic("[PCI] Couldn't get ACPI IRQ Routing Table");
            }

            // The last entry will have Length 0
            Acpica.PCIRoutingTable *table = (Acpica.PCIRoutingTable *)buffer.Pointer;
            while (table->Length > 0)
            {
                // No reference source
                if (table->Source[0] == 0)
                {
                    uint slot = (uint)(table->Address >> 16);
                    addIRQ(slot, table->Pin, table->SourceIndex, 0, 0);
                }
                // Source is not null, that means we need to lookup the reference resource
                else
                {
                    void *handle = null;
                    status = Acpica.AcpiGetHandle(Object, Util.CharPtrToString(table->Source), &handle);
                    if (status != Acpica.AE_OK)
                    {
                        Panic.DoPanic("[PCI] Couldn't load references handle");
                    }

                    status = Acpica.AcpiWalkResources(handle, Acpica.METHOD_NAME__CRS, onIRQResource, table);
                    if (status != Acpica.AE_OK)
                    {
                        Panic.DoPanic("[PCI] Couldn't process resources for IRQ");
                    }
                }

                // Next entry
                table = (Acpica.PCIRoutingTable *)((byte *)table + table->Length);
            }

            // The object returned should be freed by us
            Acpica.AcpiOsFree(buffer.Pointer);

            return(Acpica.AE_OK);
        }
示例#30
0
    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(gameObject);
            return;
        }

        rand     = new System.Random();
        startPos = transform.position;
        GameManager.OnFailGame += StopPanic;
    }
示例#31
0
        /// <summary>
        /// Main
        /// </summary>
        public static void Main()
        {
            IDT.SetInterruptHandler(null);
            Panic.Setup();
            Debugger.Setup(Serial.COM1);

            // Initialize interrupts
            PIC.Setup();
            IDT.Setup();
            GDT.Setup();

            Runtime.Internal.Setup();

            IDT.SetInterruptHandler(ProcessInterrupt);

            EnterTestReadyLoop();
        }
示例#32
0
文件: Questor.cs 项目: ahaw/Questor
        public Questor(frmMain form1)
        {
            m_Parent = form1;
            _lastPulse = DateTime.MinValue;

            _random = new Random();

            //_debugmodule = new DebugModule();

            //_scoop = new Scoop();
            _salvage = new Salvage();
            _defense = new Defense();
            _localwatch = new LocalWatch();
            _scanInteraction = new ScanInteraction();
            _combat = new Combat();
            _traveler = new Traveler();
            _unloadLoot = new UnloadLoot();
            _agentInteraction = new AgentInteraction();
            _arm = new Arm();
            _courier = new CourierMission();
            _switch = new SwitchShip();
            _missionController = new MissionController();
            _drones = new Drones();
            _panic = new Panic();
            _storyline = new Storyline();

            Settings.Instance.SettingsLoaded += SettingsLoaded;

            // State fixed on ExecuteMission
            State = QuestorState.Idle;

            _directEve = new DirectEve();
            Cache.Instance.DirectEve = _directEve;

            Cache.Instance.StopTimeSpecified = Program.stopTimeSpecified;
            Cache.Instance.MaxRuntime = Program.maxRuntime;
            Cache.Instance.StopTime = Program._stopTime;
            _questorStarted = DateTime.Now;

            _directEve.OnFrame += OnFrame;
        }
示例#33
0
 private Hardware BuildHardware(Panic.Repository.Linq.Hardware aHardware)
 {
     Hardware hardware = new Hardware(aHardware.HardwareID) {
     Enabled = (bool)aHardware.Enabled,
     Description = aHardware.Description,
     Make = aHardware.Make,
     ModelNumber = aHardware.ModelNumber,
     RXCapacity = (double)aHardware.RXCapacity,
     TXCapacity = (double)aHardware.TXCapacity,
     Notes = aHardware.Notes
       };
       return hardware;
 }
示例#34
0
 private Link BuildLink(Panic.Repository.Linq.Link aLink)
 {
     Link link = new Link(aLink.LinkID) {
     Enabled = (bool)aLink.Enabled,
     FromSiteID = aLink.FromSiteID,
     ToSiteID = aLink.ToSiteID,
     HardwareID = aLink.HardwareID,
     Notes = aLink.Notes,
     RXOverride = (double)aLink.RXOverride,
     TXOverride = (double)aLink.TXOverride
       };
       return link;
 }