Ejemplo n.º 1
0
 internal bool PointerEquals(CheckedPointer pointer)
 {
     unsafe
     {
         return(_pointer == pointer._pointer);
     }
 }
Ejemplo n.º 2
0
 // Returns the offset of the given pointer within this mapping,
 // with a bounds check.  The returned offset may be equal to the size,
 // but not greater. Throws ArgumentOutOfRangeException if pointer
 // is not within the bounds of the mapping.
 internal int OffsetOf(CheckedPointer pointer)
 {
     unsafe
     {
         return(OffsetOf(pointer._pointer));
     }
 }
Ejemplo n.º 3
0
        internal unsafe void SendMissReport(IFontCacheElement e)
        {
            //If we are not connected to the server, there's no one to send the miss report to, so don't.
            if (_conn == null)
            {
                return;
            }

            byte[] request = new byte[Math.Min(MaxMissReportSize, _conn.GetMaxRequestBytes())];

            //If the connection cannot support a long enough request to hold the message type and element type,
            //we can't send the miss report.
            if (request.Length < 2 * sizeof(int))
                return;

            fixed(byte *ptr = &request[0])
            {
                //Store the message type
                ((int *)ptr)[0] = FontCacheConstants.SendMissReportMessage;

                //Store the element type
                ((int *)ptr)[1] = e.Type;

                //Store the key information
                CheckedPointer key = new CheckedPointer(ptr, request.Length);

                key += 2 * sizeof(int);
                try
                {
                    int realSize = 0;
                    e.StoreKey(key, out realSize);
                    Debug.Assert(realSize >= 0, "realSize is negative");
                    // realSize will be zero for non-shareable elements like in-memory fonts
                    if (realSize != 0)
                    {
                        realSize += 2 * sizeof(int);//adjust for message header and miss report header
                        Debug.Assert(realSize <= request.Length, "realSize too large");

                        //Send the request as a datagram (ignore error code)
                        int errorCode = 0;
                        _protocol.TrySendRequest(_conn, request, 0, realSize, null, 0, 0, 0, out errorCode);
                    }
                }
                catch (ArgumentOutOfRangeException)
                {
                    // the key didn't fit into the buffer, just don't send the miss report
                    return;
                }
            }
        }
Ejemplo n.º 4
0
        internal void CopyTo(CheckedPointer dest)
        {
            unsafe
            {
                if (_pointer == null)
                {
                    throw new ArgumentOutOfRangeException();
                }

                byte *s = (byte *)_pointer;
                byte *d = (byte *)dest.Probe(0, _size);
                for (int i = 0; i < _size; ++i)
                {
                    d[i] = s[i];
                }
            }
        }
Ejemplo n.º 5
0
        internal void InitFromCacheImage(CheckedPointer cacheImage)
        {
            if (cacheImage.Size < MinCacheSize ||
                (cacheImage.Size % 8) != 0 ||
                cacheImage.Size > MaxCacheSize)
            {
                // Malformed input cache, just return. Assert in debug builds to catch possible bugs.
                Debug.Assert(false);
                return;
            }

            int oldCurrentSize;

            unsafe
            {
                // Validate the current size field in the existing cache image.
                oldCurrentSize = *(int *)cacheImage.Probe(offCurSize, sizeof(int));
            }

            if (Util.Align8(oldCurrentSize) != oldCurrentSize || oldCurrentSize != cacheImage.Size)
            {
                // Malformed input cache, just return. Assert in debug builds to catch possible bugs.
                Debug.Assert(false);
                return;
            }

            _mfile.Commit(cacheImage.Size);
            GetCacheHeader()->CurSize = cacheImage.Size;

            cacheImage.CopyTo(Mapping);

            // This can happen only if the current cache size field was not set properly in the cache image,
            // and we should have caught this situation earlier in this function.
            Invariant.Assert(CurrentSize == cacheImage.Size);

            SetNew();
        }