2004-06-22 06:37:04 +08:00
|
|
|
#ifndef SIGAR_OS_H
|
|
|
|
#define SIGAR_OS_H
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winreg.h>
|
|
|
|
#include <winperf.h>
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2004-06-22 14:12:51 +08:00
|
|
|
#include <tlhelp32.h>
|
2004-06-22 06:37:04 +08:00
|
|
|
|
|
|
|
#define INT64_C(val) val##i64
|
|
|
|
|
|
|
|
/* see apr/include/arch/win32/atime.h */
|
|
|
|
#define EPOCH_DELTA INT64_C(11644473600000000)
|
|
|
|
|
2004-08-03 10:45:26 +08:00
|
|
|
#define SIGAR_CMDLINE_MAX (MAX_PATH * 3)
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
static __inline sigar_uint64_t FileTimeToTime(FILETIME *ft)
|
|
|
|
{
|
|
|
|
sigar_uint64_t time;
|
|
|
|
time = ft->dwHighDateTime;
|
|
|
|
time = time << 32;
|
|
|
|
time |= ft->dwLowDateTime;
|
|
|
|
time /= 10;
|
|
|
|
time -= EPOCH_DELTA;
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: support CP_UTF8 ? */
|
|
|
|
|
|
|
|
#define SIGAR_A2W(lpa, lpw, bytes) \
|
|
|
|
(lpw[0] = 0, MultiByteToWideChar(CP_ACP, 0, \
|
|
|
|
lpa, -1, lpw, (bytes/sizeof(WCHAR))))
|
|
|
|
|
|
|
|
#define SIGAR_W2A(lpw, lpa, chars) \
|
|
|
|
(lpa[0] = '\0', WideCharToMultiByte(CP_ACP, 0, \
|
|
|
|
lpw, -1, (LPSTR)lpa, chars, \
|
|
|
|
NULL, NULL))
|
|
|
|
|
|
|
|
#include <iprtrmib.h>
|
|
|
|
|
|
|
|
/* undocumented structures */
|
|
|
|
typedef struct {
|
|
|
|
DWORD dwState;
|
|
|
|
DWORD dwLocalAddr;
|
|
|
|
DWORD dwLocalPort;
|
|
|
|
DWORD dwRemoteAddr;
|
|
|
|
DWORD dwRemotePort;
|
|
|
|
DWORD dwProcessId;
|
|
|
|
} MIB_TCPEXROW, *PMIB_TCPEXROW;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DWORD dwNumEntries;
|
|
|
|
MIB_TCPEXROW table[ANY_SIZE];
|
|
|
|
} MIB_TCPEXTABLE, *PMIB_TCPEXTABLE;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DWORD dwLocalAddr;
|
|
|
|
DWORD dwLocalPort;
|
|
|
|
DWORD dwProcessId;
|
|
|
|
} MIB_UDPEXROW, *PMIB_UDPEXROW;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DWORD dwNumEntries;
|
|
|
|
MIB_UDPEXROW table[ANY_SIZE];
|
|
|
|
} MIB_UDPEXTABLE, *PMIB_UDPEXTABLE;
|
|
|
|
|
|
|
|
/* end undocumented structures */
|
|
|
|
|
|
|
|
typedef DWORD (CALLBACK *LPGETIPFORWARDTABLE)(PMIB_IPFORWARDTABLE, PULONG, BOOL);
|
|
|
|
|
|
|
|
typedef DWORD (CALLBACK *LPGETIFTABLE)(PMIB_IFTABLE, PULONG, BOOL);
|
|
|
|
|
|
|
|
typedef DWORD (CALLBACK *LPGETTCPTABLE)(PMIB_TCPTABLE, PDWORD, BOOL);
|
|
|
|
|
|
|
|
typedef DWORD (CALLBACK *LPGETUDPTABLE)(PMIB_UDPTABLE, PDWORD, BOOL);
|
|
|
|
|
|
|
|
typedef DWORD (CALLBACK *LPGETTCPEXTABLE)(PMIB_TCPEXTABLE *, BOOL, HANDLE,
|
|
|
|
DWORD, DWORD);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
sigar_pid_t pid;
|
|
|
|
int ppid;
|
|
|
|
int priority;
|
|
|
|
time_t mtime;
|
|
|
|
sigar_uint64_t vsize;
|
|
|
|
sigar_uint64_t size;
|
|
|
|
char name[SIGAR_PROC_NAME_LEN];
|
|
|
|
char state;
|
|
|
|
sigar_uint64_t handles;
|
|
|
|
} sigar_win32_pinfo_t;
|
|
|
|
|
|
|
|
struct sigar_t {
|
|
|
|
SIGAR_T_BASE;
|
|
|
|
char *machine;
|
|
|
|
int using_wide;
|
|
|
|
long pagesize;
|
|
|
|
HKEY handle;
|
|
|
|
char *perfbuf;
|
|
|
|
DWORD perfbuf_size;
|
|
|
|
HINSTANCE ip_handle;
|
|
|
|
LPGETIFTABLE get_if_table;
|
|
|
|
LPGETIPFORWARDTABLE get_ipforward_table;
|
|
|
|
LPGETTCPTABLE get_tcp_table;
|
|
|
|
LPGETTCPEXTABLE get_tcpx_table;
|
|
|
|
LPGETUDPTABLE get_udp_table;
|
|
|
|
sigar_win32_pinfo_t pinfo;
|
|
|
|
WORD ws_version;
|
|
|
|
int ws_error;
|
|
|
|
LPBYTE peb; //scratch pad for getting peb info
|
|
|
|
int ht_enabled;
|
2004-06-23 03:22:50 +08:00
|
|
|
int lcpu; //number of logical cpus
|
2004-06-23 01:15:10 +08:00
|
|
|
int winnt;
|
2004-06-22 06:37:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int sigar_wsa_init(sigar_t *sigar);
|
|
|
|
|
2004-08-02 04:31:42 +08:00
|
|
|
int sigar_proc_exe_peb_get(sigar_t *sigar, HANDLE proc,
|
|
|
|
sigar_proc_exe_t *procexe);
|
2004-06-22 06:37:04 +08:00
|
|
|
|
2004-08-03 11:06:25 +08:00
|
|
|
int sigar_proc_args_peb_get(sigar_t *sigar, HANDLE proc,
|
|
|
|
sigar_proc_args_t *procargs);
|
2004-07-29 05:47:14 +08:00
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
unsigned int sigar_cpu_count(sigar_t *sigar);
|
|
|
|
|
|
|
|
int sigar_cpu_info_get(sigar_t *sigar, sigar_cpu_info_t *info);
|
|
|
|
|
|
|
|
#endif /* SIGAR_OS_H */
|