public static void FillWithZeros(IVirtualMemoryManager memory, ulong position, int size) { int size8 = size & ~(8 - 1); for (int offs = 0; offs < size8; offs += 8) { memory.Write <long>(position + (ulong)offs, 0); } for (int offs = size8; offs < (size - size8); offs++) { memory.Write <byte>(position + (ulong)offs, 0); } }
private static void ZeroFill(IVirtualMemoryManager memoryManager, ulong address, int size) { ulong endAddress = address + (ulong)size; while (address + 7UL < endAddress) { memoryManager.Write(address, 0UL); address += 8; } while (address < endAddress) { memoryManager.Write(address, (byte)0); address++; } }
private uint ListAudioInsImpl(IVirtualMemoryManager memory, long bufferPosition, long bufferSize, bool filtered = false) { uint count = 0; MemoryHelper.FillWithZeros(memory, bufferPosition, (int)bufferSize); if (bufferSize > 0) { // NOTE: The service also check that the input target is enabled when in filtering mode, as audctl and most of the audin logic isn't supported, we don't support it. if (!filtered) { byte[] deviceNameBuffer = Encoding.ASCII.GetBytes(DefaultAudioInsName + "\0"); memory.Write((ulong)bufferPosition, deviceNameBuffer); count++; } // NOTE: The service adds other input devices names available in the buffer, // every name is aligned to 0x100 bytes. // Since we don't support it for now, it's fine to do nothing here. } return(count); }
public void Dispose() { if (NeedsWriteback) { _mm.Write(_va, Memory.Span); } }
/// <inheritdoc/> protected override KernelResult MapMemory(ulong src, ulong dst, ulong pagesCount, KMemoryPermission oldSrcPermission, KMemoryPermission newDstPermission) { ulong size = pagesCount * PageSize; _cpuMemory.Map(dst, 0, size); ulong currentSize = size; while (currentSize > 0) { ulong copySize = Math.Min(currentSize, CopyChunckSize); _cpuMemory.Write(dst, _cpuMemory.GetSpan(src, (int)copySize)); currentSize -= copySize; } return(KernelResult.Success); }
public unsafe static void Write <T>(IVirtualMemoryManager memory, long position, T value) where T : struct { long size = Marshal.SizeOf <T>(); byte[] data = new byte[size]; fixed(byte *ptr = data) { Marshal.StructureToPtr <T>(value, (IntPtr)ptr, false); } memory.Write((ulong)position, data); }
public bool WriteBufferToMemory(IVirtualMemoryManager destination, ulong position) { lock (_bufferLock) { if (_bufferData == null) { return(false); } try { destination.Write(position, _bufferData); } catch { return(false); } return(true); } }
private uint Write(IVirtualMemoryManager memoryManager, ulong outBufferAddress, uint countMax, ReadOnlySpan <int> buffer, uint count, uint writeOffset, uint updateCount) { if (countMax == 0 || outBufferAddress == 0) { return(0); } uint targetWriteOffset = writeOffset + AuxiliaryBufferInfo.GetWriteOffset(memoryManager, BufferInfo.SendBufferInfo); if (targetWriteOffset > countMax) { return(0); } uint remaining = count; uint inBufferOffset = 0; while (remaining != 0) { uint countToWrite = Math.Min(countMax - targetWriteOffset, remaining); memoryManager.Write(outBufferAddress + targetWriteOffset * sizeof(int), MemoryMarshal.Cast <int, byte>(buffer.Slice((int)inBufferOffset, (int)countToWrite))); targetWriteOffset = (targetWriteOffset + countToWrite) % countMax; remaining -= countToWrite; inBufferOffset += countToWrite; } if (updateCount != 0) { uint newWriteOffset = (AuxiliaryBufferInfo.GetWriteOffset(memoryManager, BufferInfo.SendBufferInfo) + updateCount) % countMax; AuxiliaryBufferInfo.SetWriteOffset(memoryManager, BufferInfo.SendBufferInfo, newWriteOffset); } return(count); }
private bool TryCopyTo(IVirtualMemoryManager destination, ulong position) { if (_surface == null) { return(false); } Rectangle lockRectangle = new Rectangle(0, 0, _surface.Width, _surface.Height); BitmapData surfaceData = _surface.LockBits(lockRectangle, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); Debug.Assert(surfaceData.Stride == _surfaceInfo.Pitch); Debug.Assert(surfaceData.Stride * surfaceData.Height == _surfaceInfo.Size); // Convert the pixel format used in System.Drawing to the one required by a Switch Surface. int dataLength = surfaceData.Stride * surfaceData.Height; byte[] data = new byte[dataLength]; Span <uint> dataConvert = MemoryMarshal.Cast <byte, uint>(data); Marshal.Copy(surfaceData.Scan0, data, 0, dataLength); for (int i = 0; i < dataConvert.Length; i++) { dataConvert[i] = BitOperations.RotateRight(BinaryPrimitives.ReverseEndianness(dataConvert[i]), 8); } try { destination.Write(position, data); } finally { _surface.UnlockBits(surfaceData); } return(true); }
/// <inheritdoc/> protected override void Write(ulong va, ReadOnlySpan <byte> data) { _cpuMemory.Write(va, data); }
private uint Write(IVirtualMemoryManager memoryManager, ulong outBufferAddress, uint countMax, ReadOnlySpan <int> buffer, uint count, uint writeOffset, uint updateCount) { if (countMax == 0 || outBufferAddress == 0) { return(0); } uint targetWriteOffset = writeOffset + AuxiliaryBufferInfo.GetWriteOffset(memoryManager, DspBufferInfoAddress); if (targetWriteOffset > countMax) { return(0); } uint remaining = count; uint inBufferOffset = 0; while (remaining != 0) { uint countToWrite = Math.Min(countMax - targetWriteOffset, remaining); memoryManager.Write(outBufferAddress + targetWriteOffset * sizeof(int), MemoryMarshal.Cast <int, byte>(buffer.Slice((int)inBufferOffset, (int)countToWrite))); targetWriteOffset = (targetWriteOffset + countToWrite) % countMax; remaining -= countToWrite; inBufferOffset += countToWrite; } if (updateCount != 0) { uint dspTotalSampleCount = AuxiliaryBufferInfo.GetTotalSampleCount(memoryManager, DspBufferInfoAddress); uint cpuTotalSampleCount = AuxiliaryBufferInfo.GetTotalSampleCount(memoryManager, CpuBufferInfoAddress); uint totalSampleCountDiff = dspTotalSampleCount - cpuTotalSampleCount; if (totalSampleCountDiff >= countMax) { uint dspLostSampleCount = AuxiliaryBufferInfo.GetLostSampleCount(memoryManager, DspBufferInfoAddress); uint cpuLostSampleCount = AuxiliaryBufferInfo.GetLostSampleCount(memoryManager, CpuBufferInfoAddress); uint lostSampleCountDiff = dspLostSampleCount - cpuLostSampleCount; uint newLostSampleCount = lostSampleCountDiff + updateCount; if (lostSampleCountDiff > newLostSampleCount) { newLostSampleCount = cpuLostSampleCount - 1; } AuxiliaryBufferInfo.SetLostSampleCount(memoryManager, DspBufferInfoAddress, newLostSampleCount); } uint newWriteOffset = (AuxiliaryBufferInfo.GetWriteOffset(memoryManager, DspBufferInfoAddress) + updateCount) % countMax; AuxiliaryBufferInfo.SetWriteOffset(memoryManager, DspBufferInfoAddress, newWriteOffset); uint newTotalSampleCount = totalSampleCountDiff + newWriteOffset; AuxiliaryBufferInfo.SetTotalSampleCount(memoryManager, DspBufferInfoAddress, newTotalSampleCount); } return(count); }
public static void Reset(IVirtualMemoryManager manager, ulong bufferAddress) { // NOTE: Lost sample count is never reset, since REV10. manager.Write(bufferAddress + ReadOffsetPosition, 0UL); manager.Write(bufferAddress + TotalSampleCountPosition, 0); }
public static void SetTotalSampleCount(IVirtualMemoryManager manager, ulong bufferAddress, uint value) { manager.Write(bufferAddress + TotalSampleCountPosition, value); }
public static void SetWriteOffset(IVirtualMemoryManager manager, ulong bufferAddress, uint value) { manager.Write(bufferAddress + WriteOffsetPosition, value); }