*/
/*
-cc -I. -DKERNEL_PRIVATE -O -o sc_usage sc_usage.c -lncurses
+cc -I. -DPRIVATE -D__APPLE_PRIVATE -O -o sc_usage sc_usage.c -lncurses
*/
#define Default_DELAY 1 /* default delay interval */
#define MAX_NESTED 8
#define MAX_FAULTS 5
-/* If NUMPARMS from kernel changes, it will be reflected in PATHLENGTH as well */
+
#define NUMPARMS 23
-#define PATHLENGTH (NUMPARMS*sizeof(long))
+
char *state_name[] = {
"Dont Know",
int vfslookup;
int curpri;
long *pathptr;
- char pathname[PATHLENGTH + 1];
+ long pathname[NUMPARMS + 1];
struct entry th_entry[MAX_NESTED];
};
for (i = 0; i < num_of_threads; i++, ti++) {
struct entry *te;
+ char *p;
uint64_t now;
int secs, time_secs, time_usecs;
clen = strlen(tbuf);
/* print the tail end of the pathname */
- plen = strlen(ti->pathname);
+ p = (char *)ti->pathname;
+
+ plen = strlen(p);
if (plen > 34)
plen -= 34;
else
plen = 0;
- sprintf(&tbuf[clen], " %-34.34s ", &ti->pathname[plen]);
+ sprintf(&tbuf[clen], " %-34.34s ", &p[plen]);
clen += strlen(&tbuf[clen]);
if ((unsigned long)(((double)now - te->otime) / divisor) > 5000000) {
ti->thread = 0;
ti->vfslookup = 0;
- ti->pathptr = (long *)0;
+ ti->pathptr = (long *)NULL;
ti->pathname[0] = 0;
num_of_threads--;
}
th_state[i].depth = 0;
th_state[i].thread = 0;
th_state[i].vfslookup = 0;
- th_state[i].pathptr = (long *)0;
+ th_state[i].pathptr = (long *)NULL;
th_state[i].pathname[0] = 0;
}
num_of_threads = 0;
struct sc_entry *se;
struct entry *te;
- thread = kd[i].arg5 & KDBG_THREAD_MASK;
+ thread = kd[i].arg5;
debugid = kd[i].debugid;
type = kd[i].debugid & DBG_FUNC_MASK;
switched_out = (struct th_info *)0;
switched_in = (struct th_info *)0;
- now = kd[i].timestamp;
+ now = kd[i].timestamp & KDBG_TIMESTAMP_MASK;
baseid = debugid & 0xffff0000;
if (ti->vfslookup == 1) {
ti->vfslookup++;
- memset(&ti->pathname[0], 0, (PATHLENGTH + 1));
- sargptr = (long *)&ti->pathname[0];
+ sargptr = ti->pathname;
*sargptr++ = kd[i].arg2;
*sargptr++ = kd[i].arg3;
*sargptr++ = kd[i].arg4;
+ /*
+ * NULL terminate the 'string'
+ */
+ *sargptr = 0;
+
ti->pathptr = sargptr;
} else if (ti->vfslookup > 1) {
handle.
*/
- if ((long *)sargptr >= (long *)&ti->pathname[PATHLENGTH])
+ if (sargptr >= &ti->pathname[NUMPARMS])
continue;
/*
if (debugid & DBG_FUNC_START)
{
- (long *)ti->pathptr = (long *)&ti->pathname[PATHLENGTH];
+ ti->pathptr = &ti->pathname[NUMPARMS];
continue;
}
*sargptr++ = kd[i].arg2;
*sargptr++ = kd[i].arg3;
*sargptr++ = kd[i].arg4;
+ /*
+ * NULL terminate the 'string'
+ */
+ *sargptr = 0;
+
ti->pathptr = sargptr;
}
continue;
else if (baseid == msc_base)
code = 512 + ((debugid >> 2) & 0x1ff);
else if (type == mach_sched || type == mach_stkhandoff) {
- switched_out = find_thread((kd[i].arg5 & KDBG_THREAD_MASK));
+ switched_out = find_thread(kd[i].arg5);
switched_in = find_thread(kd[i].arg2);
if (in_idle) {