/// <summary> /// Realizes an array creation. /// </summary> /// <param name="elementType">The element type.</param> private void MakeNewArray(Type elementType) { // Setup length argument var arguments = InlineList <ValueReference> .Create( Builder.CreateConvertToInt32( Location, Block.PopInt(Location, ConvertFlags.None))); var array = Builder.CreateNewArray( Location, Builder.CreateType(elementType, MemoryAddressSpace.Generic), ref arguments); // Clear array data var callArguments = InlineList <ValueReference> .Create( Builder.CreateGetViewFromArray( Location, array)); CreateCall( LocalMemory.GetClearMethod(elementType), ref callArguments); // Push array instance Block.Push(array); }
private static Dictionary <ushort, string> GetSystemMessages(ModuleSnapshot snapshot, string pattern, int patternOffset) { Dictionary <ushort, string> result = new Dictionary <ushort, string>(); IntPtr funcAddress = new IntPtr(snapshot.FindPattern(pattern, 0, 0, false, false)); GetMessageNameFunc func = funcAddress.ToDelegate <GetMessageNameFunc>(); uint count = LocalMemory.Read <uint>(funcAddress + patternOffset); for (ushort i = 0; i < count; i++) { result.Add(i, Marshal.PtrToStringUni(func(i))); } return(result); }
/// <summary> /// Realizes an array creation. /// </summary> /// <param name="elementType">The element type.</param> private void MakeNewArray(Type elementType) { // Redirect call to the LocalMemory class to allocate an intialized array var allocateZeroMethod = LocalMemory.GetAllocateZeroMethod(elementType); // Setup length argument var arguments = InlineList <ValueReference> .Create( Builder.CreateConvertToInt64( Location, Block.PopInt(Location, ConvertFlags.None))); CreateCall(allocateZeroMethod, ref arguments); }
/// <summary> /// Read an object of the specified struct from the current process. /// </summary> /// <typeparam name="T">The type of the struct.</typeparam> /// <param name="address">The address to read from.</param> /// <param name="result">The resulting object.</param> /// <returns>Whether or not the read succeeded.</returns> public static bool Read <T>(IntPtr address, out T result) where T : struct { if (!ReadBytes(address, SizeCache <T> .Size, out var buffer)) { result = default; return(false); } using var mem = new LocalMemory(buffer.Length); mem.Write(buffer); result = mem.Read <T>(); return(true); }
/// <summary> /// Marshals data from an unmanaged block of memory to a managed object. /// </summary> /// <param name="addr">The address to read from.</param> /// <param name="type">The type to create.</param> /// <returns>The read object, or null, if it could not be read.</returns> public static object?PtrToStructure(IntPtr addr, Type type) { var size = Marshal.SizeOf(type); if (!ReadBytes(addr, size, out var buffer)) { return(null); } var mem = new LocalMemory(size); mem.Write(buffer); return(mem.Read(type)); }
/// <summary> /// Write an array of structs to the current process. /// </summary> /// <typeparam name="T">The type of the structs.</typeparam> /// <param name="address">The address to write to.</param> /// <param name="objArray">The array to write.</param> /// <returns>Whether or not the write succeeded.</returns> public static bool Write <T>(IntPtr address, T[] objArray) where T : struct { if (objArray == null || objArray.Length == 0) { return(true); } var size = SizeCache <T> .Size; using var mem = new LocalMemory(objArray.Length * size); for (var i = 0; i < objArray.Length; i++) { mem.Write(objArray[i], i * size); } return(WriteBytes(address, mem.Read())); }
internal static void MoveLoadsStoresAddressSpacesKernel( ArrayView1D <int, Stride1D.Dense> source, ArrayView1D <Int2, Stride1D.Dense> target) { var shared = ILGPU.SharedMemory.Allocate1D <int>(MaxLength); var local = LocalMemory.Allocate1D <int>(MaxLength); var index = Grid.GlobalIndex.X; var value1 = source[index]; shared[index] = 42; local[index] = shared[index]; var value2 = source[index + 1]; target[index] = new Int2(value1 + local[index], value2); }
internal static void MoveLoadsStoresAddressSpacesBarrierKernel( ArrayView1D <int, Stride1D.Dense> source, ArrayView1D <Int2, Stride1D.Dense> target) { var shared = ILGPU.SharedMemory.Allocate1D <int>(MaxLength); var local = LocalMemory.Allocate1D <int>(MaxLength); var index = Grid.GlobalIndex.X; var value1 = source[index]; shared[index] = Group.IdxX; Group.Barrier(); local[index] = shared[Group.DimX - 2]; Group.Barrier(); var value2 = target[index]; target[index] = new Int2(value1 + local[index], value2.X + value2.Y); }
/// <summary> /// Read an array of objects of the specified struct from the current process. /// </summary> /// <typeparam name="T">The type of the struct.</typeparam> /// <param name="address">The address to read from.</param> /// <param name="count">The length of the array.</param> /// <returns>An array of the read objects, or null if any entry of the array failed to read.</returns> public static T[]? Read <T>(IntPtr address, int count) where T : struct { var size = SizeOf <T>(); if (!ReadBytes(address, count * size, out var buffer)) { return(null); } var result = new T[count]; using var mem = new LocalMemory(buffer.Length); mem.Write(buffer); for (var i = 0; i < result.Length; i++) { result[i] = mem.Read <T>(i * size); } return(result); }
/// <summary> /// Write a struct to the current process. /// </summary> /// <typeparam name="T">The type of the struct.</typeparam> /// <param name="address">The address to write to.</param> /// <param name="obj">The object to write.</param> /// <returns>Whether or not the write succeeded.</returns> public static bool Write <T>(IntPtr address, T obj) where T : struct { using var mem = new LocalMemory(SizeCache <T> .Size); mem.Write(obj); return(WriteBytes(address, mem.Read())); }
private static uint GetVersion(ModuleSnapshot snapshot, string pattern, int patternOffset) => LocalMemory.Read <uint>((IntPtr)snapshot.FindPattern(pattern, patternOffset, 0, true, false));
public LocalProcess() : base(Process.GetCurrentProcess()) { Memory = new LocalMemory(Handle); }
public ILearner GetLearner(int result) { ILearner learner = null; switch (result) { case 1: learner = new ContextSwitching(1000); break; case 2: learner = new SharedResources(); break; case 3: learner = new LocalMemory(); break; case 4: learner = new ThreadPoolDemo(); break; case 5: learner = new Concepts(); break; case 6: learner = new ExceptionHandling(); break; case 7: learner = new TasksIntro(); break; case 8: learner = new TasksIOBound(); break; case 9: learner = new TasksChaining(); break; case 10: learner = new LocksAndMonitor(); break; case 11: learner = new NestedLocks(); break; case 12: learner = new DeadLocks(); break; case 13: learner = new ReaderWriterLock(); break; case 14: learner = new MutexLock(); break; case 15: learner = new Semaphores(); break; default: learner = new ContextSwitching(10); break; } return(learner); }