Beispiel #1
0
        public static unsafe Testing2.String Concat(Testing2.String str1, Testing2.String str2)
        {
            Testing2.String newStr = New(str1.length + str2.length);

            for (int i = 0; i < str1.length; i++)
            {
                newStr[i] = str1[i];
            }
            for (int i = 0; i < str2.length; i++)
            {
                newStr[i + str1.length] = str2[i];
            }
            return newStr;
        }
Beispiel #2
0
        public static void* NewArr(int length, Testing2.Type elemType)
        {
            if (!Enabled)
            {
                BasicConsole.SetTextColour(BasicConsole.warning_colour);
                BasicConsole.WriteLine("Warning! GC returning null pointer because GC not enabled.");
                BasicConsole.DelayOutput(10);
                BasicConsole.SetTextColour(BasicConsole.default_colour);

                return null;
            }

            //try
            {

                if (length < 0)
                {
                    UART.Write("length < 0. Overflow exception.");
                    return null;
                    //ExceptionMethods.Throw_OverflowException();
                }

                InsideGC = true;

                //Alloc space for GC header that prefixes object data
                //Alloc space for new array object
                //Alloc space for new array elems

                uint totalSize = ((Testing2.Type)typeof(Testing2.Array)).Size;
                if (elemType.IsValueType)
                {
                    totalSize += elemType.Size * (uint)length;
                }
                else
                {
                    totalSize += elemType.StackSize * (uint)length;
                }
                totalSize += (uint)sizeof(GCHeader);

                GCHeader* newObjPtr = (GCHeader*)Heap.AllocZeroed(totalSize, "GC : NewArray");

                if ((UInt32)newObjPtr == 0)
                {
                    InsideGC = false;

                    BasicConsole.SetTextColour(BasicConsole.error_colour);
                    BasicConsole.WriteLine("Error! GC can't create a new array because the heap returned a null pointer.");
                    BasicConsole.DelayOutput(10);
                    BasicConsole.SetTextColour(BasicConsole.default_colour);

                    return null;
                }

                NumObjs++;

                //Initialise the GCHeader
                SetSignature(newObjPtr);
                newObjPtr->RefCount = 1;

                Testing2.Array newArr = (Testing2.Array)Utilities.ObjectUtilities.GetObject(newObjPtr + 1);
                newArr._Type = (Testing2.Type)typeof(Testing2.Array);
                newArr.length = length;
                newArr.elemType = elemType;

                //Move past GCHeader
                byte* newObjBytePtr = (byte*)(newObjPtr + 1);

                InsideGC = false;

                return newObjBytePtr;
            }
            //finally
            {
            }
        }
Beispiel #3
0
        public static void* NewObj(Testing2.Type theType)
        {
            if (!Enabled)
            {
                BasicConsole.SetTextColour(BasicConsole.warning_colour);
                BasicConsole.WriteLine("Warning! GC returning null pointer because GC not enabled.");
                BasicConsole.DelayOutput(10);
                BasicConsole.SetTextColour(BasicConsole.default_colour);

                return null;
            }
            
            //try
            //{
                InsideGC = true;

                //Alloc space for GC header that prefixes object data
                //Alloc space for new object

                uint totalSize = theType.Size;
                totalSize += (uint)sizeof(GCHeader);

                GCHeader* newObjPtr = (GCHeader*)Heap.AllocZeroed(totalSize, "GC : NewObject");

                if ((UInt32)newObjPtr == 0)
                {
                    InsideGC = false;

                    BasicConsole.SetTextColour(BasicConsole.error_colour);
                    BasicConsole.WriteLine("Error! GC can't create a new object because the heap returned a null pointer.");
                    BasicConsole.DelayOutput(10);
                    BasicConsole.SetTextColour(BasicConsole.default_colour);

                    return null;
                }

                NumObjs++;

                //Initialise the GCHeader
                SetSignature(newObjPtr);
                newObjPtr->RefCount = 1;
                //Initialise the object _Type field
                Testing2.ObjectWithType newObj = (Testing2.ObjectWithType)Utilities.ObjectUtilities.GetObject(newObjPtr + 1);
                newObj._Type = theType;

                //Move past GCHeader
                byte* newObjBytePtr = (byte*)(newObjPtr + 1);

                InsideGC = false;

                return newObjBytePtr;
            //}
            //finally
            //{
            //}
        }
