Exemplo n.º 1
0
        private static unsafe int sys_open(sbyte *file, int flags, int mode)
        {
            var filename = new string(file);
            var stream   = VirtualFileSystem.GetFile(filename);

            Debug.Write("fopen: %s\n", filename);
            Heap.Free(filename);

            if (stream == null)
            {
                return(-1);
            }

            var Process = Scheduler.RunningProcess;
            var files   = Process.Files;
            int count   = files.Count;

            int fd = -1;

            for (int index = 0; index < count; index++)
            {
                if (files[index] == null)
                {
                    files[index] = stream;
                    fd           = index;
                }
            }

            if (fd == -1)
            {
                files.Add(stream);
                fd = count;
            }

            return(fd);
        }
Exemplo n.º 2
0
 internal void Free()
 {
     Heap.Free(Dead);
     Heap.Free(StackBottom, StackLimit);
     Heap.Free(this);
 }
Exemplo n.º 3
0
        internal static void Collect()
        {
            SortObjects();

            // unmark objects
            int count = mAllocatedObjectCount;

            for (int i = 0; i < count; i++)
            {
                mAllocatedObjectSize[i] &= 0x7FFFFFFF;
            }

            // trace stack
            var threads     = Scheduler.SystemProcess.Threads;
            int threadcount = threads.Count;

            for (int i = 0; i < threadcount; i++)
            {
                var  thread  = threads[i];
                uint limit   = thread.StackTop;
                uint pointer = thread.StackCurrent;
                while (pointer < limit)
                {
                    MarkObject(*(uint *)pointer);
                    pointer += 4;
                }
            }

            // trace global
            uint start = Native.GlobalVarStart();
            uint end   = Native.GlobalVarEnd();

            while (start < end)
            {
                MarkObject(*(uint *)start);
                start += 4;
            }

            // free unmarked objects
            int  index       = 0;
            uint MemoryFreed = 0;

            for (int i = 0; i < count; i++)
            {
                if ((mAllocatedObjectSize[i] & (1U << 31)) != 0)
                {
                    mAllocatedObjects[index]    = mAllocatedObjects[i];
                    mAllocatedObjectSize[index] = mAllocatedObjectSize[i];
                    index++;
                }
                else
                {
                    MemoryFreed += mAllocatedObjectSize[i];
                    Heap.Free(mAllocatedObjects[i], mAllocatedObjectSize[i]);
                }
            }

            mAllocatedObjectCount = index;
            mMemoryUsage         -= MemoryFreed;

            Debug.Write("[GC]\tMemory Freed: %d\n", MemoryFreed);
        }