Example #1
0
        /// <summary>
        /// Copies file descriptors from another one to this one
        /// </summary>
        /// <param name="source">The source file descriptors</param>
        private void copyFrom(FileDescriptors source)
        {
            Used = source.Used;

            // Copy file descriptors
            int cap = source.Capacity;

            for (int i = 0; i < cap; i++)
            {
                Node sourceNode = source.GetNode(i);
                if (sourceNode != null)
                {
                    Nodes[i]   = sourceNode.Clone();
                    Offsets[i] = source.GetOffset(i);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Cleans up this task
        /// </summary>
        public void Cleanup()
        {
            // Cleanup child threads
            Thread current = FirstThread;

            while (current.NextThread != FirstThread)
            {
                current.Cleanup();
                Heap.Free(current);
                current = current.NextThread;
            }

            // Cleanup signals
            for (int i = 0; i < Signals.NSIG; i++)
            {
                SignalAction action = m_signalActions[i];
                if (action != null)
                {
                    Heap.Free(action);
                }
            }
            Heap.Free(m_signalActions);

            // Cleanup virtual addresses claimed by this task
            int count = m_usedAddresses.Count;

            for (int i = 0; i < count; i++)
            {
                Heap.Free(m_usedAddresses.Item[i]);
            }
            m_usedAddresses.Dispose();
            Heap.Free(m_usedAddresses);

            // Filesystem stuff
            FileDescriptors.Cleanup();
            Heap.Free(FileDescriptors);
            Heap.Free(m_currentDirectory);

            // Context
            Context.Cleanup();
            Heap.Free(Context);
        }
Example #3
0
        /// <summary>
        /// Constructor of task
        /// </summary>
        /// <param name="priority">The priority of the task</param>
        /// <param name="flags">The spawn flags</param>
        public Task(TaskPriority priority, SpawnFlags flags)
        {
            PID             = NextPID++;
            FileDescriptors = new FileDescriptors();

            Priority = priority;
            TimeLeft = (int)priority;

            // Check spawn flags
            if ((flags & SpawnFlags.SWAP_PID) == SpawnFlags.SWAP_PID)
            {
                int old = PID;
                PID = Tasking.CurrentTask.PID;
                Tasking.CurrentTask.PID = old;
            }

            // Other data
            GID          = Tasking.CurrentTask.GID;
            UID          = Tasking.CurrentTask.UID;
            m_launchTime = Time.FullTicks;
            Name         = "Nameless";
            CMDLine      = "";

            // Signals
            m_signalActions = new SignalAction[Signals.NSIG];

            // Context
            Context = new X86Context();

            // Filesystem related initialization if we're not a kernel task
            if ((flags & SpawnFlags.KERNEL_TASK) != SpawnFlags.KERNEL_TASK)
            {
                SetFileDescriptors(Tasking.CurrentTask.FileDescriptors.Clone());
                CurrentDirectory = String.Clone(Tasking.CurrentTask.CurrentDirectory);
            }

            // List of addresses that need to be freed
            m_usedAddresses = new List();
        }
Example #4
0
 /// <summary>
 /// Replaces the current file descriptors
 /// </summary>
 /// <param name="fileDescriptors">The new file descriptors</param>
 public void SetFileDescriptors(FileDescriptors fileDescriptors)
 {
     FileDescriptors.Cleanup();
     Heap.Free(FileDescriptors);
     FileDescriptors = fileDescriptors;
 }