sigar 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/README +2 -0
  2. data/Rakefile +105 -0
  3. data/bindings/SigarBuild.pm +310 -0
  4. data/bindings/SigarWrapper.pm +2978 -0
  5. data/bindings/ruby/examples/arp.rb +24 -0
  6. data/bindings/ruby/examples/cpu_info.rb +35 -0
  7. data/bindings/ruby/examples/df.rb +49 -0
  8. data/bindings/ruby/examples/free.rb +36 -0
  9. data/bindings/ruby/examples/ifconfig.rb +101 -0
  10. data/bindings/ruby/examples/logging.rb +58 -0
  11. data/bindings/ruby/examples/net_info.rb +31 -0
  12. data/bindings/ruby/examples/netstat.rb +71 -0
  13. data/bindings/ruby/examples/pargs.rb +35 -0
  14. data/bindings/ruby/examples/penv.rb +31 -0
  15. data/bindings/ruby/examples/route.rb +48 -0
  16. data/bindings/ruby/examples/version.rb +40 -0
  17. data/bindings/ruby/examples/who.rb +30 -0
  18. data/bindings/ruby/extconf.rb +128 -0
  19. data/bindings/ruby/rbsigar.c +888 -0
  20. data/bindings/ruby/test/cpu_test.rb +40 -0
  21. data/bindings/ruby/test/file_system_test.rb +43 -0
  22. data/bindings/ruby/test/helper.rb +57 -0
  23. data/bindings/ruby/test/loadavg_test.rb +30 -0
  24. data/bindings/ruby/test/mem_test.rb +45 -0
  25. data/bindings/ruby/test/swap_test.rb +36 -0
  26. data/bindings/ruby/test/uptime_test.rb +26 -0
  27. data/include/sigar.h +939 -0
  28. data/include/sigar_fileinfo.h +157 -0
  29. data/include/sigar_format.h +65 -0
  30. data/include/sigar_getline.h +18 -0
  31. data/include/sigar_log.h +80 -0
  32. data/include/sigar_private.h +422 -0
  33. data/include/sigar_ptql.h +53 -0
  34. data/include/sigar_util.h +191 -0
  35. data/src/os/aix/aix_sigar.c +2151 -0
  36. data/src/os/aix/sigar_os.h +73 -0
  37. data/src/os/darwin/Info.plist.in +27 -0
  38. data/src/os/darwin/darwin_sigar.c +3709 -0
  39. data/src/os/darwin/sigar_os.h +80 -0
  40. data/src/os/hpux/hpux_sigar.c +1342 -0
  41. data/src/os/hpux/sigar_os.h +49 -0
  42. data/src/os/linux/linux_sigar.c +2782 -0
  43. data/src/os/linux/sigar_os.h +82 -0
  44. data/src/os/solaris/get_mib2.c +321 -0
  45. data/src/os/solaris/get_mib2.h +127 -0
  46. data/src/os/solaris/kstats.c +181 -0
  47. data/src/os/solaris/procfs.c +97 -0
  48. data/src/os/solaris/sigar_os.h +224 -0
  49. data/src/os/solaris/solaris_sigar.c +2717 -0
  50. data/src/os/win32/peb.c +212 -0
  51. data/src/os/win32/sigar.rc.in +40 -0
  52. data/src/os/win32/sigar_os.h +653 -0
  53. data/src/os/win32/sigar_pdh.h +47 -0
  54. data/src/os/win32/win32_sigar.c +3911 -0
  55. data/src/sigar.c +2428 -0
  56. data/src/sigar_cache.c +179 -0
  57. data/src/sigar_fileinfo.c +815 -0
  58. data/src/sigar_format.c +696 -0
  59. data/src/sigar_getline.c +1849 -0
  60. data/src/sigar_ptql.c +1967 -0
  61. data/src/sigar_signal.c +216 -0
  62. data/src/sigar_util.c +1060 -0
  63. data/src/sigar_version.c.in +22 -0
  64. data/src/sigar_version_autoconf.c.in +22 -0
  65. data/version.properties +11 -0
  66. metadata +131 -0
