Esempio n. 1
0
func munmap(b []byte) (err error) {
	m := MMap(b)
	dh := m.header()

	addr := dh.Data
	length := uintptr(dh.Len)

	flush(addr, length)
	err = syscall.UnmapViewOfFile(addr)
	if err != nil {
		return err
	}

	handleLock.Lock()
	defer handleLock.Unlock()
	handle, ok := handleMap[addr]
	if !ok {
		// should be impossible; we would've errored above
		return errors.New("unknown base address")
	}
	delete(handleMap, addr)

	e := syscall.CloseHandle(syscall.Handle(handle))
	return os.NewSyscallError("CloseHandle", e)
}
Esempio n. 2
0
// munmap Windows implementation
// Based on: https://github.com/edsrzf/mmap-go
// Based on: https://github.com/boltdb/bolt/bolt_windows.go
func munmap(b []byte) (err error) {
	handleLock.Lock()
	defer handleLock.Unlock()

	addr := (uintptr)(unsafe.Pointer(&b[0]))
	if err := syscall.UnmapViewOfFile(addr); err != nil {
		return os.NewSyscallError("UnmapViewOfFile", err)
	}

	handle, ok := handleMap[addr]
	if !ok {
		// should be impossible; we would've seen the error above
		return errors.New("unknown base address")
	}
	delete(handleMap, addr)

	e := syscall.CloseHandle(syscall.Handle(handle))
	if e != nil {
		return os.NewSyscallError("CloseHandle", e)
	}

	file, ok := fileMap[addr]
	if !ok {
		// should be impossible; we would've seen the error above
		return errors.New("unknown base address")
	}
	delete(fileMap, addr)

	e = file.Close()
	if e != nil {
		return errors.New("close file" + e.Error())
	}
	return nil
}
Esempio n. 3
0
func unmmapFile(m *mmapData) error {
	err := syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&m.d[0])))
	if err != nil {
		return err
	}

	return m.f.Close()
}
Esempio n. 4
0
func (m *mmap) unmap() error {
	slcHead := (*reflect.SliceHeader)(unsafe.Pointer(&m.buf))
	err := syscall.UnmapViewOfFile(slcHead.Data)
	if err != nil {
		return err
	}
	return os.NewSyscallError("CloseHandle", syscall.CloseHandle(syscall.Handle(m.handle)))
}
Esempio n. 5
0
// munmap unmaps a pointer from a file.
// Based on: https://github.com/edsrzf/mmap-go
func munmap(db *DB) error {
	if db.data == nil {
		return nil
	}

	addr := (uintptr)(unsafe.Pointer(&db.data[0]))
	if err := syscall.UnmapViewOfFile(addr); err != nil {
		return os.NewSyscallError("UnmapViewOfFile", err)
	}
	return nil
}
Esempio n. 6
0
func unmap(addr, len uintptr) error {
	if err := syscall.UnmapViewOfFile(addr); err != nil {
		return err
	}

	handleLock.Lock()
	defer handleLock.Unlock()
	handle := handleMap[addr]
	delete(handleMap, addr)

	return os.NewSyscallError("CloseHandle", syscall.CloseHandle(syscall.Handle(handle)))
}
Esempio n. 7
0
func unmmapFile(mm *mmapData) {
	err := syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&mm.d[0])))
	if err != nil {
		log.Fatal(err)
	}
	err2 := syscall.CloseHandle(syscall.Handle(mm.h))
	if err2 != nil {
		log.Fatal(err2)
	}
	err3 := mm.f.Close()
	if err3 != nil {
		log.Fatal(err3)
	}
}
Esempio n. 8
0
// Close closes the reader.
func (r *ReaderAt) Close() error {
	if r.data == nil {
		return nil
	}
	data := r.data
	r.data = nil
	if debug {
		var p *byte
		if len(data) != 0 {
			p = &data[0]
		}
		println("munmap", r, p)
	}
	runtime.SetFinalizer(r, nil)
	return syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&data[0])))
}
Esempio n. 9
0
func unmap(addr, len uintptr) error {
	flush(addr, len)
	err := syscall.UnmapViewOfFile(addr)
	if err != nil {
		return err
	}

	handleLock.Lock()
	defer handleLock.Unlock()
	handle, ok := handleMap[addr]
	if !ok {
		// should be impossible; we would've errored above
		return errors.New("unknown base address")
	}
	delete(handleMap, addr)

	e := syscall.CloseHandle(syscall.Handle(handle))
	return os.NewSyscallError("CloseHandle", e)
}
Esempio n. 10
0
func unmap(addr, len uintptr) os.Error {
	flush(addr, len)
	errno := syscall.UnmapViewOfFile(addr)
	if errno != 0 {
		return os.NewSyscallError("UnmapViewOfFile", errno)
	}

	handleLock.Lock()
	defer handleLock.Unlock()
	handle, ok := handleMap[addr]
	if !ok {
		// should be impossible; we would've errored above
		return os.NewError("unknown base address")
	}
	handleMap[addr] = 0, false

	e := syscall.CloseHandle(handle)
	return os.NewSyscallError("CloseHandle", e)
}
Esempio n. 11
0
func unmap(p []byte) error {
	addr := uintptr(unsafe.Pointer(&p[0]))
	syscall.FlushViewOfFile(addr, uintptr(len(p)))
	err := syscall.UnmapViewOfFile(addr)
	if err != nil {
		return err
	}

	handleLock.Lock()
	defer handleLock.Unlock()
	handle, ok := handleMap[addr]
	if !ok {
		// should be impossible; we would've errored above
		return errors.New("unknown base address")
	}
	delete(handleMap, addr)

	e := syscall.CloseHandle(syscall.Handle(handle))
	return os.NewSyscallError("CloseHandle", e)
}
Esempio n. 12
0
// Implement munmap for windows
func unmap_file(data []byte) error {

	// Use unsafe to get the buffer address
	addr := uintptr(unsafe.Pointer(&data[0]))

	// retrieve the mapping handle
	win_mapper_mutex.Lock()
	h := win_mapper_handle[addr]
	delete(win_mapper_handle, addr)
	win_mapper_mutex.Unlock()

	// unmap file view
	err := syscall.UnmapViewOfFile(addr)

	// close the mapping handle
	if err == nil {
		err = syscall.CloseHandle(h)
	}

	return err
}
Esempio n. 13
0
func unmap(addr, len uintptr) error {
	flush(addr, len)
	// Lock the UnmapViewOfFile along with the handleMap deletion.
	// As soon as we unmap the view, the OS is free to give the
	// same addr to another new map. We don't want another goroutine
	// to insert and remove the same addr into handleMap while
	// we're trying to remove our old addr/handle pair.
	handleLock.Lock()
	defer handleLock.Unlock()
	err := syscall.UnmapViewOfFile(addr)
	if err != nil {
		return err
	}

	handle, ok := handleMap[addr]
	if !ok {
		// should be impossible; we would've errored above
		return errors.New("unknown base address")
	}
	delete(handleMap, addr)

	e := syscall.CloseHandle(syscall.Handle(handle))
	return os.NewSyscallError("CloseHandle", e)
}
Esempio n. 14
0
func (agent Pagent) Close() {
	defer syscall.CloseHandle(agent.Hwnd)
	defer syscall.CloseHandle(agent.Fmap)
	defer syscall.UnmapViewOfFile(agent.SharedMemory)

}
Esempio n. 15
0
func (m *Mapping) destroy() {
	syscall.UnmapViewOfFile(m.addr)
	syscall.CloseHandle(m.mapping)
}
Esempio n. 16
0
func (mf *memfile) Close() {
	syscall.UnmapViewOfFile(mf.ptr)
}
Esempio n. 17
0
func unmmap(d []byte) error {
	return syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&d)))
}