Reserve() public static method

Reserves the pages.
public static Reserve ( uint size ) : uint
size uint The size.
return uint
Beispiel #1
0
        private static void CreateThread(Pointer methodAddress, uint stackSize, uint threadID)
        {
            var thread = Threads[threadID];

            var stack    = new Pointer(VirtualPageAllocator.Reserve(stackSize));
            var stackTop = stack + stackSize;

            // Setup stack state
            stackTop.Store32(-4, 0);                                              // Zero Sentinel
            stackTop.Store32(-8, SignalThreadTerminationMethodAddress.ToInt32()); // Address of method that will raise a interrupt signal to terminate thread

            stackTop.Store32(-12, 0x00000202);                                    // EFLAG
            stackTop.Store32(-16, 0x08);                                          // CS
            stackTop.Store32(-20, methodAddress.ToInt32());                       // EIP

            stackTop.Store32(-24, 0);                                             // ErrorCode - not used
            stackTop.Store32(-28, 0);                                             // Interrupt Number - not used

            stackTop.Store32(-32, 0);                                             // EAX
            stackTop.Store32(-36, 0);                                             // ECX
            stackTop.Store32(-40, 0);                                             // EDX
            stackTop.Store32(-44, 0);                                             // EBX
            stackTop.Store32(-48, 0);                                             // ESP (original) - not used
            stackTop.Store32(-52, (stackTop - 8).ToInt32());                      // EBP
            stackTop.Store32(-56, 0);                                             // ESI
            stackTop.Store32(-60, 0);                                             // EDI

            thread.Status            = ThreadStatus.Running;
            thread.StackBottom       = stack;
            thread.StackTop          = stackTop;
            thread.StackStatePointer = stackTop - 60;
        }
        /// <summary>
        /// Setups the process manager.
        /// </summary>
        public static unsafe void Setup()
        {
            // Allocate memory for the process table
            _table = (uint)VirtualPageAllocator.Reserve((uint)(_slots * Offset.TotalSize));

            // Create idle process
            CreateProcess(0);
        }
        /// <summary>
        /// Allocates the memory.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="size">The size.</param>
        /// <returns></returns>
        public static uint AllocateMemory(uint process, uint size)
        {
            uint address = VirtualPageAllocator.Reserve(size);

            UpdateMemoryBitMap(process, address, size, false);

            return(address);
        }
Beispiel #4
0
        /// <summary>
        /// Setups the process manager.
        /// </summary>
        public static void Setup()
        {
            // Allocate memory for the process table
            table = VirtualPageAllocator.Reserve(slots * Offset.TotalSize);

            // Create idle process
            CreateProcess(0);
        }
        /// <summary>
        /// Creates the process.
        /// </summary>
        /// <returns></returns>
        private static unsafe uint CreateProcess(uint slot)
        {
            uint process = GetProcessLocation(slot);

            Native.Set32(process + Offset.Status, Status.Running);
            Native.Set32(process + Offset.ProcessID, slot);
            Native.Set32(process + Offset.MemoryMap, (uint)VirtualPageAllocator.Reserve(32U * 4096U));
            Native.Set32(process + Offset.Lock, 0);

            return(slot);
        }
Beispiel #6
0
        /// <summary>
        /// Setups the task manager.
        /// </summary>
        public static void Setup()
        {
            // Allocate memory for the task table
            table = (uint)VirtualPageAllocator.Reserve(slots * Offset.TotalSize);

            uint stack = ProcessManager.AllocateMemory(0, defaultStackSize);

            // Create idle task
            CreateTask(0, 0);

            // Set current stack
            currenttask = 0;
        }
Beispiel #7
0
        static public uint AllocateMemory(uint size)
        {
            if (heapStart == 0 || (heapSize - heapUsed) < size)
            {
                // Go allocate memory
                heapSize  = 1024 * 1023 * 8;                // 8Mb
                heapStart = VirtualPageAllocator.Reserve(heapSize);
                heapUsed  = 0;
            }

            uint at = heapStart + heapUsed;

            heapUsed = heapUsed + size;
            return(at);
        }
Beispiel #8
0
        static public Pointer AllocateVirtualMemory(uint size)
        {
            if (heapStart == 0 || (heapSize - heapUsed) < size)
            {
                // Go allocate memory
                heapSize  = 1024 * 1023 * 8;                // 8Mb
                heapStart = VirtualPageAllocator.Reserve(heapSize);
                heapUsed  = 0;
            }

            var at = new Pointer(heapStart + heapUsed);

            heapUsed += size;
            return(at);
        }
Beispiel #9
0
        static public uint AllocateMemory(uint size)
        {
            if ((heap == 0) || (size > (allocated - used)))
            {
                // Go allocate memory

                allocated = 1024 * 1024 * 64;                 // 64Mb
                heap      = VirtualPageAllocator.Reserve(size);
                used      = 0;
            }

            uint at = heap + used;

            used = used + size;
            return(at);
        }