github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/mmap/mmap_windows.go (about)

     1  package mmap
     2  
     3  import (
     4  	"os"
     5  
     6  	"golang.org/x/sys/windows"
     7  )
     8  
     9  func readFile(f *os.File, size int64) (uintptr, error) {
    10  	handle, err := windows.CreateFileMapping(windows.Handle(f.Fd()), nil, windows.PAGE_READONLY, 0, 0, nil)
    11  	if err != nil {
    12  		return 0, os.NewSyscallError("CreateFileMappingW", err)
    13  	}
    14  	defer windows.CloseHandle(handle)
    15  
    16  	addr, err := windows.MapViewOfFile(handle, windows.FILE_MAP_READ, 0, 0, 0)
    17  	if err != nil {
    18  		return 0, os.NewSyscallError("MapViewOfFile", err)
    19  	}
    20  	return addr, nil
    21  }
    22  
    23  func unmap(addr uintptr, length int) error {
    24  	return windows.UnmapViewOfFile(addr)
    25  }