[sys] windows: add QueryWorkingSetEx

94 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Apr 26, 2022, 8:57:33 PM4/26/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

windows: add QueryWorkingSetEx

This change adds the QueryWorkingSetEx function for inspecting
the virtual memory details of pointers.

https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-queryworkingsetex

Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
GitHub-Last-Rev: 7393d66e8ca0c971817672d4abc1e62355027601
GitHub-Pull-Request: golang/sys#124
---
M windows/syscall_windows.go
M windows/syscall_windows_test.go
M windows/zsyscall_windows.go
3 files changed, 150 insertions(+), 0 deletions(-)

diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
index ce3075c..f2d8715 100644
--- a/windows/syscall_windows.go
+++ b/windows/syscall_windows.go
@@ -6,6 +6,60 @@

package windows

+/*
+#include <stdbool.h>
+#include <windows.h>
+
+typedef union _PSAPI_WORKING_SET_EX_BLOCK {
+ ULONG_PTR Flags;
+ union {
+ struct {
+ ULONG_PTR Valid : 1;
+ ULONG_PTR ShareCount : 3;
+ ULONG_PTR Win32Protection : 11;
+ ULONG_PTR Shared : 1;
+ ULONG_PTR Node : 6;
+ ULONG_PTR Locked : 1;
+ ULONG_PTR LargePage : 1;
+ ULONG_PTR Reserved : 7;
+ ULONG_PTR Bad : 1;
+ ULONG_PTR ReservedUlong : 32;
+ };
+ struct {
+ ULONG_PTR Valid : 1;
+ ULONG_PTR Reserved0 : 14;
+ ULONG_PTR Shared : 1;
+ ULONG_PTR Reserved1 : 15;
+ ULONG_PTR Bad : 1;
+ ULONG_PTR ReservedUlong : 32;
+ } Invalid;
+ };
+} PSAPI_WORKING_SET_EX_BLOCK, *PPSAPI_WORKING_SET_EX_BLOCK;
+
+typedef struct {
+ bool Valid;
+ int ShareCount;
+ int Win32Protection;
+ bool Shared;
+ int Node;
+ bool Locked;
+ bool LargePage;
+ bool Bad;
+} PSAPIWorkingSetExBlock;
+
+void PSAPIWorkingSetExBlockUnion(PSAPI_WORKING_SET_EX_BLOCK b, PSAPIWorkingSetExBlock* cBlock) {
+ cBlock->Valid = b.Valid;
+ cBlock->ShareCount = b.ShareCount;
+ cBlock->Win32Protection = b.Win32Protection;
+ cBlock->Shared = b.Shared;
+ cBlock->Node = b.Node;
+ cBlock->Locked = b.Locked;
+ cBlock->LargePage = b.LargePage;
+ cBlock->Bad = b.Bad;
+}
+*/
+import "C"
+
import (
errorspkg "errors"
"fmt"
@@ -417,6 +471,7 @@
//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 *psapiWorkingSetExInformation, cb uintptr) (err error) = psapi.QueryWorkingSetEx

// NT Native APIs
//sys rtlNtStatusToDosErrorNoTeb(ntstatus NTStatus) (ret syscall.Errno) = ntdll.RtlNtStatusToDosErrorNoTeb
@@ -1699,3 +1754,59 @@
h.Cap = int(size)
return
}
+
+type PSAPIWorkingSetExBlock struct {
+ Valid bool
+ ShareCount int
+ Win32Protection int
+ Shared bool
+ Node int
+ Locked bool
+ LargePage bool
+ Bad bool
+ Raw []byte
+}
+
+// typedef struct _PSAPI_WORKING_SET_EX_INFORMATION {
+// PVOID VirtualAddress;
+// PSAPI_WORKING_SET_EX_BLOCK VirtualAttributes;
+// } PSAPI_WORKING_SET_EX_INFORMATION, *PPSAPI_WORKING_SET_EX_INFORMATION;
+type psapiWorkingSetExInformation struct {
+ VirtualAddress Pointer
+ VirtualAttributes C.PSAPI_WORKING_SET_EX_BLOCK
+}
+
+func QueryWorkingSetEx(hProcess Handle, ptrs []unsafe.Pointer) ([]PSAPIWorkingSetExBlock, error) {
+ if len(ptrs) == 0 {
+ return nil, nil
+ }
+ infos := make([]psapiWorkingSetExInformation, len(ptrs))
+ for i, ptr := range ptrs {
+ infos[i].VirtualAddress = Pointer(ptr)
+ }
+ if err := queryWorkingSetEx(hProcess, &infos[0], uintptr(len(infos))*unsafe.Sizeof(infos[0])); err != nil {
+ return nil, err
+ }
+
+ blocks := make([]PSAPIWorkingSetExBlock, 0, len(infos))
+ for _, info := range infos {
+ var cBlock C.PSAPIWorkingSetExBlock
+ C.PSAPIWorkingSetExBlockUnion(info.VirtualAttributes, &cBlock)
+
+ var block PSAPIWorkingSetExBlock
+ block.Valid = bool(cBlock.Valid)
+ block.ShareCount = int(cBlock.ShareCount)
+ block.Win32Protection = int(cBlock.Win32Protection)
+ block.Shared = bool(cBlock.Shared)
+ block.Node = int(cBlock.Node)
+ block.Locked = bool(cBlock.Locked)
+ block.LargePage = bool(cBlock.LargePage)
+ block.Bad = bool(cBlock.Bad)
+ block.Raw = make([]byte, len(info.VirtualAttributes))
+ copy(block.Raw, info.VirtualAttributes[:])
+
+ blocks = append(blocks, block)
+ }
+
+ return blocks, nil
+}
diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go
index dcebb2c..d2187d0 100644
--- a/windows/syscall_windows_test.go
+++ b/windows/syscall_windows_test.go
@@ -777,6 +777,20 @@
}
}