Beispiel #4
0
 public static void Write(Testing2.String str)
 {
     for (int i = 0; i < str.length; i++)
     {
         Write(str[i]);
     }
 }
Beispiel #5
0
 public static void FillString(uint value, int offset, Testing2.String str)
 {
     int end = offset - 8;
     while (offset > end)
     {
         uint rem = value & 0xFu;
         switch (rem)
         {
             case 0:
                 str[offset] = '0';
                 break;
             case 1:
                 str[offset] = '1';
                 break;
             case 2:
                 str[offset] = '2';
                 break;
             case 3:
                 str[offset] = '3';
                 break;
             case 4:
                 str[offset] = '4';
                 break;
             case 5:
                 str[offset] = '5';
                 break;
             case 6:
                 str[offset] = '6';
                 break;
             case 7:
                 str[offset] = '7';
                 break;
             case 8:
                 str[offset] = '8';
                 break;
             case 9:
                 str[offset] = '9';
                 break;
             case 10:
                 str[offset] = 'A';
                 break;
             case 11:
                 str[offset] = 'B';
                 break;
             case 12:
                 str[offset] = 'C';
                 break;
             case 13:
                 str[offset] = 'D';
                 break;
             case 14:
                 str[offset] = 'E';
                 break;
             case 15:
                 str[offset] = 'F';
                 break;
         }
         value >>= 4;
         offset--;
     }
 }
Beispiel #6
0
        public static unsafe void Throw(Testing2.Exception ex)
        {
            Testing2.GC.IncrementRefCount(ex);

            BasicConsole.WriteLine("Exception thrown:");
            BasicConsole.WriteLine(ex.Message);

            if (State->CurrentHandlerPtr->Ex != null)
            {
                //GC ref count remains consistent because the Ex pointer below is going to be replaced but
                //  same pointer stored in InnerException.
                // Result is ref count goes: +1 here, -1 below
                ex.InnerException = (Testing2.Exception)Utilities.ObjectUtilities.GetObject(State->CurrentHandlerPtr->Ex);
            }
            if (ex.InstructionAddress == 0)
            {
                ex.InstructionAddress = *((uint*)BasePointer + 1);
            }
            State->CurrentHandlerPtr->Ex = Utilities.ObjectUtilities.GetHandle(ex);
            State->CurrentHandlerPtr->ExPending = 1;

            HandleException();

            // We never expect to get here...
            HaltReason = "HandleException returned!";
            BasicConsole.WriteLine(HaltReason);
            // Try to cause fault
            *((byte*)0xDEADBEEF) = 0;
        }
Beispiel #7
0
        public static void* AllocZeroedAPB(UInt32 size, UInt32 boundary, Testing2.String caller)
        {
            void* result = null;
            void* oldValue = null;
            UInt32 resultAddr;
            do
            {
                oldValue = result;
                result = AllocZeroed(size, boundary, caller);
                resultAddr = (UInt32)result;
                if (oldValue != null)
                {
                    Free(oldValue);
                }
            }
            while (resultAddr / 0x1000 != (resultAddr + size - 1) / 0x1000);

            return result;
        }
Beispiel #8
0
        public static void DecrementRefCount(Testing2.Object anObj, bool overrideInside)
        {
            if (!Enabled /*|| (InsideGC && !overrideInside)*/ || anObj == null)
            {
                return;
            }

            if (!overrideInside)
            {
                InsideGC = true;
            }

            byte* objPtr = (byte*)Utilities.ObjectUtilities.GetHandle(anObj);
            _DecrementRefCount(objPtr);

            if (!overrideInside)
            {
                InsideGC = false;
            }
        }
Beispiel #9
0
 public bool StartsWith(Testing2.String prefix)
 {
     if (this.length < prefix.length)
     {
         return false;
     }
     else
     {
         for (int i = 0; i < prefix.length; i++)
         {
             if (this[i] != prefix[i])
             {
                 return false;
             }
         }
         return true;
     }
 }
