-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
380 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.