diff options
author | Christopher Faylor <me@cgf.cx> | 2002-05-28 05:55:40 +0400 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2002-05-28 05:55:40 +0400 |
commit | 2402700d07f5592d66b7b78823ce9b9aa698801d (patch) | |
tree | f90880bca367b97356a05e7d6b4a8bc721cb3465 /winsup/cygwin/fhandler_process.cc | |
parent | 74b2f73ea42e22f5d69fd23dd2440130b1564814 (diff) |
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro.
(LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for
nonexistent function.
(NtQueryObject): Declare.
(IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not
available.
* debug.h (being_debugged): Just rely on IsDebuggerPresent return value.
* dtable.cc (handle_to_fn): New function.
(dtable::init_std_file_from_handle): Attempt to derive std handle's name via
handle_to_fn.
(dtable::build_fhandler_from_name): Fill in what we can in path_conv structure
when given a handle and path doesn't exist.
* fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use
pc->exists () to determine if file exists rather than calling GetFileAttributes
again.
* fhandler.h (fhandler_base::exec_state_isknown): New method.
(fhandler_base::fstat_helper): Add extra arguments to declaration.
(fhandler_base::fstat_by_handle): Declare new method.
(fhandler_base::fstat_by_name): Declare new method.
* fhandler_disk_file (num_entries): Make __stdcall.
(fhandler_base::fstat_by_handle): Define new method.
(fhandler_base::fstat_by_name): Define new method.
(fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate.
(fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat
structure. Move handle or name specific stuff to new methods above.
(fhandler_disk_file::open): Use real_path->exists rather than calling
GetFileAttributes again.
* ntdll.h (FILE_NAME_INFORMATION): Define new structure.
(OBJECT_INFORMATION_CLASS): Partially define new enum.
(OBJECT_NAME_INFORMATION): Define new structure.
(NtQueryInformationFile): New declaration.
(NtQueryObject): New declaration.
* path.cc (path_conv::fillin): Define new method.
* path.h (path_conv::fillin): Declare new method.
(path_conv::drive_thpe): Rename from 'get_drive_type'.
(path_conv::volser): Declare new method.
(path_conv::volname): Declare new method.
(path_conv::root_dir): Declare new method.
* syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
Diffstat (limited to 'winsup/cygwin/fhandler_process.cc')
-rw-r--r-- | winsup/cygwin/fhandler_process.cc | 546 |
1 files changed, 273 insertions, 273 deletions
diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc index 0ad729499..a7d968d4f 100644 --- a/winsup/cygwin/fhandler_process.cc +++ b/winsup/cygwin/fhandler_process.cc @@ -68,7 +68,7 @@ static off_t format_process_status (_pinfo *p, char *destbuf, size_t maxsize); static off_t format_process_statm (_pinfo *p, char *destbuf, size_t maxsize); static int get_process_state (DWORD dwProcessId); static bool get_mem_values(DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss, unsigned long *vmtext, - unsigned long *vmdata, unsigned long *vmlib, unsigned long *vmshare); + unsigned long *vmdata, unsigned long *vmlib, unsigned long *vmshare); /* Returns 0 if path doesn't exist, >0 if path is a directory, * <0 if path is a file. @@ -110,10 +110,10 @@ fhandler_process::fstat (struct __stat64 *buf, path_conv *pc) p = pids[i]; if (!proc_exists (p)) - continue; + continue; if (p->pid == pid) - goto found; + goto found; } set_errno(ENOENT); return -1; @@ -152,7 +152,7 @@ fhandler_process::readdir (DIR * dir) return NULL; strcpy (dir->__d_dirent->d_name, process_listing[dir->__d_position++]); syscall_printf ("%p = readdir (%p) (%s)", &dir->__d_dirent, dir, - dir->__d_dirent->d_name); + dir->__d_dirent->d_name); return dir->__d_dirent; } @@ -176,45 +176,45 @@ fhandler_process::open (path_conv *pc, int flags, mode_t mode) if (*path == 0) { if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) - { - set_errno (EEXIST); - res = 0; - goto out; - } + { + set_errno (EEXIST); + res = 0; + goto out; + } else if (flags & O_WRONLY) - { - set_errno (EISDIR); - res = 0; - goto out; - } + { + set_errno (EISDIR); + res = 0; + goto out; + } else - { - flags |= O_DIROPEN; - goto success; - } + { + flags |= O_DIROPEN; + goto success; + } } process_file_no = -1; for (int i = 0; process_listing[i]; i++) { if (path_prefix_p - (process_listing[i], path + 1, strlen (process_listing[i]))) - process_file_no = i; + (process_listing[i], path + 1, strlen (process_listing[i]))) + process_file_no = i; } if (process_file_no == -1) { if (flags & O_CREAT) - { - set_errno (EROFS); - res = 0; - goto out; - } + { + set_errno (EROFS); + res = 0; + goto out; + } else - { - set_errno (ENOENT); - res = 0; - goto out; - } + { + set_errno (ENOENT); + res = 0; + goto out; + } } if (flags & O_WRONLY) { @@ -227,10 +227,10 @@ fhandler_process::open (path_conv *pc, int flags, mode_t mode) p = pids[i]; if (!proc_exists (p)) - continue; + continue; if (p->pid == pid) - goto found; + goto found; } set_errno (ENOENT); res = 0; @@ -262,7 +262,7 @@ fhandler_process::fill_filebuf () if (!proc_exists (saved_p) || saved_p->pid != saved_pid) { if (filebuf) - cfree(filebuf); + cfree(filebuf); filesize = 0; bufalloc = (size_t) -1; } switch (fileid) @@ -274,95 +274,95 @@ fhandler_process::fill_filebuf () case PROCESS_CTTY: case PROCESS_PPID: { - if (!filebuf) - filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 40); - int num; - switch (fileid) - { - case PROCESS_PPID: - num = saved_p->ppid; - break; - case PROCESS_UID: - num = saved_p->uid; - break; - case PROCESS_PGID: - num = saved_p->pgid; - break; - case PROCESS_SID: - num = saved_p->sid; - break; - case PROCESS_GID: - num = saved_p->gid; - break; - case PROCESS_CTTY: - num = saved_p->ctty; - break; - default: // what's this here for? - num = 0; - break; - } - __small_sprintf (filebuf, "%d\n", num); - filesize = strlen (filebuf); - break; + if (!filebuf) + filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 40); + int num; + switch (fileid) + { + case PROCESS_PPID: + num = saved_p->ppid; + break; + case PROCESS_UID: + num = saved_p->uid; + break; + case PROCESS_PGID: + num = saved_p->pgid; + break; + case PROCESS_SID: + num = saved_p->sid; + break; + case PROCESS_GID: + num = saved_p->gid; + break; + case PROCESS_CTTY: + num = saved_p->ctty; + break; + default: // what's this here for? + num = 0; + break; + } + __small_sprintf (filebuf, "%d\n", num); + filesize = strlen (filebuf); + break; } case PROCESS_EXENAME: { - if (!filebuf) - filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = MAX_PATH); - if (saved_p->process_state & (PID_ZOMBIE | PID_EXITED)) - strcpy (filebuf, "<defunct>"); - else - { - mount_table->conv_to_posix_path (saved_p->progname, filebuf, 1); - int len = strlen (filebuf); - if (len > 4) - { - char *s = filebuf + len - 4; - if (strcasecmp (s, ".exe") == 0) - *s = 0; - } - } - filesize = strlen (filebuf); - break; + if (!filebuf) + filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = MAX_PATH); + if (saved_p->process_state & (PID_ZOMBIE | PID_EXITED)) + strcpy (filebuf, "<defunct>"); + else + { + mount_table->conv_to_posix_path (saved_p->progname, filebuf, 1); + int len = strlen (filebuf); + if (len > 4) + { + char *s = filebuf + len - 4; + if (strcasecmp (s, ".exe") == 0) + *s = 0; + } + } + filesize = strlen (filebuf); + break; } case PROCESS_WINPID: { - if (!filebuf) - filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 40); - __small_sprintf (filebuf, "%d\n", saved_p->dwProcessId); - filesize = strlen (filebuf); - break; + if (!filebuf) + filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 40); + __small_sprintf (filebuf, "%d\n", saved_p->dwProcessId); + filesize = strlen (filebuf); + break; } case PROCESS_WINEXENAME: { - int len = strlen (saved_p->progname); - if (!filebuf) - filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = (len + 2)); - strcpy (filebuf, saved_p->progname); - filebuf[len] = '\n'; - filesize = len + 1; - break; + int len = strlen (saved_p->progname); + if (!filebuf) + filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = (len + 2)); + strcpy (filebuf, saved_p->progname); + filebuf[len] = '\n'; + filesize = len + 1; + break; } case PROCESS_STATUS: { - if (!filebuf) - filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048); - filesize = format_process_status (saved_p, filebuf, bufalloc); - break; + if (!filebuf) + filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048); + filesize = format_process_status (saved_p, filebuf, bufalloc); + break; } case PROCESS_STAT: { - if (!filebuf) - filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048); - filesize = format_process_stat (saved_p, filebuf, bufalloc); - break; + if (!filebuf) + filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048); + filesize = format_process_stat (saved_p, filebuf, bufalloc); + break; } case PROCESS_STATM: { - if (!filebuf) - filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048); - filesize = format_process_statm (saved_p, filebuf, bufalloc); - break; + if (!filebuf) + filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 2048); + filesize = format_process_statm (saved_p, filebuf, bufalloc); + break; } } } @@ -374,9 +374,9 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize) char cmd[MAX_PATH]; int state = 'R'; unsigned long fault_count = 0UL, - utime = 0UL, stime = 0UL, - start_time = 0UL, - vmsize = 0UL, vmrss = 0UL, vmmaxrss = 0UL; + utime = 0UL, stime = 0UL, + start_time = 0UL, + vmsize = 0UL, vmrss = 0UL, vmmaxrss = 0UL; int priority = 0; if (p->process_state & (PID_ZOMBIE | PID_EXITED)) strcpy (cmd, "<defunct"); @@ -385,14 +385,14 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize) strcpy(cmd, p->progname); char *last_slash = strrchr (cmd, '\\'); if (last_slash != NULL) - strcpy (cmd, last_slash + 1); + strcpy (cmd, last_slash + 1); int len = strlen (cmd); if (len > 4) - { - char *s = cmd + len - 4; - if (strcasecmp (s, ".exe") == 0) - *s = 0; - } + { + char *s = cmd + len - 4; + if (strcasecmp (s, ".exe") == 0) + *s = 0; + } } /* * Note: under Windows, a _process_ is always running - it's only _threads_ @@ -415,71 +415,71 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize) SYSTEM_TIME_OF_DAY_INFORMATION stodi; SYSTEM_PROCESSOR_TIMES spt; hProcess = OpenProcess (PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, - FALSE, p->dwProcessId); + FALSE, p->dwProcessId); if (hProcess != NULL) - { - ret = ZwQueryInformationProcess (hProcess, - ProcessVmCounters, - (PVOID) &vmc, - sizeof vmc, NULL); - if (ret == STATUS_SUCCESS) - ret = ZwQueryInformationProcess (hProcess, - ProcessTimes, - (PVOID) &put, - sizeof put, NULL); - if (ret == STATUS_SUCCESS) - ret = ZwQueryInformationProcess (hProcess, - ProcessBasicInformation, - (PVOID) &pbi, - sizeof pbi, NULL); - if (ret == STATUS_SUCCESS) - ret = ZwQueryInformationProcess (hProcess, - ProcessQuotaLimits, - (PVOID) &ql, - sizeof ql, NULL); - CloseHandle (hProcess); - } + { + ret = ZwQueryInformationProcess (hProcess, + ProcessVmCounters, + (PVOID) &vmc, + sizeof vmc, NULL); + if (ret == STATUS_SUCCESS) + ret = ZwQueryInformationProcess (hProcess, + ProcessTimes, + (PVOID) &put, + sizeof put, NULL); + if (ret == STATUS_SUCCESS) + ret = ZwQueryInformationProcess (hProcess, + ProcessBasicInformation, + (PVOID) &pbi, + sizeof pbi, NULL); + if (ret == STATUS_SUCCESS) + ret = ZwQueryInformationProcess (hProcess, + ProcessQuotaLimits, + (PVOID) &ql, + sizeof ql, NULL); + CloseHandle (hProcess); + } else - { - DWORD error = GetLastError (); - __seterrno_from_win_error (error); - debug_printf("OpenProcess: ret = %d", - error); - return 0; - } + { + DWORD error = GetLastError (); + __seterrno_from_win_error (error); + debug_printf("OpenProcess: ret = %d", + error); + return 0; + } if (ret == STATUS_SUCCESS) - ret = ZwQuerySystemInformation (SystemTimeOfDayInformation, - (PVOID) &stodi, - sizeof stodi, NULL); + ret = ZwQuerySystemInformation (SystemTimeOfDayInformation, + (PVOID) &stodi, + sizeof stodi, NULL); if (ret == STATUS_SUCCESS) - ret = ZwQuerySystemInformation (SystemProcessorTimes, - (PVOID) &spt, - sizeof spt, NULL); + ret = ZwQuerySystemInformation (SystemProcessorTimes, + (PVOID) &spt, + sizeof spt, NULL); if (ret != STATUS_SUCCESS) - { - __seterrno_from_win_error (RtlNtStatusToDosError (ret)); - debug_printf("NtQueryInformationProcess: ret = %d, " - "Dos(ret) = %d", - ret, RtlNtStatusToDosError (ret)); - return 0; - } + { + __seterrno_from_win_error (RtlNtStatusToDosError (ret)); + debug_printf("NtQueryInformationProcess: ret = %d, " + "Dos(ret) = %d", + ret, RtlNtStatusToDosError (ret)); + return 0; + } fault_count = vmc.PageFaultCount; utime = put.UserTime.QuadPart / 100000ULL; stime = put.KernelTime.QuadPart / 100000ULL; if (stodi.CurrentTime.QuadPart > put.CreateTime.QuadPart) - start_time = (spt.InterruptTime.QuadPart + spt.KernelTime.QuadPart + - spt.IdleTime.QuadPart + spt.UserTime.QuadPart + - spt.DpcTime.QuadPart - stodi.CurrentTime.QuadPart + - put.CreateTime.QuadPart) / 100000ULL; + start_time = (spt.InterruptTime.QuadPart + spt.KernelTime.QuadPart + + spt.IdleTime.QuadPart + spt.UserTime.QuadPart + + spt.DpcTime.QuadPart - stodi.CurrentTime.QuadPart + + put.CreateTime.QuadPart) / 100000ULL; else - /* - * sometimes stodi.CurrentTime is a bit behind - * Note: some older versions of procps are broken and can't cope - * with process start times > time(NULL). - */ - start_time = (spt.InterruptTime.QuadPart + spt.KernelTime.QuadPart + - spt.IdleTime.QuadPart + spt.UserTime.QuadPart + - spt.DpcTime.QuadPart) / 100000ULL; + /* + * sometimes stodi.CurrentTime is a bit behind + * Note: some older versions of procps are broken and can't cope + * with process start times > time(NULL). + */ + start_time = (spt.InterruptTime.QuadPart + spt.KernelTime.QuadPart + + spt.IdleTime.QuadPart + spt.UserTime.QuadPart + + spt.DpcTime.QuadPart) / 100000ULL; priority = pbi.BasePriority; unsigned page_size = getpagesize(); vmsize = vmc.VirtualSize; @@ -491,20 +491,20 @@ format_process_stat (_pinfo *p, char *destbuf, size_t maxsize) start_time = (GetTickCount() / 1000 - time(NULL) + p->start_time) * 100; } return __small_sprintf (destbuf, "%d (%s) %c " - "%d %d %d %d %d " - "%lu %lu %lu %lu %lu %lu %lu " - "%ld %ld %ld %ld %ld %ld " - "%lu %lu " - "%ld " - "%lu", - p->pid, cmd, - state, - p->ppid, p->pgid, p->sid, p->ctty, -1, - 0, fault_count, fault_count, 0, 0, utime, stime, - utime, stime, priority, 0, 0, 0, - start_time, vmsize, - vmrss, vmmaxrss - ); + "%d %d %d %d %d " + "%lu %lu %lu %lu %lu %lu %lu " + "%ld %ld %ld %ld %ld %ld " + "%lu %lu " + "%ld " + "%lu", + p->pid, cmd, + state, + p->ppid, p->pgid, p->sid, p->ctty, -1, + 0, fault_count, fault_count, 0, 0, utime, stime, + utime, stime, priority, 0, 0, 0, + start_time, vmsize, + vmrss, vmmaxrss + ); } static @@ -515,7 +515,7 @@ format_process_status (_pinfo *p, char *destbuf, size_t maxsize) int state = 'R'; const char *state_str = "unknown"; unsigned long vmsize = 0UL, vmrss = 0UL, vmdata = 0UL, vmlib = 0UL, vmtext = 0UL, - vmshare = 0UL; + vmshare = 0UL; if (p->process_state & (PID_ZOMBIE | PID_EXITED)) strcpy (cmd, "<defunct>"); else @@ -523,14 +523,14 @@ format_process_status (_pinfo *p, char *destbuf, size_t maxsize) strcpy(cmd, p->progname); char *last_slash = strrchr (cmd, '\\'); if (last_slash != NULL) - strcpy (cmd, last_slash + 1); + strcpy (cmd, last_slash + 1); int len = strlen (cmd); if (len > 4) - { - char *s = cmd + len - 4; - if (strcasecmp (s, ".exe") == 0) - *s = 0; - } + { + char *s = cmd + len - 4; + if (strcasecmp (s, ".exe") == 0) + *s = 0; + } } /* * Note: under Windows, a _process_ is always running - it's only _threads_ @@ -564,38 +564,38 @@ format_process_status (_pinfo *p, char *destbuf, size_t maxsize) if (wincap.is_winnt ()) { if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata, &vmlib, &vmshare)) - return 0; + return 0; unsigned page_size = getpagesize(); vmsize *= page_size; vmrss *= page_size; vmdata *= page_size; vmtext *= page_size; vmlib *= page_size; } return __small_sprintf (destbuf, "Name: %s\n" - "State: %c (%s)\n" - "Tgid: %d\n" - "Pid: %d\n" - "PPid: %d\n" - "Uid: %d %d %d %d\n" - "Gid: %d %d %d %d\n" - "VmSize: %8d kB\n" - "VmLck: %8d kB\n" - "VmRSS: %8d kB\n" - "VmData: %8d kB\n" - "VmStk: %8d kB\n" - "VmExe: %8d kB\n" - "VmLib: %8d kB\n" - "SigPnd: %016x\n" - "SigBlk: %016x\n" - "SigIgn: %016x\n", - cmd, - state, state_str, - p->pgid, - p->pid, - p->ppid, - p->uid, cygheap->user.real_uid, cygheap->user.real_uid, p->uid, - p->gid, cygheap->user.real_gid, cygheap->user.real_gid, p->gid, - vmsize >> 10, 0, vmrss >> 10, vmdata >> 10, 0, vmtext >> 10, vmlib >> 10, - 0, 0, p->getsigmask () - ); + "State: %c (%s)\n" + "Tgid: %d\n" + "Pid: %d\n" + "PPid: %d\n" + "Uid: %d %d %d %d\n" + "Gid: %d %d %d %d\n" + "VmSize: %8d kB\n" + "VmLck: %8d kB\n" + "VmRSS: %8d kB\n" + "VmData: %8d kB\n" + "VmStk: %8d kB\n" + "VmExe: %8d kB\n" + "VmLib: %8d kB\n" + "SigPnd: %016x\n" + "SigBlk: %016x\n" + "SigIgn: %016x\n", + cmd, + state, state_str, + p->pgid, + p->pid, + p->ppid, + p->uid, cygheap->user.real_uid, cygheap->user.real_uid, p->uid, + p->gid, cygheap->user.real_gid, cygheap->user.real_gid, p->gid, + vmsize >> 10, 0, vmrss >> 10, vmdata >> 10, 0, vmtext >> 10, vmlib >> 10, + 0, 0, p->getsigmask () + ); } static @@ -603,15 +603,15 @@ off_t format_process_statm (_pinfo *p, char *destbuf, size_t maxsize) { unsigned long vmsize = 0UL, vmrss = 0UL, vmtext = 0UL, vmdata = 0UL, vmlib = 0UL, - vmshare = 0UL; + vmshare = 0UL; if (wincap.is_winnt ()) { if (!get_mem_values (p->dwProcessId, &vmsize, &vmrss, &vmtext, &vmdata, &vmlib, &vmshare)) - return 0; + return 0; } return __small_sprintf (destbuf, "%ld %ld %ld %ld %ld %ld %ld", - vmsize, vmrss, vmshare, vmtext, vmlib, vmdata, 0 - ); + vmsize, vmrss, vmshare, vmtext, vmlib, vmdata, 0 + ); } static @@ -629,15 +629,15 @@ get_process_state (DWORD dwProcessId) PULONG p = new ULONG[n]; int state =' '; while (STATUS_INFO_LENGTH_MISMATCH == - (ret = ZwQuerySystemInformation (SystemProcessesAndThreadsInformation, - (PVOID) p, - n * sizeof *p, NULL))) + (ret = ZwQuerySystemInformation (SystemProcessesAndThreadsInformation, + (PVOID) p, + n * sizeof *p, NULL))) delete [] p, p = new ULONG[n *= 2]; if (ret != STATUS_SUCCESS) { debug_printf("NtQuerySystemInformation: ret = %d, " - "Dos(ret) = %d", - ret, RtlNtStatusToDosError (ret)); + "Dos(ret) = %d", + ret, RtlNtStatusToDosError (ret)); goto out; } state = 'Z'; @@ -645,36 +645,36 @@ get_process_state (DWORD dwProcessId) for (;;) { if (sp->ProcessId == dwProcessId) - { - SYSTEM_THREADS *st; - if (wincap.has_process_io_counters ()) - /* - * Windows 2000 and XP have an extra member in SYSTEM_PROCESSES - * which means the offset of the first SYSTEM_THREADS entry is - * different on these operating systems compared to NT 4. - */ - st = &sp->Threads[0]; - else - /* - * 136 is the offset of the first SYSTEM_THREADS entry on - * Windows NT 4. - */ - st = (SYSTEM_THREADS *) ((char *) sp + 136); - state = 'S'; - for (unsigned i = 0; i < sp->ThreadCount; i++) - { - if (st->State == StateRunning || - st->State == StateReady) - { - state = 'R'; - goto out; - } - st++; - } - break; - } + { + SYSTEM_THREADS *st; + if (wincap.has_process_io_counters ()) + /* + * Windows 2000 and XP have an extra member in SYSTEM_PROCESSES + * which means the offset of the first SYSTEM_THREADS entry is + * different on these operating systems compared to NT 4. + */ + st = &sp->Threads[0]; + else + /* + * 136 is the offset of the first SYSTEM_THREADS entry on + * Windows NT 4. + */ + st = (SYSTEM_THREADS *) ((char *) sp + 136); + state = 'S'; + for (unsigned i = 0; i < sp->ThreadCount; i++) + { + if (st->State == StateRunning || + st->State == StateReady) + { + state = 'R'; + goto out; + } + st++; + } + break; + } if (!sp->NextEntryDelta) - break; + break; sp = (SYSTEM_PROCESSES *) ((char *) sp + sp->NextEntryDelta); } out: @@ -685,7 +685,7 @@ out: static bool get_mem_values(DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss, unsigned long *vmtext, - unsigned long *vmdata, unsigned long *vmlib, unsigned long *vmshare) + unsigned long *vmdata, unsigned long *vmlib, unsigned long *vmshare) { bool res = true; NTSTATUS ret; @@ -696,27 +696,27 @@ get_mem_values(DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss, u PULONG p = new ULONG[n]; unsigned page_size = getpagesize(); hProcess = OpenProcess (PROCESS_QUERY_INFORMATION, - FALSE, dwProcessId); + FALSE, dwProcessId); if (hProcess == NULL) { DWORD error = GetLastError(); __seterrno_from_win_error (error); debug_printf("OpenProcess: ret = %d", - error); + error); return false; } while ((ret = ZwQueryVirtualMemory (hProcess, 0, - MemoryWorkingSetList, - (PVOID) p, - n * sizeof *p, &length)), - (ret == STATUS_SUCCESS || ret == STATUS_INFO_LENGTH_MISMATCH) && - length >= n * sizeof *p) + MemoryWorkingSetList, + (PVOID) p, + n * sizeof *p, &length)), + (ret == STATUS_SUCCESS || ret == STATUS_INFO_LENGTH_MISMATCH) && + length >= n * sizeof *p) delete [] p, p = new ULONG[n *= 2]; if (ret != STATUS_SUCCESS) { debug_printf("NtQueryVirtualMemory: ret = %d, " - "Dos(ret) = %d", - ret, RtlNtStatusToDosError (ret)); + "Dos(ret) = %d", + ret, RtlNtStatusToDosError (ret)); res = false; goto out; } @@ -726,23 +726,23 @@ get_mem_values(DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss, u ++*vmrss; unsigned flags = mwsl->WorkingSetList[i] & 0x0FFF; if (flags & (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE) == (WSLE_PAGE_EXECUTE | WSLE_PAGE_SHAREABLE)) - ++*vmlib; + ++*vmlib; else if (flags & WSLE_PAGE_SHAREABLE) - ++*vmshare; + ++*vmshare; else if (flags & WSLE_PAGE_EXECUTE) - ++*vmtext; + ++*vmtext; else - ++*vmdata; + ++*vmdata; } ret = ZwQueryInformationProcess (hProcess, - ProcessVmCounters, - (PVOID) &vmc, - sizeof vmc, NULL); + ProcessVmCounters, + (PVOID) &vmc, + sizeof vmc, NULL); if (ret != STATUS_SUCCESS) { debug_printf("NtQueryInformationProcess: ret = %d, " - "Dos(ret) = %d", - ret, RtlNtStatusToDosError (ret)); + "Dos(ret) = %d", + ret, RtlNtStatusToDosError (ret)); res = false; goto out; } |