Esempio n. 1
0
        public void ReadAsync(ulong alignedSourceAddress, IntPtr alignedDestinationAddress, uint aligned_read_length, IOCompletionCallback callback, IAsyncResult asyncResult)
        {
            long logicalAddress = (long)alignedSourceAddress;
            long page           = logicalAddress >> PageSizeBits;
            int  pageIndex      = (int)(page % BufferSize);

            Debug.Assert(page == pageIndex);

            Overlapped        ov        = new Overlapped(0, 0, IntPtr.Zero, asyncResult);
            NativeOverlapped *ov_native = ov.UnsafePack(callback, IntPtr.Zero);

            ov_native->OffsetLow  = unchecked ((int)(alignedSourceAddress & 0xFFFFFFFF));
            ov_native->OffsetHigh = unchecked ((int)((alignedSourceAddress >> 32) & 0xFFFFFFFF));

            if (values[pageIndex] == null)
            {
                callback(2, 0, ov_native);
            }
            else
            {
                long physicalAddress = GetPhysicalAddress(logicalAddress);
                Utility.Copy((byte *)physicalAddress, (byte *)alignedDestinationAddress, (int)aligned_read_length);
                callback(0, aligned_read_length, ov_native);
            }
        }
Esempio n. 2
0
        public void WriteAsync(IntPtr alignedSourceAddress, ulong alignedDestinationAddress, uint numBytesToWrite, IOCompletionCallback callback, IAsyncResult asyncResult)
        {
            long logicalAddress = (long)alignedDestinationAddress;
            long page           = logicalAddress >> PageSizeBits;
            int  pageIndex      = (int)(page % BufferSize);

            Debug.Assert(page == pageIndex);

            if (values[pageIndex] == null)
            {
                // Allocate a new page
                AllocatePage(pageIndex);
            }
            else
            {
                //Clear an old used page
                Array.Clear(values[pageIndex], 0, values[pageIndex].Length);
            }

            long physicalAddress = GetPhysicalAddress(logicalAddress);

            Utility.Copy((byte *)alignedSourceAddress, (byte *)physicalAddress, (int)numBytesToWrite);

            Overlapped        ov        = new Overlapped(0, 0, IntPtr.Zero, asyncResult);
            NativeOverlapped *ov_native = ov.UnsafePack(callback, IntPtr.Zero);

            ov_native->OffsetLow  = unchecked ((int)(alignedDestinationAddress & 0xFFFFFFFF));
            ov_native->OffsetHigh = unchecked ((int)((alignedDestinationAddress >> 32) & 0xFFFFFFFF));

            callback(0, numBytesToWrite, ov_native);
        }
Esempio n. 3
0
 public static void Copy(Key *src, Key *dst)
 {
     Utility.Copy((byte *)src, (byte *)dst, kSizeInBytes);
 }