Ejemplo n.º 1
0
 /// <summary>
 /// Init heap.
 /// </summary>
 /// <exception cref="Exception">Thrown on fatal error, contact support.</exception>
 public static unsafe void Init()
 {
     StackStart = (uint *)CPU.GetStackStart();
     HeapSmall.Init();
     HeapMedium.Init();
     HeapLarge.Init();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Alloc memory block, of a given size.
 /// </summary>
 /// <param name="aSize">A size of block to alloc, in bytes.</param>
 /// <returns>Byte pointer to the start of the block.</returns>
 public static byte *Alloc(Native aSize)
 {
     if (aSize <= HeapSmall.mMaxItemSize)
     {
         return(HeapSmall.Alloc(aSize));
     }
     else if (aSize <= HeapMedium.MaxItemSize)
     {
         return(HeapMedium.Alloc(aSize));
     }
     else
     {
         return(HeapLarge.Alloc(aSize));
     }
 }
Ejemplo n.º 3
0
        // Keep as void* and not byte* or other. Reduces typecasting from callers
        // who may have typed the pointer to their own needs.
        /// <summary>
        /// Free a heap item.
        /// </summary>
        /// <param name="aPtr">A pointer to the heap item to be freed.</param>
        /// <exception cref="Exception">Thrown if:
        /// <list type="bullet">
        /// <item>Page type is not found.</item>
        /// <item>Heap item not found in RAT.</item>
        /// </list>
        /// </exception>
        public static void Free(void *aPtr)
        {
            //TODO find a better way to remove the double look up here for GetPageType and then again in the
            // .Free methods which actually free the entries in the RAT.
            var xType = RAT.GetPageType(aPtr);

            switch (xType)
            {
            case RAT.PageType.HeapLarge:
                HeapLarge.Free(aPtr);
                break;

            default:
                throw new Exception("Heap item not found in RAT.");
            }
        }
Ejemplo n.º 4
0
        // Keep as void* and not byte* or other. Reduces typecasting from callers
        // who may have typed the pointer to their own needs.
        /// <summary>
        /// Free a heap item.
        /// </summary>
        /// <param name="aPtr">A pointer to the heap item to be freed.</param>
        /// <exception cref="Exception">Thrown if:
        /// <list type="bullet">
        /// <item>Page type is not found.</item>
        /// <item>Heap item not found in RAT.</item>
        /// </list>
        /// </exception>
        public static void Free(void *aPtr)
        {
            //TODO find a better way to remove the double look up here for GetPageType and then again in the
            // .Free methods which actually free the entries in the RAT.
            //Debugger.DoSendNumber(0x77);
            //Debugger.DoSendNumber((uint)aPtr);
            var xType = RAT.GetPageType(aPtr);

            switch (xType)
            {
            case RAT.PageType.HeapSmall:
                HeapSmall.Free(aPtr);
                break;

            case RAT.PageType.HeapMedium:
            case RAT.PageType.HeapLarge:
                HeapLarge.Free(aPtr);
                break;

            default:
                throw new Exception("Heap item not found in RAT.");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Alloc memory block, of a given size.
        /// </summary>
        /// <param name="aSize">A size of block to alloc, in bytes.</param>
        /// <returns>Byte pointer to the start of the block.</returns>
        public static byte *Alloc(uint aSize)
        {
            CPU.DisableInterrupts();

            if (aSize <= HeapSmall.mMaxItemSize)
            {
                byte *ptr = HeapSmall.Alloc((ushort)aSize);
                CPU.EnableInterrupts();
                return(ptr);
            }
            else if (aSize <= HeapMedium.MaxItemSize)
            {
                byte *ptr = HeapMedium.Alloc(aSize);
                CPU.EnableInterrupts();
                return(ptr);
            }
            else
            {
                byte *ptr = HeapLarge.Alloc(aSize);
                CPU.EnableInterrupts();
                return(ptr);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Init heap.
 /// </summary>
 /// <exception cref="Exception">Thrown on fatal error, contact support.</exception>
 public static void Init()
 {
     HeapSmall.Init();
     HeapMedium.Init();
     HeapLarge.Init();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Free block.
 /// </summary>
 /// <param name="aPtr">A pointer to the block.</param>
 /// <exception cref="Exception">Thrown if page type is not found.</exception>
 static public void Free(void *aPtr)
 {
     HeapLarge.Free(aPtr);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Alloc memory block, of a given size.
 /// </summary>
 /// <param name="aSize">A size of block to alloc, in bytes.</param>
 /// <returns>Byte pointer to the start of the block.</returns>
 static public byte *Alloc(Native aSize)
 {
     return(HeapLarge.Alloc(aSize));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Alloc memory block, of a given size.
 /// </summary>
 /// <param name="aSize">A size of block to alloc, in bytes.</param>
 /// <returns>Byte pointer to the start of the block.</returns>
 static public byte *Alloc(uint aSize)
 {
     return(HeapLarge.Alloc(aSize, RAT.PageType.HeapMedium));
 }