Example #1
0
        public int ReadAt(IDebugMemoryContext2 pStartContext, uint dwCount, byte[] rgbMemory, out uint pdwRead, ref uint pdwUnreadable)
        {
            pdwUnreadable = 0;
            AD7MemoryAddress addr      = (AD7MemoryAddress)pStartContext;
            uint             bytesRead = 0;
            int hr = Constants.S_OK;

            DebuggedProcess.WorkerThread.RunOperation(async() =>
            {
                bytesRead = await DebuggedProcess.ReadProcessMemory(addr.Address, dwCount, rgbMemory);
            });

            if (bytesRead == uint.MaxValue)
            {
                bytesRead = 0;
            }

            if (bytesRead < dwCount) // copied from Concord
            {
                // assume 4096 sized pages: ARM has 4K or 64K pages
                uint  pageSize      = 4096;
                ulong readEnd       = addr.Address + bytesRead;
                ulong nextPageStart = (readEnd + pageSize - 1) / pageSize * pageSize;
                if (nextPageStart == readEnd)
                {
                    nextPageStart = readEnd + pageSize;
                }
                // if we have crossed a page boundry - Unreadable = bytes till end of page
                uint maxUnreadable = dwCount - bytesRead;
                if (addr.Address + dwCount > nextPageStart)
                {
                    pdwUnreadable = (uint)Math.Min(maxUnreadable, nextPageStart - readEnd);
                }
                else
                {
                    pdwUnreadable = (uint)Math.Min(maxUnreadable, pageSize);
                }
            }
            pdwRead = bytesRead;
            return(hr);
        }