public void Setup() { if (setup) { return; } // get file descriptor for /dev/mem devMemFileDescriptor = Syscall.open(DevMemFilePath, OpenFlags.O_RDWR | OpenFlags.O_SYNC); var gpioMem = Stdlib.malloc(BLOCK_SIZE + (PAGE_SIZE - 1)); var gpioMemInt = gpioMem.ToInt32(); if ((gpioMemInt % PAGE_SIZE) == 1) { gpioMem = IntPtr.Add(gpioMem, PAGE_SIZE - (gpioMemInt % PAGE_SIZE)); } var periBase = GetPeriBase(); var gpioBase = (periBase == 0 ? BCM2708_PERI_BASE_DEFAULT : periBase) + GPIO_BASE_OFFSET; gpioMap = Syscall.mmap(gpioMem, BLOCK_SIZE, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_SHARED, devMemFileDescriptor, gpioBase); setup = true; }
public static IntPtr AllocHeap(long size) { if (size < (long)0) { throw new ArgumentOutOfRangeException("size", "< 0"); } return(Stdlib.malloc((ulong)size)); }
private static IPAddress PtrToAddress(IntPtr ptr) { IPAddress address = null; if (ptr != IntPtr.Zero) { IntPtr buf = Stdlib.malloc(256); IntPtr addrPtr = avahi_address_snprint(buf, 256, ptr); address = IPAddress.Parse(GLib.Marshaller.Utf8PtrToString(addrPtr)); Stdlib.free(addrPtr); } return(address); }
internal IntPtr GetDataPointer() { if (Data1 == null && Data2 == null && Data3 == null) { return(IntPtr.Zero); } var payload = new Payload(); #if !ObjectPointersPinnedByDefault if (!DataIsAccessibleToNative) #endif { payload.data1 = Util.SerializeToPointer(Data1); payload.data2 = Util.SerializeToPointer(Data2); payload.data3 = Util.SerializeToPointer(Data3); } #if !ObjectPointersPinnedByDefault else { payload.data1 = Util.SerializeToPointer(Data1, GCHandleType.Pinned); payload.data2 = Util.SerializeToPointer(Data2, GCHandleType.Pinned); payload.data3 = Util.SerializeToPointer(Data3, GCHandleType.Pinned); } #endif var result = Stdlib.malloc((ulong)Marshal.SizeOf(payload)); if (result == IntPtr.Zero) { Util.FreeSerializePointer(payload.data1); Util.FreeSerializePointer(payload.data2); Util.FreeSerializePointer(payload.data3); return(IntPtr.Zero); } Marshal.StructureToPtr(payload, result, false); BPS.RegisterSerializedPointer(payload.data1); BPS.RegisterSerializedPointer(payload.data2); BPS.RegisterSerializedPointer(payload.data3); return(result); }