예제 #1
0
파일: PATABase.cs 프로젝트: zrbruce/FlingOS
        public virtual void Reset()
        {
            IO.Control.Write_Byte(0x4);
            Wait();
            IO.Control.Write_Byte(0x0);
            Status xStatus;
            int    timeout = 20000000;

            do
            {
                Wait();
                xStatus = (Status)IO.Control.Read_Byte();
            } while ((xStatus & Status.Busy) != 0 &&
                     (xStatus & Status.Error) == 0 &&
                     timeout-- > 0);

            // Error occurred
            if ((xStatus & Status.Error) != 0)
            {
                ExceptionMethods.Throw(new FOS_System.Exception("ATA software reset error!"));
            }
            else if (timeout == 0)
            {
                ExceptionMethods.Throw(new FOS_System.Exception("ATA software reset timeout!"));
            }

            //Reselect the correct drive
            SelectDrive(0, false);
        }
예제 #2
0
        /// <summary>
        /// Reads up to the specified length of data into the specified buffer at the specified offset in the buffer.
        /// </summary>
        /// <param name="Data">The buffer to read into.</param>
        /// <param name="Offset">The offset in the buffer to write data to.</param>
        /// <param name="Length">The maximum length of data to read.</param>
        /// <param name="Blocking">Whether the read should be blocking or non-blocking.</param>
        /// <returns>The actual number of bytes read.</returns>
        public int Read(byte[] Data, int Offset, int Length, bool Blocking)
        {
            int BytesRead = 0;

            Pipes.ReadPipeRequest *ReadPipeRequestPtr = (Pipes.ReadPipeRequest *)Heap.AllocZeroed((uint)sizeof(Pipes.ReadPipeRequest), "BasicInPipe : Alloc ReadPipeRequest");
            try
            {
                if (ReadPipeRequestPtr != null)
                {
                    ReadPipeRequestPtr->PipeId    = PipeId;
                    ReadPipeRequestPtr->Offset    = Offset;
                    ReadPipeRequestPtr->Length    = FOS_System.Math.Min(Data.Length - Offset, Length);
                    ReadPipeRequestPtr->OutBuffer = (byte *)Utilities.ObjectUtilities.GetHandle(Data) + FOS_System.Array.FieldsBytesSize;
                    ReadPipeRequestPtr->Blocking  = Blocking;

                    SystemCallResults SysCallResult = SystemCalls.ReadPipe(ReadPipeRequestPtr, out BytesRead);
                    switch (SysCallResult)
                    {
                    case SystemCallResults.Unhandled:
                        //BasicConsole.WriteLine("BasicInPipe > ReadPipe: Unhandled!");
                        ExceptionMethods.Throw(new Exceptions.RWUnhandledException("BasicInPipe : Read Pipe unexpected unhandled!"));
                        break;

                    case SystemCallResults.Fail:
                        //BasicConsole.WriteLine("BasicInPipe > ReadPipe: Failed!");
                        if (Blocking)
                        {
                            ExceptionMethods.Throw(new Exceptions.RWFailedException("BasicInPipe : Write Pipe unexpected failed! (Blocking call)"));
                        }
                        else
                        {
                            ExceptionMethods.Throw(new Exceptions.RWFailedException("BasicInPipe : Write Pipe failed. (Non-blocking call)"));
                        }
                        break;

                    case SystemCallResults.OK:
                        //BasicConsole.WriteLine("BasicInPipe > ReadPipe: Succeeded.");
                        break;

                    default:
                        //BasicConsole.WriteLine("BasicInPipe > ReadPipe: Unexpected system call result!");
                        ExceptionMethods.Throw(new Exceptions.RWUnhandledException("BasicInPipe : Read Pipe unexpected result!"));
                        break;
                    }
                }
                else
                {
                    ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicInPipe : Couldn't allocate memory to read from pipe!"));
                }
            }
            finally
            {
                if (ReadPipeRequestPtr != null)
                {
                    Heap.Free(ReadPipeRequestPtr);
                }
            }

            return(BytesRead);
        }
