1 /*
2 * Copyright (c) 1994 William F. Jolitz, TeleMuse
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This software is a component of "386BSD" developed by
16 * William F. Jolitz, TeleMuse.
17 * 4. Neither the name of the developer nor the name "386BSD"
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 * 5. Non-commercial distribution of this complete file in either source and/or
21 * binary form at no charge to the user (such as from an official Internet
22 * archive site) is permitted.
23 * 6. Commercial distribution and sale of this complete file in either source
24 * and/or binary form on any media, including that of floppies, tape, or
25 * CD-ROM, or through a per-charge download such as that of a BBS, is not
26 * permitted without specific prior written permission.
27 * 7. Non-commercial and/or commercial distribution of an incomplete, altered,
28 * or otherwise modified file in either source and/or binary form is not
29 * permitted.
30 *
31 * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
32 * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
33 * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
34 * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
35 * NOT MAKE USE OF THIS WORK.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
38 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 * ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER BE LIABLE
41 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * SUCH DAMAGE.
48 *
49 * $Id: prof.c,v 1.1 94/10/20 00:03:08 bill Exp $
50 *
51 * Process profiling control.
52 */
53
54 #include "sys/param.h"
55 #include "sys/user.h"
56 #include "sys/file.h"
57 #include "sys/mman.h"
58 #include "resourcevar.h"
59 #include "vm.h"
60 #include "vmspace.h"
61
62 #include "machine/reg.h"
63 #include "machine/psl.h"
64 #include "machine/cpu.h"
65
66 #include "prototypes.h"
67
68 /*
69 * Request process profiling system call handler.
70 */
71 int
profil(p,args,retval)72 profil(p, args, retval)
73 struct proc *p;
74 struct uprof *args;
75 int *retval;
76 {
77 caddr_t base;
78 int sz;
79
80 /* insure offset never exceeds user address space size */
81 if (args->pr_off > VM_MAX_ADDRESS)
82 return (EFAULT);
83
84 /* next, check that the buffer is writable */
85 base = (caddr_t)args->pr_base;
86 sz = args->pr_size * sizeof (short);
87 if (vmspace_access(p->p_vmspace, base, sz, PROT_WRITE) == 0)
88 return EFAULT;
89
90 /* force allocated and resident the statitics buffer */
91 vmspace_notpageable(p->p_vmspace, base, sz);
92
93 /* force mapped the buffer to avoid skewed results */
94 vmspace_activate(p->p_vmspace, base, sz);
95
96 /* load profiling arguements, start profiling on next clock tick */
97 p->p_stats->p_prof = *args;
98
99 return (0);
100 }
101