@@ -0,0 +1,212 @@
1
+ /*
2
+ * Copyright (c) 2004, 2006-2008 Hyperic, Inc.
3
+ * Copyright (c) 2009 SpringSource, Inc.
4
+ * Copyright (c) 2009 VMware, Inc.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ /*
20
+ * functions for getting info from the Process Environment Block
21
+ */
22
+ #define UNICODE
23
+ #define _UNICODE
24
+
25
+ #include "sigar.h"
26
+ #include "sigar_private.h"
27
+ #include "sigar_os.h"
28
+ #include <shellapi.h>
29
+
30
+ void dllmod_init_ntdll(sigar_t *sigar);
31
+
32
+ #define sigar_NtQueryInformationProcess \
33
+ sigar->ntdll.query_proc_info.func
34
+
35
+ static int sigar_pbi_get(sigar_t *sigar, HANDLE proc, PEB *peb)
36
+ {
37
+ int status;
38
+ PROCESS_BASIC_INFORMATION pbi;
39
+ DWORD size=sizeof(pbi);
40
+
41
+ dllmod_init_ntdll(sigar);
42
+
43
+ if (!sigar_NtQueryInformationProcess) {
44
+ return SIGAR_ENOTIMPL;
45
+ }
46
+
47
+ SIGAR_ZERO(&pbi);
48
+ status =
49
+ sigar_NtQueryInformationProcess(proc,
50
+ ProcessBasicInformation,
51
+ &pbi,
52
+ size, NULL);
53
+ if (status != ERROR_SUCCESS) {
54
+ return status;
55
+ }
56
+
57
+ if (!pbi.PebBaseAddress) {
58
+ /* likely we are 32-bit, pid process is 64-bit */
59
+ return ERROR_DATATYPE_MISMATCH;
60
+ }
61
+
62
+ size = sizeof(*peb);
63
+
64
+ if (ReadProcessMemory(proc, pbi.PebBaseAddress, peb, size, NULL)) {
65
+ return SIGAR_OK;
66
+ }
67
+ else {
68
+ return GetLastError();
69
+ }
70
+ }
71
+
72
+ static int sigar_rtl_get(sigar_t *sigar, HANDLE proc,
73
+ RTL_USER_PROCESS_PARAMETERS *rtl)
74
+ {
75
+ PEB peb;
76
+ int status = sigar_pbi_get(sigar, proc, &peb);
77
+ DWORD size=sizeof(*rtl);
78
+
79
+ if (status != SIGAR_OK) {
80
+ return status;
81
+ }
82
+
83
+ if (ReadProcessMemory(proc, peb.ProcessParameters, rtl, size, NULL)) {
84
+ return SIGAR_OK;
85
+ }
86
+ else {
87
+ return GetLastError();
88
+ }
89
+ }
90
+
91
+ #define rtl_bufsize(buf, uc) \
92
+ ((sizeof(buf) < uc.Length) ? sizeof(buf) : uc.Length)
93
+
94
+ int sigar_proc_exe_peb_get(sigar_t *sigar, HANDLE proc,
95
+ sigar_proc_exe_t *procexe)
96
+ {
97
+ int status;
98
+ WCHAR buf[MAX_PATH+1];
99
+ RTL_USER_PROCESS_PARAMETERS rtl;
100
+ DWORD size;
101
+
102
+ procexe->name[0] = '\0';
103
+ procexe->cwd[0] = '\0';
104
+
105
+ if ((status = sigar_rtl_get(sigar, proc, &rtl)) != SIGAR_OK) {
106
+ return status;
107
+ }
108
+
109
+ size = rtl_bufsize(buf, rtl.ImagePathName);
110
+ memset(buf, '\0', sizeof(buf));
111
+
112
+ if ((size > 0) &&
113
+ ReadProcessMemory(proc, rtl.ImagePathName.Buffer, buf, size, NULL))
114
+ {
115
+ SIGAR_W2A(buf, procexe->name, sizeof(procexe->name));
116
+ }
117
+
118
+ size = rtl_bufsize(buf, rtl.CurrentDirectoryName);
119
+ memset(buf, '\0', sizeof(buf));
120
+
121
+ if ((size > 0) &&
122
+ ReadProcessMemory(proc, rtl.CurrentDirectoryName.Buffer, buf, size, NULL))
123
+ {
124
+ SIGAR_W2A(buf, procexe->cwd, sizeof(procexe->cwd));
125
+ }
126
+
127
+ return SIGAR_OK;
128
+ }
129
+
130
+ int sigar_parse_proc_args(sigar_t *sigar, WCHAR *buf,
131
+ sigar_proc_args_t *procargs)
132
+ {
133
+ char arg[SIGAR_CMDLINE_MAX];
134
+ LPWSTR *args;
135
+ int num, i;
136
+
137
+ if (!buf) {
138
+ buf = GetCommandLine();
139
+ }
140
+
141
+ args = CommandLineToArgvW(buf, &num);
142
+
143
+ if (args == NULL) {
144
+ return SIGAR_OK;
145
+ }
146
+
147
+ for (i=0; i<num; i++) {
148
+ SIGAR_W2A(args[i], arg, SIGAR_CMDLINE_MAX);
149
+ SIGAR_PROC_ARGS_GROW(procargs);
150
+ procargs->data[procargs->number++] = sigar_strdup(arg);
151
+ }
152
+
153
+ GlobalFree(args);
154
+
155
+ return SIGAR_OK;
156
+ }
157
+
158
+ int sigar_proc_args_peb_get(sigar_t *sigar, HANDLE proc,
159
+ sigar_proc_args_t *procargs)
160
+ {
161
+ int status;
162
+ WCHAR buf[SIGAR_CMDLINE_MAX];
163
+ RTL_USER_PROCESS_PARAMETERS rtl;
164
+ DWORD size;
165
+
166
+ if ((status = sigar_rtl_get(sigar, proc, &rtl)) != SIGAR_OK) {
167
+ return status;
168
+ }
169
+
170
+ size = rtl_bufsize(buf, rtl.CommandLine);
171
+ if (size <= 0) {
172
+ return ERROR_DATATYPE_MISMATCH; /* fallback to wmi */
173
+ }
174
+ memset(buf, '\0', sizeof(buf));
175
+
176
+ if (ReadProcessMemory(proc, rtl.CommandLine.Buffer, buf, size, NULL)) {
177
+ return sigar_parse_proc_args(sigar, buf, procargs);
178
+ }
179
+ else {
180
+ return GetLastError();
181
+ }
182
+ }
183
+
184
+ int sigar_proc_env_peb_get(sigar_t *sigar, HANDLE proc,
185
+ WCHAR *buf, DWORD size)
186
+ {
187
+ int status;
188
+ RTL_USER_PROCESS_PARAMETERS rtl;
189
+ MEMORY_BASIC_INFORMATION info;
190
+
191
+ if ((status = sigar_rtl_get(sigar, proc, &rtl)) != SIGAR_OK) {
192
+ return status;
193
+ }
194
+
195
+ memset(buf, '\0', size);
196
+ /* -2 to ensure \0\0 terminator */
197
+ size -= 2;
198
+
199
+ if (VirtualQueryEx(proc, rtl.Environment, &info, sizeof(info))) {
200
+ if (size > info.RegionSize) {
201
+ /* ReadProcessMemory beyond region would fail */
202
+ size = info.RegionSize;
203
+ }
204
+ }
205
+
206
+ if (ReadProcessMemory(proc, rtl.Environment, buf, size, NULL)) {
207
+ return SIGAR_OK;
208
+ }
209
+ else {
210
+ return GetLastError();
211
+ }
212
+ }
@@ -0,0 +1,40 @@
1
+ #define SIGAR_VERSION_CSV \
2
+ @@VERSION_MAJOR@@,@@VERSION_MINOR@@,@@VERSION_MAINT@@,@@VERSION_BUILD@@
3
+ #define SIGAR_VERSION_STR \
4
+ "@@VERSION_MAJOR@@.@@VERSION_MINOR@@.@@VERSION_MAINT@@.@@VERSION_BUILD@@"
5
+
6
+ #define SIGAR_ARCHLIB "@@ARCHLIB@@"
7
+
8
+ 1 VERSIONINFO
9
+ FILEVERSION SIGAR_VERSION_CSV
10
+ PRODUCTVERSION SIGAR_VERSION_CSV
11
+ FILEFLAGSMASK 0x3fL
12
+ FILEFLAGS 0x00L
13
+ #if defined(WINNT) || defined(WIN64)
14
+ FILEOS 0x40004L
15
+ #else
16
+ FILEOS 0x4L
17
+ #endif
18
+ FILETYPE 0x2L
19
+ FILESUBTYPE 0x0L
20
+ BEGIN
21
+ BLOCK "StringFileInfo"
22
+ BEGIN
23
+ BLOCK "040904b0"
24
+ BEGIN
25
+ VALUE "Comments", "http://sigar.hyperic.com/\0"
26
+ VALUE "CompanyName", "Hyperic, Inc.\0"
27
+ VALUE "FileDescription", "System Information Gatherer And Reporter DLL\0"
28
+ VALUE "FileVersion", SIGAR_VERSION_STR "\0"
29
+ VALUE "InternalName", "sigar.dll\0"
30
+ VALUE "LegalCopyright", "Copyright [@@COPYRIGHT_YEAR@@], Hyperic, Inc.\0"
31
+ VALUE "OriginalFilename", SIGAR_ARCHLIB "\0"
32
+ VALUE "ProductName", "Hyperic SIGAR\0"
33
+ VALUE "ProductVersion", SIGAR_VERSION_STR "\0"
34
+ END
35
+ END
36
+ BLOCK "VarFileInfo"
37
+ BEGIN
38
+ VALUE "Translation", 0x409, 1200
39
+ END
40
+ END
@@ -0,0 +1,653 @@
1
+ /*
2
+ * Copyright (c) 2004-2009 Hyperic, Inc.
3
+ * Copyright (c) 2009 SpringSource, Inc.
4
+ * Copyright (c) 2009-2010 VMware, Inc.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #ifndef SIGAR_OS_H
20
+ #define SIGAR_OS_H
21
+
22
+ #if _MSC_VER <= 1200
23
+ #define SIGAR_USING_MSC6 /* Visual Studio version 6 */
24
+ #endif
25
+
26
+ #define WIN32_LEAN_AND_MEAN
27
+ #include <windows.h>
28
+ #include <winreg.h>
29
+ #include <winperf.h>
30
+ #include <winsock2.h>
31
+ #include <ws2tcpip.h>
32
+ #include <stddef.h>
33
+ #include <sys/types.h>
34
+ #include <malloc.h>
35
+ #include <stdio.h>
36
+ #include <errno.h>
37
+ #include <tlhelp32.h>
38
+
39
+ #include "sigar_util.h"
40
+
41
+ #define INT64_C(val) val##i64
42
+
43
+ /* see apr/include/arch/win32/atime.h */
44
+ #define EPOCH_DELTA INT64_C(11644473600000000)
45
+
46
+ #define SIGAR_CMDLINE_MAX 4096
47
+
48
+ /* XXX: support CP_UTF8 ? */
49
+
50
+ #define SIGAR_A2W(lpa, lpw, bytes) \
51
+ (lpw[0] = 0, MultiByteToWideChar(CP_ACP, 0, \
52
+ lpa, -1, lpw, (bytes/sizeof(WCHAR))))
53
+
54
+ #define SIGAR_W2A(lpw, lpa, chars) \
55
+ (lpa[0] = '\0', WideCharToMultiByte(CP_ACP, 0, \
56
+ lpw, -1, (LPSTR)lpa, chars, \
57
+ NULL, NULL))
58
+
59
+ /* iptypes.h from vc7, not available in vc6 */
60
+ /* copy from PSDK if using vc6 */
61
+ #include "iptypes.h"
62
+
63
+ /* from wtsapi32.h not in vs6.0 */
64
+ typedef enum {
65
+ WTSInitialProgram,
66
+ WTSApplicationName,
67
+ WTSWorkingDirectory,
68
+ WTSOEMId,
69
+ WTSSessionId,
70
+ WTSUserName,
71
+ WTSWinStationName,
72
+ WTSDomainName,
73
+ WTSConnectState,
74
+ WTSClientBuildNumber,
75
+ WTSClientName,
76
+ WTSClientDirectory,
77
+ WTSClientProductId,
78
+ WTSClientHardwareId,
79
+ WTSClientAddress,
80
+ WTSClientDisplay,
81
+ WTSClientProtocolType,
82
+ } WTS_INFO_CLASS;
83
+
84
+ typedef enum _WTS_CONNECTSTATE_CLASS {
85
+ WTSActive,
86
+ WTSConnected,
87
+ WTSConnectQuery,
88
+ WTSShadow,
89
+ WTSDisconnected,
90
+ WTSIdle,
91
+ WTSListen,
92
+ WTSReset,
93
+ WTSDown,
94
+ WTSInit
95
+ } WTS_CONNECTSTATE_CLASS;
96
+
97
+ #define WTS_PROTOCOL_TYPE_CONSOLE 0
98
+ #define WTS_PROTOCOL_TYPE_ICA 1
99
+ #define WTS_PROTOCOL_TYPE_RDP 2
100
+
101
+ typedef struct _WTS_SESSION_INFO {
102
+ DWORD SessionId;
103
+ LPTSTR pWinStationName;
104
+ DWORD State;
105
+ } WTS_SESSION_INFO, *PWTS_SESSION_INFO;
106
+
107
+ typedef struct _WTS_PROCESS_INFO {
108
+ DWORD SessionId;
109
+ DWORD ProcessId;
110
+ LPSTR pProcessName;
111
+ PSID pUserSid;
112
+ } WTS_PROCESS_INFO, *PWTS_PROCESS_INFO;
113
+
114
+ typedef struct _WTS_CLIENT_ADDRESS {
115
+ DWORD AddressFamily;
116
+ BYTE Address[20];
117
+ } WTS_CLIENT_ADDRESS, *PWTS_CLIENT_ADDRESS;
118
+
119
+ /* the WINSTATION_INFO stuff here is undocumented
120
+ * got the howto from google groups:
121
+ * http://redirx.com/?31gy
122
+ */
123
+ typedef enum _WINSTATION_INFO_CLASS {
124
+ WinStationInformation = 8
125
+ } WINSTATION_INFO_CLASS;
126
+
127
+ typedef struct _WINSTATION_INFO {
128
+ BYTE Reserved1[72];
129
+ ULONG SessionId;
130
+ BYTE Reserved2[4];
131
+ FILETIME ConnectTime;
132
+ FILETIME DisconnectTime;
133
+ FILETIME LastInputTime;
134
+ FILETIME LoginTime;
135
+ BYTE Reserved3[1096];
136
+ FILETIME CurrentTime;
137
+ } WINSTATION_INFO, *PWINSTATION_INFO;
138
+
139
+ /* end wtsapi32.h */
140
+
141
+ #ifdef SIGAR_USING_MSC6
142
+
143
+ /* from winbase.h not in vs6.0 */
144
+ typedef struct {
145
+ DWORD dwLength;
146
+ DWORD dwMemoryLoad;
147
+ DWORDLONG ullTotalPhys;
148
+ DWORDLONG ullAvailPhys;
149
+ DWORDLONG ullTotalPageFile;
150
+ DWORDLONG ullAvailPageFile;
151
+ DWORDLONG ullTotalVirtual;
152
+ DWORDLONG ullAvailVirtual;
153
+ DWORDLONG ullAvailExtendedVirtual;
154
+ } MEMORYSTATUSEX;
155
+
156
+ /* service manager stuff not in vs6.0 */
157
+ typedef struct _SERVICE_STATUS_PROCESS {
158
+ DWORD dwServiceType;
159
+ DWORD dwCurrentState;
160
+ DWORD dwControlsAccepted;
161
+ DWORD dwWin32ExitCode;
162
+ DWORD dwServiceSpecificExitCode;
163
+ DWORD dwCheckPoint;
164
+ DWORD dwWaitHint;
165
+ DWORD dwProcessId;
166
+ DWORD dwServiceFlags;
167
+ } SERVICE_STATUS_PROCESS;
168
+
169
+ typedef enum {
170
+ SC_STATUS_PROCESS_INFO = 0
171
+ } SC_STATUS_TYPE;
172
+
173
+ #ifndef ERROR_DATATYPE_MISMATCH
174
+ #define ERROR_DATATYPE_MISMATCH 1629L
175
+ #endif
176
+
177
+ #endif /* _MSC_VER */
178
+
179
+ #include <iprtrmib.h>
180
+
181
+ /* undocumented structures */
182
+ typedef struct {
183
+ DWORD dwState;
184
+ DWORD dwLocalAddr;
185
+ DWORD dwLocalPort;
186
+ DWORD dwRemoteAddr;
187
+ DWORD dwRemotePort;
188
+ DWORD dwProcessId;
189
+ } MIB_TCPEXROW, *PMIB_TCPEXROW;
190
+
191
+ typedef struct {
192
+ DWORD dwNumEntries;
193
+ MIB_TCPEXROW table[ANY_SIZE];
194
+ } MIB_TCPEXTABLE, *PMIB_TCPEXTABLE;
195
+
196
+ typedef struct {
197
+ DWORD dwLocalAddr;
198
+ DWORD dwLocalPort;
199
+ DWORD dwProcessId;
200
+ } MIB_UDPEXROW, *PMIB_UDPEXROW;
201
+
202
+ typedef struct {
203
+ DWORD dwNumEntries;
204
+ MIB_UDPEXROW table[ANY_SIZE];
205
+ } MIB_UDPEXTABLE, *PMIB_UDPEXTABLE;
206
+
207
+ /* end undocumented structures */
208
+
209
+ /* no longer in the standard header files */
210
+ typedef struct {
211
+ LARGE_INTEGER IdleTime;
212
+ LARGE_INTEGER KernelTime;
213
+ LARGE_INTEGER UserTime;
214
+ LARGE_INTEGER DpcTime;
215
+ LARGE_INTEGER InterruptTime;
216
+ ULONG InterruptCount;
217
+ } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
218
+
219
+ #define SystemProcessorPerformanceInformation 8
220
+
221
+ /* PEB decls from msdn docs w/ slight mods */
222
+ #define ProcessBasicInformation 0
223
+
224
+ typedef struct _UNICODE_STRING {
225
+ USHORT Length;
226
+ USHORT MaximumLength;
227
+ PWSTR Buffer;
228
+ } UNICODE_STRING, *PUNICODE_STRING;
229
+
230
+ typedef struct _PEB_LDR_DATA {
231
+ BYTE Reserved1[8];
232
+ PVOID Reserved2[3];
233
+ LIST_ENTRY InMemoryOrderModuleList;
234
+ } PEB_LDR_DATA, *PPEB_LDR_DATA;
235
+
236
+ typedef struct RTL_DRIVE_LETTER_CURDIR {
237
+ USHORT Flags;
238
+ USHORT Length;
239
+ ULONG TimeStamp;
240
+ UNICODE_STRING DosPath;
241
+ } RTL_DRIVE_LETTER_CURDIR, *PRTL_DRIVE_LETTER_CURDIR;
242
+
243
+ /* from: http://source.winehq.org/source/include/winternl.h */
244
+ typedef struct _RTL_USER_PROCESS_PARAMETERS {
245
+ ULONG AllocationSize;
246
+ ULONG Size;
247
+ ULONG Flags;
248
+ ULONG DebugFlags;
249
+ HANDLE hConsole;
250
+ ULONG ProcessGroup;
251
+ HANDLE hStdInput;
252
+ HANDLE hStdOutput;
253
+ HANDLE hStdError;
254
+ UNICODE_STRING CurrentDirectoryName;
255
+ HANDLE CurrentDirectoryHandle;
256
+ UNICODE_STRING DllPath;
257
+ UNICODE_STRING ImagePathName;
258
+ UNICODE_STRING CommandLine;
259
+ PWSTR Environment;
260
+ ULONG dwX;
261
+ ULONG dwY;
262
+ ULONG dwXSize;
263
+ ULONG dwYSize;
264
+ ULONG dwXCountChars;
265
+ ULONG dwYCountChars;
266
+ ULONG dwFillAttribute;
267
+ ULONG dwFlags;
268
+ ULONG wShowWindow;
269
+ UNICODE_STRING WindowTitle;
270
+ UNICODE_STRING Desktop;
271
+ UNICODE_STRING ShellInfo;
272
+ UNICODE_STRING RuntimeInfo;
273
+ RTL_DRIVE_LETTER_CURDIR DLCurrentDirectory[0x20];
274
+ } RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
275
+
276
+ /* from msdn docs
277
+ typedef struct _RTL_USER_PROCESS_PARAMETERS {
278
+ BYTE Reserved1[16];
279
+ PVOID Reserved2[10];
280
+ UNICODE_STRING ImagePathName;
281
+ UNICODE_STRING CommandLine;
282
+ } RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
283
+ */
284
+
285
+ typedef struct _PEB {
286
+ BYTE Reserved1[2];
287
+ BYTE BeingDebugged;
288
+ BYTE Reserved2[1];
289
+ PVOID Reserved3[2];
290
+ PPEB_LDR_DATA Ldr;
291
+ PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
292
+ BYTE Reserved4[104];
293
+ PVOID Reserved5[52];
294
+ /*PPS_POST_PROCESS_INIT_ROUTINE*/ PVOID PostProcessInitRoutine;
295
+ BYTE Reserved6[128];
296
+ PVOID Reserved7[1];
297
+ ULONG SessionId;
298
+ } PEB, *PPEB;
299
+
300
+ typedef struct _PROCESS_BASIC_INFORMATION {
301
+ PVOID Reserved1;
302
+ PPEB PebBaseAddress;
303
+ PVOID Reserved2[2];
304
+ /*ULONG_PTR*/ UINT_PTR UniqueProcessId;
305
+ PVOID Reserved3;
306
+ } PROCESS_BASIC_INFORMATION;
307
+
308
+ typedef struct {
309
+ sigar_pid_t pid;
310
+ int ppid;
311
+ int priority;
312
+ time_t mtime;
313
+ sigar_uint64_t size;
314
+ sigar_uint64_t resident;
315
+ char name[SIGAR_PROC_NAME_LEN];
316
+ char state;
317
+ sigar_uint64_t handles;
318
+ sigar_uint64_t threads;
319
+ sigar_uint64_t page_faults;
320
+ } sigar_win32_pinfo_t;
321
+
322
+ typedef struct {
323
+ const char *name;
324
+ HINSTANCE handle;
325
+ } sigar_dll_handle_t;
326
+
327
+ typedef struct {
328
+ const char *name;
329
+ FARPROC func;
330
+ } sigar_dll_func_t;
331
+
332
+ typedef struct {
333
+ const char *name;
334
+ HINSTANCE handle;
335
+ sigar_dll_func_t funcs[12];
336
+ } sigar_dll_module_t;
337
+
338
+ /* wtsapi.dll */
339
+ typedef BOOL (CALLBACK *wtsapi_enum_sessions)(HANDLE,
340
+ DWORD,
341
+ DWORD,
342
+ PWTS_SESSION_INFO *,
343
+ DWORD *);
344
+
345
+ typedef void (CALLBACK *wtsapi_free_mem)(PVOID);
346
+
347
+ typedef BOOL (CALLBACK *wtsapi_query_session)(HANDLE,
348
+ DWORD,
349
+ WTS_INFO_CLASS,
350
+ LPSTR *, DWORD *);
351
+ /* iphlpapi.dll */
352
+
353
+ typedef DWORD (CALLBACK *iphlpapi_get_ipforward_table)(PMIB_IPFORWARDTABLE,
354
+ PULONG,
355
+ BOOL);
356
+
357
+ typedef DWORD (CALLBACK *iphlpapi_get_ipaddr_table)(PMIB_IPADDRTABLE,
358
+ PULONG,
359
+ BOOL);
360
+
361
+ typedef DWORD (CALLBACK *iphlpapi_get_if_table)(PMIB_IFTABLE,
362
+ PULONG,
363
+ BOOL);
364
+
365
+ typedef DWORD (CALLBACK *iphlpapi_get_if_entry)(PMIB_IFROW);
366
+
367
+ typedef DWORD (CALLBACK *iphlpapi_get_num_if)(PDWORD);
368
+
369
+ typedef DWORD (CALLBACK *iphlpapi_get_tcp_table)(PMIB_TCPTABLE,
370
+ PDWORD,
371
+ BOOL);
372
+
373
+ typedef DWORD (CALLBACK *iphlpapi_get_udp_table)(PMIB_UDPTABLE,
374
+ PDWORD,
375
+ BOOL);
376
+
377
+ typedef DWORD (CALLBACK *iphlpapi_get_tcpx_table)(PMIB_TCPEXTABLE *,
378
+ BOOL,
379
+ HANDLE,
380
+ DWORD,
381
+ DWORD);
382
+
383
+ typedef DWORD (CALLBACK *iphlpapi_get_udpx_table)(PMIB_UDPEXTABLE *,
384
+ BOOL,
385
+ HANDLE,
386
+ DWORD,
387
+ DWORD);
388
+
389
+ typedef DWORD (CALLBACK *iphlpapi_get_tcp_stats)(PMIB_TCPSTATS);
390
+
391
+ typedef DWORD (CALLBACK *iphlpapi_get_net_params)(PFIXED_INFO,
392
+ PULONG);
393
+
394
+ typedef DWORD (CALLBACK *iphlpapi_get_adapters_info)(PIP_ADAPTER_INFO,
395
+ PULONG);
396
+
397
+ typedef ULONG (CALLBACK *iphlpapi_get_adapters_addrs)(ULONG,
398
+ ULONG,
399
+ PVOID,
400
+ PIP_ADAPTER_ADDRESSES,
401
+ PULONG);
402
+
403
+ /* advapi32.dll */
404
+ typedef BOOL (CALLBACK *advapi_convert_string_sid)(LPCSTR,
405
+ PSID *);
406
+
407
+ typedef BOOL (CALLBACK *advapi_query_service_status)(SC_HANDLE,
408
+ SC_STATUS_TYPE,
409
+ LPBYTE,
410
+ DWORD,
411
+ LPDWORD);
412
+
413
+ typedef DWORD (CALLBACK *iphlpapi_get_ipnet_table)(PMIB_IPNETTABLE,
414
+ PDWORD,
415
+ BOOL);
416
+
417
+ /* ntdll.dll */
418
+ typedef DWORD (CALLBACK *ntdll_query_sys_info)(DWORD,
419
+ PVOID,
420
+ ULONG,
421
+ PULONG);
422
+
423
+ typedef DWORD (CALLBACK *ntdll_query_proc_info)(HANDLE,
424
+ DWORD,
425
+ PVOID,
426
+ ULONG,
427
+ PULONG);
428
+
429
+ /* psapi.dll */
430
+ typedef BOOL (CALLBACK *psapi_enum_modules)(HANDLE,
431
+ HMODULE *,
432
+ DWORD,
433
+ LPDWORD);
434
+
435
+ typedef DWORD (CALLBACK *psapi_get_module_name)(HANDLE,
436
+ HMODULE,
437
+ LPTSTR,
438
+ DWORD);
439
+
440
+ typedef BOOL (CALLBACK *psapi_enum_processes)(DWORD *,
441
+ DWORD,
442
+ DWORD *);
443
+
444
+ /* winsta.dll */
445
+ typedef BOOLEAN (CALLBACK *winsta_query_info)(HANDLE,
446
+ ULONG,
447
+ WINSTATION_INFO_CLASS,
448
+ PVOID,
449
+ ULONG,
450
+ PULONG);
451
+
452
+ /* kernel32.dll */
453
+ typedef BOOL (CALLBACK *kernel_memory_status)(MEMORYSTATUSEX *);
454
+
455
+ /* mpr.dll */
456
+ typedef BOOL (CALLBACK *mpr_get_net_connection)(LPCTSTR,
457
+ LPTSTR,
458
+ LPDWORD);
459
+
460
+ #define SIGAR_DLLFUNC(api, name) \
461
+ struct { \
462
+ const char *name; \
463
+ ##api##_##name func; \
464
+ } ##name
465
+
466
+ typedef struct {
467
+ sigar_dll_handle_t handle;
468
+
469
+ SIGAR_DLLFUNC(wtsapi, enum_sessions);
470
+ SIGAR_DLLFUNC(wtsapi, free_mem);
471
+ SIGAR_DLLFUNC(wtsapi, query_session);
472
+
473
+ sigar_dll_func_t end;
474
+ } sigar_wtsapi_t;
475
+
476
+ typedef struct {
477
+ sigar_dll_handle_t handle;
478
+
479
+ SIGAR_DLLFUNC(iphlpapi, get_ipforward_table);
480
+ SIGAR_DLLFUNC(iphlpapi, get_ipaddr_table);
481
+ SIGAR_DLLFUNC(iphlpapi, get_if_table);
482
+ SIGAR_DLLFUNC(iphlpapi, get_if_entry);
483
+ SIGAR_DLLFUNC(iphlpapi, get_num_if);
484
+ SIGAR_DLLFUNC(iphlpapi, get_tcp_table);
485
+ SIGAR_DLLFUNC(iphlpapi, get_udp_table);
486
+ SIGAR_DLLFUNC(iphlpapi, get_tcpx_table);
487
+ SIGAR_DLLFUNC(iphlpapi, get_udpx_table);
488
+ SIGAR_DLLFUNC(iphlpapi, get_tcp_stats);
489
+ SIGAR_DLLFUNC(iphlpapi, get_net_params);
490
+ SIGAR_DLLFUNC(iphlpapi, get_adapters_info);
491
+ SIGAR_DLLFUNC(iphlpapi, get_adapters_addrs);
492
+ SIGAR_DLLFUNC(iphlpapi, get_ipnet_table);
493
+
494
+ sigar_dll_func_t end;
495
+ } sigar_iphlpapi_t;
496
+
497
+ typedef struct {
498
+ sigar_dll_handle_t handle;
499
+
500
+ SIGAR_DLLFUNC(advapi, convert_string_sid);
501
+ SIGAR_DLLFUNC(advapi, query_service_status);
502
+
503
+ sigar_dll_func_t end;
504
+ } sigar_advapi_t;
505
+
506
+ typedef struct {
507
+ sigar_dll_handle_t handle;
508
+
509
+ SIGAR_DLLFUNC(ntdll, query_sys_info);
510
+ SIGAR_DLLFUNC(ntdll, query_proc_info);
511
+
512
+ sigar_dll_func_t end;
513
+ } sigar_ntdll_t;
514
+
515
+ typedef struct {
516
+ sigar_dll_handle_t handle;
517
+
518
+ SIGAR_DLLFUNC(psapi, enum_modules);
519
+ SIGAR_DLLFUNC(psapi, enum_processes);
520
+ SIGAR_DLLFUNC(psapi, get_module_name);
521
+
522
+ sigar_dll_func_t end;
523
+ } sigar_psapi_t;
524
+
525
+ typedef struct {
526
+ sigar_dll_handle_t handle;
527
+
528
+ SIGAR_DLLFUNC(winsta, query_info);
529
+
530
+ sigar_dll_func_t end;
531
+ } sigar_winsta_t;
532
+
533
+ typedef struct {
534
+ sigar_dll_handle_t handle;
535
+
536
+ SIGAR_DLLFUNC(kernel, memory_status);
537
+
538
+ sigar_dll_func_t end;
539
+ } sigar_kernel_t;
540
+
541
+ typedef struct {
542
+ sigar_dll_handle_t handle;
543
+
544
+ SIGAR_DLLFUNC(mpr, get_net_connection);
545
+
546
+ sigar_dll_func_t end;
547
+ } sigar_mpr_t;
548
+
549
+ struct sigar_t {
550
+ SIGAR_T_BASE;
551
+ char *machine;
552
+ int using_wide;
553
+ long pagesize;
554
+ HKEY handle;
555
+ char *perfbuf;
556
+ DWORD perfbuf_size;
557
+ sigar_wtsapi_t wtsapi;
558
+ sigar_iphlpapi_t iphlpapi;
559
+ sigar_advapi_t advapi;
560
+ sigar_ntdll_t ntdll;
561
+ sigar_psapi_t psapi;
562
+ sigar_winsta_t winsta;
563
+ sigar_kernel_t kernel;
564
+ sigar_mpr_t mpr;
565
+ sigar_win32_pinfo_t pinfo;
566
+ sigar_cache_t *netif_adapters;
567
+ sigar_cache_t *netif_mib_rows;
568
+ sigar_cache_t *netif_addr_rows;
569
+ sigar_cache_t *netif_names; /* dwIndex -> net_interface_config.name */
570
+
571
+ WORD ws_version;
572
+ int ws_error;
573
+ int ht_enabled;
574
+ int lcpu; //number of logical cpus
575
+ int winnt;
576
+ };
577
+
578
+ #ifdef __cplusplus
579
+ extern "C" {
580
+ #endif
581
+
582
+ sigar_uint64_t sigar_FileTimeToTime(FILETIME *ft);
583
+
584
+ int sigar_wsa_init(sigar_t *sigar);
585
+
586
+ int sigar_proc_exe_peb_get(sigar_t *sigar, HANDLE proc,
587
+ sigar_proc_exe_t *procexe);
588
+
589
+ int sigar_proc_args_peb_get(sigar_t *sigar, HANDLE proc,
590
+ sigar_proc_args_t *procargs);
591
+
592
+ int sigar_proc_env_peb_get(sigar_t *sigar, HANDLE proc,
593
+ WCHAR *env, DWORD envlen);
594
+
595
+ int sigar_proc_args_wmi_get(sigar_t *sigar, sigar_pid_t pid,
596
+ sigar_proc_args_t *procargs);
597
+
598
+ int sigar_proc_exe_wmi_get(sigar_t *sigar, sigar_pid_t pid,
599
+ sigar_proc_exe_t *procexe);
600
+
601
+ int sigar_parse_proc_args(sigar_t *sigar, WCHAR *buf,
602
+ sigar_proc_args_t *procargs);
603
+
604
+ int sigar_service_pid_get(sigar_t *sigar, char *name, sigar_pid_t *pid);
605
+
606
+ typedef struct {
607
+ DWORD size;
608
+ DWORD count;
609
+ ENUM_SERVICE_STATUS *services;
610
+ SC_HANDLE handle;
611
+ } sigar_services_status_t;
612
+
613
+ int sigar_services_status_get(sigar_services_status_t *ss, DWORD state);
614
+
615
+ void sigar_services_status_close(sigar_services_status_t *ss);
616
+
617
+ typedef struct sigar_services_walker_t sigar_services_walker_t;
618
+
619
+ struct sigar_services_walker_t {
620
+ sigar_t *sigar;
621
+ int flags;
622
+ void *data; /* user data */
623
+ int (*add_service)(sigar_services_walker_t *walker, char *name);
624
+ };
625
+
626
+ int sigar_services_query(char *ptql,
627
+ sigar_ptql_error_t *error,
628
+ sigar_services_walker_t *walker);
629
+
630
+ char *sigar_service_exe_get(char *path, char *buffer, int basename);
631
+
632
+ typedef struct {
633
+ WORD product_major;
634
+ WORD product_minor;
635
+ WORD product_build;
636
+ WORD product_revision;
637
+ WORD file_major;
638
+ WORD file_minor;
639
+ WORD file_build;
640
+ WORD file_revision;
641
+ } sigar_file_version_t;
642
+
643
+ int sigar_file_version_get(sigar_file_version_t *version,
644
+ char *name,
645
+ sigar_proc_env_t *infocb);
646
+
647
+ #ifdef __cplusplus
648
+ }
649
+ #endif
650
+
651
+ #define SIGAR_NO_SUCH_PROCESS (SIGAR_OS_START_ERROR+1)
652
+
653
+ #endif /* SIGAR_OS_H */