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) }
// 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 }
func unmmapFile(m *mmapData) error { err := syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&m.d[0]))) if err != nil { return err } return m.f.Close() }
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))) }
// 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 }
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))) }
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) } }
// 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]))) }
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) }
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) }
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) }
// 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 }
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) }
func (agent Pagent) Close() { defer syscall.CloseHandle(agent.Hwnd) defer syscall.CloseHandle(agent.Fmap) defer syscall.UnmapViewOfFile(agent.SharedMemory) }
func (m *Mapping) destroy() { syscall.UnmapViewOfFile(m.addr) syscall.CloseHandle(m.mapping) }
func (mf *memfile) Close() { syscall.UnmapViewOfFile(mf.ptr) }
func unmmap(d []byte) error { return syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&d))) }