Upgrade x/sync, Prometheus client and faas-provider

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alex@openfaas.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2022-08-24 18:12:23 +01:00
parent 20b62e3cc9
commit ce5ea178ec
347 changed files with 23183 additions and 18188 deletions

View File

@ -15,11 +15,11 @@ import (
// in http://msdn.microsoft.com/en-us/library/ms880421.
// This function returns "" (2 double quotes) if s is empty.
// Alternatively, these transformations are done:
// - every back slash (\) is doubled, but only if immediately
// followed by double quote (");
// - every double quote (") is escaped by back slash (\);
// - finally, s is wrapped with double quotes (arg -> "arg"),
// but only if there is space or tab inside s.
// - every back slash (\) is doubled, but only if immediately
// followed by double quote (");
// - every double quote (") is escaped by back slash (\);
// - finally, s is wrapped with double quotes (arg -> "arg"),
// but only if there is space or tab inside s.
func EscapeArg(s string) string {
if len(s) == 0 {
return "\"\""

View File

@ -296,7 +296,7 @@ const (
// Flag to indicate that the sorting from the INF file should be used.
DI_INF_IS_SORTED DI_FLAGS = 0x00008000
// Flag to indicate that only the the INF specified by SP_DEVINSTALL_PARAMS.DriverPath should be searched.
// Flag to indicate that only the INF specified by SP_DEVINSTALL_PARAMS.DriverPath should be searched.
DI_ENUMSINGLEINF DI_FLAGS = 0x00010000
// Flag that prevents ConfigMgr from removing/re-enumerating devices during device

View File

@ -10,6 +10,7 @@ import (
errorspkg "errors"
"fmt"
"runtime"
"strings"
"sync"
"syscall"
"time"
@ -86,10 +87,8 @@ func StringToUTF16(s string) []uint16 {
// s, with a terminating NUL added. If s contains a NUL byte at any
// location, it returns (nil, syscall.EINVAL).
func UTF16FromString(s string) ([]uint16, error) {
for i := 0; i < len(s); i++ {
if s[i] == 0 {
return nil, syscall.EINVAL
}
if strings.IndexByte(s, 0) != -1 {
return nil, syscall.EINVAL
}
return utf16.Encode([]rune(s + "\x00")), nil
}
@ -186,8 +185,8 @@ func NewCallbackCDecl(fn interface{}) uintptr {
//sys GetNamedPipeInfo(pipe Handle, flags *uint32, outSize *uint32, inSize *uint32, maxInstances *uint32) (err error)
//sys GetNamedPipeHandleState(pipe Handle, state *uint32, curInstances *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32, userName *uint16, maxUserNameSize uint32) (err error) = GetNamedPipeHandleStateW
//sys SetNamedPipeHandleState(pipe Handle, state *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32) (err error) = SetNamedPipeHandleState
//sys ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error)
//sys WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error)
//sys readFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) = ReadFile
//sys writeFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) = WriteFile
//sys GetOverlappedResult(handle Handle, overlapped *Overlapped, done *uint32, wait bool) (err error)
//sys SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) [failretval==0xffffffff]
//sys CloseHandle(handle Handle) (err error)
@ -418,6 +417,7 @@ func NewCallbackCDecl(fn interface{}) uintptr {
//sys GetModuleInformation(process Handle, module Handle, modinfo *ModuleInfo, cb uint32) (err error) = psapi.GetModuleInformation
//sys GetModuleFileNameEx(process Handle, module Handle, filename *uint16, size uint32) (err error) = psapi.GetModuleFileNameExW
//sys GetModuleBaseName(process Handle, module Handle, baseName *uint16, size uint32) (err error) = psapi.GetModuleBaseNameW
//sys QueryWorkingSetEx(process Handle, pv uintptr, cb uint32) (err error) = psapi.QueryWorkingSetEx
// NT Native APIs
//sys rtlNtStatusToDosErrorNoTeb(ntstatus NTStatus) (ret syscall.Errno) = ntdll.RtlNtStatusToDosErrorNoTeb
@ -549,12 +549,6 @@ func Read(fd Handle, p []byte) (n int, err error) {
}
return 0, e
}
if raceenabled {
if done > 0 {
raceWriteRange(unsafe.Pointer(&p[0]), int(done))
}
raceAcquire(unsafe.Pointer(&ioSync))
}
return int(done), nil
}
@ -567,12 +561,31 @@ func Write(fd Handle, p []byte) (n int, err error) {
if e != nil {
return 0, e
}
if raceenabled && done > 0 {
raceReadRange(unsafe.Pointer(&p[0]), int(done))
}
return int(done), nil
}
func ReadFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error {
err := readFile(fd, p, done, overlapped)
if raceenabled {
if *done > 0 {
raceWriteRange(unsafe.Pointer(&p[0]), int(*done))
}
raceAcquire(unsafe.Pointer(&ioSync))
}
return err
}
func WriteFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error {
if raceenabled {
raceReleaseMerge(unsafe.Pointer(&ioSync))
}
err := writeFile(fd, p, done, overlapped)
if raceenabled && *done > 0 {
raceReadRange(unsafe.Pointer(&p[0]), int(*done))
}
return err
}
var ioSync int64
func Seek(fd Handle, offset int64, whence int) (newoffset int64, err error) {
@ -611,7 +624,6 @@ var (
func getStdHandle(stdhandle uint32) (fd Handle) {
r, _ := GetStdHandle(stdhandle)
CloseOnExec(r)
return r
}
@ -850,6 +862,7 @@ const socket_error = uintptr(^uint32(0))
//sys GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) = iphlpapi.GetAdaptersAddresses
//sys GetACP() (acp uint32) = kernel32.GetACP
//sys MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) = kernel32.MultiByteToWideChar
//sys getBestInterfaceEx(sockaddr unsafe.Pointer, pdwBestIfIndex *uint32) (errcode error) = iphlpapi.GetBestInterfaceEx
// For testing: clients can set this flag to force
// creation of IPv6 sockets to return EAFNOSUPPORT.
@ -959,6 +972,32 @@ func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, int32, error) {
return unsafe.Pointer(&sa.raw), sl, nil
}
type RawSockaddrBth struct {
AddressFamily [2]byte
BtAddr [8]byte
ServiceClassId [16]byte
Port [4]byte
}
type SockaddrBth struct {
BtAddr uint64
ServiceClassId GUID
Port uint32
raw RawSockaddrBth
}
func (sa *SockaddrBth) sockaddr() (unsafe.Pointer, int32, error) {
family := AF_BTH
sa.raw = RawSockaddrBth{
AddressFamily: *(*[2]byte)(unsafe.Pointer(&family)),
BtAddr: *(*[8]byte)(unsafe.Pointer(&sa.BtAddr)),
Port: *(*[4]byte)(unsafe.Pointer(&sa.Port)),
ServiceClassId: *(*[16]byte)(unsafe.Pointer(&sa.ServiceClassId)),
}
return unsafe.Pointer(&sa.raw), int32(unsafe.Sizeof(sa.raw)), nil
}
func (rsa *RawSockaddrAny) Sockaddr() (Sockaddr, error) {
switch rsa.Addr.Family {
case AF_UNIX:
@ -1034,6 +1073,14 @@ func Connect(fd Handle, sa Sockaddr) (err error) {
return connect(fd, ptr, n)
}
func GetBestInterfaceEx(sa Sockaddr, pdwBestIfIndex *uint32) (err error) {
ptr, _, err := sa.sockaddr()
if err != nil {
return err
}
return getBestInterfaceEx(ptr, pdwBestIfIndex)
}
func Getsockname(fd Handle) (sa Sockaddr, err error) {
var rsa RawSockaddrAny
l := int32(unsafe.Sizeof(rsa))
@ -1687,3 +1734,71 @@ func LoadResourceData(module, resInfo Handle) (data []byte, err error) {
h.Cap = int(size)
return
}
// PSAPI_WORKING_SET_EX_BLOCK contains extended working set information for a page.
type PSAPI_WORKING_SET_EX_BLOCK uint64
// Valid returns the validity of this page.
// If this bit is 1, the subsequent members are valid; otherwise they should be ignored.
func (b PSAPI_WORKING_SET_EX_BLOCK) Valid() bool {
return (b & 1) == 1
}
// ShareCount is the number of processes that share this page. The maximum value of this member is 7.
func (b PSAPI_WORKING_SET_EX_BLOCK) ShareCount() uint64 {
return b.intField(1, 3)
}
// Win32Protection is the memory protection attributes of the page. For a list of values, see
// https://docs.microsoft.com/en-us/windows/win32/memory/memory-protection-constants
func (b PSAPI_WORKING_SET_EX_BLOCK) Win32Protection() uint64 {
return b.intField(4, 11)
}
// Shared returns the shared status of this page.
// If this bit is 1, the page can be shared.
func (b PSAPI_WORKING_SET_EX_BLOCK) Shared() bool {
return (b & (1 << 15)) == 1
}
// Node is the NUMA node. The maximum value of this member is 63.
func (b PSAPI_WORKING_SET_EX_BLOCK) Node() uint64 {
return b.intField(16, 6)
}
// Locked returns the locked status of this page.
// If this bit is 1, the virtual page is locked in physical memory.
func (b PSAPI_WORKING_SET_EX_BLOCK) Locked() bool {
return (b & (1 << 22)) == 1
}
// LargePage returns the large page status of this page.
// If this bit is 1, the page is a large page.
func (b PSAPI_WORKING_SET_EX_BLOCK) LargePage() bool {
return (b & (1 << 23)) == 1
}
// Bad returns the bad status of this page.
// If this bit is 1, the page is has been reported as bad.
func (b PSAPI_WORKING_SET_EX_BLOCK) Bad() bool {
return (b & (1 << 31)) == 1
}
// intField extracts an integer field in the PSAPI_WORKING_SET_EX_BLOCK union.
func (b PSAPI_WORKING_SET_EX_BLOCK) intField(start, length int) uint64 {
var mask PSAPI_WORKING_SET_EX_BLOCK
for pos := start; pos < start+length; pos++ {
mask |= (1 << pos)
}
masked := b & mask
return uint64(masked >> start)
}
// PSAPI_WORKING_SET_EX_INFORMATION contains extended working set information for a process.
type PSAPI_WORKING_SET_EX_INFORMATION struct {
// The virtual address.
VirtualAddress Pointer
// A PSAPI_WORKING_SET_EX_BLOCK union that indicates the attributes of the page at VirtualAddress.
VirtualAttributes PSAPI_WORKING_SET_EX_BLOCK
}

View File

@ -160,6 +160,10 @@ const (
MAX_COMPUTERNAME_LENGTH = 15
MAX_DHCPV6_DUID_LENGTH = 130
MAX_DNS_SUFFIX_STRING_LENGTH = 256
TIME_ZONE_ID_UNKNOWN = 0
TIME_ZONE_ID_STANDARD = 1
@ -2000,27 +2004,62 @@ type IpAdapterPrefix struct {
}
type IpAdapterAddresses struct {
Length uint32
IfIndex uint32
Next *IpAdapterAddresses
AdapterName *byte
FirstUnicastAddress *IpAdapterUnicastAddress
FirstAnycastAddress *IpAdapterAnycastAddress
FirstMulticastAddress *IpAdapterMulticastAddress
FirstDnsServerAddress *IpAdapterDnsServerAdapter
DnsSuffix *uint16
Description *uint16
FriendlyName *uint16
PhysicalAddress [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte
PhysicalAddressLength uint32
Flags uint32
Mtu uint32
IfType uint32
OperStatus uint32
Ipv6IfIndex uint32
ZoneIndices [16]uint32
FirstPrefix *IpAdapterPrefix
/* more fields might be present here. */
Length uint32
IfIndex uint32
Next *IpAdapterAddresses
AdapterName *byte
FirstUnicastAddress *IpAdapterUnicastAddress
FirstAnycastAddress *IpAdapterAnycastAddress
FirstMulticastAddress *IpAdapterMulticastAddress
FirstDnsServerAddress *IpAdapterDnsServerAdapter
DnsSuffix *uint16
Description *uint16
FriendlyName *uint16
PhysicalAddress [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte
PhysicalAddressLength uint32
Flags uint32
Mtu uint32
IfType uint32
OperStatus uint32
Ipv6IfIndex uint32
ZoneIndices [16]uint32
FirstPrefix *IpAdapterPrefix
TransmitLinkSpeed uint64
ReceiveLinkSpeed uint64
FirstWinsServerAddress *IpAdapterWinsServerAddress
FirstGatewayAddress *IpAdapterGatewayAddress
Ipv4Metric uint32
Ipv6Metric uint32
Luid uint64
Dhcpv4Server SocketAddress
CompartmentId uint32
NetworkGuid GUID
ConnectionType uint32
TunnelType uint32
Dhcpv6Server SocketAddress
Dhcpv6ClientDuid [MAX_DHCPV6_DUID_LENGTH]byte
Dhcpv6ClientDuidLength uint32
Dhcpv6Iaid uint32
FirstDnsSuffix *IpAdapterDNSSuffix
}
type IpAdapterWinsServerAddress struct {
Length uint32
Reserved uint32
Next *IpAdapterWinsServerAddress
Address SocketAddress
}
type IpAdapterGatewayAddress struct {
Length uint32
Reserved uint32
Next *IpAdapterGatewayAddress
Address SocketAddress
}
type IpAdapterDNSSuffix struct {
Next *IpAdapterDNSSuffix
String [MAX_DNS_SUFFIX_STRING_LENGTH]uint16
}
const (

View File

@ -177,6 +177,7 @@ var (
procDnsRecordListFree = moddnsapi.NewProc("DnsRecordListFree")
procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
procGetBestInterfaceEx = modiphlpapi.NewProc("GetBestInterfaceEx")
procGetIfEntry = modiphlpapi.NewProc("GetIfEntry")
procAssignProcessToJobObject = modkernel32.NewProc("AssignProcessToJobObject")
procCancelIo = modkernel32.NewProc("CancelIo")
@ -407,6 +408,7 @@ var (
procGetModuleBaseNameW = modpsapi.NewProc("GetModuleBaseNameW")
procGetModuleFileNameExW = modpsapi.NewProc("GetModuleFileNameExW")
procGetModuleInformation = modpsapi.NewProc("GetModuleInformation")
procQueryWorkingSetEx = modpsapi.NewProc("QueryWorkingSetEx")
procSubscribeServiceChangeNotifications = modsechost.NewProc("SubscribeServiceChangeNotifications")
procUnsubscribeServiceChangeNotifications = modsechost.NewProc("UnsubscribeServiceChangeNotifications")
procGetUserNameExW = modsecur32.NewProc("GetUserNameExW")
@ -1539,6 +1541,14 @@ func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
return
}
func getBestInterfaceEx(sockaddr unsafe.Pointer, pdwBestIfIndex *uint32) (errcode error) {
r0, _, _ := syscall.Syscall(procGetBestInterfaceEx.Addr(), 2, uintptr(sockaddr), uintptr(unsafe.Pointer(pdwBestIfIndex)), 0)
if r0 != 0 {
errcode = syscall.Errno(r0)
}
return
}
func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
r0, _, _ := syscall.Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
if r0 != 0 {
@ -2761,7 +2771,7 @@ func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree
return
}
func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
func readFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
var _p0 *byte
if len(buf) > 0 {
_p0 = &buf[0]
@ -3203,7 +3213,7 @@ func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32,
return
}
func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
func writeFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
var _p0 *byte
if len(buf) > 0 {
_p0 = &buf[0]
@ -3495,6 +3505,14 @@ func GetModuleInformation(process Handle, module Handle, modinfo *ModuleInfo, cb
return
}
func QueryWorkingSetEx(process Handle, pv uintptr, cb uint32) (err error) {
r1, _, e1 := syscall.Syscall(procQueryWorkingSetEx.Addr(), 3, uintptr(process), uintptr(pv), uintptr(cb))
if r1 == 0 {
err = errnoErr(e1)
}
return
}
func SubscribeServiceChangeNotifications(service Handle, eventType uint32, callback uintptr, callbackCtx uintptr, subscription *uintptr) (ret error) {
ret = procSubscribeServiceChangeNotifications.Find()
if ret != nil {