예제 #3
0
 public UInt64 this[UInt64 key]
 {
     get
     {
         KeyValuePair *cPair = list;
         while (cPair != null)
         {
             if (cPair->Key == key)
             {
                 return(cPair->Value);
             }
             cPair = cPair->Prev;
         }
         ExceptionMethods.Throw(new Exceptions.ArgumentException("Key not found in dictionary!"));
         return(0);
     }
     set
     {
         KeyValuePair *cPair = list;
         while (cPair != null)
         {
             if (cPair->Key == key)
             {
                 cPair->Value = value;
                 break;
             }
             cPair = cPair->Prev;
         }
         if (cPair == null)
         {
             Add(key, value);
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Gets the UInt32 at the specified index.
        /// </summary>
        /// <param name="index">The index of the UInt32 to get.</param>
        /// <returns>The UInt32 at the specified index.</returns>
        /// <exception cref="Kernel.FOS_System.Exceptions.IndexOutOfRangeException">
        /// Throws IndexOutOfRangeException if "index" is &lt; 0 or greater than the length of the list.
        /// </exception>
        public UInt32 this[int index]
        {
            [Drivers.Compiler.Attributes.NoDebug]
            get
            {
                if (index >= nextIndex)
                {
                    ExceptionMethods.Throw(new Exceptions.IndexOutOfRangeException(index, nextIndex));
                }
                else if (index < 0)
                {
                    ExceptionMethods.Throw(new Exceptions.IndexOutOfRangeException(index, nextIndex));
                }

                return(_array[index]);
            }
            [Drivers.Compiler.Attributes.NoDebug]
            set
            {
                //Throw an exception if the index to set is beyond the length of
                //  the list.
                //Note: Beyond the length of the list not the capacity!
                if (index >= nextIndex)
                {
                    ExceptionMethods.Throw(new Exceptions.IndexOutOfRangeException(index, nextIndex));
                }
                else if (index < 0)
                {
                    ExceptionMethods.Throw(new Exceptions.IndexOutOfRangeException(index, nextIndex));
                }

                _array[index] = value;
            }
        }
예제 #5
0
        public ELFFile(File file)
        {
            theFile = file;
            if (theFile == null)
            {
                Console.Default.ErrorColour();
                Console.Default.Write("Error constructing ELF file! theFile is null");
                BasicConsole.Write("Error constructing ELF file! theFile is null");
                if (file == null)
                {
                    Console.Default.Write(" and file is null");
                    BasicConsole.Write(" and file is null");
                }
                else
                {
                    Console.Default.Write(" and file is NOT null");
                    BasicConsole.Write(" and file is NOT null");
                }
                Console.Default.WriteLine(".");
                BasicConsole.WriteLine(".");
                Console.Default.DefaultColour();
                ExceptionMethods.Throw(new FOS_System.Exception("Error loading ELF file! Supplied file is null."));
            }
            theStream = new CachedFileStream(theFile.GetStream());
            ReadHeader();

            if (IsValidFile())
            {
                ReadSectionHeaders();
                ReadSegmentHeaders();
            }
        }
예제 #6
0
        /// <summary>
        /// Creates and registers a new outpoint of the specified class and subclass.
        /// </summary>
        /// <param name="aClass">The class of pipe allowed to connect to the outpoint.</param>
        /// <param name="aSubclass">The subclass of pipe allowed to connect to the outpoint.</param>
        /// <param name="MaxConnections">
        /// The maximum number of connections allowed. Use <see cref="PipeConstants.UnlimitedConnections"/> for unlimited connections.
        /// </param>
        public BasicOutpoint(PipeClasses aClass, PipeSubclasses aSubclass, int MaxConnections)
        {
            Class    = aClass;
            Subclass = aSubclass;

            SystemCallResults SysCallResult = SystemCalls.RegisterPipeOutpoint(Class, Subclass, MaxConnections);

            switch (SysCallResult)
            {
            case SystemCallResults.Unhandled:
                //BasicConsole.WriteLine("BasicOutPipe > RegisterPipeOutpoint: Unhandled!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Register Pipe Outpoint system call unhandled!"));
                break;

            case SystemCallResults.Fail:
                //BasicConsole.WriteLine("BasicOutPipe > RegisterPipeOutpoint: Failed!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Register Pipe Outpoint system call failed!"));
                break;

            case SystemCallResults.OK:
                //BasicConsole.WriteLine("BasicOutPipe > RegisterPipeOutpoint: Succeeded.");
                break;

            default:
                //BasicConsole.WriteLine("BasicOutPipe > RegisterPipeOutpoint: Unexpected system call result!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Register Pipe Outpoint system call unexpected result!"));
                break;
            }
        }
예제 #7
0
        /// <summary>
        /// Waits for a pipe to connect to the outpoint.
        /// </summary>
        /// <returns>The Id of the newly connected pipe.</returns>
        public int WaitForConnect()
        {
            int aPipeId;
            SystemCallResults SysCallResult = SystemCalls.WaitOnPipeCreate(Class, Subclass, out aPipeId);

            switch (SysCallResult)
            {
            case SystemCallResults.Unhandled:
                //BasicConsole.WriteLine("BasicOutPipe > WaitOnPipeCreate: Unhandled!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Wait On Pipe Create unhandled!"));
                break;

            case SystemCallResults.Fail:
                //BasicConsole.WriteLine("BasicOutPipe > WaitOnPipeCreate: Failed!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Wait On Pipe Create failed!"));
                break;

            case SystemCallResults.OK:
                //BasicConsole.WriteLine("BasicOutPipe > WaitOnPipeCreate: Succeeded.");
                //BasicConsole.Write("BasicOutPipe > New pipe id: ");
                //BasicConsole.WriteLine(aPipeId);
                break;

            default:
                //BasicConsole.WriteLine("BasicOutPipe > WaitOnPipeCreate: Unexpected system call result!");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicOutPipe : Wait On Pipe Create unexpected result!"));
                break;
            }
            return(aPipeId);
        }
예제 #8
0
        public FOS_System.Object Peek()
        {
            AccessLock.Enter();

            try
            {
                if (WriteIdx == -1)
                {
                    if (ThrowExceptions)
                    {
                        ExceptionMethods.Throw(new Exceptions.OverflowException("Circular buffer cannot Peek because the buffer is empty."));
                    }
                    return(null);
                }

                int tmpReadIdx = ReadIdx;

                tmpReadIdx++;
                if (tmpReadIdx == _array.Length)
                {
                    tmpReadIdx = 0;
                }

                return(_array[tmpReadIdx]);
            }
            finally
            {
                AccessLock.Exit();
            }
        }
예제 #9
0
        /// <summary>
        /// Initializes the specified disk device.
        /// </summary>
        /// <param name="aDiskDevice">The disk device to initialize.</param>
        public static void InitDisk(DiskDevice aDiskDevice)
        {
            //TODO - Add more partitioning schemes.


            if (InitAsISO9660(aDiskDevice))
            {
#if FSM_TRACE
                BasicConsole.WriteLine("ISO9660 CD/DVD disc detected!");
                BasicConsole.DelayOutput(3);
#endif
            }
            //Must check for GPT before MBR because GPT uses a protective
            //  MBR entry so will be seen as valid MBR.
            else if (InitAsGPT(aDiskDevice))
            {
#if FSM_TRACE
                BasicConsole.WriteLine("GPT formatted disk detected!");
                BasicConsole.DelayOutput(3);
#endif
            }
            else if (!InitAsMBR(aDiskDevice))
            {
                ExceptionMethods.Throw(new FOS_System.Exceptions.NotSupportedException("Non MBR/EBR/GPT/ISO9660 formatted disks not supported."));
            }
        }
예제 #10
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (count < 0)
            {
                ExceptionMethods.Throw(new Exceptions.ArgumentException("CachedFileStream.Write: count must be > 0"));
            }
            else if (offset < 0)
            {
                ExceptionMethods.Throw(new Exceptions.ArgumentException("CachedFileStream.Write: offset must be > 0"));
            }
            else if (buffer == null)
            {
                ExceptionMethods.Throw(new Exceptions.ArgumentException("CachedFileStream.Write: buffer must not be null!"));
            }
            else if (buffer.Length - offset < count)
            {
                ExceptionMethods.Throw(new Exceptions.ArgumentException("CachedFileStream.Write: Invalid offset / length values!"));
            }


            if (CachedData.Length < ((int)Position + count))
            {
                byte[] NewCachedData = new byte[offset + count];
                FOS_System.Array.Copy(CachedData, 0, NewCachedData, 0, CachedData.Length);
                CachedData = NewCachedData;
            }

            FOS_System.Array.Copy(buffer, offset, CachedData, (int)Position, count);

            UnderlyingStream.Write(buffer, offset, count);
        }
예제 #11
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int maxToRead = FOS_System.Math.Min(count, CachedData.Length - (int)Position);

            if (count < 0)
            {
                ExceptionMethods.Throw(new Exceptions.ArgumentException("CachedFileStream.Read: count must be > 0"));
            }
            else if (offset < 0)
            {
                ExceptionMethods.Throw(new Exceptions.ArgumentException("CachedFileStream.Read: offset must be > 0"));
            }
            else if (buffer == null)
            {
                ExceptionMethods.Throw(new Exceptions.ArgumentException("CachedFileStream.Read: buffer must not be null!"));
            }
            else if (buffer.Length - offset < count)
            {
                ExceptionMethods.Throw(new Exceptions.ArgumentException("CachedFileStream.Read: Invalid offset / length values!"));
            }

            FOS_System.Array.Copy(CachedData, (int)Position, buffer, offset, maxToRead);

            return(maxToRead);
        }
예제 #12
0
        public void Add(UInt32 key, UInt32 value, bool SkipCheck = false)
        {
            if (!SkipCheck)
            {
                if (Contains(key))
                {
                    ExceptionMethods.Throw(new FOS_System.Exception("Cannot add duplicate key to the dictionary!"));
                }
            }

            KeyValuePair *newItem     = null;
            KeyValuePair *newNext     = null;
            KeyValuePair *newPrev     = null;
            KeyValuePair *newListNext = null;
            bool          Alloc       = true;

            if (list != null)
            {
                if (list->Empty)
                {
                    newItem     = list;
                    newNext     = newItem->Next;
                    newPrev     = null;
                    newListNext = newItem->Next;
                    Alloc       = false;
                }
                else if (list->Next != null)
                {
                    newItem     = list->Next;
                    newNext     = newItem->Next;
                    newPrev     = newItem->Prev;
                    newListNext = newItem;
                    Alloc       = false;
                }
                else
                {
                    Alloc = true;
                }
            }
            if (Alloc)
            {
                newItem     = (KeyValuePair *)Heap.Alloc((uint)sizeof(KeyValuePair), "UInt32Dictionary.Add");
                newNext     = null;
                newPrev     = list;
                newListNext = newItem;
            }

            newItem->Key   = key;
            newItem->Value = value;
            newItem->Next  = newNext;
            newItem->Prev  = newPrev;
            newItem->Empty = false;

            if (list != null && newItem != list)
            {
                list->Next = newListNext;
            }
            list = newItem;
        }
예제 #13
0
 /// <summary>
 /// Initializes a new ISO9660 file stream for the specified file.
 /// </summary>
 /// <param name="aFile">The file to create a stream to.</param>
 public ISO9660FileStream(ISO9660File aFile)
     : base(aFile)
 {
     if (TheISO9660File == null)
     {
         ExceptionMethods.Throw(new Exception("Could not create ISO9660FileStream. Specified file object was null!"));
     }
 }
예제 #14
0
 public CircularBuffer(int size, bool throwExceptions)
 {
     ThrowExceptions = throwExceptions;
     if (ThrowExceptions && size <= 0)
     {
         ExceptionMethods.Throw(new Exceptions.ArgumentException("Size of circular buffer cannot be less than or equal to zero!"));
     }
     _array = new FOS_System.Object[size];
 }
예제 #15
0
        public void ReadSegmentHeaders()
        {
            byte[] segmentsData = new byte[header.ProgHeaderEntrySize * header.ProgHeaderNumEntries];
            theStream.Position = header.ProgHeaderTableOffset;
            int bytesRead = theStream.Read(segmentsData, 0, segmentsData.Length);

            if (bytesRead == segmentsData.Length)
            {
                uint offset = 0;
                while (offset < segmentsData.Length)
                {
                    ELFSegmentHeader newHeader  = new ELFSegmentHeader(segmentsData, ref offset);
                    ELFSegment       newSegment = ELFSegment.GetSegment(newHeader);

                    newSegment.Read(theStream);

                    Segments.Add(newSegment);
                }

                //BasicConsole.WriteLine();

                #region Segments Output

                //for (int i = 0; i < Segments.Count; i++)
                //{
                //    ELFSegment theSegment = (ELFSegment)Segments[i];
                //    ELFSegmentHeader theHeader = theSegment.Header;
                //    BasicConsole.WriteLine("ELF Segment: ");
                //    BasicConsole.Write(" - Type : ");
                //    BasicConsole.WriteLine((uint)theHeader.Type);
                //    BasicConsole.Write(" - File offset : ");
                //    BasicConsole.WriteLine(theHeader.FileOffset);
                //    BasicConsole.Write(" - Virtual address : ");
                //    BasicConsole.WriteLine((uint)theHeader.VAddr);
                //    BasicConsole.Write(" - Physical address : ");
                //    BasicConsole.WriteLine((uint)theHeader.PAddr);
                //    BasicConsole.Write(" - File size : ");
                //    BasicConsole.WriteLine(theHeader.FileSize);
                //    BasicConsole.Write(" - Memory size : ");
                //    BasicConsole.WriteLine(theHeader.MemSize);
                //    BasicConsole.Write(" - Flags : ");
                //    BasicConsole.WriteLine((uint)theHeader.Flags);
                //    BasicConsole.Write(" - Alignment : ");
                //    BasicConsole.WriteLine(theHeader.Align);

                //    Hardware.Processes.Thread.Sleep(500);
                //      TODO: Use system call not direct call
                //}

                #endregion
            }
            else
            {
                ExceptionMethods.Throw(new FOS_System.Exception("Failed to read segments table data from file!"));
            }
        }
예제 #16
0
        public void Add(UInt32 key, UInt32 value)
        {
            if (Keys.IndexOf(key) > -1)
            {
                ExceptionMethods.Throw(new FOS_System.Exception("Cannot add duplicate key to the dictionary!"));
            }

            Keys.Add(key);
            Values.Add(value);
        }
예제 #17
0
파일: FATFile.cs 프로젝트: zrbruce/FlingOS
        /// <summary>
        /// Deletes the listing from the file system.
        /// </summary>
        /// <returns>True if the listing was deleted. Otherwise, false.</returns>
        public override bool Delete()
        {
            if (TheFATFileSystem.FATType != FATFileSystem.FATTypeEnum.FAT32)
            {
                ExceptionMethods.Throw(new Exceptions.NotSupportedException("FATFile.Delete for non-FAT32 not supported!"));
            }

#if FATFILE_TRACE
            BasicConsole.WriteLine("FATFile.Delete : Reading cluster chain...");
#endif
            UInt32List clusters = TheFATFileSystem.ReadClusterChain(Size, FirstClusterNum);
#if FATFILE_TRACE
            BasicConsole.WriteLine("FATFile.Delete : Processing cluster chain...");
#endif
            for (int i = 0; i < clusters.Count; i++)
            {
#if FATFILE_TRACE
                BasicConsole.WriteLine("FATFile.Delete : Writing cluster...");
#endif
                //Write 0s (null) to clusters
                TheFATFileSystem.WriteCluster(clusters[i], null);

#if FATFILE_TRACE
                BasicConsole.WriteLine("FATFile.Delete : Setting FAT entry...");
#endif
                //Write "empty" to FAT entries
                TheFATFileSystem.SetFATEntryAndSave(clusters[i], 0);
            }

            //If the file actually being used to read/write a FATDirectory,
            //      it will not be in the parent listings, the FATDirectory instance will be.
            //      So we should not attempt to edit the parent listings from within the
            //      FATFile instance.
            if (!IsDirectoryFile)
            {
#if FATFILE_TRACE
                BasicConsole.WriteLine("FATFile.Delete : Removing listing...");
#endif
                //Remove listing
                Parent.RemoveListing(this);

#if FATFILE_TRACE
                BasicConsole.WriteLine("FATFile.Delete : Writing listings...");
#endif
                //Write listings
                Parent.WriteListings();
            }

#if FATFILE_TRACE
            BasicConsole.WriteLine("FATFile.Delete : Complete.");
#endif

            return(true);
        }
예제 #18
0
파일: PIT.cs 프로젝트: zrbruce/FlingOS
        public int RegisterHandler(PITHandler handler)
        {
            if (handler.id != -1)
            {
                ExceptionMethods.Throw(new FOS_System.Exception("Timer has already been registered!"));
            }

            handler.id = (TimerIdGenerator++);
            ActiveHandlers.Add(handler);

            return(handler.id);
        }
예제 #19
0
        public virtual int Read(FileStream stream)
        {
            data            = new byte[header.SectionSize];
            stream.Position = header.SectionFileOffset;
            int bytesRead = stream.Read(data, 0, data.Length);

            if (bytesRead != data.Length)
            {
                ExceptionMethods.Throw(new FOS_System.Exception("Failed to read section data from file!"));
            }
            return(bytesRead);
        }
예제 #20
0
 public bool CheckSiganture()
 {
     if (header != null)
     {
         return(header.SignatureOK);
     }
     else
     {
         ExceptionMethods.Throw(new FOS_System.Exception("Failed to load ELF header so cannot check signature!"));
     }
     return(false);
 }
예제 #21
0
 public bool CheckDataEncoding()
 {
     if (header != null)
     {
         return(header.DataEncoding == ELFDataEncoding.LSB);
     }
     else
     {
         ExceptionMethods.Throw(new FOS_System.Exception("Failed to load ELF header so cannot check data encoding!"));
     }
     return(false);
 }
예제 #22
0
 public bool CheckMachine()
 {
     if (header != null)
     {
         return(header.Machine == ELFMachines.Intel80386);
     }
     else
     {
         ExceptionMethods.Throw(new FOS_System.Exception("Failed to load ELF header so cannot check file class!"));
     }
     return(false);
 }
예제 #23
0
 public bool IsSharedObject()
 {
     if (header != null)
     {
         return(header.FileType == ELFFileType.Shared);
     }
     else
     {
         ExceptionMethods.Throw(new FOS_System.Exception("Failed to load ELF header so cannot check file class!"));
     }
     return(false);
 }
예제 #24
0
        /// <summary>
        /// Initializes a new FAT file stream for the specified file.
        /// </summary>
        /// <param name="aFile">The file to create a stream to.</param>
        /// <param name="ignoreFileSize">Whether to ignore the file size or not. True for directories.</param>
        public FATFileStream(FATFile aFile, bool ignoreFileSize)
            : base(aFile)
        {
            IgnoreFileSize = ignoreFileSize;

            if (TheFATFile == null)
            {
                ExceptionMethods.Throw(new Exception("Could not create FATFileStream. Specified file object was null!"));
            }

            GetClusterNums();
        }
예제 #25
0
        public ELFProcess LoadExecutable(bool UserMode)
        {
            if (!IsExecutable())
            {
                ExceptionMethods.Throw(new FOS_System.Exception("Attempted to load non-executable ELF as executable!"));
            }

            ELFProcess process = new ELFProcess(this);

            process.Load(UserMode);
            return(process);
        }
예제 #26
0
        public ELFSharedObject LoadSharedObject(ELFProcess theProcess)
        {
            if (!IsSharedObject())
            {
                ExceptionMethods.Throw(new FOS_System.Exception("Attempted to load non-shared ELF as shared object!"));
            }

            ELFSharedObject sharedObject = new ELFSharedObject(this, theProcess);

            sharedObject.Load();
            return(sharedObject);
        }
예제 #27
0
        /// <summary>
        /// Gets the outpoint desciptors of the available outpoints of the specified class and subclass.
        /// </summary>
        /// <param name="numOutpoints">The known number of available outpoints. Use GetNumPipeOutpoints to obtain this number.</param>
        /// <param name="SysCallResult">Out : The result of the system call. Check this is set to OK.</param>
        /// <param name="OutpointDescriptors">Out : The array of outpoint descriptors.</param>
        /// <param name="Class">The class of pipe to search for.</param>
        /// <param name="Subclass">The subclass of pipe to search for.</param>
        public static void GetOutpointDescriptors(int numOutpoints, out SystemCallResults SysCallResult, out Pipes.PipeOutpointDescriptor[] OutpointDescriptors, Pipes.PipeClasses Class, Pipes.PipeSubclasses Subclass)
        {
            OutpointDescriptors = new Pipes.PipeOutpointDescriptor[numOutpoints];

            Pipes.PipeOutpointsRequest *RequestPtr = (Pipes.PipeOutpointsRequest *)Heap.AllocZeroed((uint)sizeof(Pipes.PipeOutpointsRequest), "BasicServerHelpers : Alloc PipeOutpointsRequest");
            if (RequestPtr != null)
            {
                try
                {
                    RequestPtr->MaxDescriptors = numOutpoints;
                    RequestPtr->Outpoints      = (Pipes.PipeOutpointDescriptor *)((byte *)Utilities.ObjectUtilities.GetHandle(OutpointDescriptors) + FOS_System.Array.FieldsBytesSize);
                    if (RequestPtr->Outpoints != null)
                    {
                        SysCallResult = SystemCalls.GetPipeOutpoints(Class, Subclass, RequestPtr);
                        switch (SysCallResult)
                        {
                        case SystemCallResults.Unhandled:
                            //BasicConsole.WriteLine("BasicServerHelpers > GetPipeOutpoints: Unhandled!");
                            break;

                        case SystemCallResults.Fail:
                            //BasicConsole.WriteLine("BasicServerHelpers > GetPipeOutpoints: Failed!");
                            break;

                        case SystemCallResults.OK:
                            //BasicConsole.WriteLine("BasicServerHelpers > GetPipeOutpoints: Succeeded.");
                            break;

                        default:
                            //BasicConsole.WriteLine("BasicServerHelpers > GetPipeOutpoints: Unexpected system call result!");
                            break;
                        }
                    }
                    else
                    {
                        SysCallResult = SystemCallResults.Fail;
                        //BasicConsole.WriteLine("BasicServerHelpers > RequestPtr->Outpoints null! No memory allocated.");
                        ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicServerHelpers : Couldn't allocate memory outpoints list in outpoints request!"));
                    }
                }
                finally
                {
                    Heap.Free(RequestPtr);
                }
            }
            else
            {
                SysCallResult = SystemCallResults.Fail;
                //BasicConsole.WriteLine("BasicServerHelpers > RequestPtr null! No memory allocated.");
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicServerHelpers : Couldn't allocate memory get outpoints request!"));
            }
        }
예제 #28
0
파일: String.cs 프로젝트: zrbruce/FlingOS
 public static unsafe FOS_System.String New(int length)
 {
     if (length < 0)
     {
         ExceptionMethods.Throw(new Exceptions.ArgumentException("Parameter \"length\" cannot be less than 0 in FOS_System.String.New(int length)."));
     }
     FOS_System.String result = (FOS_System.String)Utilities.ObjectUtilities.GetObject(GC.NewString(length));
     if (result == null)
     {
         ExceptionMethods.Throw(new Exceptions.NullReferenceException());
     }
     return(result);
 }
예제 #29
0
        /// <summary>
        /// Creates and connects a new pipe to the specified target process.
        /// </summary>
        /// <param name="anOutProcessId">The target process to connect to.</param>
        /// <param name="aClass">The class of pipe to create.</param>
        /// <param name="aSubclass">The subclass of pipe to create.</param>
        /// <param name="aBufferSize">The size of buffer to use within the core OS.</param>
        public BasicInpoint(uint anOutProcessId, PipeClasses aClass, PipeSubclasses aSubclass, int aBufferSize)
        {
            OutProcessId = anOutProcessId;
            Class        = aClass;
            Subclass     = aSubclass;
            BufferSize   = aBufferSize;

            Pipes.CreatePipeRequest *RequestPtr = (Pipes.CreatePipeRequest *)Heap.AllocZeroed((uint)sizeof(Pipes.CreatePipeRequest), "BasicInPipe : Alloc CreatePipeRequest");
            if (RequestPtr != null)
            {
                try
                {
                    RequestPtr->BufferSize = aBufferSize;
                    RequestPtr->Class      = aClass;
                    RequestPtr->Subclass   = aSubclass;

                    SystemCallResults SysCallResult = SystemCalls.CreatePipe(anOutProcessId, RequestPtr);
                    switch (SysCallResult)
                    {
                    case SystemCallResults.Unhandled:
                        //BasicConsole.WriteLine("BasicInPipe > CreatePipe: Unhandled!");
                        break;

                    case SystemCallResults.Fail:
                        //BasicConsole.WriteLine("BasicInPipe > CreatePipe: Failed!");
                        break;

                    case SystemCallResults.OK:
                        //BasicConsole.WriteLine("BasicInPipe > CreatePipe: Succeeded.");
                        PipeId = RequestPtr->Result.Id;

                        //BasicConsole.Write("BasicInPipe > CreatePipe: New pipe id = ");
                        //BasicConsole.WriteLine(PipeId);
                        break;

                    default:
                        //BasicConsole.WriteLine("BasicInPipe > CreatePipe: Unexpected system call result!");
                        break;
                    }
                }
                finally
                {
                    Heap.Free(RequestPtr);
                }
            }
            else
            {
                ExceptionMethods.Throw(new FOS_System.Exceptions.ArgumentException("BasicInPipe : Couldn't allocate memory to create pipe!"));
                //BasicConsole.WriteLine("BasicInPipe > RequestPtr null! No memory allocated.");
            }
        }
예제 #30
0
        public override uint FindFreeVirtPageAddrs(int num)
        {
            int result = UsedVirtPages.FindContiguousClearEntries(num);

            if (result == -1)
            {
                BasicConsole.WriteLine("Error finding free virtual pages!");
                BasicConsole.DelayOutput(10);

                ExceptionMethods.Throw(new FOS_System.Exceptions.OutOfMemoryException("Could not find any more free virtual pages."));
            }

            return((uint)(result * 4096));
        }