|
28 | 28 |
|
29 | 29 | import com.sun.jna.platform.win32.WinDef.DWORD;
|
30 | 30 | import com.sun.jna.platform.win32.WinNT.HANDLE;
|
| 31 | +import com.sun.jna.platform.win32.Psapi.PSAPI_WORKING_SET_EX_BLOCK; |
31 | 32 | import com.sun.jna.ptr.IntByReference;
|
32 | 33 |
|
33 | 34 | /**
|
@@ -87,4 +88,79 @@ public static String GetProcessImageFileName(HANDLE hProcess) {
|
87 | 88 | }
|
88 | 89 | }
|
89 | 90 | }
|
| 91 | + |
| 92 | + @Override |
| 93 | + public void read() { |
| 94 | + super.read(); |
| 95 | + innerValue = this.Data[0].longValue(); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * If this bit is 1, the other values in the PSAPI_WORKING_SET_EX_BLOCK are valid. |
| 100 | + */ |
| 101 | + public static boolean isPsapiWorkingSetExBlockValid(PSAPI_WORKING_SET_EX_BLOCK psapiWorkingSetExBlock) { |
| 102 | + return PsapiUtil.getBitFieldValue(psapiWorkingSetExBlock.Data[0].longValue(), 1, 0) == 1; |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * The number of processes that share the page addressed by the PSAPI_WORKING_SET_EX_BLOCK. The maximum value of this member is 7. |
| 107 | + */ |
| 108 | + public static int getPsapiWorkingSetExBlockShareCount(PSAPI_WORKING_SET_EX_BLOCK psapiWorkingSetExBlock) { |
| 109 | + return PsapiUtil.getBitFieldValue(psapiWorkingSetExBlock.Data[0].longValue(), 3, 1); |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * The memory protection attributes of the page addressed by the PSAPI_WORKING_SET_EX_BLOCK. For a list of values see below. |
| 114 | + * @see <a href="https://docs.microsoft.com/en-us/windows/desktop/Memory/memory-protection-constants">Memory Protection Constants</a>. |
| 115 | + */ |
| 116 | + public static int getPsapiWorkingSetExBlockWin32Protection(PSAPI_WORKING_SET_EX_BLOCK psapiWorkingSetExBlock) { |
| 117 | + return PsapiUtil.getBitFieldValue(psapiWorkingSetExBlock.Data[0].longValue(),11, 3 + 1); |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * If this bit is 1, the page addressed by the PSAPI_WORKING_SET_EX_BLOCK can be shared. |
| 122 | + */ |
| 123 | + public static boolean isPsapiWorkingSetExBlockShared(PSAPI_WORKING_SET_EX_BLOCK psapiWorkingSetExBlock) { |
| 124 | + return PsapiUtil.getBitFieldValue(psapiWorkingSetExBlock.Data[0].longValue(), 1, 11 + 3 + 1) == 1; |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * The NUMA node of the page addressed by the PSAPI_WORKING_SET_EX_BLOCK. The maximum value of this member is 63. |
| 129 | + */ |
| 130 | + public static int getPsapiWorkingSetExBlockNode(PSAPI_WORKING_SET_EX_BLOCK psapiWorkingSetExBlock) { |
| 131 | + return PsapiUtil.getBitFieldValue(psapiWorkingSetExBlock.Data[0].longValue(), 6, 1 + 11 + 3 + 1); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * If this bit is 1, the virtual page addressed by the PSAPI_WORKING_SET_EX_BLOCK is locked in physical memory. |
| 136 | + */ |
| 137 | + public static boolean isPsapiWorkingSetExBlockLocked(PSAPI_WORKING_SET_EX_BLOCK psapiWorkingSetExBlock) { |
| 138 | + return PsapiUtil.getBitFieldValue(psapiWorkingSetExBlock.Data[0].longValue(), 1, 6 + 1 + 11 + 3 + 1) == 1; |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * If this bit is 1, the page addressed by the PSAPI_WORKING_SET_EX_BLOCK is a large page. |
| 143 | + */ |
| 144 | + public static boolean isPsapiWorkingSetExBlockLargePage(PSAPI_WORKING_SET_EX_BLOCK psapiWorkingSetExBlock) { |
| 145 | + return PsapiUtil.getBitFieldValue(psapiWorkingSetExBlock.Data[0].longValue(),1, 1 + 6 + 1 + 11 + 3 + 1) == 1; |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * If this bit is 1, the page addressed by the PSAPI_WORKING_SET_EX_BLOCK is has been reported as bad. |
| 150 | + */ |
| 151 | + public static boolean isPsapiWorkingSetExBlockBad(PSAPI_WORKING_SET_EX_BLOCK psapiWorkingSetExBlock) { |
| 152 | + return PsapiUtil.getBitFieldValue(psapiWorkingSetExBlock.Data[0].longValue(), 1,1 + 1 + 1 + 6 + 1 + 11 + 3 + 1) == 1; |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * Returns a Right Shifted and Masked version of value. |
| 157 | + */ |
| 158 | + public static int getBitFieldValue(final int value, final int maskLength, final int rightShiftAmount) { |
| 159 | + long bitMask = 0; |
| 160 | + |
| 161 | + for (int l = 0; l < maskLength; l++) { |
| 162 | + bitMask |= 1 << l; |
| 163 | + } |
| 164 | + return (int) ((value >>> rightShiftAmount) & bitMask); |
| 165 | + } |
90 | 166 | }
|
0 commit comments