github.com/metacubex/sing-tun@v0.2.7-0.20240512075008-89e7c6208eec/internal/winsys/zsyscall_windows.go (about)

     1  // Code generated by 'go generate'; DO NOT EDIT.
     2  
     3  package winsys
     4  
     5  import (
     6  	"syscall"
     7  	"unsafe"
     8  
     9  	"golang.org/x/sys/windows"
    10  )
    11  
    12  var _ unsafe.Pointer
    13  
    14  // Do the interface allocations only once for common
    15  // Errno values.
    16  const (
    17  	errnoERROR_IO_PENDING = 997
    18  )
    19  
    20  var (
    21  	errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
    22  	errERROR_EINVAL     error = syscall.EINVAL
    23  )
    24  
    25  // errnoErr returns common boxed Errno values, to prevent
    26  // allocations at runtime.
    27  func errnoErr(e syscall.Errno) error {
    28  	switch e {
    29  	case 0:
    30  		return errERROR_EINVAL
    31  	case errnoERROR_IO_PENDING:
    32  		return errERROR_IO_PENDING
    33  	}
    34  	// TODO: add more here, after collecting data on the common
    35  	// error values see on Windows. (perhaps when running
    36  	// all.bat?)
    37  	return e
    38  }
    39  
    40  var (
    41  	modfwpuclnt = windows.NewLazySystemDLL("fwpuclnt.dll")
    42  
    43  	procFwpmEngineClose0          = modfwpuclnt.NewProc("FwpmEngineClose0")
    44  	procFwpmEngineOpen0           = modfwpuclnt.NewProc("FwpmEngineOpen0")
    45  	procFwpmFilterAdd0            = modfwpuclnt.NewProc("FwpmFilterAdd0")
    46  	procFwpmFreeMemory0           = modfwpuclnt.NewProc("FwpmFreeMemory0")
    47  	procFwpmGetAppIdFromFileName0 = modfwpuclnt.NewProc("FwpmGetAppIdFromFileName0")
    48  	procFwpmSubLayerAdd0          = modfwpuclnt.NewProc("FwpmSubLayerAdd0")
    49  )
    50  
    51  func FwpmEngineClose0(engineHandle uintptr) (err error) {
    52  	r1, _, e1 := syscall.Syscall(procFwpmEngineClose0.Addr(), 1, uintptr(engineHandle), 0, 0)
    53  	if r1 != 0 {
    54  		err = errnoErr(e1)
    55  	}
    56  	return
    57  }
    58  
    59  func FwpmEngineOpen0(serverName *uint16, authnService uint32, authIdentity *uintptr, session *FWPM_SESSION0, engineHandle unsafe.Pointer) (err error) {
    60  	r1, _, e1 := syscall.Syscall6(procFwpmEngineOpen0.Addr(), 5, uintptr(unsafe.Pointer(serverName)), uintptr(authnService), uintptr(unsafe.Pointer(authIdentity)), uintptr(unsafe.Pointer(session)), uintptr(engineHandle), 0)
    61  	if r1 != 0 {
    62  		err = errnoErr(e1)
    63  	}
    64  	return
    65  }
    66  
    67  func FwpmFilterAdd0(engineHandle uintptr, filter *FWPM_FILTER0, sd uintptr, id *uint64) (err error) {
    68  	r1, _, e1 := syscall.Syscall6(procFwpmFilterAdd0.Addr(), 4, uintptr(engineHandle), uintptr(unsafe.Pointer(filter)), uintptr(sd), uintptr(unsafe.Pointer(id)), 0, 0)
    69  	if r1 != 0 {
    70  		err = errnoErr(e1)
    71  	}
    72  	return
    73  }
    74  
    75  func FwpmFreeMemory0(p unsafe.Pointer) {
    76  	syscall.Syscall(procFwpmFreeMemory0.Addr(), 1, uintptr(p), 0, 0)
    77  	return
    78  }
    79  
    80  func FwpmGetAppIdFromFileName0(fileName *uint16, appID unsafe.Pointer) (err error) {
    81  	r1, _, e1 := syscall.Syscall(procFwpmGetAppIdFromFileName0.Addr(), 2, uintptr(unsafe.Pointer(fileName)), uintptr(appID), 0)
    82  	if r1 != 0 {
    83  		err = errnoErr(e1)
    84  	}
    85  	return
    86  }
    87  
    88  func FwpmSubLayerAdd0(engineHandle uintptr, subLayer *FWPM_SUBLAYER0, sd uintptr) (err error) {
    89  	r1, _, e1 := syscall.Syscall(procFwpmSubLayerAdd0.Addr(), 3, uintptr(engineHandle), uintptr(unsafe.Pointer(subLayer)), uintptr(sd))
    90  	if r1 != 0 {
    91  		err = errnoErr(e1)
    92  	}
    93  	return
    94  }