Beispiel #10
0
        public void processCommand(String data)
        {
            GameClient Client = null;

            String header = data.Split(Convert.ToChar(1))[0];
            String param  = data.Split(Convert.ToChar(1))[1];

            string[] Params = param.ToString().Split(':');
            int      UserId, RoomId = 0;

            switch (header.ToLower())
            {
                #region User Related
                #region :reload_credits <UserID>
            case "reload_credits":
            {
                UserId = Convert.ToInt32(Params[0]);
                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                int Credits = 0;
                using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `credits` FROM `users` WHERE `id` = @id LIMIT 1");
                    dbClient.AddParameter("id", UserId);
                    Credits = dbClient.getInteger();
                }

                Client.GetHabbo().Credits = Credits;
                Client.SendMessage(new CreditBalanceComposer(Client.GetHabbo().Credits));
                break;
            }

                #endregion
                #region :reload_pixels <UserID>
            case "reload_pixels":
            {
                UserId = Convert.ToInt32(Params[0]);
                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                int Pixels = 0;
                using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `activity_points` FROM `users` WHERE `id` = @id LIMIT 1");
                    dbClient.AddParameter("id", UserId);
                    Pixels = dbClient.getInteger();
                }

                Client.GetHabbo().Duckets = Pixels;
                Client.SendMessage(new HabboActivityPointNotificationComposer(Client.GetHabbo().Duckets, Pixels));
                break;
            }

                #endregion
                #region :reload_diamonds <UserID>
            case "reload_diamonds":
            {
                UserId = Convert.ToInt32(Params[0]);
                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                int Diamonds = 0;
                using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `vip_points` FROM `users` WHERE `id` = @id LIMIT 1");
                    dbClient.AddParameter("id", UserId);
                    Diamonds = dbClient.getInteger();
                }

                Client.GetHabbo().Diamonds = Diamonds;
                Client.SendMessage(new HabboActivityPointNotificationComposer(Diamonds, 0, 5));
                break;
            }

                #endregion
                #region :reload_gotw <UserID>
            case "reload_gotw":
            {
                UserId = Convert.ToInt32(Params[0]);
                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                int GOTWPoints = 0;
                using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `gotw_points` FROM `users` WHERE `id` = @id LIMIT 1");
                    dbClient.AddParameter("id", UserId);
                    GOTWPoints = dbClient.getInteger();
                }

                Client.GetHabbo().GOTWPoints = GOTWPoints;
                Client.SendMessage(new HabboActivityPointNotificationComposer(GOTWPoints, 0, 103));
                break;
            }

                #endregion
            case "moveto":
            {
                UserId = Convert.ToInt32(Params[0]);

                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                Room     Testing = Client?.GetHabbo()?.CurrentRoom;
                RoomUser Testing2;
                if ((Testing2 = Testing?.GetRoomUserManager()?.GetRoomUserByHabbo(Client.GetHabbo().Username)) != null)
                {
                    Testing2.MoveTo(12, 12);
                }
                break;
            }

                #region :reload_user_rank userID
            case "reload_user_rank":
            {
                UserId = Convert.ToInt32(Params[0]);

                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `rank` FROM `users` WHERE `id` = @userID LIMIT 1");
                    dbClient.AddParameter("userID", UserId);
                    Client.GetHabbo().Rank = dbClient.getInteger();
                }
                break;
            }

                #endregion
                #region :reload_user_vip userID
            case "reload_user_vip":
            {
                UserId = Convert.ToInt32(Params[0]);

                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `rank_vip` FROM `users` WHERE `id` = @userID LIMIT 1");
                    dbClient.AddParameter("userID", UserId);
                    Client.GetHabbo().VIPRank = dbClient.getInteger();
                }
                break;
            }

                #endregion
                #region :reload_motto userID
            case "reload_motto":
            {
                UserId = Convert.ToInt32(Params[0]);

                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `motto` FROM `users` WHERE `id` = @userID LIMIT 1");
                    dbClient.AddParameter("userID", UserId);
                    Client.GetHabbo().Motto = dbClient.getString();
                }

                if (Client.GetHabbo().InRoom)
                {
                    Room Room = Client.GetHabbo().CurrentRoom;
                    if (Room == null)
                    {
                        return;
                    }

                    RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Client.GetHabbo().Id);
                    if (User == null || User.GetClient() == null)
                    {
                        return;
                    }

                    Room.SendMessage(new UserChangeComposer(User, false));
                }
                break;
            }

                #endregion
                #region :alert_user <userid> <message>
            case "alert":
            case "alert_user":
            {
                UserId = Convert.ToInt32(Params[0]);
                string alertMessage = Convert.ToString(Params[1]);

                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                Client.SendMessage(new BroadcastMessageAlertComposer(alertMessage));
                break;
            }

                #endregion
                #region :reload_badges <UserID>
            case "update_badges":
            case "reload_badges":
            {
                UserId = Convert.ToInt32(Params[0]);
                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);

                if (Client != null)
                {
                    if (Client.GetHabbo() != null)
                    {
                        Client.SendMessage(new BadgesComposer(Client));
                    }
                }
                break;
            }

                #endregion
                #region :givebadge <UserID> <badge>
            case "givebadge":
            {
                UserId = Convert.ToInt32(Params[0]);
                string badgeCode = Convert.ToString(Params[1]);
                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);

                if (Client != null)
                {
                    if (Client.GetHabbo() != null)
                    {
                        Client.GetHabbo().GetBadgeComponent().GiveBadge(badgeCode, true, Client);
                    }
                }
                break;
            }

                #endregion
                #region :disconnect <username>
            case "disconnect":
            {
                try
                {
                    GameClient TargetClient = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(Convert.ToInt32(Params[0]));
                    if (TargetClient != null && TargetClient.GetConnection() != null)
                    {
                        TargetClient.GetConnection().Dispose();
                    }
                }
                catch
                {
                    string CurrentTime = DateTime.Now.ToString("HH:mm:ss" + " | ");
                    Console.WriteLine(CurrentTime + "» Fout tijdens disconnecten van een gebruiker via MUS");
                }
                return;
            }

                #endregion
                #region :reload_last_change userID
            case "reload_last_change":
            {
                UserId = Convert.ToInt32(Params[0]);

                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                using (IQueryAdapter dbClient = QuasarEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `last_change` FROM `users` WHERE `id` = @userID LIMIT 1");
                    dbClient.AddParameter("userID", UserId);
                    Client.GetHabbo().LastNameChange = dbClient.getInteger();
                }
                break;
            }

                #endregion
                #region :goto <UserID> <RoomID>
            case "goto":
            {
                UserId = Convert.ToInt32(Params[0]);
                RoomId = Convert.ToInt32(Params[1]);

                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                if (!int.TryParse(Params[1], out RoomId))
                {
                    break;
                }
                else
                {
                    Room _room = QuasarEnvironment.GetGame().GetRoomManager().LoadRoom(RoomId);
                    if (_room == null)
                    {
                        Client.SendNotification("Failed to find the requested room!");
                    }
                    else
                    {
                        if (!Client.GetHabbo().InRoom)
                        {
                            Client.SendMessage(new RoomForwardComposer(_room.Id));
                        }
                        else
                        {
                            Client.GetHabbo().PrepareRoom(_room.Id, "");
                        }
                    }
                }
            }
            break;
                #endregion
                #endregion

                #region Fastfood
                #region :progress_achievement
            case "progress_achievement":
            {
                UserId = Convert.ToInt32(Params[0]);
                Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);
                if (Client == null || Client.GetHabbo() == null)
                {
                    break;
                }

                string Achievement = Convert.ToString(Params[1]);
                int    Progress    = Convert.ToInt32(Params[2]);

                QuasarEnvironment.GetGame().GetAchievementManager().ProgressAchievement(Client, Achievement, Progress);
                break;
            }
                #endregion
                #endregion

                #region Settings related
                #region :reload_filter/:update_filter
            case "update_filter":
            case "reload_filter":
            case "recache_filter":
            case "refresh_filter":
            {
                QuasarEnvironment.GetGame().GetChatManager().GetFilter().InitWords();
                QuasarEnvironment.GetGame().GetChatManager().GetFilter().InitCharacters();
                break;
            }

                #endregion
                #region :reload_catalog/:reload_catalog
            case "update_catalog":
            case "reload_catalog":
            case "recache_catalog":
            case "refresh_catalog":
            case "update_catalogue":
            case "reload_catalogue":
            case "recache_catalogue":
            case "refresh_catalogue":
            {
                QuasarEnvironment.GetGame().GetCatalog().Init(QuasarEnvironment.GetGame().GetItemManager());
                QuasarEnvironment.GetGame().GetClientManager().SendMessage(new CatalogUpdatedComposer());
                break;
            }

                #endregion
                #region :reload_items/:update_items
            case "update_items":
            case "reload_items":
            case "recache_items":
            case "refresh_items":
            {
                QuasarEnvironment.GetGame().GetItemManager().Init();
                break;
            }

                #endregion
                #region :reload_navigator/:update_navigator
            case "update_navigator":
            case "reload_navigator":
            case "recache_navigator":
            case "refresh_navigator":
            {
                QuasarEnvironment.GetGame().GetNavigator().Init();
                break;
            }

                #endregion
                #region :reload_ranks/:update_ranks
            case "update_ranks":
            case "reload_ranks":
            case "recache_ranks":
            case "refresh_ranks":
            {
                QuasarEnvironment.GetGame().GetPermissionManager().Init();

                foreach (GameClient C in QuasarEnvironment.GetGame().GetClientManager().GetClients.ToList())
                {
                    if (C == null || C.GetHabbo() == null || C.GetHabbo().GetPermissions() == null)
                    {
                        continue;
                    }

                    C.GetHabbo().GetPermissions().Init(Client.GetHabbo());
                }
                break;
            }

                #endregion
                #region :reload_settings/:update_settings
            case "update_settings":
            case "reload_settings":
            case "recache_settings":
            case "refresh_settings":
            {
                QuasarEnvironment.ConfigData = new ConfigData();
                break;
            }

                #endregion
                #region :reload_quests/:update_quests
            case "reload_quests":
            case "update_quests":
            {
                QuasarEnvironment.GetGame().GetQuestManager().Init();
                break;
            }

                #endregion
                #region :reload_vouchers/:update_vouchers
            case "reload_vouchers":
            case "update_vouchers":
            {
                QuasarEnvironment.GetGame().GetCatalog().GetVoucherManager().Init();
                break;
            }

                #endregion
                #region :reload_bans/:update_bans
            case "update_bans":
            case "reload_bans":
            {
                QuasarEnvironment.GetGame().GetModerationManager().ReCacheBans();
                break;
            }
                #endregion
                #endregion


            //#region Camera related

            //    #region :add_preview <photo_id> <user_id> <created_at>
            //    case "add_preview":
            //    {
            //        int PhotoId = Convert.ToInt32(Params[0]);
            //        UserId = Convert.ToInt32(Params[1]);
            //        long CreatedAt = Convert.ToInt64(Params[2]);

            //        Client = QuasarEnvironment.GetGame().GetClientManager().GetClientByUserID(UserId);

            //                    if (Client == null || Client.GetHabbo() == null || Client.GetHabbo().CurrentRoomId < 1)
            //                           break;

            //        QuasarEnvironment.GetGame().GetCameraManager().AddPreview(new CameraPhotoPreview(PhotoId, UserId, CreatedAt));
            //                    break;
            //    }

            //    #endregion

            //    #endregion

            default:
            {
                string CurrentTime = DateTime.Now.ToString("HH:mm:ss" + " | ");
                Console.WriteLine(CurrentTime + "» Onbekende Mus-pakket: '" + header + "'");
                return;
            }
            }
            string CurrentTime1 = DateTime.Now.ToString("HH:mm:ss" + " | ");
            Console.WriteLine(CurrentTime1 + "» Mus-command gestuurd: '" + header + "'");
        }
