11590Srgrimes/*-
21590Srgrimes * Copyright (c) 1988, 1993
31590Srgrimes *	The Regents of the University of California.  All rights reserved.
41590Srgrimes *
51590Srgrimes * Redistribution and use in source and binary forms, with or without
61590Srgrimes * modification, are permitted provided that the following conditions
71590Srgrimes * are met:
81590Srgrimes * 1. Redistributions of source code must retain the above copyright
91590Srgrimes *    notice, this list of conditions and the following disclaimer.
101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111590Srgrimes *    notice, this list of conditions and the following disclaimer in the
121590Srgrimes *    documentation and/or other materials provided with the distribution.
131590Srgrimes * 4. Neither the name of the University nor the names of its contributors
141590Srgrimes *    may be used to endorse or promote products derived from this software
151590Srgrimes *    without specific prior written permission.
161590Srgrimes *
171590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271590Srgrimes * SUCH DAMAGE.
281590Srgrimes */
291590Srgrimes
30110401Scharnier#if 0
311590Srgrimes#ifndef lint
321590Srgrimesstatic char sccsid[] = "@(#)subr.c	8.1 (Berkeley) 6/6/93";
33110401Scharnier#endif /* not lint */
3416509Sjraynard#endif
351590Srgrimes
3693523Sdwmalone#include <sys/cdefs.h>
3793523Sdwmalone__FBSDID("$FreeBSD$");
3893523Sdwmalone
391590Srgrimes#include <sys/param.h>
401590Srgrimes#include <sys/file.h>
411590Srgrimes#include <sys/proc.h>
421590Srgrimes#include <sys/time.h>
43138129Sdas#include <sys/uio.h>
441590Srgrimes#include <sys/ktrace.h>
4516509Sjraynard
46200462Sdelphij#include <stdio.h>
47200462Sdelphij
481590Srgrimes#include "ktrace.h"
491590Srgrimes
5093523Sdwmalonevoid timevaladd(struct timeval *, struct timeval *);
5193523Sdwmalonevoid timevalsub(struct timeval *, struct timeval *);
5293523Sdwmalonevoid timevalfix(struct timeval *);
5393523Sdwmalone
5493523Sdwmaloneint
5595649Smarkmgetpoints(char *s)
561590Srgrimes{
571590Srgrimes	int facs = 0;
581590Srgrimes
591590Srgrimes	while (*s) {
601590Srgrimes		switch(*s) {
611590Srgrimes		case 'c':
621590Srgrimes			facs |= KTRFAC_SYSCALL | KTRFAC_SYSRET;
631590Srgrimes			break;
64226269Sdes		case 'i':
65226269Sdes			facs |= KTRFAC_GENIO;
66226269Sdes			break;
67233925Sjhb		case 'f':
68233925Sjhb			facs |= KTRFAC_FAULT | KTRFAC_FAULTEND;
69233925Sjhb			break;
701590Srgrimes		case 'n':
711590Srgrimes			facs |= KTRFAC_NAMEI;
721590Srgrimes			break;
73226269Sdes		case 'p':
74226269Sdes			facs |= KTRFAC_CAPFAIL;
751590Srgrimes			break;
761590Srgrimes		case 's':
771590Srgrimes			facs |= KTRFAC_PSIG;
781590Srgrimes			break;
79176471Sdes		case 't':
80176471Sdes			facs |= KTRFAC_STRUCT;
81176471Sdes			break;
8218399Sphk		case 'u':
8318399Sphk			facs |= KTRFAC_USER;
8418399Sphk			break;
851590Srgrimes		case 'w':
861590Srgrimes			facs |= KTRFAC_CSW;
871590Srgrimes			break;
88189707Sjhb		case 'y':
89189707Sjhb			facs |= KTRFAC_SYSCTL;
90189707Sjhb			break;
911590Srgrimes		case '+':
921590Srgrimes			facs |= DEF_POINTS;
931590Srgrimes			break;
941590Srgrimes		default:
951590Srgrimes			return (-1);
961590Srgrimes		}
971590Srgrimes		s++;
981590Srgrimes	}
991590Srgrimes	return (facs);
1001590Srgrimes}
1011590Srgrimes
10293523Sdwmalonevoid
10395649Smarkmtimevaladd(struct timeval *t1, struct timeval *t2)
1041590Srgrimes{
1051590Srgrimes	t1->tv_sec += t2->tv_sec;
1061590Srgrimes	t1->tv_usec += t2->tv_usec;
1071590Srgrimes	timevalfix(t1);
1081590Srgrimes}
1091590Srgrimes
11093523Sdwmalonevoid
11195649Smarkmtimevalsub(struct timeval *t1, struct timeval *t2)
1121590Srgrimes{
1131590Srgrimes	t1->tv_sec -= t2->tv_sec;
1141590Srgrimes	t1->tv_usec -= t2->tv_usec;
1151590Srgrimes	timevalfix(t1);
1161590Srgrimes}
1171590Srgrimes
11893523Sdwmalonevoid
11995649Smarkmtimevalfix(struct timeval *t1)
1201590Srgrimes{
1211590Srgrimes	if (t1->tv_usec < 0) {
1221590Srgrimes		t1->tv_sec--;
1231590Srgrimes		t1->tv_usec += 1000000;
1241590Srgrimes	}
1251590Srgrimes	if (t1->tv_usec >= 1000000) {
1261590Srgrimes		t1->tv_sec++;
1271590Srgrimes		t1->tv_usec -= 1000000;
1281590Srgrimes	}
1291590Srgrimes}
130