+func TestQueryWorkingSetEx(t *testing.T) {
+ var a int
+
+ process := windows.CurrentProcess()
+ pointers := []unsafe.Pointer{unsafe.Pointer(&a)}
+ blocks, err := windows.QueryWorkingSetEx(process, pointers)
+ if err != nil {
+ t.Fatalf("%+v", err)
+ }
+ if !blocks[0].Valid {
+ t.Errorf("memory location not valid")
+ }
+}
+
func TestReadWriteProcessMemory(t *testing.T) {
testBuffer := []byte{0xBA, 0xAD, 0xF0, 0x0D}

diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go
index 68f52c1..de7891a 100644
--- a/windows/zsyscall_windows.go
+++ b/windows/zsyscall_windows.go
@@ -407,6 +407,7 @@
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")
@@ -3495,6 +3496,14 @@
return
}

+func queryWorkingSetEx(process Handle, pv *psapiWorkingSetExInformation, cb uintptr) (err error) {
+ r1, _, e1 := syscall.Syscall(procQueryWorkingSetEx.Addr(), 3, uintptr(process), uintptr(unsafe.Pointer(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 {

To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sys
Gerrit-Branch: master
Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
Gerrit-Change-Number: 402494
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-MessageType: newchange

Gopher Robot (Gerrit)

unread,
Apr 26, 2022, 8:57:59 PM4/26/22
to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.

View Change

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Wed, 27 Apr 2022 00:57:55 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Alex Brainman (Gerrit)

    unread,
    Jul 10, 2022, 12:31:36 AM7/10/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Brad Fitzpatrick, Gopher Robot, golang-co...@googlegroups.com

    Patch set 1:Run-TryBot +1

    View Change

    11 comments:

    • Patchset:

      • Patch Set #1:

        Thank you for adding this functionality.

        See my comments.

        Alex

    • File windows/syscall_windows.go:

      • Patch Set #1, Line 61: import "C"

        This makes users of this package automatically use Cgo.

        Are you sure you intended to introduce this dependency on all users of this package?

        Please remove all your changes up to line 61.

      • Patch Set #1, Line 474: uintptr

        s/uintptr/uint32/

        because this parameters is documented as DWORD

        https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-queryworkingsetex

        and DWORD is uint32 as per

        https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types

      • Patch Set #1, Line 474: queryWorkingSetEx

        s/queryWorkingSetEx/QueryWorkingSetEx/

        I suggest you let users call this function directly. See my comments below for explanations.

      • Patch Set #1, Line 1758: PSAPIWorkingSetExBlock

        s/PSAPIWorkingSetExBlock/PSAPI_WORKING_SET_EX_BLOCK/

        to keep its original name. Otherwise code readers will not find any documentation if the google for PSAPIWorkingSetExBlock.

      • Patch Set #1, Line 1759: Valid bool

        I suggest you replace all these with some private fields

        hidden uint64

        and then add methods like

        func (b *PSAPI_WORKING_SET_EX_BLOCK) Valid() bool

        that pick correct bits our of b.hidden.

        Feel free to suggest something different if you have better ideas.

      • Patch Set #1, Line 1770: // typedef struct _PSAPI_WORKING_SET_EX_INFORMATION {

        Remove commented lines 1770-1773.

        I don't see why they are needed.

      • Patch Set #1, Line 1774: psapiWorkingSetExInformation

        s/psapiWorkingSetExInformation/PSAPI_WORKING_SET_EX_INFORMATION/

        to keep its original name. Otherwise code readers will not find any documentation if the google for psapiWorkingSetExInformation.

      • Patch Set #1, Line 1775: Pointer

        s/Pointer/uintptr/

        because we always convert PVOID into uintptr.

      • Patch Set #1, Line 1776: C.PSAPI_WORKING_SET_EX_BLOCK

        s/C.PSAPI_WORKING_SET_EX_BLOCK/PSAPI_WORKING_SET_EX_BLOCK/

      • Patch Set #1, Line 1779: func QueryWorkingSetEx(hProcess Handle, ptrs []unsafe.Pointer) ([]PSAPIWorkingSetExBlock, error) {

        This function allocates memory. windows package tries not to allocate memory if possible. It would be confusing if windows.QueryWorkingSetEx silently allocates memory.

        On the other hand fill free to move this code into test part of your change, if it is useful there.

        I won't review this code and the test until you address my other comment. I suspect this code will change a bit.

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Sun, 10 Jul 2022 04:31:30 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Fumin A (Gerrit)

    unread,
    Jul 10, 2022, 11:14:05 PM7/10/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Alex Brainman, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman.

    View Change

    2 comments:

    • Patchset:

      • Patch Set #1:

        Thank you for adding this functionality. […]

        Alex, thanks for your review.

        In general, following your suggestion to let users call `queryWorkingSetEx` directly would dramatically simplify this change.
        Following this line of thinking, I would like to ask for your advice for the following questions pursuing this route:

        • Is there a place in this folder where we can place a helper function to convert the C union `_PSAPI_WORKING_SET_EX_BLOCK` into a vanilla Go struct?
        • In fact, the reason why this change seems so complicated is because it tries to provide said function.
        • What is the recommended way of converting a C union into a vanilla Go struct.
        • The only way I am aware of relies of CGO, hence the reluctantly inclusion of it in this change. Could you kindly advice of an alternative way that avoids the dreaded CGO?

        On a related note, could you confirm that it is safe to set the type of psapiWorkingSetExInformation.VirtualAddress to `uintptr`. My understanding of the discussion in https://github.com/golang/go/issues/21376 suggests that since `VirtualAddress` is meant to point to a location in memory, to avoid the garbage collector from moving it around during the syscall, it needs to be pinned by the semantics of the `Pointer` type. Could you confirm that such pinning is not needed in this case?

        Again, thanks for your time and helpful review.

      • Patch Set #1:

        I intend to follow your suggestion in simplifying this change.
        However, I need your advice on a few issues described in more detail below.
        Thanks in advance for your advise.

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Comment-Date: Sun, 10 Jul 2022 09:52:39 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Alex Brainman <alex.b...@gmail.com>
    Gerrit-MessageType: comment

    Alex Brainman (Gerrit)

    unread,
    Jul 11, 2022, 4:41:45 AM7/11/22
    to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Fumin A.

    View Change

    1 comment:

      • Alex, thanks for your review.

        In general, following your suggestion to let users call `queryWorkingSetEx` directly would dramatically simplify this change.

      • Sounds good to me.

      • Following this line of thinking, I would like to ask for your advice for the following questions pursuing this route:

        • Is there a place in this folder where we can place a helper function to convert the C union `_PSAPI_WORKING_SET_EX_BLOCK` into a vanilla Go struct?
        • In fact, the reason why this change seems so complicated is because it tries to provide said function.
        • What is the recommended way of converting a C union into a vanilla Go struct.
        • The only way I am aware of relies of CGO, hence the reluctantly inclusion of it in this change. Could you kindly advice of an alternative way that avoids the dreaded CGO?
      • I don't know of a way to convert C union into Go struct. I propose you assume that PSAPI_WORKING_SET_EX_BLOCK is a struct containing [8]byte or uint64, and then implement C union fields as PSAPI_WORKING_SET_EX_BLOCK methods. For example PSAPI_WORKING_SET_EX_BLOCK will have methods like Valid() bool and ShareCount() byte and so on, and you just pick correspondent bits to implement these methods.


      • On a related note, could you confirm that it is safe to set the type of psapiWorkingSetExInformation.VirtualAddress to `uintptr`. My understanding of the discussion in https://github.com/golang/go/issues/21376 suggests that since `VirtualAddress` is meant to point to a location in memory, to avoid the garbage collector from moving it around during the syscall, it needs to be pinned by the semantics of the `Pointer` type. Could you confirm that such pinning is not needed in this case?

      • PSAPI_WORKING_SET_EX_INFORMATION.VirtualAddress will contain address set by Windows. I don't see why Go garbage collector should see it. That is why I suggest you define it as uintptr. And then user can convert it into unsafe.Pointer when required.

        Perhaps I misunderstand your concerns.


      • Again, thanks for your time and helpful review.

      • No worries. All is good.

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Fumin A <awaw...@gmail.com>
    Gerrit-Comment-Date: Mon, 11 Jul 2022 08:41:39 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Fumin A <awaw...@gmail.com>

    Fumin A (Gerrit)

    unread,
    Jul 11, 2022, 11:38:52 AM7/11/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Alex Brainman, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman.

    View Change

    1 comment:

    • Patchset:

      • Patch Set #1:

        > Alex, thanks for your review. […]

        Thanks for the elaboration, I am close to having a complete understanding of the new proposal.

        Just one last question and sorry for being a little repetitive:
        With respect of the type of `psapiWorkingSetExInformation.VirtualAddress`,
        my understanding is that it is *not* set by Windows, but by us in Go.
        It is an input to the `queryWorkingSetEx` function, and it's usage is to let Windows know which particular memory addresses we are interested in.
        Since `VirtualAddress` is an input, would it not require the same care that were given to similar fields in https://go-review.googlesource.com/c/go/+/106275/ ?

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Comment-Date: Mon, 11 Jul 2022 15:38:47 +0000

    Gerrit Bot (Gerrit)

    unread,
    Jul 11, 2022, 10:28:14 PM7/11/22
    to Fumin A, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman.

    Gerrit Bot uploaded patch set #2 to this change.

    View Change

    The following approvals got outdated and were removed: Run-TryBot+1 by Alex Brainman, TryBot-Result-1 by Gopher Robot

    windows: add QueryWorkingSetEx

    This change adds the QueryWorkingSetEx function for inspecting
    the virtual memory details of pointers.

    https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-queryworkingsetex

    Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    GitHub-Last-Rev: 131f6ffa756f6f70264ca2dd0da0db55a64ec94e

    GitHub-Pull-Request: golang/sys#124
    ---
    M windows/syscall_windows.go
    M windows/syscall_windows_test.go
    M windows/zsyscall_windows.go
    3 files changed, 81 insertions(+), 0 deletions(-)

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-MessageType: newpatchset

    Fumin A (Gerrit)

    unread,
    Jul 11, 2022, 10:54:00 PM7/11/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Alex Brainman, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman.

    View Change

    11 comments:

    • Patchset:

      • Patch Set #2:

        I have addressed all comments except for the type of VirtualAddress.
        Would appreciate if you could take another look of my concerns for it not being of type `Pointer`.
        Following your suggestions does make this change much cleaner now, thanks for them.

    • File windows/syscall_windows.go:

      • This makes users of this package automatically use Cgo. […]

        Done

      • s/uintptr/uint32/ […]

        Done

      • s/queryWorkingSetEx/QueryWorkingSetEx/ […]

        Done

      • s/PSAPIWorkingSetExBlock/PSAPI_WORKING_SET_EX_BLOCK/ […]

        Done

      • I suggest you replace all these with some private fields […]

        Done

      • Remove commented lines 1770-1773. […]

        Done

      • s/psapiWorkingSetExInformation/PSAPI_WORKING_SET_EX_INFORMATION/ […]

        Done

      • s/Pointer/uintptr/ […]

        Since this field is set by users in Go, as opposed to by Windows, should it not be pinned to avoid being moved by the garbage collector?

      • s/C. […]

        Done

      • Patch Set #1, Line 1779: func QueryWorkingSetEx(hProcess Handle, ptrs []unsafe.Pointer) ([]PSAPIWorkingSetExBlock, error) {

      • This function allocates memory. windows package tries not to allocate memory if possible. […]

        Done

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Comment-Date: Tue, 12 Jul 2022 02:53:55 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No

    Dan Kortschak (Gerrit)

    unread,
    Jul 12, 2022, 2:53:00 AM7/12/22
    to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Alex Brainman, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman.

    View Change

    1 comment:

    • File windows/syscall_windows.go:

      • Patch Set #2, Line 1705: type PSAPI_WORKING_SET_EX_BLOCK uint64

        Is it worth adding methods for the `ShareCount`, `Win32Protection` and `Node` bit fields?

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 2
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Dan Kortschak <d...@kortschak.io>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Comment-Date: Tue, 12 Jul 2022 06:52:55 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Gerrit Bot (Gerrit)

    unread,
    Jul 12, 2022, 4:59:13 AM7/12/22
    to Fumin A, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman.

    Gerrit Bot uploaded patch set #3 to this change.

    View Change

    windows: add QueryWorkingSetEx


    This change adds the QueryWorkingSetEx function for inspecting
    the virtual memory details of pointers.

    https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-queryworkingsetex

    Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    GitHub-Last-Rev: a729815e8a475104a725b9fe7acd906618557c79

    GitHub-Pull-Request: golang/sys#124
    ---
    M windows/syscall_windows.go
    M windows/syscall_windows_test.go
    M windows/zsyscall_windows.go
    3 files changed, 108 insertions(+), 0 deletions(-)

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Dan Kortschak <d...@kortschak.io>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-MessageType: newpatchset

    Fumin A (Gerrit)

    unread,
    Jul 12, 2022, 5:02:48 AM7/12/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Dan Kortschak, Gopher Robot, Alex Brainman, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman, Dan Kortschak.

    View Change

    1 comment:

    • File windows/syscall_windows.go:

      • Patch Set #2, Line 1705: type PSAPI_WORKING_SET_EX_BLOCK uint64

        Is it worth adding methods for the `ShareCount`, `Win32Protection` and `Node` bit fields?

      • Yes, it is. I have added getters for these fields. Thanks for the suggestion.

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Dan Kortschak <d...@kortschak.io>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
    Gerrit-Comment-Date: Tue, 12 Jul 2022 09:02:43 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Dan Kortschak <d...@kortschak.io>
    Gerrit-MessageType: comment

    Alex Brainman (Gerrit)

    unread,
    Jul 17, 2022, 6:02:37 AM7/17/22
    to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Austin Clements, Dan Kortschak, Gopher Robot, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Dan Kortschak, Fumin A.

    Patch set 3:Run-TryBot +1

    View Change

    4 comments:

    • Patchset:

      • Patch Set #2:

        I have addressed all comments except for the type of VirtualAddress.
        Would appreciate if you could take another look of my concerns for it not being of type `Pointer`.

      • Following your suggestions does make this change much cleaner now, thanks for them.

    • Patchset:

    • File windows/syscall_windows.go:

      • Patch Set #3, Line 1749: int

        s/int/uint64/

        otherwise this will not work on 386 arch.

        Same for all methods that call this method.

    • File windows/syscall_windows_test.go:

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Austin Clements <aus...@google.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Dan Kortschak <d...@kortschak.io>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
    Gerrit-Comment-Date: Sun, 17 Jul 2022 10:02:31 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: Fumin A <awaw...@gmail.com>
    Gerrit-MessageType: comment

    Alex Brainman (Gerrit)

    unread,
    Jul 17, 2022, 6:05:48 AM7/17/22
    to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Dan Kortschak, Fumin A.

    Patch set 3:-Run-TryBot

    View Change

    1 comment:

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Austin Clements <aus...@google.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Dan Kortschak <d...@kortschak.io>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
    Gerrit-Comment-Date: Sun, 17 Jul 2022 10:05:42 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Alex Brainman (Gerrit)

    unread,
    Jul 17, 2022, 6:10:19 AM7/17/22
    to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Dan Kortschak, Fumin A.

    View Change

    1 comment:

    • Patchset:

      • Patch Set #3:

        14 of 16 TryBots failed. […]

        I don't understand why try-bots are failing. Perhaps you are using old commit that had bug in it. Can you, please, rebase your work onto current tip?

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 3
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Austin Clements <aus...@google.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Dan Kortschak <d...@kortschak.io>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
    Gerrit-Comment-Date: Sun, 17 Jul 2022 10:10:13 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Gopher Robot <go...@golang.org>
    Gerrit-MessageType: comment

    Gerrit Bot (Gerrit)

    unread,
    Jul 17, 2022, 9:55:28 PM7/17/22
    to Fumin A, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Dan Kortschak, Fumin A.

    Gerrit Bot uploaded patch set #4 to this change.

    View Change

    The following approvals got outdated and were removed: TryBot-Result-1 by Gopher Robot

    windows: add QueryWorkingSetEx

    This change adds the QueryWorkingSetEx function for inspecting
    the virtual memory details of pointers.

    https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-queryworkingsetex

    Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    GitHub-Last-Rev: 8d544e3068dee02016df1ca850588f931294c5de

    GitHub-Pull-Request: golang/sys#124
    ---
    M windows/syscall_windows.go
    M windows/syscall_windows_test.go
    M windows/zsyscall_windows.go
    3 files changed, 108 insertions(+), 0 deletions(-)

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 4
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Austin Clements <aus...@google.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Dan Kortschak <d...@kortschak.io>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
    Gerrit-MessageType: newpatchset

    Gerrit Bot (Gerrit)

    unread,
    Jul 17, 2022, 9:59:29 PM7/17/22
    to Fumin A, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Dan Kortschak, Fumin A.

    Gerrit Bot uploaded patch set #5 to this change.

    View Change

    windows: add QueryWorkingSetEx


    This change adds the QueryWorkingSetEx function for inspecting
    the virtual memory details of pointers.

    https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-queryworkingsetex

    Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    GitHub-Last-Rev: a7c07dc3546c7a3392b883c34a679d74286018e6

    GitHub-Pull-Request: golang/sys#124
    ---
    M windows/syscall_windows.go
    M windows/syscall_windows_test.go
    M windows/zsyscall_windows.go
    3 files changed, 108 insertions(+), 0 deletions(-)

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 5

    Fumin A (Gerrit)

    unread,
    Jul 17, 2022, 10:07:22 PM7/17/22
    to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Alex Brainman, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman, Dan Kortschak.

    View Change

    5 comments:

    • Patchset:

      • Patch Set #3:

        I don't understand why try-bots are failing. Perhaps you are using old commit that had bug in it. […]

        Done

    • Patchset:

      • Patch Set #5:

        Thanks for the review, I have pulled this branch from the current tip and addressed the issues raised.

    • File windows/syscall_windows.go:

      • Patch Set #1, Line 1775: Pointer

        Since this field is set by users in Go, as opposed to by Windows, should it not be pinned to avoid b […]

        Done

    • File windows/syscall_windows.go:

    • File windows/syscall_windows_test.go:

      • Is it possible to test other infos[0]. […]

        Yes, I'd love to, but I am afraid based on my understanding, it's hard to do it in a clean and automated way.

        For my use case, I specifically wanted to trigger a locked page while allocating a large `[]byte` in Go. In practice, I had to reconfigure my machine following the steps in https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/enable-the-lock-pages-in-memory-option-windows?view=sql-server-ver16 .
        I am not sure if this is possible in Go's continuous integration setup?
        Furthermore, even after reconfiguration, what I got on my machine was sometimes my page would get the `Locked` flag, and sometimes it would get the `LargePage` flag! Whether I got `Locked` or `LargePage` seems to depend on the load on my machine, with the probability of `LargePage` higher when my machine is idle.
        Also, it seems that on my machine of 24GB RAM, the size of the `[]byte` needs to exceed 16GB in order to trigger `LargePage`.

        As for the `Node` flag, it seems to be only supported on special NUMA machines, such as Itanium, which I am not sure is present in Go's CI fleet.

        All in all, I am afraid turning the other flags on is beyond my expertise, but would be happy to help if someone could provide me with further guidance.

    To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
    Gerrit-Change-Number: 402494
    Gerrit-PatchSet: 5
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Austin Clements <aus...@google.com>
    Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-CC: Dan Kortschak <d...@kortschak.io>
    Gerrit-CC: Fumin A <awaw...@gmail.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
    Gerrit-Comment-Date: Mon, 18 Jul 2022 02:07:16 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Fumin A <awaw...@gmail.com>
    Comment-In-Reply-To: Alex Brainman <alex.b...@gmail.com>

    Alex Brainman (Gerrit)

    unread,
    Jul 19, 2022, 4:12:55 AM7/19/22
    to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

    Attention is currently required from: Dan Kortschak.

    Patch set 5:Run-TryBot +1

    View Change

      To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sys
      Gerrit-Branch: master
      Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
      Gerrit-Change-Number: 402494
      Gerrit-PatchSet: 5
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-CC: Austin Clements <aus...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Dan Kortschak <d...@kortschak.io>
      Gerrit-CC: Fumin A <awaw...@gmail.com>
      Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
      Gerrit-Comment-Date: Tue, 19 Jul 2022 08:12:48 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      Gerrit-MessageType: comment

      Alex Brainman (Gerrit)

      unread,
      Jul 19, 2022, 4:27:44 AM7/19/22
      to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

      Attention is currently required from: Dan Kortschak, Fumin A.

      View Change

      2 comments:

      • Patchset:

        • Patch Set #5:

          Thanks for making changes as requested.

          Your change LGTM. But I would like for Austin to confirm that we use correct type for PSAPI_WORKING_SET_EX_INFORMATION.VirtualAddress. When confirmed I will submit.

          Feel free to ping me here, if nothing happens.

          Alex

      • File windows/syscall_windows_test.go:

        • Yes, I'd love to, but I am afraid based on my understanding, it's hard to do it in a clean and autom […]

          Thanks for explaining what you tried. I don't have any suggestions on how to improve your test too.

          It is OK to leave your test as is.

          It is my job to ask these questions. :-)

      To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sys
      Gerrit-Branch: master
      Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
      Gerrit-Change-Number: 402494
      Gerrit-PatchSet: 5
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-CC: Austin Clements <aus...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Dan Kortschak <d...@kortschak.io>
      Gerrit-CC: Fumin A <awaw...@gmail.com>
      Gerrit-Attention: Fumin A <awaw...@gmail.com>
      Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
      Gerrit-Comment-Date: Tue, 19 Jul 2022 08:27:39 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Fumin A <awaw...@gmail.com>
      Comment-In-Reply-To: Alex Brainman <alex.b...@gmail.com>
      Gerrit-MessageType: comment

      Fumin A (Gerrit)

      unread,
      Jul 19, 2022, 5:40:51 AM7/19/22
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Gopher Robot, Alex Brainman, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

      Attention is currently required from: Alex Brainman, Dan Kortschak.

      View Change

      4 comments:

      • Patchset:

        • Patch Set #1:

          I intend to follow your suggestion in simplifying this change. […]

          Done

        • Patch Set #1:

          Thanks for the elaboration, I am close to having a complete understanding of the new proposal. […]

          Done

      • Patchset:

        • Patch Set #5:

          Thanks Alex for your review, I look forward to Austin's advice on the `Pointer` question.

      • File windows/syscall_windows_test.go:

        • Thanks for explaining what you tried. I don't have any suggestions on how to improve your test too. […]

          Thank you Alex for your generosity with your time and experience.
          I am glad that this change hopefully upholds the extremely high standards of Go's codebase, of which I am a lucky and grateful beneficiary.

      To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sys
      Gerrit-Branch: master
      Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
      Gerrit-Change-Number: 402494
      Gerrit-PatchSet: 5
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-CC: Austin Clements <aus...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Dan Kortschak <d...@kortschak.io>
      Gerrit-CC: Fumin A <awaw...@gmail.com>
      Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
      Gerrit-Comment-Date: Tue, 19 Jul 2022 09:40:46 +0000

      Alex Brainman (Gerrit)

      unread,
      Jul 24, 2022, 12:01:44 AM7/24/22
      to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Gopher Robot, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

      Attention is currently required from: Austin Clements, Dan Kortschak, Fumin A.

      View Change

      2 comments:

      • File windows/syscall_windows.go:

        • Patch Set #3, Line 1762: VirtualAddress Pointer

          Austin, can you, please, confirm that VirtualAddress should be Pointer here, and not uintptr. […]

          Sorry to bother you Ian.

          Perhaps you can also confirm if we should use windows.Pointer or unintptr for PSAPI_WORKING_SET_EX_INFORMATION.VirtualAddress field.

          According to your statement https://github.com/golang/go/issues/21376#issuecomment-380097296 we should use windows.Pointer here. Is that still correct?

          Also, please, +1 this CL because I will need to find 2 +1s from Googlers anyway to submit the CL.

          Thank you.

      • File windows/syscall_windows_test.go:

        • Thank you Alex for your generosity with your time and experience.


        • I am glad that this change hopefully upholds the extremely high standards of Go's codebase, of which I am a lucky and grateful beneficiary.

      To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sys
      Gerrit-Branch: master
      Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
      Gerrit-Change-Number: 402494
      Gerrit-PatchSet: 5
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-CC: Austin Clements <aus...@google.com>
      Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-CC: Dan Kortschak <d...@kortschak.io>
      Gerrit-CC: Fumin A <awaw...@gmail.com>
      Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
      Gerrit-Attention: Fumin A <awaw...@gmail.com>
      Gerrit-Attention: Austin Clements <aus...@google.com>
      Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
      Gerrit-Comment-Date: Sun, 24 Jul 2022 04:01:38 +0000

      Than McIntosh (Gerrit)

      unread,
      Jul 28, 2022, 4:48:11 AM7/28/22
      to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Gopher Robot, Alex Brainman, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

      Attention is currently required from: Austin Clements, Dan Kortschak, Fumin A.

      Patch set 5:Code-Review +1

      View Change

        To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: sys
        Gerrit-Branch: master
        Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
        Gerrit-Change-Number: 402494
        Gerrit-PatchSet: 5
        Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
        Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Than McIntosh <th...@google.com>
        Gerrit-CC: Austin Clements <aus...@google.com>
        Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-CC: Dan Kortschak <d...@kortschak.io>
        Gerrit-CC: Fumin A <awaw...@gmail.com>
        Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Attention: Fumin A <awaw...@gmail.com>
        Gerrit-Attention: Austin Clements <aus...@google.com>
        Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
        Gerrit-Comment-Date: Thu, 28 Jul 2022 08:48:04 +0000

        Dmitri Shuralyov (Gerrit)

        unread,
        Jul 28, 2022, 8:47:03 AM7/28/22
        to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Dmitri Shuralyov, Than McIntosh, Ian Lance Taylor, Gopher Robot, Alex Brainman, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

        Attention is currently required from: Austin Clements, Dan Kortschak, Fumin A.

        View Change

        1 comment:

        • File windows/syscall_windows.go:

          • Patch Set #5, Line 1715: // If this bit is 1, the subsequent members are valid; otherwise they should be ignored.

            The Valid method is exported, and should follow Go documentation style as suggested at https://go.dev/doc/comment#func. A convention is to begin the comment with the identifier name, so these should be like "// Valid reports whether ...", "// Win32Protection returns the memory protection attributes of ...".

        To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: sys
        Gerrit-Branch: master
        Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
        Gerrit-Change-Number: 402494
        Gerrit-PatchSet: 5
        Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
        Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Than McIntosh <th...@google.com>
        Gerrit-CC: Austin Clements <aus...@google.com>
        Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-CC: Dan Kortschak <d...@kortschak.io>
        Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
        Gerrit-CC: Fumin A <awaw...@gmail.com>
        Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Attention: Fumin A <awaw...@gmail.com>
        Gerrit-Attention: Austin Clements <aus...@google.com>
        Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
        Gerrit-Comment-Date: Thu, 28 Jul 2022 12:46:58 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Gerrit-MessageType: comment

        Dmitri Shuralyov (Gerrit)

        unread,
        Jul 28, 2022, 8:47:32 AM7/28/22
        to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Dmitri Shuralyov, Than McIntosh, Ian Lance Taylor, Gopher Robot, Alex Brainman, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

        Attention is currently required from: Austin Clements, Dan Kortschak, Fumin A.

        Patch set 5:Code-Review +1

        View Change

          To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: sys
          Gerrit-Branch: master
          Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
          Gerrit-Change-Number: 402494
          Gerrit-PatchSet: 5
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
          Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
          Gerrit-Reviewer: Gopher Robot <go...@golang.org>
          Gerrit-Reviewer: Than McIntosh <th...@google.com>
          Gerrit-CC: Austin Clements <aus...@google.com>
          Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
          Gerrit-CC: Dan Kortschak <d...@kortschak.io>
          Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
          Gerrit-CC: Fumin A <awaw...@gmail.com>
          Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Attention: Fumin A <awaw...@gmail.com>
          Gerrit-Attention: Austin Clements <aus...@google.com>
          Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
          Gerrit-Comment-Date: Thu, 28 Jul 2022 12:47:28 +0000

          Keith Randall (Gerrit)

          unread,
          Jul 28, 2022, 12:50:15 PM7/28/22
          to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Dmitri Shuralyov, Dmitri Shuralyov, Than McIntosh, Ian Lance Taylor, Gopher Robot, Alex Brainman, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

          Attention is currently required from: Alex Brainman, Austin Clements, Dan Kortschak, Fumin A.

          View Change

          1 comment:

          • File windows/syscall_windows.go:

            • Patch Set #3, Line 1762: VirtualAddress Pointer

              Sorry to bother you Ian. […]

              I suspect it doesn't really matter. This API is kind of strange in that it isn't reading or writing from that pointer - it's just querying the page mapping at that address. There's no worry that the Go object it is pointing to may be moved or GC'd or anything like that.

              Other APIs that do this kind of thing use pointers, not uintptrs, e.g. x/sys/unix.Madvise (it take a []byte to refer to a page, but slice internals use pointers. It would be nice to use []byte here as well to be consistent, but I don't think that is possible.)

              So I would stick with Pointer.

          To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: sys
          Gerrit-Branch: master
          Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
          Gerrit-Change-Number: 402494
          Gerrit-PatchSet: 5
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
          Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
          Gerrit-Reviewer: Gopher Robot <go...@golang.org>
          Gerrit-Reviewer: Than McIntosh <th...@google.com>
          Gerrit-CC: Austin Clements <aus...@google.com>
          Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
          Gerrit-CC: Dan Kortschak <d...@kortschak.io>
          Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
          Gerrit-CC: Fumin A <awaw...@gmail.com>
          Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
          Gerrit-CC: Keith Randall <k...@golang.org>
          Gerrit-Attention: Fumin A <awaw...@gmail.com>
          Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
          Gerrit-Attention: Austin Clements <aus...@google.com>
          Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
          Gerrit-Comment-Date: Thu, 28 Jul 2022 16:50:11 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No

          Gerrit Bot (Gerrit)

          unread,
          Jul 28, 2022, 9:46:38 PM7/28/22
          to Fumin A, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

          Attention is currently required from: Alex Brainman, Austin Clements, Dan Kortschak, Fumin A.

          Gerrit Bot uploaded patch set #6 to this change.

          View Change

          The following approvals got outdated and were removed: Run-TryBot+1 by Alex Brainman, TryBot-Result+1 by Gopher Robot

          windows: add QueryWorkingSetEx

          This change adds the QueryWorkingSetEx function for inspecting
          the virtual memory details of pointers.

          https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-queryworkingsetex

          Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
          GitHub-Last-Rev: c5ac00435245c4d6b83003949dd06014b52e59e0

          GitHub-Pull-Request: golang/sys#124
          ---
          M windows/syscall_windows.go
          M windows/syscall_windows_test.go
          M windows/zsyscall_windows.go
          3 files changed, 113 insertions(+), 0 deletions(-)

          To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: sys
          Gerrit-Branch: master
          Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
          Gerrit-Change-Number: 402494
          Gerrit-PatchSet: 6
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
          Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
          Gerrit-Reviewer: Gopher Robot <go...@golang.org>
          Gerrit-Reviewer: Than McIntosh <th...@google.com>
          Gerrit-CC: Austin Clements <aus...@google.com>
          Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
          Gerrit-CC: Dan Kortschak <d...@kortschak.io>
          Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
          Gerrit-CC: Fumin A <awaw...@gmail.com>
          Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
          Gerrit-CC: Keith Randall <k...@golang.org>
          Gerrit-Attention: Fumin A <awaw...@gmail.com>
          Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
          Gerrit-Attention: Austin Clements <aus...@google.com>
          Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
          Gerrit-MessageType: newpatchset

          Fumin A (Gerrit)

          unread,
          Jul 28, 2022, 9:48:15 PM7/28/22
          to Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Dmitri Shuralyov, Dmitri Shuralyov, Than McIntosh, Ian Lance Taylor, Gopher Robot, Alex Brainman, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

          Attention is currently required from: Alex Brainman, Austin Clements, Dan Kortschak, Dmitri Shuralyov.

          View Change

          1 comment:

          • File windows/syscall_windows.go:

            • Patch Set #5, Line 1715: // If this bit is 1, the subsequent members are valid; otherwise they should be ignored.

              The Valid method is exported, and should follow Go documentation style as suggested at https://go. […]

              Done

          To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: sys
          Gerrit-Branch: master
          Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
          Gerrit-Change-Number: 402494
          Gerrit-PatchSet: 6
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
          Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
          Gerrit-Reviewer: Gopher Robot <go...@golang.org>
          Gerrit-Reviewer: Than McIntosh <th...@google.com>
          Gerrit-CC: Austin Clements <aus...@google.com>
          Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
          Gerrit-CC: Dan Kortschak <d...@kortschak.io>
          Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
          Gerrit-CC: Fumin A <awaw...@gmail.com>
          Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
          Gerrit-CC: Keith Randall <k...@golang.org>
          Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
          Gerrit-Attention: Austin Clements <aus...@google.com>
          Gerrit-Attention: Dmitri Shuralyov <dmit...@golang.org>
          Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
          Gerrit-Comment-Date: Fri, 29 Jul 2022 01:48:10 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          Comment-In-Reply-To: Dmitri Shuralyov <dmit...@golang.org>
          Gerrit-MessageType: comment

          Alex Brainman (Gerrit)

          unread,
          Jul 30, 2022, 5:58:26 AM7/30/22
          to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Dmitri Shuralyov, Dmitri Shuralyov, Than McIntosh, Ian Lance Taylor, Gopher Robot, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

          Attention is currently required from: Austin Clements, Dan Kortschak, Dmitri Shuralyov, Keith Randall.

          Patch set 6:Run-TryBot +1Code-Review +2

          View Change

          2 comments:

          • Patchset:

            • Patch Set #6:

              Thank you Dmitri and Keith for your comments.

              LGTM once try-bots are happy.

              Alex

          • File windows/syscall_windows.go:

            • I suspect it doesn't really matter. […]

              Ack.

          To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: sys
          Gerrit-Branch: master
          Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
          Gerrit-Change-Number: 402494
          Gerrit-PatchSet: 6
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
          Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
          Gerrit-Reviewer: Gopher Robot <go...@golang.org>
          Gerrit-Reviewer: Than McIntosh <th...@google.com>
          Gerrit-CC: Austin Clements <aus...@google.com>
          Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
          Gerrit-CC: Dan Kortschak <d...@kortschak.io>
          Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
          Gerrit-CC: Fumin A <awaw...@gmail.com>
          Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
          Gerrit-CC: Keith Randall <k...@golang.org>
          Gerrit-Attention: Austin Clements <aus...@google.com>
          Gerrit-Attention: Dmitri Shuralyov <dmit...@golang.org>
          Gerrit-Attention: Keith Randall <k...@golang.org>
          Gerrit-Attention: Dan Kortschak <d...@kortschak.io>
          Gerrit-Comment-Date: Sat, 30 Jul 2022 09:58:20 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: Yes
          Comment-In-Reply-To: Alex Brainman <alex.b...@gmail.com>
          Comment-In-Reply-To: Keith Randall <k...@golang.org>
          Gerrit-MessageType: comment

          Alex Brainman (Gerrit)

          unread,
          Jul 30, 2022, 6:01:37 AM7/30/22
          to Fumin A, Gerrit Bot, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Gopher Robot, Keith Randall, Dmitri Shuralyov, Dmitri Shuralyov, Than McIntosh, Ian Lance Taylor, Austin Clements, Dan Kortschak, Brad Fitzpatrick, golang-co...@googlegroups.com

          Alex Brainman submitted this change.

          View Change


          Approvals: Alex Brainman: Looks good to me, approved; Run TryBots Than McIntosh: Looks good to me, but someone else must approve Dmitri Shuralyov: Looks good to me, but someone else must approve Gopher Robot: TryBots succeeded
          windows: add QueryWorkingSetEx

          This change adds the QueryWorkingSetEx function for inspecting
          the virtual memory details of pointers.

          https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-queryworkingsetex

          Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
          GitHub-Last-Rev: c5ac00435245c4d6b83003949dd06014b52e59e0
          GitHub-Pull-Request: golang/sys#124
          Reviewed-on: https://go-review.googlesource.com/c/sys/+/402494
          Run-TryBot: Alex Brainman <alex.b...@gmail.com>
          TryBot-Result: Gopher Robot <go...@golang.org>
          Reviewed-by: Than McIntosh <th...@google.com>
          Reviewed-by: Alex Brainman <alex.b...@gmail.com>
          Reviewed-by: Dmitri Shuralyov <dmit...@google.com>

          ---
          M windows/syscall_windows.go
          M windows/syscall_windows_test.go
          M windows/zsyscall_windows.go
          3 files changed, 119 insertions(+), 0 deletions(-)

          diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
          index be3ec2b..d180a65 100644
          --- a/windows/syscall_windows.go
          +++ b/windows/syscall_windows.go
          @@ -417,6 +417,7 @@
          //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
          @@ -1707,3 +1708,71 @@
          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
          +}
          diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go
          index dcebb2c..997396a 100644
          --- a/windows/syscall_windows_test.go
          +++ b/windows/syscall_windows_test.go
          @@ -777,6 +777,25 @@
          }
          }

          +func TestQueryWorkingSetEx(t *testing.T) {
          + var a int
          +
          + process := windows.CurrentProcess()
          + information := windows.PSAPI_WORKING_SET_EX_INFORMATION{
          + VirtualAddress: windows.Pointer(unsafe.Pointer(&a)),
          + }
          + infos := []windows.PSAPI_WORKING_SET_EX_INFORMATION{information}
          +
          + cb := uint32(uintptr(len(infos)) * unsafe.Sizeof(infos[0]))
          + if err := windows.QueryWorkingSetEx(process, uintptr(unsafe.Pointer(&infos[0])), cb); err != nil {
          + t.Fatalf("%+v", err)
          + }
          +
          + if !infos[0].VirtualAttributes.Valid() {
          + t.Errorf("memory location not valid")
          + }
          +}
          +
          func TestReadWriteProcessMemory(t *testing.T) {
          testBuffer := []byte{0xBA, 0xAD, 0xF0, 0x0D}

          diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go
          index 678262c..52d4742 100644
          --- a/windows/zsyscall_windows.go
          +++ b/windows/zsyscall_windows.go
          @@ -408,6 +408,7 @@
          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")
          @@ -3504,6 +3505,14 @@
          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 {

          To view, visit change 402494. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: sys
          Gerrit-Branch: master
          Gerrit-Change-Id: I2bc92bb0b65d34ed1caf88e4d368d64946dfcc5c
          Gerrit-Change-Number: 402494
          Gerrit-PatchSet: 7
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
          Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
          Gerrit-Reviewer: Gopher Robot <go...@golang.org>
          Gerrit-Reviewer: Than McIntosh <th...@google.com>
          Gerrit-CC: Austin Clements <aus...@google.com>
          Gerrit-CC: Brad Fitzpatrick <brad...@golang.org>
          Gerrit-CC: Dan Kortschak <d...@kortschak.io>
          Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
          Gerrit-CC: Fumin A <awaw...@gmail.com>
          Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
          Gerrit-CC: Keith Randall <k...@golang.org>
          Gerrit-MessageType: merged
          Reply all
          Reply to author
          Forward
          0 new messages