mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-31 22:36:44 -04:00
windows: add memory-related VirtualX calls and associated constants
Fixes golang/go#20086 Change-Id: Ifdc2561fe6cc125fa45a57bad9750f3f3f055e66 Reviewed-on: https://go-review.googlesource.com/47335 TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2017 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package windows
|
||||||
|
|
||||||
|
const (
|
||||||
|
MEM_COMMIT = 0x00001000
|
||||||
|
MEM_RESERVE = 0x00002000
|
||||||
|
MEM_DECOMMIT = 0x00004000
|
||||||
|
MEM_RELEASE = 0x00008000
|
||||||
|
MEM_RESET = 0x00080000
|
||||||
|
MEM_TOP_DOWN = 0x00100000
|
||||||
|
MEM_WRITE_WATCH = 0x00200000
|
||||||
|
MEM_PHYSICAL = 0x00400000
|
||||||
|
MEM_RESET_UNDO = 0x01000000
|
||||||
|
MEM_LARGE_PAGES = 0x20000000
|
||||||
|
|
||||||
|
PAGE_NOACCESS = 0x01
|
||||||
|
PAGE_READONLY = 0x02
|
||||||
|
PAGE_READWRITE = 0x04
|
||||||
|
)
|
||||||
@@ -154,6 +154,9 @@ func NewCallbackCDecl(fn interface{}) uintptr
|
|||||||
//sys FlushViewOfFile(addr uintptr, length uintptr) (err error)
|
//sys FlushViewOfFile(addr uintptr, length uintptr) (err error)
|
||||||
//sys VirtualLock(addr uintptr, length uintptr) (err error)
|
//sys VirtualLock(addr uintptr, length uintptr) (err error)
|
||||||
//sys VirtualUnlock(addr uintptr, length uintptr) (err error)
|
//sys VirtualUnlock(addr uintptr, length uintptr) (err error)
|
||||||
|
//sys VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint32) (value uintptr, err error) = kernel32.VirtualAlloc
|
||||||
|
//sys VirtualFree(address uintptr, size uintptr, freetype uint32) (err error) = kernel32.VirtualFree
|
||||||
|
//sys VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect *uint32) (err error) = kernel32.VirtualProtect
|
||||||
//sys TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) = mswsock.TransmitFile
|
//sys TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) = mswsock.TransmitFile
|
||||||
//sys ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) = kernel32.ReadDirectoryChangesW
|
//sys ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) = kernel32.ReadDirectoryChangesW
|
||||||
//sys CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) = crypt32.CertOpenSystemStoreW
|
//sys CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) = crypt32.CertOpenSystemStoreW
|
||||||
|
|||||||
@@ -139,6 +139,9 @@ var (
|
|||||||
procFlushViewOfFile = modkernel32.NewProc("FlushViewOfFile")
|
procFlushViewOfFile = modkernel32.NewProc("FlushViewOfFile")
|
||||||
procVirtualLock = modkernel32.NewProc("VirtualLock")
|
procVirtualLock = modkernel32.NewProc("VirtualLock")
|
||||||
procVirtualUnlock = modkernel32.NewProc("VirtualUnlock")
|
procVirtualUnlock = modkernel32.NewProc("VirtualUnlock")
|
||||||
|
procVirtualAlloc = modkernel32.NewProc("VirtualAlloc")
|
||||||
|
procVirtualFree = modkernel32.NewProc("VirtualFree")
|
||||||
|
procVirtualProtect = modkernel32.NewProc("VirtualProtect")
|
||||||
procTransmitFile = modmswsock.NewProc("TransmitFile")
|
procTransmitFile = modmswsock.NewProc("TransmitFile")
|
||||||
procReadDirectoryChangesW = modkernel32.NewProc("ReadDirectoryChangesW")
|
procReadDirectoryChangesW = modkernel32.NewProc("ReadDirectoryChangesW")
|
||||||
procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW")
|
procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW")
|
||||||
@@ -1384,6 +1387,43 @@ func VirtualUnlock(addr uintptr, length uintptr) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint32) (value uintptr, err error) {
|
||||||
|
r0, _, e1 := syscall.Syscall6(procVirtualAlloc.Addr(), 4, uintptr(address), uintptr(size), uintptr(alloctype), uintptr(protect), 0, 0)
|
||||||
|
value = uintptr(r0)
|
||||||
|
if value == 0 {
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
} else {
|
||||||
|
err = syscall.EINVAL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func VirtualFree(address uintptr, size uintptr, freetype uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall(procVirtualFree.Addr(), 3, uintptr(address), uintptr(size), uintptr(freetype))
|
||||||
|
if r1 == 0 {
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
} else {
|
||||||
|
err = syscall.EINVAL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect *uint32) (err error) {
|
||||||
|
r1, _, e1 := syscall.Syscall6(procVirtualProtect.Addr(), 4, uintptr(address), uintptr(size), uintptr(newprotect), uintptr(unsafe.Pointer(oldprotect)), 0, 0)
|
||||||
|
if r1 == 0 {
|
||||||
|
if e1 != 0 {
|
||||||
|
err = errnoErr(e1)
|
||||||
|
} else {
|
||||||
|
err = syscall.EINVAL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) {
|
func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall9(procTransmitFile.Addr(), 7, uintptr(s), uintptr(handle), uintptr(bytesToWrite), uintptr(bytsPerSend), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transmitFileBuf)), uintptr(flags), 0, 0)
|
r1, _, e1 := syscall.Syscall9(procTransmitFile.Addr(), 7, uintptr(s), uintptr(handle), uintptr(bytesToWrite), uintptr(bytsPerSend), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transmitFileBuf)), uintptr(flags), 0, 0)
|
||||||
if r1 == 0 {
|
if r1 == 0 {
|
||||||
|
|||||||
@@ -165,8 +165,6 @@ const (
|
|||||||
PROCESS_QUERY_INFORMATION = 0x00000400
|
PROCESS_QUERY_INFORMATION = 0x00000400
|
||||||
SYNCHRONIZE = 0x00100000
|
SYNCHRONIZE = 0x00100000
|
||||||
|
|
||||||
PAGE_READONLY = 0x02
|
|
||||||
PAGE_READWRITE = 0x04
|
|
||||||
PAGE_WRITECOPY = 0x08
|
PAGE_WRITECOPY = 0x08
|
||||||
PAGE_EXECUTE_READ = 0x20
|
PAGE_EXECUTE_READ = 0x20
|
||||||
PAGE_EXECUTE_READWRITE = 0x40
|
PAGE_EXECUTE_READWRITE = 0x40
|
||||||
|
|||||||
Reference in New Issue
Block a user