diff options
Diffstat (limited to 'vendor/github.com/ncruces/go-sqlite3/internal/util')
3 files changed, 62 insertions, 5 deletions
| diff --git a/vendor/github.com/ncruces/go-sqlite3/internal/util/mmap.go b/vendor/github.com/ncruces/go-sqlite3/internal/util/mmap.go index 5788eeb24..613bb90b1 100644 --- a/vendor/github.com/ncruces/go-sqlite3/internal/util/mmap.go +++ b/vendor/github.com/ncruces/go-sqlite3/internal/util/mmap.go @@ -1,4 +1,4 @@ -//go:build unix && (386 || arm || amd64 || arm64 || riscv64 || ppc64le) && !(sqlite3_noshm || sqlite3_nosys) +//go:build unix && !sqlite3_nosys  package util @@ -55,10 +55,10 @@ type MappedRegion struct {  	used bool  } -func MapRegion(ctx context.Context, mod api.Module, f *os.File, offset int64, size int32, prot int) (*MappedRegion, error) { +func MapRegion(ctx context.Context, mod api.Module, f *os.File, offset int64, size int32, readOnly bool) (*MappedRegion, error) {  	s := ctx.Value(moduleKey{}).(*moduleState)  	r := s.new(ctx, mod, size) -	err := r.mmap(f, offset, prot) +	err := r.mmap(f, offset, readOnly)  	if err != nil {  		return nil, err  	} @@ -75,7 +75,11 @@ func (r *MappedRegion) Unmap() error {  	return err  } -func (r *MappedRegion) mmap(f *os.File, offset int64, prot int) error { +func (r *MappedRegion) mmap(f *os.File, offset int64, readOnly bool) error { +	prot := unix.PROT_READ +	if !readOnly { +		prot |= unix.PROT_WRITE +	}  	_, err := unix.MmapPtr(int(f.Fd()), offset, r.addr, uintptr(r.size),  		prot, unix.MAP_SHARED|unix.MAP_FIXED)  	r.used = err == nil diff --git a/vendor/github.com/ncruces/go-sqlite3/internal/util/mmap_other.go b/vendor/github.com/ncruces/go-sqlite3/internal/util/mmap_other.go index a2fbf24df..e11f953a7 100644 --- a/vendor/github.com/ncruces/go-sqlite3/internal/util/mmap_other.go +++ b/vendor/github.com/ncruces/go-sqlite3/internal/util/mmap_other.go @@ -1,4 +1,4 @@ -//go:build !unix || !(386 || arm || amd64 || arm64 || riscv64 || ppc64le) || sqlite3_noshm || sqlite3_nosys +//go:build !unix || sqlite3_nosys  package util 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) +} | 
