func (r *OutputDebugStringReceiver) createMemoryMappedFile() {
	if nil != r.err {
		return
	}

	var str *uint16
	str, r.err = windows.UTF16PtrFromString("DBWIN_BUFFER")
	if nil != r.err {
		return
	}

	r.buffer, r.err = windows.CreateFileMapping(
		windows.InvalidHandle,
		nil,
		0x4,
		0,
		4096,
		str)
	if nil != r.err {
		return
	}

	r.view, r.err = windows.MapViewOfFile(r.buffer, 0x4, 0, 0, 0)
}
Пример #2
0
func mmap(fd int, length int) (data []byte, err error) {
	h, errno := windows.CreateFileMapping(windows.Handle(fd), nil,
		uint32(windows.PAGE_READONLY), 0, uint32(length), nil)
	if h == 0 {
		return nil, os.NewSyscallError("CreateFileMapping", errno)
	}

	addr, errno := windows.MapViewOfFile(h, uint32(windows.FILE_MAP_READ), 0,
		0, uintptr(length))
	if addr == 0 {
		return nil, os.NewSyscallError("MapViewOfFile", errno)
	}
	handleLock.Lock()
	handleMap[addr] = h
	handleLock.Unlock()

	m := memoryMap{}
	dh := m.header()
	dh.Data = addr
	dh.Len = length
	dh.Cap = dh.Len

	return m, nil
}