Beispiel #11
0
 /// <summary>
 /// Creates a new exception with specified message.
 /// </summary>
 /// <param name="aMessage">The exception message.</param>
 public Exception(Testing2.String aMessage)
     : base()
 {
     Message = aMessage;
 }
Beispiel #12
0
        public static unsafe void WriteLine(Testing2.String str)
        {
            if (!Initialised) return;
            if (str == null)
            {
                return;
            }

            //This outputs the string
            Write(str);
            Write("\n");
        }
Beispiel #13
0
        public static unsafe void Write(Testing2.String str)
        {
            if (!Initialised) return;
            //If string is null, just don't write anything
            if (str == null)
            {
                //Do not make this throw an exception. The BasicConsole
                //  is largely a debugging tool - it should be reliable,
                //  robust and not throw exceptions.
                return;
            }

            UART.Write(str);
        }
Beispiel #14
0
        public static void* Alloc(UInt32 size, UInt32 boundary, Testing2.String caller)
        {
#if HEAP_TRACE
            BasicConsole.SetTextColour(BasicConsole.warning_colour);
            BasicConsole.WriteLine("Attempt to alloc mem....");
            BasicConsole.SetTextColour(BasicConsole.default_colour);
#endif
            HeapBlock* b;
            byte* bm;
            UInt32 bcnt;
            UInt32 x, y, z;
            UInt32 bneed;
            byte nid;

            if (boundary > 1)
            {
                size += (boundary - 1);
            }

            /* iterate blocks */
            for (b = fblock; (UInt32)b != 0; b = b->next)
            {
                /* check if block has enough room */
                if (b->size - (b->used * b->bsize) >= size)
                {

                    bcnt = b->size / b->bsize;
                    bneed = (size / b->bsize) * b->bsize < size ? size / b->bsize + 1 : size / b->bsize;
                    bm = (byte*)&b[1];

                    for (x = (b->lfb + 1 >= bcnt ? 0 : b->lfb + 1); x != b->lfb; ++x)
                    {
                        /* just wrap around */
                        if (x >= bcnt)
                        {
                            x = 0;
                        }

                        if (bm[x] == 0)
                        {
                            /* count free blocks */
                            for (y = 0; bm[x + y] == 0 && y < bneed && (x + y) < bcnt; ++y) ;

                            /* we have enough, now allocate them */
                            if (y == bneed)
                            {
                                /* find ID that does not match left or right */
                                nid = GetNID(bm[x - 1], bm[x + y]);

                                /* allocate by setting id */
                                for (z = 0; z < y; ++z)
                                {
                                    bm[x + z] = nid;
                                }

                                /* optimization */
                                b->lfb = (x + bneed) - 2;

                                /* count used blocks NOT bytes */
                                b->used += y;

                                void* result = (void*)(x * b->bsize + (UInt32)(&b[1]));
                                if (boundary > 1)
                                {
                                    result = (void*)((((UInt32)result) + (boundary - 1)) & ~(boundary - 1));

#if HEAP_TRACE
                                    ExitCritical();
                                    BasicConsole.WriteLine(((Testing2.String)"Allocated address ") + (uint)result + " on boundary " + boundary + " for " + caller);
                                    EnterCritical("Alloc:Boundary condition");
#endif
                                }

                                return result;
                            }

                            /* x will be incremented by one ONCE more in our FOR loop */
                            x += (y - 1);
                            continue;
                        }
                    }
                }
            }

#if HEAP_TRACE
            BasicConsole.SetTextColour(BasicConsole.error_colour);
            BasicConsole.WriteLine("!!Heap out of memory!!");
            BasicConsole.SetTextColour(BasicConsole.default_colour);
            BasicConsole.DelayOutput(2);
#endif

            return null;
        }
