aboutsummaryrefslogtreecommitdiff
path: root/libps/procstat.c
diff options
context:
space:
mode:
Diffstat (limited to 'libps/procstat.c')
-rw-r--r--libps/procstat.c340
1 files changed, 198 insertions, 142 deletions
diff --git a/libps/procstat.c b/libps/procstat.c
index 0938073e..ba923780 100644
--- a/libps/procstat.c
+++ b/libps/procstat.c
@@ -1,8 +1,7 @@
/* The proc_stat type, which holds information about a hurd process.
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
-
- Written by Miles Bader <miles@gnu.ai.mit.edu>
+ Copyright (C) 1995,96,97,98,99,2002 Free Software Foundation, Inc.
+ Written by Miles Bader <miles@gnu.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -43,7 +42,7 @@ typedef threadinfo_data_t *threadinfo_t;
/* Return the PSTAT_STATE_ bits describing the state of an individual thread,
from that thread's thread_basic_info_t struct */
-static int
+static int
thread_state (thread_basic_info_t bi)
{
int state = 0;
@@ -79,19 +78,26 @@ thread_state (thread_basic_info_t bi)
/* ---------------------------------------------------------------- */
-/* The set of PSTAT_ flags that we get using proc_getprocinfo. */
-#define PSTAT_PROCINFO \
- (PSTAT_PROC_INFO | PSTAT_TASK_BASIC | PSTAT_NUM_THREADS \
- | PSTAT_THREAD_BASIC | PSTAT_THREAD_SCHED | PSTAT_THREAD_WAIT \
- | PSTAT_THREAD_WAITS)
-/* The set of things we get from procinfo that's thread dependent. */
+/* The set of things we get from procinfo that are per-thread. */
#define PSTAT_PROCINFO_THREAD \
- (PSTAT_NUM_THREADS |PSTAT_THREAD_BASIC |PSTAT_THREAD_SCHED \
- | PSTAT_THREAD_WAIT | PSTAT_THREAD_WAITS)
+ (PSTAT_THREAD_BASIC | PSTAT_THREAD_SCHED | PSTAT_THREAD_WAIT)
+
+/* The set of things we get from procinfo that are per-task, and thread dependent. */
+#define PSTAT_PROCINFO_TASK_THREAD_DEP \
+ (PSTAT_PROCINFO_THREAD | PSTAT_NUM_THREADS | PSTAT_THREAD_WAITS)
+
+/* The set of things we get from procinfo that are per-task (note that this
+ includes thread fields, because tasks use them for thread summaries). */
+#define PSTAT_PROCINFO_TASK \
+ (PSTAT_PROCINFO_TASK_THREAD_DEP | PSTAT_PROC_INFO \
+ | PSTAT_TASK_BASIC | PSTAT_TASK_EVENTS)
+
+/* The set of PSTAT_ flags that we get using proc_getprocinfo. */
+#define PSTAT_PROCINFO PSTAT_PROCINFO_TASK
/* The set of things in PSTAT_PROCINFO that we will not attempt to refetch on
subsequent getprocinfo calls. */
-#define PSTAT_PROCINFO_MERGE PSTAT_TASK_BASIC
+#define PSTAT_PROCINFO_MERGE (PSTAT_TASK_BASIC | PSTAT_TASK_EVENTS)
#define PSTAT_PROCINFO_REFETCH (PSTAT_PROCINFO - PSTAT_PROCINFO_MERGE)
/* Fetches process information from the set in PSTAT_PROCINFO, returning it
@@ -103,18 +109,22 @@ fetch_procinfo (process_t server, pid_t pid,
struct procinfo **pi, size_t *pi_size,
char **waits, size_t *waits_len)
{
+ static const struct { ps_flags_t ps_flag; int pi_flags; } map[] =
+ {
+ { PSTAT_TASK_BASIC, PI_FETCH_TASKINFO },
+ { PSTAT_TASK_EVENTS, PI_FETCH_TASKEVENTS },
+ { PSTAT_NUM_THREADS, PI_FETCH_THREADS },
+ { PSTAT_THREAD_BASIC, PI_FETCH_THREAD_BASIC | PI_FETCH_THREADS },
+ { PSTAT_THREAD_SCHED, PI_FETCH_THREAD_SCHED | PI_FETCH_THREADS },
+ { PSTAT_THREAD_WAITS, PI_FETCH_THREAD_WAITS | PI_FETCH_THREADS },
+ { 0, }
+ };
int pi_flags = 0;
+ int i;
- if ((need & PSTAT_TASK_BASIC) && !(*have & PSTAT_TASK_BASIC))
- pi_flags |= PI_FETCH_TASKINFO;
- if ((need & PSTAT_NUM_THREADS) && !(*have & PSTAT_NUM_THREADS))
- pi_flags |= PI_FETCH_THREADS;
- if ((need & PSTAT_THREAD_BASIC) && !(*have & PSTAT_THREAD_BASIC))
- pi_flags |= PI_FETCH_THREAD_BASIC | PI_FETCH_THREADS;
- if ((need & PSTAT_THREAD_SCHED) && !(*have & PSTAT_THREAD_SCHED))
- pi_flags |= PI_FETCH_THREAD_SCHED | PI_FETCH_THREADS;
- if ((need & PSTAT_THREAD_WAITS) && !(*have & PSTAT_THREAD_WAITS))
- pi_flags |= PI_FETCH_THREAD_WAITS | PI_FETCH_THREADS;
+ for (i = 0; map[i].ps_flag; i++)
+ if ((need & map[i].ps_flag) && !(*have & map[i].ps_flag))
+ pi_flags |= map[i].pi_flags;
if (pi_flags || ((need & PSTAT_PROC_INFO) && !(*have & PSTAT_PROC_INFO)))
{
@@ -129,16 +139,9 @@ fetch_procinfo (process_t server, pid_t pid,
/* Update *HAVE to reflect what we've successfully fetched. */
{
*have |= PSTAT_PROC_INFO;
- if (pi_flags & PI_FETCH_TASKINFO)
- *have |= PSTAT_TASK_BASIC;
- if (pi_flags & PI_FETCH_THREADS)
- *have |= PSTAT_NUM_THREADS;
- if (pi_flags & PI_FETCH_THREAD_BASIC)
- *have |= PSTAT_THREAD_BASIC;
- if (pi_flags & PI_FETCH_THREAD_SCHED)
- *have |= PSTAT_THREAD_SCHED;
- if (pi_flags & PI_FETCH_THREAD_WAITS)
- *have |= PSTAT_THREAD_WAITS;
+ for (i = 0; map[i].ps_flag; i++)
+ if ((pi_flags & map[i].pi_flags) == map[i].pi_flags)
+ *have |= map[i].ps_flag;
}
return err;
}
@@ -150,7 +153,7 @@ fetch_procinfo (process_t server, pid_t pid,
vm_alloced memory for the procinfo structure returned by getprocinfo.
Here we just give enough for four threads. */
#define PROCINFO_MALLOC_SIZE \
- (sizeof (struct procinfo) + 4 * sizeof (threadinfo_data_t))
+ (sizeof (struct procinfo) + 4 * sizeof (threadinfo_data_t))
#define WAITS_MALLOC_SIZE 128
@@ -229,8 +232,7 @@ merge_procinfo (struct proc_stat *ps, ps_flags_t need, ps_flags_t have)
/* We got new memory vm_alloced by the getprocinfo, discard the old. */
{
if (ps->proc_info_vm_alloced)
- vm_deallocate (mach_task_self (),
- (vm_address_t)ps->proc_info, ps->proc_info_size);
+ munmap (ps->proc_info, ps->proc_info_size);
else
free (ps->proc_info);
ps->proc_info = new_pi;
@@ -248,8 +250,7 @@ merge_procinfo (struct proc_stat *ps, ps_flags_t need, ps_flags_t have)
/* We got new memory vm_alloced by the getprocinfo, discard the old. */
{
if (ps->thread_waits_vm_alloced)
- vm_deallocate (mach_task_self (),
- (vm_address_t)ps->thread_waits, ps->thread_waits_len);
+ munmap (ps->thread_waits, ps->thread_waits_len);
else
free (ps->thread_waits);
ps->thread_waits = new_waits;
@@ -266,7 +267,7 @@ merge_procinfo (struct proc_stat *ps, ps_flags_t need, ps_flags_t have)
/* Returns FLAGS augmented with any other flags that are necessary
preconditions to setting them. */
-static ps_flags_t
+static ps_flags_t
add_preconditions (ps_flags_t flags, struct ps_context *context)
{
/* Implement any inter-flag dependencies: if the new flags in FLAGS depend on
@@ -287,7 +288,7 @@ add_preconditions (ps_flags_t flags, struct ps_context *context)
flags |= PSTAT_PROC_INFO;
if (flags & PSTAT_SUSPEND_COUNT)
/* We just request the resources require for both the thread and task
- versions, as the extraneous info won't be possible to aquire anyway. */
+ versions, as the extraneous info won't be possible to acquire anyway. */
flags |= PSTAT_TASK_BASIC | PSTAT_THREAD_BASIC;
if (flags & (PSTAT_CTTYID | PSTAT_CWDIR | PSTAT_AUTH | PSTAT_UMASK)
&& !(flags & PSTAT_NO_MSGPORT))
@@ -295,8 +296,6 @@ add_preconditions (ps_flags_t flags, struct ps_context *context)
flags |= PSTAT_MSGPORT;
flags |= PSTAT_TASK; /* for authentication */
}
- if (flags & PSTAT_TASK_EVENTS)
- flags |= PSTAT_TASK;
return flags;
}
@@ -359,7 +358,8 @@ summarize_thread_basic_info (struct procinfo *pi)
bzero (tbi, sizeof *tbi);
for (i = 0; i < pi->nthreads; i++)
- if (! pi->threadinfos[i].died)
+ if (! pi->threadinfos[i].died
+ && ! (pi->threadinfos[i].pis_bi.flags & TH_FLAGS_IDLE))
{
thread_basic_info_t bi = &pi->threadinfos[i].pis_bi;
int thread_run_state = bi->run_state;
@@ -446,7 +446,8 @@ summarize_thread_sched_info (struct procinfo *pi)
bzero (tsi, sizeof *tsi);
for (i = 0; i < pi->nthreads; i++)
- if (! pi->threadinfos[i].died)
+ if (! pi->threadinfos[i].died
+ && ! (pi->threadinfos[i].pis_bi.flags & TH_FLAGS_IDLE))
{
thread_sched_info_t si = &pi->threadinfos[i].pis_si;
tsi->base_priority += si->base_priority;
@@ -476,7 +477,8 @@ summarize_thread_states (struct procinfo *pi)
/* The union of all thread state bits... */
for (i = 0; i < pi->nthreads; i++)
- if (! pi->threadinfos[i].died)
+ if (! pi->threadinfos[i].died
+ && ! (pi->threadinfos[i].pis_bi.flags & TH_FLAGS_IDLE))
state |= thread_state (&pi->threadinfos[i].pis_bi);
return state;
@@ -485,7 +487,7 @@ summarize_thread_states (struct procinfo *pi)
/* Returns what's blocking the first blocked thread in PI in WAIT and RPC. */
static void
summarize_thread_waits (struct procinfo *pi, char *waits, size_t waits_len,
- char **wait, int *rpc)
+ char **wait, mach_msg_id_t *rpc)
{
int i;
char *next_wait = waits;
@@ -495,38 +497,42 @@ summarize_thread_waits (struct procinfo *pi, char *waits, size_t waits_len,
for (i = 0; i < pi->nthreads; i++)
if (! pi->threadinfos[i].died)
- if (next_wait > waits + waits_len)
- break;
- else
- {
- int left = waits + waits_len - next_wait;
-
- if (strncmp (next_wait, "msgport", left) == 0
- || strncmp (next_wait, "itimer", left) == 0)
- ; /* libc internal threads; ignore. */
- else if (*wait)
- /* There are multiple user threads. Punt. */
- {
- *wait = "*";
- *rpc = 0;
- break;
- }
- else
- {
- *wait = next_wait;
- *rpc = pi->threadinfos[i].rpc_block;
- }
-
- /* Advance NEXT_WAIT to the next wait string. */
- next_wait += strnlen (next_wait, left) + 1;
- }
+ {
+ if (next_wait > waits + waits_len)
+ break;
+ else
+ {
+ int left = waits + waits_len - next_wait;
+
+ if (pi->threadinfos[i].pis_bi.flags & TH_FLAGS_IDLE)
+ ; /* kernel idle thread; ignore */
+ else if (strncmp (next_wait, "msgport", left) == 0
+ || strncmp (next_wait, "itimer", left) == 0)
+ ; /* libc internal threads; ignore. */
+ else if (*wait)
+ /* There are multiple user threads. Punt. */
+ {
+ *wait = "*";
+ *rpc = 0;
+ break;
+ }
+ else
+ {
+ *wait = next_wait;
+ *rpc = pi->threadinfos[i].rpc_block;
+ }
+
+ /* Advance NEXT_WAIT to the next wait string. */
+ next_wait += strnlen (next_wait, left) + 1;
+ }
+ }
}
/* Returns the number of threads in PI that aren't marked dead. */
static unsigned
count_threads (struct procinfo *pi, ps_flags_t have)
{
- if (have & (PSTAT_PROCINFO_THREAD & ~PSTAT_NUM_THREADS))
+ if (have & (PSTAT_PROCINFO_TASK_THREAD_DEP & ~PSTAT_NUM_THREADS))
/* If we have thread info besides the number of threads, then the
threadinfos structures in PI are valid (we use the died bit). */
{
@@ -683,20 +689,19 @@ set_procinfo_flags (struct proc_stat *ps, ps_flags_t need, ps_flags_t have)
/* Now copy out the information for this particular thread from the
ORIGIN's list of thread information. */
- if ((need & PSTAT_THREAD_BASIC) && ! (have & PSTAT_THREAD_BASIC)
- && (oflags & PSTAT_THREAD_BASIC)
+ need &= ~have;
+
+ if ((need & PSTAT_THREAD_BASIC) && (oflags & PSTAT_THREAD_BASIC)
&& (ps->thread_basic_info =
clone (&ti->pis_bi, sizeof (struct thread_basic_info))))
have |= PSTAT_THREAD_BASIC;
- if ((need & PSTAT_THREAD_SCHED) && ! (have & PSTAT_THREAD_SCHED)
- && (oflags & PSTAT_THREAD_SCHED)
+ if ((need & PSTAT_THREAD_SCHED) && (oflags & PSTAT_THREAD_SCHED)
&& (ps->thread_sched_info =
clone (&ti->pis_si, sizeof (struct thread_sched_info))))
have |= PSTAT_THREAD_SCHED;
- if ((need & PSTAT_THREAD_WAIT) && ! (have & PSTAT_THREAD_WAIT)
- && (oflags & PSTAT_THREAD_WAITS))
+ if ((need & PSTAT_THREAD_WAIT) && (oflags & PSTAT_THREAD_WAITS))
{
ps->thread_wait =
get_thread_wait (origin->thread_waits,
@@ -709,6 +714,11 @@ set_procinfo_flags (struct proc_stat *ps, ps_flags_t need, ps_flags_t have)
}
}
}
+
+ /* Mark things that don't apply to threads (note that we don't do the
+ analogous thing for tasks above, as tasks do have thread fields
+ containing summary information for all their threads). */
+ ps->inapp |= need & ~have & PSTAT_PROCINFO & ~PSTAT_PROCINFO_THREAD;
}
return have;
@@ -762,23 +772,45 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags)
need = flags & ~have & ~ps->failed;
+ /* Returns true if (1) FLAGS is in NEED, and (2) the appropriate
+ preconditions PRECOND are available; if only (1) is true, FLAG is added
+ to the INAPP set if appropriate (to distinguish it from an error), and
+ returns false. */
+#define NEED(flag, precond) \
+ ({ \
+ ps_flags_t __flag = (flag), _precond = (precond); \
+ int val; \
+ if (! (__flag & need)) \
+ val = 0; \
+ else if ((_precond & have) == _precond) \
+ val = 1; \
+ else \
+ { \
+ val = 0; \
+ if (_precond & ps->inapp) \
+ ps->inapp |= __flag; \
+ } \
+ val; \
+ })
+
/* MGET: If we're trying to set FLAG, and the preconditions PRECOND are set
in the flags already, then eval CALL and set ERR to the result.
If the resulting ERR is 0 add FLAG to the set of valid flags. ERR is
returned. */
-#define MGET(_flag, _precond, call) \
- ({ ps_flags_t flag = (_flag), precond = (_precond); \
- error_t err; \
- if (!(need & (flag)) || (have & (precond)) != (precond)) \
- err = 0; \
- else \
- { \
- err = (call); \
- if (!err) \
- have |= flag; \
- } \
- err; \
- })
+#define MGET(flag, precond, call) \
+ ({ \
+ error_t err; \
+ ps_flags_t _flag = (flag); \
+ if (NEED (_flag, precond)) \
+ { \
+ err = (call); \
+ if (!err) \
+ have |= _flag; \
+ } \
+ else \
+ err = 0; \
+ err; \
+ })
/* A version of MGET specifically for the msg port, that turns off the msg
port if a call to it times out. It also implies a precondition of
@@ -795,11 +827,8 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags)
later. */
have = set_procinfo_flags (ps, need & ~have & test_msgport_flags, have);
- if ((need & PSTAT_SUSPEND_COUNT)
- &&
- ((have & PSTAT_PID)
- ? (have & PSTAT_TASK_BASIC)
- : (have & PSTAT_THREAD_BASIC)))
+ if (NEED (PSTAT_SUSPEND_COUNT,
+ ((have & PSTAT_PID) ? PSTAT_TASK_BASIC : PSTAT_THREAD_BASIC)))
{
if (have & PSTAT_PID)
ps->suspend_count = ps->task_basic_info->suspend_count;
@@ -823,31 +852,21 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags)
/* The process's task port. */
MGET(PSTAT_TASK, PSTAT_PID, proc_pid2task (server, ps->pid, &ps->task));
- /* VM statistics for the task. See <mach/task_info.h>. */
- if ((need & PSTAT_TASK_EVENTS) && (have & PSTAT_TASK))
- {
- ps->task_events_info = &ps->task_events_info_buf;
- ps->task_events_info_size = TASK_EVENTS_INFO_COUNT;
- if (task_info (ps->task, TASK_EVENTS_INFO,
- (task_info_t)ps->task_events_info,
- &ps->task_events_info_size)
- == 0)
- have |= PSTAT_TASK_EVENTS;
- }
-
/* PSTAT_STATE_ bits for the process and all its threads. */
if ((need & PSTAT_STATE) && (have & (PSTAT_PROC_INFO | PSTAT_THREAD_BASIC)))
{
ps->state = 0;
if (have & PSTAT_THREAD_BASIC)
- /* Thread states. */
- if (have & PSTAT_THREAD)
- ps->state |= thread_state (ps->thread_basic_info);
- else
- /* For a process, we use the thread list instead of
- PS->thread_basic_info because it contains more information. */
- ps->state |= summarize_thread_states (ps->proc_info);
+ {
+ /* Thread states. */
+ if (have & PSTAT_THREAD)
+ ps->state |= thread_state (ps->thread_basic_info);
+ else
+ /* For a process, we use the thread list instead of
+ PS->thread_basic_info because it contains more information. */
+ ps->state |= summarize_thread_states (ps->proc_info);
+ }
if (have & PSTAT_PROC_INFO)
/* Process state. */
@@ -881,21 +900,43 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags)
}
/* The process's exec arguments */
- if ((need & PSTAT_ARGS) && (have & PSTAT_PID))
+ if (NEED (PSTAT_ARGS, PSTAT_PID))
{
char *buf = malloc (100);
ps->args_len = 100;
ps->args = buf;
if (ps->args)
- if (proc_getprocargs (server, ps->pid, &ps->args, &ps->args_len))
- free (buf);
- else
- {
- have |= PSTAT_ARGS;
- ps->args_vm_alloced = (ps->args != buf);
- if (ps->args_vm_alloced)
- free (buf);
- }
+ {
+ if (proc_getprocargs (server, ps->pid, &ps->args, &ps->args_len))
+ free (buf);
+ else
+ {
+ have |= PSTAT_ARGS;
+ ps->args_vm_alloced = (ps->args != buf);
+ if (ps->args_vm_alloced)
+ free (buf);
+ }
+ }
+ }
+
+ /* The process's exec environment */
+ if (NEED (PSTAT_ENV, PSTAT_PID))
+ {
+ char *buf = malloc (100);
+ ps->env_len = 100;
+ ps->env = buf;
+ if (ps->env)
+ {
+ if (proc_getprocenv (server, ps->pid, &ps->env, &ps->env_len))
+ free (buf);
+ else
+ {
+ have |= PSTAT_ENV;
+ ps->env_vm_alloced = (ps->env != buf);
+ if (ps->env_vm_alloced)
+ free (buf);
+ }
+ }
}
/* The ctty id port; note that this is just a magic cookie;
@@ -920,9 +961,9 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags)
when creating a file. */
MP_MGET (PSTAT_UMASK, PSTAT_TASK,
ps_msg_get_init_int (ps->msgport, ps->task, INIT_UMASK,
- &ps->umask));
+ (int *) &ps->umask));
- if ((need & PSTAT_OWNER_UID) && (have & PSTAT_PROC_INFO))
+ if (NEED (PSTAT_OWNER_UID, PSTAT_PROC_INFO))
{
if (ps->proc_info->state & PI_NOTOWNED)
ps->owner_uid = -1;
@@ -932,34 +973,43 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags)
}
/* A ps_user object for the process's owner. */
- if ((need & PSTAT_OWNER) && (have & PSTAT_OWNER_UID))
- if (ps->owner_uid < 0)
- {
- ps->owner = 0;
+ if (NEED (PSTAT_OWNER, PSTAT_OWNER_UID))
+ {
+ if (ps->owner_uid < 0)
+ {
+ ps->owner = 0;
+ have |= PSTAT_OWNER;
+ }
+ else if (! ps_context_find_user (ps->context, ps->owner_uid, &ps->owner))
have |= PSTAT_OWNER;
- }
- else if (! ps_context_find_user (ps->context, ps->owner_uid, &ps->owner))
- have |= PSTAT_OWNER;
+ }
/* A ps_tty for the process's controlling terminal, or NULL if it
doesn't have one. */
- if ((need & PSTAT_TTY) && (have & PSTAT_CTTYID))
+ if (NEED (PSTAT_TTY, PSTAT_CTTYID))
if (ps_context_find_tty_by_cttyid (ps->context, ps->cttyid, &ps->tty) == 0)
have |= PSTAT_TTY;
+ /* The number of Mach ports in the task. */
+ MGET (PSTAT_NUM_PORTS, PSTAT_PID,
+ proc_getnports (server, ps->pid, &ps->num_ports));
+
/* Update PS's flag state. We haven't tried user flags yet, so don't mark
them as having failed. We do this before checking user bits so that the
user fetch hook sees PS in a consistent state. */
ps->failed |= (need & ~PSTAT_USER_MASK) & ~have;
ps->flags = have;
- need &= PSTAT_USER_MASK; /* Only consider user bits now. */
+ need &= ~have;
if (need && ps->context->user_hooks && ps->context->user_hooks->fetch)
/* There is some user state we need to fetch. */
{
have |= (*ps->context->user_hooks->fetch) (ps, need, have);
- /* Update the flag state again having tried the user bits. */
- ps->failed |= need & ~have;
+ /* Update the flag state again having tried the user bits. We allow
+ the user hook to turn on non-user bits, in which case we remove them
+ from the failed set; the user hook may know some way of getting the
+ info that we don't. */
+ ps->failed = (ps->failed | need) & ~have;
ps->flags = have;
}
@@ -968,7 +1018,7 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags)
/* ---------------------------------------------------------------- */
/* Discard PS and any resources it holds. */
-void
+void
_proc_stat_free (ps)
struct proc_stat *ps;
{
@@ -982,7 +1032,7 @@ _proc_stat_free (ps)
? mach_port_deallocate(mach_task_self (), (ps->port)) : 0)
/* If FLAG is set in PS's flags, then if VM_ALLOCED is zero, free the malloced
- field MEM in PS; othrewise, vm_deallocate MEM, consisting of SIZE
+ field MEM in PS; othrewise, vm_deallocate MEM, consisting of SIZE
elements of type ELTYPE, *unless* MEM == SBUF, which usually means
that MEM points to a static buffer somewhere instead of vm_alloc'd
memory. */
@@ -999,13 +1049,16 @@ _proc_stat_free (ps)
MFREEPORT (PSTAT_AUTH, auth);
/* free any allocated memory pointed to by PS */
- MFREEMEM (PSTAT_PROCINFO, proc_info, ps->proc_info_size,
+ MFREEMEM (PSTAT_PROC_INFO, proc_info, ps->proc_info_size,
ps->proc_info_vm_alloced, 0, char);
MFREEMEM (PSTAT_THREAD_BASIC, thread_basic_info, 0, 0, 0, 0);
MFREEMEM (PSTAT_THREAD_SCHED, thread_sched_info, 0, 0, 0, 0);
MFREEMEM (PSTAT_ARGS, args, ps->args_len, ps->args_vm_alloced, 0, char);
+ MFREEMEM (PSTAT_ENV, env, ps->env_len, ps->env_vm_alloced, 0, char);
MFREEMEM (PSTAT_TASK_EVENTS, task_events_info, ps->task_events_info_size,
0, &ps->task_events_info_buf, char);
+ MFREEMEM (PSTAT_THREAD_WAITS, thread_waits, ps->thread_waits_len,
+ ps->thread_waits_vm_alloced, 0, char);
FREE (ps);
}
@@ -1023,6 +1076,7 @@ _proc_stat_create (pid_t pid, struct ps_context *context, struct proc_stat **ps)
(*ps)->pid = pid;
(*ps)->flags = PSTAT_PID;
(*ps)->failed = 0;
+ (*ps)->inapp = PSTAT_THREAD;
(*ps)->context = context;
(*ps)->hook = 0;
@@ -1036,7 +1090,7 @@ _proc_stat_create (pid_t pid, struct ps_context *context, struct proc_stat **ps)
resulting proc_stat isn't fully functional -- most flags can't be set in
it. It also contains a pointer to PS, so PS shouldn't be freed without
also freeing THREAD_PS. If N was out of range, EINVAL is returned. If a
- memory allocation error occured, ENOMEM is returned. Otherwise, 0 is
+ memory allocation error occurred, ENOMEM is returned. Otherwise, 0 is
returned. */
error_t
proc_stat_thread_create (struct proc_stat *ps, unsigned index, struct proc_stat **thread_ps)
@@ -1057,6 +1111,8 @@ proc_stat_thread_create (struct proc_stat *ps, unsigned index, struct proc_stat
/* A value of -1 for the PID indicates that this is a thread. */
tps->pid = -1;
tps->flags = PSTAT_THREAD;
+ tps->failed = 0;
+ tps->inapp = PSTAT_PID;
tps->thread_origin = ps;
tps->thread_index = index;