コード例 #1
0
ファイル: MemoryManager.cs プロジェクト: Paul1nh0/Singularity
        //
        // Get and map multiple new pages. On failure, no pages are allocated.
        //
        internal static bool CommitAndMapRange(UIntPtr virtualAddr,
                                               UIntPtr limitAddr,
                                               ProtectionDomain inDomain)
        {
            DebugStub.Assert(IsPageAligned(virtualAddr));
            DebugStub.Assert(IsPageAligned(limitAddr));

            for (UIntPtr step = virtualAddr;
                 step < limitAddr;
                 step += PageSize)
            {
                if (!CommitAndMapNewPage(step, inDomain))
                {
                    // Uh oh; we failed.
                    for (UIntPtr unmapStep = virtualAddr;
                         unmapStep < virtualAddr;
                         unmapStep += PageSize)
                    {
                        UnmapAndReleasePage(unmapStep);
                    }

                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        public static string GetCodeSourceLocation()
        {
            var f = default(FileInfo);

            try
            {
                // Error	40	The call is ambiguous between the following methods or properties: 'ScriptCoreLibJava.Extensions.BCLImplementationExtensions.ToClass(System.Type)' and 'ScriptCoreLibJava.Extensions.BCLImplementationExtensions.ToClass(System.Type)'	X:\jsc.svn\core\ScriptCoreLib.Ultra\ScriptCoreLib.Ultra\Java\Interop\CodeSourceLocationProvider.cs	22	27	ScriptCoreLib.Ultra

                var cls = BCLImplementationExtensions.ToClass(typeof(CodeSourceLocationProvider));

                ProtectionDomain pDomain = cls.getProtectionDomain();
                CodeSource       cSource = pDomain.getCodeSource();
                URL loc = cSource.getLocation();


                var ff     = loc.getFile();
                var prefix = "file:/";

                if (prefix == ff.Substring(0, prefix.Length))
                {
                    ff = ff.Substring(prefix.Length);
                }

                f = new FileInfo(ff);
            }
            catch
            {
                throw new NotSupportedException();
            }

            return(f.FullName);
        }
コード例 #3
0
 internal unsafe VirtualMemoryRange(VirtualMemoryRange_struct *pRange,
                                    ProtectionDomain inDomain)
 {
     this.pRange   = pRange;
     this.indirect = true;
     // never use this.range
     DebugStub.Assert(inDomain != null);
     this.parentDomain = inDomain;
 }
コード例 #4
0
        internal unsafe VirtualMemoryRange(UIntPtr baseAddr,
                                           UIntPtr limitAddr,
                                           ProtectionDomain inDomain)
        {
            DebugStub.Assert(inDomain != null);
            this.parentDomain = inDomain;

            range = new VirtualMemoryRange_struct(baseAddr, limitAddr,
                                                  baseAddr, limitAddr,
                                                  inDomain);
            this.indirect = false;
            // never use this.pRange
        }
コード例 #5
0
ファイル: MemoryManager.cs プロジェクト: Paul1nh0/Singularity
        //
        // Get a new physical page and map it to the provided virtual address
        //
        private static bool CommitAndMapNewPage(UIntPtr virtualAddr,
                                                ProtectionDomain inDomain)
        {
            DebugStub.Assert(IsPageAligned(virtualAddr));
            PhysicalAddress newPage = PhysicalPages.AllocPage();

            if (newPage == PhysicalAddress.Null)
            {
                // Failed.
                return(false);
            }

            VMManager.MapPage(newPage, virtualAddr, inDomain);
            return(true);
        }
コード例 #6
0
        //
        // Allocates and commits a new range of memory.
        //
        internal UIntPtr Allocate(UIntPtr numPages, Process process,
                                  uint extra, PageType type,
                                  ProtectionDomain inDomain)
        {
            DebugStub.Assert(numPages > 0);
            UIntPtr mapAddr = UIntPtr.Zero;

            bool iflag = Lock();

            // Within our lock, figure out where we're going to stick the newly
            // mapped memory, and mark it used.
            try {
                mapAddr = ReserveInternal(numPages, process, extra, type);

                if (mapAddr == UIntPtr.Zero)
                {
                    DebugStub.Assert(false, "Failed to find a mapping point for new memory");
                    return(mapAddr);
                }
            }
            finally {
                Unlock(iflag);
            }

            UIntPtr limitAddr = mapAddr + MemoryManager.BytesFromPages(numPages);

            // Now actually map pages to the chosen region.
            if (!MemoryManager.CommitAndMapRange(mapAddr, limitAddr, inDomain))
            {
                // yikes; failure
                return(UIntPtr.Zero);
            }

            allocatedCount++;
            allocatedBytes += (ulong)MemoryManager.BytesFromPages(numPages);

            if (process != null)
            {
                process.Allocated(MemoryManager.BytesFromPages(numPages));
            }

            return(mapAddr);
        }
コード例 #7
0
 /// <summary>
 /// Converts an array of bytes into an instance of class <tt>Class</tt>, with an optional <tt>ProtectionDomain</tt>.
 /// </summary>
 protected Class defineClass(string name, sbyte[] b, int off, int len, ProtectionDomain protectionDomain)
 {
     return(default(Class));
 }
コード例 #8
0
        /////////////////////////////////////
        // PUBLIC METHODS
        /////////////////////////////////////

        //
        // The range of memory turned over to a VirtualMemoryRange structure
        // must not have *any* mapped pages in it to start out with
        //
        // A VirtualMemoryRange can build a pagetable that *describes*
        // more memory than it *manages* (this supports some kernel GC
        // oddities). In that case, pages out-of-range are marked
        // as PageType.Unknown. Obviously, allocation requests are never
        // satisfied with out-of-bounds data.
        //
        internal unsafe VirtualMemoryRange_struct(
            UIntPtr baseAddr, UIntPtr limitAddr,
            UIntPtr descrBaseAddr, UIntPtr descrLimitAddr,
            ProtectionDomain inDomain)
        {
            DebugStub.Assert(MemoryManager.IsPageAligned(baseAddr));
            DebugStub.Assert(MemoryManager.IsPageAligned(limitAddr));
            DebugStub.Assert(MemoryManager.IsPageAligned(descrBaseAddr));
            DebugStub.Assert(MemoryManager.IsPageAligned(descrLimitAddr));

            // The descriptive range can't be smaller than the managed range
            DebugStub.Assert(descrLimitAddr >= limitAddr);
            DebugStub.Assert(descrBaseAddr <= baseAddr);

            descrBase  = descrBaseAddr;
            descrLimit = descrLimitAddr;
            rangeBase  = baseAddr;
            rangeLimit = limitAddr;
            rangeLock  = new SpinLock(SpinLock.Types.VirtualMemoryRange);

            describedPages = MemoryManager.PagesFromBytes(descrLimit - descrBase);

            // Figure out how many pages we need for a page description table
            UIntPtr pageTableSize = MemoryManager.PagePad(describedPages * sizeof(uint));

            dataStart = baseAddr + pageTableSize;
            nextAlloc = dataStart;

            // Commit and prepare the page table
            pageTable = (uint *)baseAddr;

            bool success = MemoryManager.CommitAndMapRange(
                baseAddr, baseAddr + pageTableSize, inDomain);

            if (!success)
            {
                Kernel.Panic("Couldn't get pages to create a new VirtualMemoryRange page table");
            }

            allocatedBytes = 0;
            allocatedCount = 0;
            freedBytes     = 0;
            freedCount     = 0;

            // Describe the pages outside our range as Unknown
            if (descrBase < rangeBase)
            {
                SetRange(descrBase, rangeBase, MemoryManager.PageUnknown);
            }

            if (descrLimit > rangeLimit)
            {
                SetRange(rangeLimit, descrLimit, MemoryManager.PageUnknown);
            }

            // The page-table pages themselves are in use by the System
            SetRange((UIntPtr)pageTable,
                     (UIntPtr)pageTable + pageTableSize,
                     MemoryManager.KernelPageNonGC);

            // Describe pages in-range as Free
            SetRange(dataStart, rangeLimit, MemoryManager.PageFree);

#if DEBUG
            // Check that our data range is pristine
            for (UIntPtr stepAddr = dataStart;
                 stepAddr < rangeLimit;
                 stepAddr += MemoryManager.PageSize)
            {
                DebugStub.Assert(!VMManager.IsPageMapped(stepAddr));
            }
#endif
        }
コード例 #9
0
ファイル: PolicySpi.cs プロジェクト: ranganathsb/JavaSharp
 /// <summary>
 /// Check whether the policy has granted a Permission to a ProtectionDomain.
 /// </summary>
 /// <param name="domain"> the ProtectionDomain to check.
 /// </param>
 /// <param name="permission"> check whether this permission is granted to the
 ///          specified domain.
 /// </param>
 /// <returns> boolean true if the permission is granted to the domain. </returns>
 protected internal abstract bool EngineImplies(ProtectionDomain domain, Permission permission);
コード例 #10
0
ファイル: PolicySpi.cs プロジェクト: ranganathsb/JavaSharp
 /// <summary>
 /// Return a PermissionCollection object containing the set of
 /// permissions granted to the specified ProtectionDomain.
 ///
 /// <para> The default implementation of this method returns
 /// Policy.UNSUPPORTED_EMPTY_COLLECTION object.  This method can be
 /// overridden if the policy implementation can return a set of
 /// permissions granted to a ProtectionDomain.
 ///
 /// </para>
 /// </summary>
 /// <param name="domain"> the ProtectionDomain to which the returned
 ///          PermissionCollection has been granted.
 /// </param>
 /// <returns> a set of permissions granted to the specified ProtectionDomain.
 ///          If this operation is supported, the returned
 ///          set of permissions must be a new mutable instance
 ///          and it must support heterogeneous Permission types.
 ///          If this operation is not supported,
 ///          Policy.UNSUPPORTED_EMPTY_COLLECTION is returned. </returns>
 protected internal virtual PermissionCollection EngineGetPermissions(ProtectionDomain domain)
 {
     return(Policy.UNSUPPORTED_EMPTY_COLLECTION);
 }
コード例 #11
0
 public Key(ProtectionDomain outerInstance)
 {
     this.OuterInstance = outerInstance;
 }
コード例 #12
0
 public PrivilegedActionAnonymousInnerClassHelper(ProtectionDomain outerInstance)
 {
     this.OuterInstance = outerInstance;
 }
コード例 #13
0
 public virtual PermissionCollection Get(ProtectionDomain pd)
 {
     return(pd == null?map.get(null) : map.get(pd.Key));
 }
コード例 #14
0
 public virtual void Put(ProtectionDomain pd, PermissionCollection pc)
 {
     map.put((pd == null ? null : pd.Key), pc);
 }