mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-03 15:47:35 -04:00
windows: copy latest changes from internal/syscall/windows
Copy of CL 4310, 6140, 17412, 17997 and 17998. Change-Id: I7db8722a1c37f033d5ce6644859ef15c58289a46 Reviewed-on: https://go-review.googlesource.com/18552 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
@@ -701,17 +701,19 @@ func TestGetMUIStringValue(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer timezoneK.Close()
|
defer timezoneK.Close()
|
||||||
|
|
||||||
var tests = []struct {
|
type testType struct {
|
||||||
key registry.Key
|
|
||||||
name string
|
name string
|
||||||
want string
|
want string
|
||||||
}{
|
}
|
||||||
{timezoneK, "MUI_Std", syscall.UTF16ToString(dtzi.StandardName[:])},
|
var tests = []testType{
|
||||||
{timezoneK, "MUI_Dlt", syscall.UTF16ToString(dtzi.DaylightName[:])},
|
{"MUI_Std", syscall.UTF16ToString(dtzi.StandardName[:])},
|
||||||
|
}
|
||||||
|
if dtzi.DynamicDaylightTimeDisabled == 0 {
|
||||||
|
tests = append(tests, testType{"MUI_Dlt", syscall.UTF16ToString(dtzi.DaylightName[:])})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
got, err := test.key.GetMUIStringValue(test.name)
|
got, err := timezoneK.GetMUIStringValue(test.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("GetMUIStringValue:", err)
|
t.Error("GetMUIStringValue:", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ func NewCallbackCDecl(fn interface{}) uintptr
|
|||||||
//sys RemoveDirectory(path *uint16) (err error) = RemoveDirectoryW
|
//sys RemoveDirectory(path *uint16) (err error) = RemoveDirectoryW
|
||||||
//sys DeleteFile(path *uint16) (err error) = DeleteFileW
|
//sys DeleteFile(path *uint16) (err error) = DeleteFileW
|
||||||
//sys MoveFile(from *uint16, to *uint16) (err error) = MoveFileW
|
//sys MoveFile(from *uint16, to *uint16) (err error) = MoveFileW
|
||||||
|
//sys MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) = MoveFileExW
|
||||||
//sys GetComputerName(buf *uint16, n *uint32) (err error) = GetComputerNameW
|
//sys GetComputerName(buf *uint16, n *uint32) (err error) = GetComputerNameW
|
||||||
//sys GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) = GetComputerNameExW
|
//sys GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) = GetComputerNameExW
|
||||||
//sys SetEndOfFile(handle Handle) (err error)
|
//sys SetEndOfFile(handle Handle) (err error)
|
||||||
@@ -369,7 +370,7 @@ func Rename(oldpath, newpath string) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return MoveFile(from, to)
|
return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ComputerName() (name string, err error) {
|
func ComputerName() (name string, err error) {
|
||||||
@@ -528,6 +529,9 @@ const socket_error = uintptr(^uint32(0))
|
|||||||
//sys GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) = iphlpapi.GetAdaptersInfo
|
//sys GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) = iphlpapi.GetAdaptersInfo
|
||||||
//sys SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) = kernel32.SetFileCompletionNotificationModes
|
//sys SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) = kernel32.SetFileCompletionNotificationModes
|
||||||
//sys WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) [failretval==-1] = ws2_32.WSAEnumProtocolsW
|
//sys WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) [failretval==-1] = ws2_32.WSAEnumProtocolsW
|
||||||
|
//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
|
||||||
|
|
||||||
// For testing: clients can set this flag to force
|
// For testing: clients can set this flag to force
|
||||||
// creation of IPv6 sockets to return EAFNOSUPPORT.
|
// creation of IPv6 sockets to return EAFNOSUPPORT.
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ var (
|
|||||||
procRemoveDirectoryW = modkernel32.NewProc("RemoveDirectoryW")
|
procRemoveDirectoryW = modkernel32.NewProc("RemoveDirectoryW")
|
||||||
procDeleteFileW = modkernel32.NewProc("DeleteFileW")
|
procDeleteFileW = modkernel32.NewProc("DeleteFileW")
|
||||||
procMoveFileW = modkernel32.NewProc("MoveFileW")
|
procMoveFileW = modkernel32.NewProc("MoveFileW")
|
||||||
|
procMoveFileExW = modkernel32.NewProc("MoveFileExW")
|
||||||
procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
|
procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
|
||||||
procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
|
procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
|
||||||
procSetEndOfFile = modkernel32.NewProc("SetEndOfFile")
|
procSetEndOfFile = modkernel32.NewProc("SetEndOfFile")
|
||||||
@@ -169,6 +170,9 @@ var (
|
|||||||
procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
|
procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
|
||||||
procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
|
procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
|
||||||
procWSAEnumProtocolsW = modws2_32.NewProc("WSAEnumProtocolsW")
|
procWSAEnumProtocolsW = modws2_32.NewProc("WSAEnumProtocolsW")
|
||||||
|
procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
|
||||||
|
procGetACP = modkernel32.NewProc("GetACP")
|
||||||
|
procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
|
||||||
procTranslateNameW = modsecur32.NewProc("TranslateNameW")
|
procTranslateNameW = modsecur32.NewProc("TranslateNameW")
|
||||||
procGetUserNameExW = modsecur32.NewProc("GetUserNameExW")
|
procGetUserNameExW = modsecur32.NewProc("GetUserNameExW")
|
||||||
procNetUserGetInfo = modnetapi32.NewProc("NetUserGetInfo")
|
procNetUserGetInfo = modnetapi32.NewProc("NetUserGetInfo")
|
||||||
@@ -700,6 +704,18 @@ func MoveFile(from *uint16, to *uint16) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
|
||||||
|
if r1 == 0 {
|
||||||
|
if e1 != 0 {
|
||||||
|
err = error(e1)
|
||||||
|
} else {
|
||||||
|
err = syscall.EINVAL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func GetComputerName(buf *uint16, n *uint32) (err error) {
|
func GetComputerName(buf *uint16, n *uint32) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
|
r1, _, e1 := syscall.Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
@@ -1996,6 +2012,33 @@ func WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferL
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
|
||||||
|
r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0)
|
||||||
|
if r0 != 0 {
|
||||||
|
errcode = syscall.Errno(r0)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetACP() (acp uint32) {
|
||||||
|
r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
|
||||||
|
acp = uint32(r0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
|
||||||
|
r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
|
||||||
|
nwrite = int32(r0)
|
||||||
|
if nwrite == 0 {
|
||||||
|
if e1 != 0 {
|
||||||
|
err = error(e1)
|
||||||
|
} else {
|
||||||
|
err = syscall.EINVAL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) {
|
func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall6(procTranslateNameW.Addr(), 5, uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize)), 0)
|
r1, _, e1 := syscall.Syscall6(procTranslateNameW.Addr(), 5, uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize)), 0)
|
||||||
if r1&0xff == 0 {
|
if r1&0xff == 0 {
|
||||||
|
|||||||
@@ -1135,3 +1135,108 @@ const (
|
|||||||
ComputerNamePhysicalDnsFullyQualified = 7
|
ComputerNamePhysicalDnsFullyQualified = 7
|
||||||
ComputerNameMax = 8
|
ComputerNameMax = 8
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MOVEFILE_REPLACE_EXISTING = 0x1
|
||||||
|
MOVEFILE_COPY_ALLOWED = 0x2
|
||||||
|
MOVEFILE_DELAY_UNTIL_REBOOT = 0x4
|
||||||
|
MOVEFILE_WRITE_THROUGH = 0x8
|
||||||
|
MOVEFILE_CREATE_HARDLINK = 0x10
|
||||||
|
MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20
|
||||||
|
)
|
||||||
|
|
||||||
|
const GAA_FLAG_INCLUDE_PREFIX = 0x00000010
|
||||||
|
|
||||||
|
const (
|
||||||
|
IF_TYPE_OTHER = 1
|
||||||
|
IF_TYPE_ETHERNET_CSMACD = 6
|
||||||
|
IF_TYPE_ISO88025_TOKENRING = 9
|
||||||
|
IF_TYPE_PPP = 23
|
||||||
|
IF_TYPE_SOFTWARE_LOOPBACK = 24
|
||||||
|
IF_TYPE_ATM = 37
|
||||||
|
IF_TYPE_IEEE80211 = 71
|
||||||
|
IF_TYPE_TUNNEL = 131
|
||||||
|
IF_TYPE_IEEE1394 = 144
|
||||||
|
)
|
||||||
|
|
||||||
|
type SocketAddress struct {
|
||||||
|
Sockaddr *syscall.RawSockaddrAny
|
||||||
|
SockaddrLength int32
|
||||||
|
}
|
||||||
|
|
||||||
|
type IpAdapterUnicastAddress struct {
|
||||||
|
Length uint32
|
||||||
|
Flags uint32
|
||||||
|
Next *IpAdapterUnicastAddress
|
||||||
|
Address SocketAddress
|
||||||
|
PrefixOrigin int32
|
||||||
|
SuffixOrigin int32
|
||||||
|
DadState int32
|
||||||
|
ValidLifetime uint32
|
||||||
|
PreferredLifetime uint32
|
||||||
|
LeaseLifetime uint32
|
||||||
|
OnLinkPrefixLength uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
type IpAdapterAnycastAddress struct {
|
||||||
|
Length uint32
|
||||||
|
Flags uint32
|
||||||
|
Next *IpAdapterAnycastAddress
|
||||||
|
Address SocketAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
type IpAdapterMulticastAddress struct {
|
||||||
|
Length uint32
|
||||||
|
Flags uint32
|
||||||
|
Next *IpAdapterMulticastAddress
|
||||||
|
Address SocketAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
type IpAdapterDnsServerAdapter struct {
|
||||||
|
Length uint32
|
||||||
|
Reserved uint32
|
||||||
|
Next *IpAdapterDnsServerAdapter
|
||||||
|
Address SocketAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
type IpAdapterPrefix struct {
|
||||||
|
Length uint32
|
||||||
|
Flags uint32
|
||||||
|
Next *IpAdapterPrefix
|
||||||
|
Address SocketAddress
|
||||||
|
PrefixLength uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
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. */
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
IfOperStatusUp = 1
|
||||||
|
IfOperStatusDown = 2
|
||||||
|
IfOperStatusTesting = 3
|
||||||
|
IfOperStatusUnknown = 4
|
||||||
|
IfOperStatusDormant = 5
|
||||||
|
IfOperStatusNotPresent = 6
|
||||||
|
IfOperStatusLowerLayerDown = 7
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user