Exemplo n.º 1
0
        public void GetPage_ShouldResolveAndReturnPageSpecifiedPageType(string name)
        {
            // Arrange
            var container    = Substitute.For <IObjectContainer>();
            var expectedPage = new DummyPage();

            container.Resolve <DummyPage>(name).Returns(expectedPage);
            PageProvider.SetContainer(container);

            // Act
            var result = PageProvider.GetPage <DummyPage>(name);

            // Assert
            result.Should().BeSameAs(expectedPage);
        }
Exemplo n.º 2
0
        internal PageResult GetPageResult(string lang, string rel, bool dynamic, bool isMobile,
                                          string searchScript = null, string searchTones = null)
        {
            if (rel == null)
            {
                rel = "";
            }
            // Dynamic-only pages
            bool isDynOnly = false;

            foreach (var x in dynOnlyPrefixes)
            {
                if (rel.StartsWith(x))
                {
                    isDynOnly = true; break;
                }
            }
            if (isDynOnly)
            {
                if (dynamic)
                {
                    if (rel == "search" || rel.StartsWith("search/"))
                    {
                        return(doSearch(rel, lang, searchScript, searchTones, isMobile));
                    }
                    else if (rel == "corpus" || rel.StartsWith("corpus/"))
                    {
                        return(doCorpus(rel, lang, isMobile));
                    }
                    else if (rel.StartsWith("edit/history"))
                    {
                        return(doHistory(rel, lang));
                    }
                    else if (rel.StartsWith("edit/new"))
                    {
                        return(doNewEntry(rel, lang));
                    }
                    else if (rel.StartsWith("edit/existing"))
                    {
                        return(doEditExisting(rel, lang));
                    }
                    else if (rel.StartsWith("user/confirm/"))
                    {
                        return(doUserConfirm(rel, lang));
                    }
                    else if (rel.StartsWith("user/users"))
                    {
                        return(doUserList(rel, lang, isMobile));
                    }
                    else if (rel.StartsWith("user/profile"))
                    {
                        return(doUserProfile(rel, lang));
                    }
                }
                else
                {
                    PageResult xpr = pageProvider.GetPage(lang, "404", false);
                    xpr.Html = xpr.Keywords = xpr.Title = xpr.Description = "";
                    return(xpr);
                }
            }
            // Welcome is special: we must infuse dictionary size
            if (rel == "")
            {
                return(doWelcome(lang));
            }
            // Just a regular static page
            PageResult pr = pageProvider.GetPage(lang, rel, false);

            if (pr == null)
            {
                pr = pageProvider.GetPage(lang, "404", false);
            }
            return(pr);
        }
Exemplo n.º 3
0
        private void Map4k(ulong vaddr, ulong paddr, PageProvider pp, uint flags = 0)
        {
            /* in the current 48 bit implementation of x86_64, only the first 48 bits of the address
             * are used, the upper 16 bits need to be a sign-extension (i.e. equal to the 48th bit)
             * The virtual region system should ensure this sign extension, but we need to chop off the sign
             * extension to properly index into the tables */
            ulong page_index = vaddr & canonical_only;

            // Traverse the paging structures to map the page
            ulong pml4t_entry_addr = get_pml4t_entry_addr(page_index);
            ulong pdpt_entry_addr  = get_pdpt_entry_addr(page_index);
            ulong pd_entry_addr    = get_pd_entry_addr(page_index);
            ulong pt_entry_addr    = get_pt_entry_addr(page_index);

            // Create pages in the paging hierarchy as necessary
            if ((pstructs[pml4t_entry_addr] & 0x1) == 0)
            {
                ulong p_page = pp.GetPage();
                pstructs[pml4t_entry_addr] = 0x3 | (p_page & paddr_mask);
                libsupcs.x86_64.Cpu.Invlpg((pdpt_entry_addr * 8 + pstruct_start) & page_mask);
                libsupcs.MemoryOperations.QuickClearAligned16((pdpt_entry_addr * 8 + pstruct_start) & page_mask, 0x1000);
            }
            if ((pstructs[pdpt_entry_addr] & 0x1) == 0)
            {
                ulong p_page = pp.GetPage();
                pstructs[pdpt_entry_addr] = 0x3 | (p_page & paddr_mask);
                libsupcs.x86_64.Cpu.Invlpg((pd_entry_addr * 8 + pstruct_start) & page_mask);
                libsupcs.MemoryOperations.QuickClearAligned16((pd_entry_addr * 8 + pstruct_start) & page_mask, 0x1000);
            }
            if ((pstructs[pdpt_entry_addr] & 0x1) == 0)
            {
                ulong p_page = pp.GetPage();
                pstructs[pdpt_entry_addr] = 0x3 | (p_page & paddr_mask);
                libsupcs.x86_64.Cpu.Invlpg((pd_entry_addr * 8 + pstruct_start) & page_mask);
                libsupcs.MemoryOperations.QuickClearAligned16((pd_entry_addr * 8 + pstruct_start) & page_mask, 0x1000);
            }
            if ((pstructs[pd_entry_addr] & 0x1) == 0)
            {
                ulong p_page = pp.GetPage();
                pstructs[pd_entry_addr] = 0x3 | (p_page & paddr_mask);
                libsupcs.x86_64.Cpu.Invlpg((pt_entry_addr * 8 + pstruct_start) & page_mask);
                libsupcs.MemoryOperations.QuickClearAligned16((pt_entry_addr * 8 + pstruct_start) & page_mask, 0x1000);
            }

            /* Set the attributes of the page */
            ulong page_attrs = 0x1; // Present bit

            if ((flags & FLAG_writeable) != 0)
            {
                page_attrs |= 0x2;
            }
            if ((flags & FLAG_write_through) != 0)
            {
                page_attrs |= 0x8;
            }
            if ((flags & FLAG_cache_disable) != 0)
            {
                page_attrs |= 0x10;
            }

            pstructs[pt_entry_addr] = page_attrs | (paddr & paddr_mask);
            libsupcs.x86_64.Cpu.Invlpg(vaddr & page_mask);
        }