4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
29 #include <sys/cpuvar.h>
33 * Install process context ops for the current process.
40 void (*restore
)(void *),
41 void (*fork
)(void *, void *),
43 void (*free
)(void *, int))
47 pctx
= kmem_alloc(sizeof (struct pctxop
), KM_SLEEP
);
49 pctx
->restore_op
= restore
;
54 pctx
->next
= p
->p_pctx
;
59 * Remove a process context ops from the current process.
66 void (*restore
)(void *),
67 void (*fork
)(void *, void *),
69 void (*free
)(void *, int))
71 struct pctxop
*pctx
, *prev_pctx
;
75 for (pctx
= p
->p_pctx
; pctx
!= NULL
; pctx
= pctx
->next
) {
76 if (pctx
->save_op
== save
&& pctx
->restore_op
== restore
&&
77 pctx
->fork_op
== fork
&&
78 pctx
->exit_op
== exit
&& pctx
->free_op
== free
&&
81 prev_pctx
->next
= pctx
->next
;
83 p
->p_pctx
= pctx
->next
;
84 if (pctx
->free_op
!= NULL
)
85 (pctx
->free_op
)(pctx
->arg
, 0);
86 kmem_free(pctx
, sizeof (struct pctxop
));
101 ASSERT(p
== curthread
->t_procp
);
102 for (pctx
= p
->p_pctx
; pctx
!= 0; pctx
= pctx
->next
)
103 if (pctx
->save_op
!= NULL
)
104 (pctx
->save_op
)(pctx
->arg
);
108 restorepctx(proc_t
*p
)
112 ASSERT(p
== curthread
->t_procp
);
113 for (pctx
= p
->p_pctx
; pctx
!= 0; pctx
= pctx
->next
)
114 if (pctx
->restore_op
!= NULL
)
115 (pctx
->restore_op
)(pctx
->arg
);
119 forkpctx(proc_t
*p
, proc_t
*cp
)
123 for (pctx
= p
->p_pctx
; pctx
!= NULL
; pctx
= pctx
->next
)
124 if (pctx
->fork_op
!= NULL
)
125 (pctx
->fork_op
)(p
, cp
);
129 * exitpctx is called during thread/lwp exit to perform any actions
130 * needed when an LWP in the process leaves the processor for the last
131 * time. This routine is not intended to deal with freeing memory; freepctx()
132 * is used for that purpose during proc_exit(). This routine is provided to
133 * allow for clean-up that can't wait until thread_free().
140 for (pctx
= p
->p_pctx
; pctx
!= NULL
; pctx
= pctx
->next
)
141 if (pctx
->exit_op
!= NULL
)
146 * freepctx is called from proc_exit() to get rid of the actual context ops.
149 freepctx(proc_t
*p
, int isexec
)
154 while ((pctx
= p
->p_pctx
) != NULL
) {
155 p
->p_pctx
= pctx
->next
;
156 if (pctx
->free_op
!= NULL
)
157 (pctx
->free_op
)(pctx
->arg
, isexec
);
158 kmem_free(pctx
, sizeof (struct pctxop
));
164 secflag_enabled(proc_t
*p
, secflag_t flag
)
166 return (secflag_isset(p
->p_secflags
.psf_effective
, flag
));
170 secflags_promote(proc_t
*p
)
172 secflags_copy(&p
->p_secflags
.psf_effective
, &p
->p_secflags
.psf_inherit
);