Beispiel #15
0
 public static void* AllocZeroed(UInt32 size, UInt32 boundary, Testing2.String caller)
 {
     void* result = Alloc(size, boundary, caller);
     if(result == null)
     {
         return null;
     }
     return Utilities.MemoryUtils.ZeroMem(result, size);
 }
Beispiel #16
0
        public static void IncrementRefCount(Testing2.Object anObj)
        {
            if (!Enabled /*|| InsideGC*/ || anObj == null)
            {
                return;
            }

            InsideGC = true;

            byte* objPtr = (byte*)Utilities.ObjectUtilities.GetHandle(anObj);
            _IncrementRefCount(objPtr);

            InsideGC = false;
        }
Beispiel #17
0
 public static void DecrementRefCount(Testing2.Object anObj)
 {
     DecrementRefCount(anObj, false);
 }
Beispiel #18
0
 public bool EndsWith(Testing2.String postfix)
 {
     if (this.length < postfix.length)
     {
         return false;
     }
     else
     {
         int offset = this.length - postfix.length;
         for (int i = this.length - 1; i >= offset; i--)
         {
             if (this[i] != postfix[i - offset])
             {
                 return false;
             }
         }
         return true;
     }
 }
Beispiel #19
0
        public static void Disable(Testing2.String caller)
        {
            //BasicConsole.Write(caller);
            //BasicConsole.WriteLine(" disabling GC.");
            //BasicConsole.DelayOutput(2);

            GC.Enabled = false;
        }
Beispiel #20
0
 public static void* AllocZeroed(UInt32 size, Testing2.String caller)
 {
     return AllocZeroed(size, 1, caller);
 }