diff options
author | 2024-11-07 00:16:28 +0000 | |
---|---|---|
committer | 2024-11-07 00:16:28 +0000 | |
commit | 45e1609377631070765065ffb35ed7d29e8e81f1 (patch) | |
tree | 51d170ff0d5fab1ab0f8b1b79c9dd8c31d4ce5b9 /vendor/github.com/ncruces/go-sqlite3/internal/util/mmap_windows.go | |
parent | [chore] update go ffmpreg to v0.6.0 (#3515) (diff) | |
download | gotosocial-45e1609377631070765065ffb35ed7d29e8e81f1.tar.xz |
bump ncruces/go-sqlite3 to v0.20.2 (#3524)
Diffstat (limited to 'vendor/github.com/ncruces/go-sqlite3/internal/util/mmap_windows.go')
-rw-r--r-- | vendor/github.com/ncruces/go-sqlite3/internal/util/mmap_windows.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/github.com/ncruces/go-sqlite3/internal/util/mmap_windows.go b/vendor/github.com/ncruces/go-sqlite3/internal/util/mmap_windows.go new file mode 100644 index 000000000..fdf6f439a --- /dev/null +++ b/vendor/github.com/ncruces/go-sqlite3/internal/util/mmap_windows.go @@ -0,0 +1,53 @@ +//go:build !sqlite3_nosys + +package util + +import ( + "context" + "os" + "reflect" + "unsafe" + + "github.com/tetratelabs/wazero/api" + "golang.org/x/sys/windows" +) + +type MappedRegion struct { + windows.Handle + Data []byte + addr uintptr +} + +func MapRegion(ctx context.Context, mod api.Module, f *os.File, offset int64, size int32) (*MappedRegion, error) { + h, err := windows.CreateFileMapping(windows.Handle(f.Fd()), nil, windows.PAGE_READWRITE, 0, 0, nil) + if h == 0 { + return nil, err + } + + a, err := windows.MapViewOfFile(h, windows.FILE_MAP_WRITE, + uint32(offset>>32), uint32(offset), uintptr(size)) + if a == 0 { + windows.CloseHandle(h) + return nil, err + } + + res := &MappedRegion{Handle: h, addr: a} + // SliceHeader, although deprecated, avoids a go vet warning. + sh := (*reflect.SliceHeader)(unsafe.Pointer(&res.Data)) + sh.Len = int(size) + sh.Cap = int(size) + sh.Data = a + return res, nil +} + +func (r *MappedRegion) Unmap() error { + if r.Data == nil { + return nil + } + err := windows.UnmapViewOfFile(r.addr) + if err != nil { + return err + } + r.Data = nil + return windows.CloseHandle(r.Handle) +} |