-int
-profil(struct proc *p, register struct profil_args *uap, __unused register_t *retval)
-{
- struct uprof *upp = &p->p_stats->p_prof;
- int s;
-
- if (uap->pcscale > (1 << 16))
- return (EINVAL);
- if (uap->pcscale == 0) {
- stopprofclock(p);
- return (0);
- }
-
- /* Block profile interrupts while changing state. */
- s = ml_set_interrupts_enabled(FALSE);
-
- if (proc_is64bit(p)) {
- struct user_uprof *user_upp = &p->p_stats->user_p_prof;
- struct user_uprof *upc, *nupc;
-
- PROFILE_LOCK(&user_upp->pr_lock);
- user_upp->pr_base = uap->bufbase;
- user_upp->pr_size = uap->bufsize;
- user_upp->pr_off = uap->pcoffset;
- user_upp->pr_scale = uap->pcscale;
- upp->pr_base = NULL;
- upp->pr_size = 0;
- upp->pr_scale = 0;
-
- /* remove buffers previously allocated with add_profil() */
- for (upc = user_upp->pr_next; upc; upc = nupc) {
- nupc = upc->pr_next;
- kfree(upc, sizeof (*upc));
- }
- user_upp->pr_next = 0;
- PROFILE_UNLOCK(&user_upp->pr_lock);
- }
- else {
- struct uprof *upc, *nupc;
-
- PROFILE_LOCK(&upp->pr_lock);
- upp->pr_base = CAST_DOWN(caddr_t, uap->bufbase);
- upp->pr_size = uap->bufsize;
- upp->pr_off = uap->pcoffset;
- upp->pr_scale = uap->pcscale;
-
- /* remove buffers previously allocated with add_profil() */
- for (upc = upp->pr_next; upc; upc = nupc) {
- nupc = upc->pr_next;
- kfree(upc, sizeof (struct uprof));
- }
- upp->pr_next = 0;
- PROFILE_UNLOCK(&upp->pr_lock);
- }
-
- startprofclock(p);
- ml_set_interrupts_enabled(s);
- return(0);
-}
-
-int
-add_profil(struct proc *p, register struct add_profil_args *uap, __unused register_t *retval)
-{
- struct uprof *upp = &p->p_stats->p_prof, *upc;
- struct user_uprof *user_upp = NULL, *user_upc;
- int s;
- boolean_t is64bit = proc_is64bit(p);
-
- if (is64bit) {
- user_upp = &p->p_stats->user_p_prof;
- if (user_upp->pr_scale == 0)
- return (0);
- }
- else {
- if (upp->pr_scale == 0)
- return (0);
- }
-
- s = ml_set_interrupts_enabled(FALSE);
-
- if (is64bit) {
- user_upc = (struct user_uprof *) kalloc(sizeof (struct user_uprof));
- user_upc->pr_base = uap->bufbase;
- user_upc->pr_size = uap->bufsize;
- user_upc->pr_off = uap->pcoffset;
- user_upc->pr_scale = uap->pcscale;
- PROFILE_LOCK(&user_upp->pr_lock);
- user_upc->pr_next = user_upp->pr_next;
- user_upp->pr_next = user_upc;
- PROFILE_UNLOCK(&user_upp->pr_lock);
- }
- else {
- upc = (struct uprof *) kalloc(sizeof (struct uprof));
- upc->pr_base = CAST_DOWN(caddr_t, uap->bufbase);
- upc->pr_size = uap->bufsize;
- upc->pr_off = uap->pcoffset;
- upc->pr_scale = uap->pcscale;
- PROFILE_LOCK(&upp->pr_lock);
- upc->pr_next = upp->pr_next;
- upp->pr_next = upc;
- PROFILE_UNLOCK(&upp->pr_lock);
- }
-
- ml_set_interrupts_enabled(s);
- return(0);
-}