4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
29 * Copyright 2023 Oxide Computer Company
32 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/cmn_err.h>
37 #include <sys/policy.h>
38 #include <sys/debug.h>
39 #include <sys/errno.h>
41 #include <sys/inline.h>
44 #include <sys/brand.h>
45 #include <sys/regset.h>
46 #include <sys/sysmacros.h>
47 #include <sys/systm.h>
49 #include <sys/vnode.h>
50 #include <sys/signal.h>
53 #include <sys/class.h>
54 #include <sys/fault.h>
55 #include <sys/syscall.h>
56 #include <sys/procfs.h>
58 #include <sys/copyops.h>
59 #include <sys/schedctl.h>
62 #include <fs/proc/prdata.h>
63 #include <sys/contract/process_impl.h>
64 #include <sys/stdalign.h>
66 static void pr_settrace(proc_t
*, sigset_t
*);
67 static int pr_setfpregs(prnode_t
*, prfpregset_t
*);
68 static int pr_setxregs(prnode_t
*, prxregset_t
*);
69 static int pr_setvaddr(prnode_t
*, caddr_t
);
70 static int pr_clearsig(prnode_t
*);
71 static int pr_clearflt(prnode_t
*);
72 static int pr_watch(prnode_t
*, prwatch_t
*, int *);
73 static int pr_agent(prnode_t
*, prgregset_t
, int *);
74 static int pr_rdwr(proc_t
*, enum uio_rw
, priovec_t
*);
75 static int pr_scred(proc_t
*, prcred_t
*, cred_t
*, boolean_t
);
76 static int pr_spriv(proc_t
*, prpriv_t
*, cred_t
*);
77 static int pr_szoneid(proc_t
*, zoneid_t
, cred_t
*);
78 static void pauselwps(proc_t
*);
79 static void unpauselwps(proc_t
*);
82 * This union represents the size of commands that are generally fixed size in
83 * /proc. There are some commands that are variable size because the actual data
84 * is structured. Of things in the latter category, some of these are the same
85 * across all architectures (e.g. prcred_t, prpriv_t) and some vary and are
86 * opaque (e.g. the prxregset_t).
89 long sig
; /* PCKILL, PCUNKILL */
90 long nice
; /* PCNICE */
91 long timeo
; /* PCTWSTOP */
92 ulong_t flags
; /* PCRUN, PCSET, PCUNSET */
93 caddr_t vaddr
; /* PCSVADDR */
94 siginfo_t siginfo
; /* PCSSIG */
95 sigset_t sigset
; /* PCSTRACE, PCSHOLD */
96 fltset_t fltset
; /* PCSFAULT */
97 sysset_t sysset
; /* PCSENTRY, PCSEXIT */
98 prgregset_t prgregset
; /* PCSREG, PCAGENT */
99 prfpregset_t prfpregset
; /* PCSFPREG */
100 prwatch_t prwatch
; /* PCWATCH */
101 priovec_t priovec
; /* PCREAD, PCWRITE */
102 prcred_t prcred
; /* PCSCRED */
103 prpriv_t prpriv
; /* PCSPRIV */
104 long przoneid
; /* PCSZONE */
108 prwritectl_pcscredx_sizef(const void *datap
, size_t *sizep
)
110 const prcred_t
*cred
= datap
;
112 if (cred
->pr_ngroups
< 0 || cred
->pr_ngroups
> ngroups_max
) {
116 if (cred
->pr_ngroups
== 0) {
119 *sizep
= (cred
->pr_ngroups
- 1) * sizeof (gid_t
);
125 prwritectl_pcspriv_sizef(const void *datap
, size_t *sizep
)
127 const prpriv_t
*priv
= datap
;
128 *sizep
= priv_prgetprivsize(priv
) - sizeof (prpriv_t
);
133 * This structure represents a single /proc write command that we support and
134 * metadata about how to ensure we have sufficient data for it. To determine the
135 * data that we need to read, this combines information from three different
136 * sources for a given named command in 'pcs_cmd'. The main goal is to first
137 * make sure we have the right minimum amount of information so we can read and
138 * validate the data around variable length structures.
140 * o Most commands have a fixed static size. This is represented in the
141 * pcs_size member. This also is used to represent the base structure size
142 * in the case of entries like PCSCREDX.
144 * o Other commands have an unknown minimum size to determine how much data
145 * there is and they use the pcs_minf() function to determine the right
146 * value. This is often unknown at compile time because it is say a
147 * machdep or ISA based feature (ala PCSXREGS) and we'd rather not #ifdef
148 * this code to death. This may be skipped and is for most things. The value
149 * it returns is added to the static value.
151 * o The final piece is the pcs_sizef() function pointer which determines the
152 * total required size for this. It is given a pointer that has at least
153 * pcs_size and pcs_minf() bytes. This is used to determine the total
154 * expected size of the structure. Callers must not dereference data beyond
155 * what they've indicated previously. This should only return extra bytes
156 * that are required beyond what was already indicated between the two
159 * In all cases, the core prwritectl() logic will determine if there is
160 * sufficient step along the way for each of these to proceed.
162 typedef struct proc_control_info
{
165 boolean_t (*pcs_minf
)(size_t *);
166 boolean_t (*pcs_sizef
)(const void *, size_t *);
167 } proc_control_info_t
;
169 static const proc_control_info_t proc_ctl_info
[] = {
170 { PCNULL
, 0, NULL
, NULL
},
171 { PCSTOP
, 0, NULL
, NULL
},
172 { PCDSTOP
, 0, NULL
, NULL
},
173 { PCWSTOP
, 0, NULL
, NULL
},
174 { PCCSIG
, 0, NULL
, NULL
},
175 { PCCFAULT
, 0, NULL
, NULL
},
176 { PCSSIG
, sizeof (siginfo_t
), NULL
, NULL
},
177 { PCTWSTOP
, sizeof (long), NULL
, NULL
},
178 { PCKILL
, sizeof (long), NULL
, NULL
},
179 { PCUNKILL
, sizeof (long), NULL
, NULL
},
180 { PCNICE
, sizeof (long), NULL
, NULL
},
181 { PCRUN
, sizeof (ulong_t
), NULL
, NULL
},
182 { PCSET
, sizeof (ulong_t
), NULL
, NULL
},
183 { PCUNSET
, sizeof (ulong_t
), NULL
, NULL
},
184 { PCSTRACE
, sizeof (sigset_t
), NULL
, NULL
},
185 { PCSHOLD
, sizeof (sigset_t
), NULL
, NULL
},
186 { PCSFAULT
, sizeof (fltset_t
), NULL
, NULL
},
187 { PCSENTRY
, sizeof (sysset_t
), NULL
, NULL
},
188 { PCSEXIT
, sizeof (sysset_t
), NULL
, NULL
},
189 { PCSREG
, sizeof (prgregset_t
), NULL
, NULL
},
190 { PCAGENT
, sizeof (prgregset_t
), NULL
, NULL
},
191 { PCSFPREG
, sizeof (prfpregset_t
), NULL
, NULL
},
192 { PCSXREG
, 0, prwriteminxreg
,
194 { PCWATCH
, sizeof (prwatch_t
), NULL
, NULL
},
195 { PCREAD
, sizeof (priovec_t
), NULL
, NULL
},
196 { PCWRITE
, sizeof (priovec_t
), NULL
, NULL
},
197 { PCSCRED
, sizeof (prcred_t
), NULL
, NULL
},
198 { PCSCREDX
, sizeof (prcred_t
), NULL
,
199 prwritectl_pcscredx_sizef
},
200 { PCSPRIV
, sizeof (prpriv_t
), NULL
,
201 prwritectl_pcspriv_sizef
},
202 { PCSZONE
, sizeof (long), NULL
, NULL
},
206 * We need a default buffer that we're going to allocate when we need memory to
207 * read control operations. This is on average large enough to hold multiple
208 * control operations. We leave this as a smaller value on debug builds just
209 * to exercise our reallocation logic.
212 #define PROC_CTL_DEFSIZE 32
214 #define PROC_CTL_DEFSIZE 1024
218 * This structure is used to track all of the information that we have around a
219 * prwritectl call. This is used to reduce function parameters and make state
225 size_t prwc_curvalid
;
228 boolean_t prwc_locked
;
229 boolean_t prwc_need32
;
234 * Ensure that we have at least "needed" data marked as valid and present. If we
235 * require additional data, then we will read that in from uio_t. When we read
236 * data, we try to buffer as much data as will fit in our internal buffers in
240 prwritectl_readin(prwritectl_t
*prwc
, size_t needed
)
247 * If we have as much data as we need then we're good to go.
249 if (prwc
->prwc_curvalid
> needed
) {
250 ASSERT3U(prwc
->prwc_buflen
, >=, prwc
->prwc_curvalid
);
251 ASSERT3U(prwc
->prwc_buflen
, >=, needed
);
256 * We don't have all of our data. We must make sure of several things:
258 * 1. That there actually is enough data in the uio_t for what we
259 * need, considering what we've already read.
260 * 2. If the process is locked, at this point, we want to unlock it
261 * before we deal with any I/O or memory allocation. Otherwise we
262 * can wreak havoc with p_lock / paging.
263 * 3. We need to make sure that our buffer is large enough to actually
265 * 4. Only at that point can we actually perform the read.
267 if (needed
- prwc
->prwc_curvalid
> prwc
->prwc_uiop
->uio_resid
) {
271 if (prwc
->prwc_locked
) {
272 prunlock(prwc
->prwc_pnp
);
273 prwc
->prwc_locked
= B_FALSE
;
276 if (needed
> prwc
->prwc_buflen
) {
277 size_t new_len
= P2ROUNDUP(needed
, PROC_CTL_DEFSIZE
);
278 prwc
->prwc_buf
= kmem_rezalloc(prwc
->prwc_buf
,
279 prwc
->prwc_buflen
, new_len
, KM_SLEEP
);
280 if (prwc
->prwc_need32
) {
281 prwc
->prwc_buf32
= kmem_rezalloc(prwc
->prwc_buf32
,
282 prwc
->prwc_buflen
, new_len
, KM_SLEEP
);
284 prwc
->prwc_buflen
= new_len
;
287 toread
= MIN(prwc
->prwc_buflen
- prwc
->prwc_curvalid
,
288 prwc
->prwc_uiop
->uio_resid
);
289 ASSERT3U(toread
, >=, needed
- prwc
->prwc_curvalid
);
290 start
= (void *)((uintptr_t)prwc
->prwc_buf
+ prwc
->prwc_curvalid
);
291 if ((ret
= uiomove(start
, toread
, UIO_WRITE
, prwc
->prwc_uiop
)) != 0) {
295 prwc
->prwc_curvalid
+= toread
;
299 static const proc_control_info_t
*
300 prwritectl_cmd_identify(const prwritectl_t
*prwc
,
301 const proc_control_info_t
*info
, size_t ninfo
, size_t cmdsize
)
305 ASSERT(cmdsize
== sizeof (int32_t) || cmdsize
== sizeof (long));
307 cmd
= (long)*(int32_t *)prwc
->prwc_buf
;
309 cmd
= *(long *)prwc
->prwc_buf
;
313 for (size_t i
= 0; i
< ninfo
; i
++) {
314 if (info
[i
].pcs_cmd
== cmd
) {
323 * Control operations (lots).
325 * Users can submit one or more commands to us in the uio_t. They are required
326 * to always be complete messages. The first one that fails will cause all
327 * subsequent things to fail. Processing this can be a little tricky as the
328 * actual data size that may be required is variable, not all structures are
329 * fixed sizes and some vary based on the instructing set (e.g. x86 vs.
332 * The way that we handle process locking deserves some consideration. Prior to
333 * the colonization of prwritectl and the support for dynamic sizing of data,
334 * the logic would try to read in a large chunk of data and keep a process
335 * locked throughout that period and then unlock it before reading more data. As
336 * such, we mimic that logically and basically lock it before executing the
337 * first (or any subsequent) command and then only unlock it either when we're
338 * done entirely or we need to allocate memory or read from the process.
340 * This function is a common implementation for both the ILP32 and LP64 entry
341 * points as they are mostly the same except for the sizing and control function
345 prwritectl_common(vnode_t
*vp
, uio_t
*uiop
, cred_t
*cr
,
346 const proc_control_info_t
*proc_info
, size_t ninfo
, size_t cmdsize
,
347 int (*pr_controlf
)(long, void *, prnode_t
*, cred_t
*))
352 VERIFY(cmdsize
== sizeof (int32_t) || cmdsize
== sizeof (long));
354 bzero(&prwc
, sizeof (prwc
));
355 prwc
.prwc_pnp
= VTOP(vp
);
356 prwc
.prwc_uiop
= uiop
;
357 prwc
.prwc_need32
= (cmdsize
== sizeof (int32_t));
360 * We may have multiple commands to read and want to try to minimize the
361 * amount of reading that we do. Our callers expect us to have a
362 * contiguous buffer for a command's actual implementation. However, we
363 * must have at least a single long worth of data, otherwise it's not
366 while (uiop
->uio_resid
> 0 || prwc
.prwc_curvalid
> 0) {
367 const proc_control_info_t
*proc_cmd
;
371 * Check if we have enough data to identify a command. If not,
372 * we read as much as we can in one gulp.
374 if ((ret
= prwritectl_readin(&prwc
, cmdsize
)) != 0) {
379 * Identify the command and figure out how how much data we
380 * should have read in the kernel. Some commands have a variable
381 * length and we need to make sure the minimum is met before
382 * asking how much there is in general. Most things know what
383 * the minimum length is and this pcs_minf() is not implemented.
384 * However things that are ISA-specific require us to ask that
387 * We also must be aware that there may not actually be enough
388 * data present in the uio_t.
390 if ((proc_cmd
= prwritectl_cmd_identify(&prwc
, proc_info
,
391 ninfo
, cmdsize
)) == NULL
) {
396 size_t needed_data
= cmdsize
+ proc_cmd
->pcs_size
;
397 if (proc_cmd
->pcs_minf
!= NULL
) {
400 if (!proc_cmd
->pcs_minf(&min
)) {
408 if (proc_cmd
->pcs_sizef
!= NULL
) {
412 * Make sure we have the minimum amount of data that
413 * they asked us to between the static and minf
416 if ((ret
= prwritectl_readin(&prwc
, needed_data
)) !=
421 VERIFY3U(prwc
.prwc_curvalid
, >, cmdsize
);
422 data
= (void *)((uintptr_t)prwc
.prwc_buf
+ cmdsize
);
423 if (!proc_cmd
->pcs_sizef(data
, &extra
)) {
428 needed_data
+= extra
;
432 * Now that we know how much data we're supposed to have,
433 * finally ensure we have the total amount we need.
435 if ((ret
= prwritectl_readin(&prwc
, needed_data
)) != 0) {
440 * /proc has traditionally assumed control writes come in
441 * multiples of a long. This is 4 bytes for ILP32 and 8 bytes
442 * for LP64. When calculating the required size for a structure,
443 * it would always round that up to the next long. However, the
444 * exact combination of circumstances changes with the
445 * introduction of the 64-bit kernel. For 64-bit processes we
446 * round up when the current command we're processing isn't the
449 * Because of our tracking structures and caching we need to
450 * look beyond the uio_t to make this determination. In
451 * particular, the uio_t can have a zero resid, but we may still
452 * have additional data to read as indicated by prwc_curvalid
453 * exceeding the current command size. In the end, we must check
454 * both of these cases.
456 if ((needed_data
% cmdsize
) != 0) {
457 if (cmdsize
== sizeof (int32_t) ||
458 prwc
.prwc_curvalid
> needed_data
||
459 prwc
.prwc_uiop
->uio_resid
> 0) {
460 needed_data
= P2ROUNDUP(needed_data
,
462 if ((ret
= prwritectl_readin(&prwc
,
463 needed_data
)) != 0) {
469 if (!prwc
.prwc_locked
) {
470 ret
= prlock(prwc
.prwc_pnp
, ZNO
);
474 prwc
.prwc_locked
= B_TRUE
;
478 * Run our actual command. When there is an error, then the
479 * underlying pr_control call will have unlocked the prnode_t
480 * on our behalf. pr_control can return -1, which is a special
481 * error indicating a timeout occurred. In such a case the node
482 * is unlocked; however, that we are supposed to continue
483 * processing commands regardless.
485 * Finally, we must deal with with one actual wrinkle. The LP64
486 * based logic always guarantees that we have data that is
487 * 8-byte aligned. However, the ILP32 logic is 4-byte aligned
488 * and the rest of the /proc code assumes it can always
489 * dereference it. If we're not aligned, we have to bcopy it to
490 * a temporary buffer.
492 data
= (void *)((uintptr_t)prwc
.prwc_buf
+ cmdsize
);
494 if (cmdsize
== sizeof (long)) {
495 ASSERT0((uintptr_t)data
% alignof (long));
498 if (prwc
.prwc_need32
&& ((uintptr_t)data
% alignof (long)) !=
499 0 && needed_data
> cmdsize
) {
500 bcopy(data
, prwc
.prwc_buf32
, needed_data
- cmdsize
);
501 data
= prwc
.prwc_buf32
;
503 ret
= pr_controlf(proc_cmd
->pcs_cmd
, data
, prwc
.prwc_pnp
, cr
);
505 prwc
.prwc_locked
= B_FALSE
;
512 * Finally, now that we have processed this command, we need to
513 * move on. To make our life simple, we basically shift all the
514 * data in our buffer over to indicate it's been consumed. While
515 * a little wasteful, this simplifies buffer management and
516 * guarantees that command processing uses a semi-sanitized
517 * state. Visually, this is the following transformation:
519 * 0 20 prwc.prwc_curvalid
520 * +------------------+----------------+
521 * | needed_data | remaining_data |
522 * +------------------+----------------+
524 * In the above example we are shifting all the data over by 20,
525 * so remaining data starts at 0. This leaves us needed_data
526 * bytes to clean up from what was valid.
528 if (prwc
.prwc_buf32
!= NULL
) {
529 bzero(prwc
.prwc_buf32
, needed_data
- cmdsize
);
532 if (prwc
.prwc_curvalid
> needed_data
) {
533 size_t save_size
= prwc
.prwc_curvalid
- needed_data
;
534 void *first_save
= (void *)((uintptr_t)prwc
.prwc_buf
+
536 memmove(prwc
.prwc_buf
, first_save
, save_size
);
537 void *first_zero
= (void *)((uintptr_t)prwc
.prwc_buf
+
539 bzero(first_zero
, needed_data
);
541 bzero(prwc
.prwc_buf
, prwc
.prwc_curvalid
);
543 prwc
.prwc_curvalid
-= needed_data
;
547 * We've managed to successfully process everything. We can actually say
548 * this was successful now.
553 if (prwc
.prwc_locked
) {
554 prunlock(prwc
.prwc_pnp
);
555 prwc
.prwc_locked
= B_FALSE
;
558 if (prwc
.prwc_buf
!= NULL
) {
559 kmem_free(prwc
.prwc_buf
, prwc
.prwc_buflen
);
562 if (prwc
.prwc_buf32
!= NULL
) {
563 VERIFY(prwc
.prwc_need32
);
564 kmem_free(prwc
.prwc_buf32
, prwc
.prwc_buflen
);
571 pr_control(long cmd
, void *generic
, prnode_t
*pnp
, cred_t
*cr
)
577 arg_t
*argp
= generic
;
582 pcp
= pnp
->pr_common
;
586 /* System processes defy control. */
587 if (p
->p_flag
& SSYS
) {
598 case PCSTOP
: /* direct process or lwp to stop and wait for stop */
599 case PCDSTOP
: /* direct process or lwp to stop, don't wait */
600 case PCWSTOP
: /* wait for process or lwp to stop */
601 case PCTWSTOP
: /* wait for process or lwp to stop, with timeout */
606 * Can't apply to a system process.
608 if (p
->p_as
== &kas
) {
613 if (cmd
== PCSTOP
|| cmd
== PCDSTOP
)
620 * If an lwp is waiting for itself or its process,
621 * don't wait. The stopped lwp would never see the
622 * fact that it is stopped.
624 if ((pcp
->prc_flags
& PRC_LWP
)?
625 (pcp
->prc_thread
== curthread
) : (p
== curproc
)) {
626 if (cmd
== PCWSTOP
|| cmd
== PCTWSTOP
)
631 timeo
= (cmd
== PCTWSTOP
)? (time_t)argp
->timeo
: 0;
632 if ((error
= pr_wait_stop(pnp
, timeo
)) != 0)
638 case PCRUN
: /* make lwp or process runnable */
639 error
= pr_setrun(pnp
, argp
->flags
);
642 case PCSTRACE
: /* set signal trace mask */
643 pr_settrace(p
, &argp
->sigset
);
646 case PCSSIG
: /* set current signal */
647 error
= pr_setsig(pnp
, &argp
->siginfo
);
648 if (argp
->siginfo
.si_signo
== SIGKILL
&& error
== 0) {
655 case PCKILL
: /* send signal */
656 error
= pr_kill(pnp
, (int)argp
->sig
, cr
);
657 if (error
== 0 && argp
->sig
== SIGKILL
) {
664 case PCUNKILL
: /* delete a pending signal */
665 error
= pr_unkill(pnp
, (int)argp
->sig
);
668 case PCNICE
: /* set nice priority */
669 error
= pr_nice(p
, (int)argp
->nice
, cr
);
672 case PCSENTRY
: /* set syscall entry bit mask */
673 case PCSEXIT
: /* set syscall exit bit mask */
674 pr_setentryexit(p
, &argp
->sysset
, cmd
== PCSENTRY
);
677 case PCSET
: /* set process flags */
678 error
= pr_set(p
, argp
->flags
);
681 case PCUNSET
: /* unset process flags */
682 error
= pr_unset(p
, argp
->flags
);
685 case PCSREG
: /* set general registers */
687 kthread_t
*t
= pr_thread(pnp
);
689 if (!ISTOPPED(t
) && !VSTOPPED(t
) && !DSTOPPED(t
)) {
694 mutex_exit(&p
->p_lock
);
695 prsetprregs(ttolwp(t
), argp
->prgregset
, 0);
696 mutex_enter(&p
->p_lock
);
701 case PCSFPREG
: /* set floating-point registers */
702 error
= pr_setfpregs(pnp
, &argp
->prfpregset
);
705 case PCSXREG
: /* set extra registers */
706 error
= pr_setxregs(pnp
, (prxregset_t
*)argp
);
709 case PCSVADDR
: /* set virtual address at which to resume */
710 error
= pr_setvaddr(pnp
, argp
->vaddr
);
713 case PCSHOLD
: /* set signal-hold mask */
714 pr_sethold(pnp
, &argp
->sigset
);
717 case PCSFAULT
: /* set mask of traced faults */
718 pr_setfault(p
, &argp
->fltset
);
721 case PCCSIG
: /* clear current signal */
722 error
= pr_clearsig(pnp
);
725 case PCCFAULT
: /* clear current fault */
726 error
= pr_clearflt(pnp
);
729 case PCWATCH
: /* set or clear watched areas */
730 error
= pr_watch(pnp
, &argp
->prwatch
, &unlocked
);
731 if (error
&& unlocked
)
735 case PCAGENT
: /* create the /proc agent lwp in the target process */
736 error
= pr_agent(pnp
, argp
->prgregset
, &unlocked
);
737 if (error
&& unlocked
)
741 case PCREAD
: /* read from the address space */
742 error
= pr_rdwr(p
, UIO_READ
, &argp
->priovec
);
745 case PCWRITE
: /* write to the address space */
746 error
= pr_rdwr(p
, UIO_WRITE
, &argp
->priovec
);
749 case PCSCRED
: /* set the process credentials */
751 error
= pr_scred(p
, &argp
->prcred
, cr
, cmd
== PCSCREDX
);
754 case PCSPRIV
: /* set the process privileges */
755 error
= pr_spriv(p
, &argp
->prpriv
, cr
);
757 case PCSZONE
: /* set the process's zoneid credentials */
758 error
= pr_szoneid(p
, (zoneid_t
)argp
->przoneid
, cr
);
768 prwritectl(vnode_t
*vp
, uio_t
*uiop
, cred_t
*cr
)
770 return (prwritectl_common(vp
, uiop
, cr
, proc_ctl_info
,
771 ARRAY_SIZE(proc_ctl_info
), sizeof (long), pr_control
));
774 #ifdef _SYSCALL32_IMPL
777 int32_t sig
; /* PCKILL, PCUNKILL */
778 int32_t nice
; /* PCNICE */
779 int32_t timeo
; /* PCTWSTOP */
780 uint32_t flags
; /* PCRUN, PCSET, PCUNSET */
781 caddr32_t vaddr
; /* PCSVADDR */
782 siginfo32_t siginfo
; /* PCSSIG */
783 sigset_t sigset
; /* PCSTRACE, PCSHOLD */
784 fltset_t fltset
; /* PCSFAULT */
785 sysset_t sysset
; /* PCSENTRY, PCSEXIT */
786 prgregset32_t prgregset
; /* PCSREG, PCAGENT */
787 prfpregset32_t prfpregset
; /* PCSFPREG */
788 prwatch32_t prwatch
; /* PCWATCH */
789 priovec32_t priovec
; /* PCREAD, PCWRITE */
790 prcred32_t prcred
; /* PCSCRED */
791 prpriv_t prpriv
; /* PCSPRIV */
792 int32_t przoneid
; /* PCSZONE */
795 static int pr_setfpregs32(prnode_t
*, prfpregset32_t
*);
798 prwritectl_pcscredx32_sizef(const void *datap
, size_t *sizep
)
800 const prcred32_t
*cred
= datap
;
802 if (cred
->pr_ngroups
< 0 || cred
->pr_ngroups
> ngroups_max
) {
806 if (cred
->pr_ngroups
== 0) {
809 *sizep
= (cred
->pr_ngroups
- 1) * sizeof (gid32_t
);
815 * When dealing with ILP32 code, we are not at a point where we can assume
816 * 64-bit aligned data. Any functions that are operating here must be aware of
819 static const proc_control_info_t proc_ctl_info32
[] = {
820 { PCNULL
, 0, NULL
, NULL
},
821 { PCSTOP
, 0, NULL
, NULL
},
822 { PCDSTOP
, 0, NULL
, NULL
},
823 { PCWSTOP
, 0, NULL
, NULL
},
824 { PCCSIG
, 0, NULL
, NULL
},
825 { PCCFAULT
, 0, NULL
, NULL
},
826 { PCSSIG
, sizeof (siginfo32_t
), NULL
, NULL
},
827 { PCTWSTOP
, sizeof (int32_t), NULL
, NULL
},
828 { PCKILL
, sizeof (int32_t), NULL
, NULL
},
829 { PCUNKILL
, sizeof (int32_t), NULL
, NULL
},
830 { PCNICE
, sizeof (int32_t), NULL
, NULL
},
831 { PCRUN
, sizeof (uint32_t), NULL
, NULL
},
832 { PCSET
, sizeof (uint32_t), NULL
, NULL
},
833 { PCUNSET
, sizeof (uint32_t), NULL
, NULL
},
834 { PCSVADDR
, sizeof (caddr32_t
), NULL
, NULL
},
835 { PCSTRACE
, sizeof (sigset_t
), NULL
, NULL
},
836 { PCSHOLD
, sizeof (sigset_t
), NULL
, NULL
},
837 { PCSFAULT
, sizeof (fltset_t
), NULL
, NULL
},
838 { PCSENTRY
, sizeof (sysset_t
), NULL
, NULL
},
839 { PCSEXIT
, sizeof (sysset_t
), NULL
, NULL
},
840 { PCSREG
, sizeof (prgregset32_t
), NULL
, NULL
},
841 { PCAGENT
, sizeof (prgregset32_t
), NULL
, NULL
},
842 { PCSFPREG
, sizeof (prfpregset32_t
), NULL
, NULL
},
843 { PCSXREG
, 0, prwriteminxreg
,
845 { PCWATCH
, sizeof (prwatch32_t
), NULL
, NULL
},
846 { PCREAD
, sizeof (priovec32_t
), NULL
, NULL
},
847 { PCWRITE
, sizeof (priovec32_t
), NULL
, NULL
},
848 { PCSCRED
, sizeof (prcred32_t
), NULL
, NULL
},
849 { PCSCREDX
, sizeof (prcred32_t
), NULL
,
850 prwritectl_pcscredx32_sizef
},
851 { PCSPRIV
, sizeof (prpriv_t
), NULL
,
852 prwritectl_pcspriv_sizef
},
853 { PCSZONE
, sizeof (long), NULL
, NULL
},
857 pr_control32(long cmd
, void *generic
, prnode_t
*pnp
, cred_t
*cr
)
863 arg32_t
*argp
= generic
;
868 pcp
= pnp
->pr_common
;
872 if (p
->p_flag
& SSYS
) {
883 case PCSTOP
: /* direct process or lwp to stop and wait for stop */
884 case PCDSTOP
: /* direct process or lwp to stop, don't wait */
885 case PCWSTOP
: /* wait for process or lwp to stop */
886 case PCTWSTOP
: /* wait for process or lwp to stop, with timeout */
891 * Can't apply to a system process.
893 if (p
->p_as
== &kas
) {
898 if (cmd
== PCSTOP
|| cmd
== PCDSTOP
)
905 * If an lwp is waiting for itself or its process,
906 * don't wait. The lwp will never see the fact that
909 if ((pcp
->prc_flags
& PRC_LWP
)?
910 (pcp
->prc_thread
== curthread
) : (p
== curproc
)) {
911 if (cmd
== PCWSTOP
|| cmd
== PCTWSTOP
)
916 timeo
= (cmd
== PCTWSTOP
)? (time_t)argp
->timeo
: 0;
917 if ((error
= pr_wait_stop(pnp
, timeo
)) != 0)
923 case PCRUN
: /* make lwp or process runnable */
924 error
= pr_setrun(pnp
, (ulong_t
)argp
->flags
);
927 case PCSTRACE
: /* set signal trace mask */
928 pr_settrace(p
, &argp
->sigset
);
931 case PCSSIG
: /* set current signal */
932 if (PROCESS_NOT_32BIT(p
))
935 int sig
= (int)argp
->siginfo
.si_signo
;
938 bzero(&siginfo
, sizeof (siginfo
));
939 siginfo_32tok(&argp
->siginfo
, (k_siginfo_t
*)&siginfo
);
940 error
= pr_setsig(pnp
, &siginfo
);
941 if (sig
== SIGKILL
&& error
== 0) {
949 case PCKILL
: /* send signal */
950 error
= pr_kill(pnp
, (int)argp
->sig
, cr
);
951 if (error
== 0 && argp
->sig
== SIGKILL
) {
958 case PCUNKILL
: /* delete a pending signal */
959 error
= pr_unkill(pnp
, (int)argp
->sig
);
962 case PCNICE
: /* set nice priority */
963 error
= pr_nice(p
, (int)argp
->nice
, cr
);
966 case PCSENTRY
: /* set syscall entry bit mask */
967 case PCSEXIT
: /* set syscall exit bit mask */
968 pr_setentryexit(p
, &argp
->sysset
, cmd
== PCSENTRY
);
971 case PCSET
: /* set process flags */
972 error
= pr_set(p
, (long)argp
->flags
);
975 case PCUNSET
: /* unset process flags */
976 error
= pr_unset(p
, (long)argp
->flags
);
979 case PCSREG
: /* set general registers */
980 if (PROCESS_NOT_32BIT(p
))
983 kthread_t
*t
= pr_thread(pnp
);
985 if (!ISTOPPED(t
) && !VSTOPPED(t
) && !DSTOPPED(t
)) {
989 prgregset_t prgregset
;
990 klwp_t
*lwp
= ttolwp(t
);
993 mutex_exit(&p
->p_lock
);
994 prgregset_32ton(lwp
, argp
->prgregset
,
996 prsetprregs(lwp
, prgregset
, 0);
997 mutex_enter(&p
->p_lock
);
1002 case PCSFPREG
: /* set floating-point registers */
1003 if (PROCESS_NOT_32BIT(p
))
1006 error
= pr_setfpregs32(pnp
, &argp
->prfpregset
);
1009 case PCSXREG
: /* set extra registers */
1010 if (PROCESS_NOT_32BIT(p
))
1013 error
= pr_setxregs(pnp
, (prxregset_t
*)argp
);
1016 case PCSVADDR
: /* set virtual address at which to resume */
1017 if (PROCESS_NOT_32BIT(p
))
1020 error
= pr_setvaddr(pnp
,
1021 (caddr_t
)(uintptr_t)argp
->vaddr
);
1024 case PCSHOLD
: /* set signal-hold mask */
1025 pr_sethold(pnp
, &argp
->sigset
);
1028 case PCSFAULT
: /* set mask of traced faults */
1029 pr_setfault(p
, &argp
->fltset
);
1032 case PCCSIG
: /* clear current signal */
1033 error
= pr_clearsig(pnp
);
1036 case PCCFAULT
: /* clear current fault */
1037 error
= pr_clearflt(pnp
);
1040 case PCWATCH
: /* set or clear watched areas */
1041 if (PROCESS_NOT_32BIT(p
))
1046 prwatch
.pr_vaddr
= argp
->prwatch
.pr_vaddr
;
1047 prwatch
.pr_size
= argp
->prwatch
.pr_size
;
1048 prwatch
.pr_wflags
= argp
->prwatch
.pr_wflags
;
1049 prwatch
.pr_pad
= argp
->prwatch
.pr_pad
;
1050 error
= pr_watch(pnp
, &prwatch
, &unlocked
);
1051 if (error
&& unlocked
)
1056 case PCAGENT
: /* create the /proc agent lwp in the target process */
1057 if (PROCESS_NOT_32BIT(p
))
1060 prgregset_t prgregset
;
1061 kthread_t
*t
= pr_thread(pnp
);
1062 klwp_t
*lwp
= ttolwp(t
);
1064 mutex_exit(&p
->p_lock
);
1065 prgregset_32ton(lwp
, argp
->prgregset
, prgregset
);
1066 mutex_enter(&p
->p_lock
);
1067 error
= pr_agent(pnp
, prgregset
, &unlocked
);
1068 if (error
&& unlocked
)
1073 case PCREAD
: /* read from the address space */
1074 case PCWRITE
: /* write to the address space */
1075 if (PROCESS_NOT_32BIT(p
) || (pnp
->pr_flags
& PR_OFFMAX
))
1078 enum uio_rw rw
= (cmd
== PCREAD
)? UIO_READ
: UIO_WRITE
;
1082 (void *)(uintptr_t)argp
->priovec
.pio_base
;
1083 priovec
.pio_len
= (size_t)argp
->priovec
.pio_len
;
1084 priovec
.pio_offset
= (off_t
)
1085 (uint32_t)argp
->priovec
.pio_offset
;
1086 error
= pr_rdwr(p
, rw
, &priovec
);
1090 case PCSCRED
: /* set the process credentials */
1094 * All the fields in these structures are exactly the
1095 * same and so the structures are compatible. In case
1096 * this ever changes, we catch this with the ASSERT
1099 prcred_t
*prcred
= (prcred_t
*)&argp
->prcred
;
1102 ASSERT(sizeof (prcred_t
) == sizeof (prcred32_t
));
1105 error
= pr_scred(p
, prcred
, cr
, cmd
== PCSCREDX
);
1109 case PCSPRIV
: /* set the process privileges */
1110 error
= pr_spriv(p
, &argp
->prpriv
, cr
);
1113 case PCSZONE
: /* set the process's zoneid */
1114 error
= pr_szoneid(p
, (zoneid_t
)argp
->przoneid
, cr
);
1124 prwritectl32(struct vnode
*vp
, struct uio
*uiop
, cred_t
*cr
)
1126 return (prwritectl_common(vp
, uiop
, cr
, proc_ctl_info32
,
1127 ARRAY_SIZE(proc_ctl_info32
), sizeof (int32_t), pr_control32
));
1129 #endif /* _SYSCALL32_IMPL */
1132 * Return the specific or chosen thread/lwp for a control operation.
1133 * Returns with the thread locked via thread_lock(t).
1136 pr_thread(prnode_t
*pnp
)
1138 prcommon_t
*pcp
= pnp
->pr_common
;
1141 if (pcp
->prc_flags
& PRC_LWP
) {
1142 t
= pcp
->prc_thread
;
1146 proc_t
*p
= pcp
->prc_proc
;
1147 t
= prchoose(p
); /* returns locked thread */
1155 * Direct the process or lwp to stop.
1158 pr_stop(prnode_t
*pnp
)
1160 prcommon_t
*pcp
= pnp
->pr_common
;
1161 proc_t
*p
= pcp
->prc_proc
;
1166 * If already stopped, do nothing; otherwise flag
1167 * it to be stopped the next time it tries to run.
1168 * If sleeping at interruptible priority, set it
1169 * running so it will stop within cv_wait_sig().
1171 * Take care to cooperate with jobcontrol: if an lwp
1172 * is stopped due to the default action of a jobcontrol
1173 * stop signal, flag it to be stopped the next time it
1174 * starts due to a SIGCONT signal.
1176 if (pcp
->prc_flags
& PRC_LWP
)
1177 t
= pcp
->prc_thread
;
1188 t
->t_proc_flag
|= TP_PRSTOP
;
1189 t
->t_sig_check
= 1; /* do ISSIG */
1192 /* Move the thread from wait queue to run queue */
1196 if (ISWAKEABLE(t
)) {
1197 if (t
->t_wchan0
== NULL
)
1199 else if (!VSTOPPED(t
)) {
1201 * Mark it virtually stopped.
1203 t
->t_proc_flag
|= TP_PRVSTOP
;
1208 * force the thread into the kernel
1209 * if it is not already there.
1214 (vp
= p
->p_lwpdir
[t
->t_dslot
].ld_entry
->le_trace
) != NULL
)
1216 if (pcp
->prc_flags
& PRC_LWP
)
1218 } while ((t
= t
->t_forw
) != p
->p_tlist
);
1221 * We do this just in case the thread we asked
1222 * to stop is in holdlwps() (called from cfork()).
1224 cv_broadcast(&p
->p_holdlwps
);
1228 * Sleep until the lwp stops, but cooperate with
1229 * jobcontrol: Don't wake up if the lwp is stopped
1230 * due to the default action of a jobcontrol stop signal.
1231 * If this is the process file descriptor, sleep
1232 * until all of the process's lwps stop.
1235 pr_wait_stop(prnode_t
*pnp
, time_t timeo
)
1237 prcommon_t
*pcp
= pnp
->pr_common
;
1238 proc_t
*p
= pcp
->prc_proc
;
1240 timestruc_t
*rqtp
= NULL
;
1245 if (timeo
> 0) { /* millisecond timeout */
1247 * Determine the precise future time of the requested timeout.
1251 timecheck
= timechanged
;
1254 rqtp
->tv_sec
= timeo
/ MILLISEC
;
1255 rqtp
->tv_nsec
= (timeo
% MILLISEC
) * MICROSEC
;
1256 timespecadd(rqtp
, &now
);
1259 if (pcp
->prc_flags
& PRC_LWP
) { /* lwp file descriptor */
1260 t
= pcp
->prc_thread
;
1263 while (!ISTOPPED(t
) && !VSTOPPED(t
)) {
1265 mutex_enter(&pcp
->prc_mutex
);
1267 error
= pr_wait(pcp
, rqtp
, timecheck
);
1268 if (error
) /* -1 is timeout */
1270 if ((error
= prlock(pnp
, ZNO
)) != 0)
1272 ASSERT(p
== pcp
->prc_proc
);
1273 ASSERT(t
== pcp
->prc_thread
);
1277 } else { /* process file descriptor */
1278 t
= prchoose(p
); /* returns locked thread */
1280 ASSERT(MUTEX_HELD(&p
->p_lock
));
1281 while ((!ISTOPPED(t
) && !VSTOPPED(t
) && !SUSPENDED(t
)) ||
1282 (p
->p_flag
& SEXITLWPS
)) {
1284 mutex_enter(&pcp
->prc_mutex
);
1286 error
= pr_wait(pcp
, rqtp
, timecheck
);
1287 if (error
) /* -1 is timeout */
1289 if ((error
= prlock(pnp
, ZNO
)) != 0)
1291 ASSERT(p
== pcp
->prc_proc
);
1292 t
= prchoose(p
); /* returns locked t */
1298 ASSERT(!(pcp
->prc_flags
& PRC_DESTROY
) && p
->p_stat
!= SZOMB
&&
1299 t
!= NULL
&& t
->t_state
!= TS_ZOMB
);
1305 pr_setrun(prnode_t
*pnp
, ulong_t flags
)
1307 prcommon_t
*pcp
= pnp
->pr_common
;
1308 proc_t
*p
= pcp
->prc_proc
;
1313 * Cannot set an lwp running if it is not stopped.
1314 * Also, no lwp other than the /proc agent lwp can
1315 * be set running so long as the /proc agent lwp exists.
1317 t
= pr_thread(pnp
); /* returns locked thread */
1318 if ((!ISTOPPED(t
) && !VSTOPPED(t
) &&
1319 !(t
->t_proc_flag
& TP_PRSTOP
)) ||
1320 (p
->p_agenttp
!= NULL
&&
1321 (t
!= p
->p_agenttp
|| !(pcp
->prc_flags
& PRC_LWP
)))) {
1326 if (flags
& ~(PRCSIG
|PRCFAULT
|PRSTEP
|PRSTOP
|PRSABORT
))
1329 if ((flags
& PRCSIG
) && lwp
->lwp_cursig
!= SIGKILL
) {
1331 * Discard current siginfo_t, if any.
1333 lwp
->lwp_cursig
= 0;
1334 lwp
->lwp_extsig
= 0;
1335 if (lwp
->lwp_curinfo
) {
1336 siginfofree(lwp
->lwp_curinfo
);
1337 lwp
->lwp_curinfo
= NULL
;
1340 if (flags
& PRCFAULT
)
1341 lwp
->lwp_curflt
= 0;
1343 * We can't hold p->p_lock when we touch the lwp's registers.
1344 * It may be swapped out and we will get a page fault.
1346 if (flags
& PRSTEP
) {
1347 mutex_exit(&p
->p_lock
);
1349 mutex_enter(&p
->p_lock
);
1351 if (flags
& PRSTOP
) {
1352 t
->t_proc_flag
|= TP_PRSTOP
;
1353 t
->t_sig_check
= 1; /* do ISSIG */
1355 if (flags
& PRSABORT
)
1356 lwp
->lwp_sysabort
= 1;
1358 if ((pcp
->prc_flags
& PRC_LWP
) || (flags
& (PRSTEP
|PRSTOP
))) {
1360 * Here, we are dealing with a single lwp.
1363 t
->t_schedflag
|= TS_PSTART
;
1364 t
->t_dtrace_stop
= 0;
1366 } else if (flags
& PRSABORT
) {
1368 ~(TP_PRSTOP
|TP_PRVSTOP
|TP_STOPPING
);
1370 } else if (!(flags
& PRSTOP
)) {
1372 ~(TP_PRSTOP
|TP_PRVSTOP
|TP_STOPPING
);
1377 * Here, we are dealing with the whole process.
1381 * The representative lwp is stopped on an event
1382 * of interest. We demote it to PR_REQUESTED and
1383 * choose another representative lwp. If the new
1384 * representative lwp is not stopped on an event of
1385 * interest (other than PR_REQUESTED), we set the
1386 * whole process running, else we leave the process
1387 * stopped showing the next event of interest.
1389 kthread_t
*tx
= NULL
;
1391 if (!(flags
& PRSABORT
) &&
1392 t
->t_whystop
== PR_SYSENTRY
&&
1393 t
->t_whatstop
== SYS_lwp_exit
)
1394 tx
= t
; /* remember the exiting lwp */
1395 t
->t_whystop
= PR_REQUESTED
;
1398 t
= prchoose(p
); /* returns locked t */
1399 ASSERT(ISTOPPED(t
) || VSTOPPED(t
));
1401 t
->t_whystop
== PR_REQUESTED
) {
1407 * As a special case, if the old representative
1408 * lwp was stopped on entry to _lwp_exit()
1409 * (and we are not aborting the system call),
1410 * we set the old representative lwp running.
1411 * We do this so that the next process stop
1412 * will find the exiting lwp gone.
1416 tx
->t_schedflag
|= TS_PSTART
;
1417 t
->t_dtrace_stop
= 0;
1424 * No event of interest; set all of the lwps running.
1426 if (flags
& PRSABORT
) {
1428 ~(TP_PRSTOP
|TP_PRVSTOP
|TP_STOPPING
);
1439 * Wait until process/lwp stops or until timer expires.
1440 * Return EINTR for an interruption, -1 for timeout, else 0.
1443 pr_wait(prcommon_t
*pcp
, /* prcommon referring to process/lwp */
1444 timestruc_t
*ts
, /* absolute time of timeout, if any */
1449 ASSERT(MUTEX_HELD(&pcp
->prc_mutex
));
1450 rval
= cv_waituntil_sig(&pcp
->prc_wait
, &pcp
->prc_mutex
, ts
, timecheck
);
1451 mutex_exit(&pcp
->prc_mutex
);
1463 * Make all threads in the process runnable.
1466 allsetrun(proc_t
*p
)
1470 ASSERT(MUTEX_HELD(&p
->p_lock
));
1472 if ((t
= p
->p_tlist
) != NULL
) {
1475 ASSERT(!(t
->t_proc_flag
& TP_LWPEXIT
));
1476 t
->t_proc_flag
&= ~(TP_PRSTOP
|TP_PRVSTOP
|TP_STOPPING
);
1478 t
->t_schedflag
|= TS_PSTART
;
1479 t
->t_dtrace_stop
= 0;
1483 } while ((t
= t
->t_forw
) != p
->p_tlist
);
1488 * Wait for the process to die.
1489 * We do this after sending SIGKILL because we know it will
1490 * die soon and we want subsequent operations to return ENOENT.
1493 pr_wait_die(prnode_t
*pnp
)
1497 mutex_enter(&pidlock
);
1498 while ((p
= pnp
->pr_common
->prc_proc
) != NULL
&& p
->p_stat
!= SZOMB
) {
1499 if (!cv_wait_sig(&p
->p_srwchan_cv
, &pidlock
))
1502 mutex_exit(&pidlock
);
1506 pr_settrace(proc_t
*p
, sigset_t
*sp
)
1508 prdelset(sp
, SIGKILL
);
1509 prassignset(&p
->p_sigmask
, sp
);
1510 if (!sigisempty(&p
->p_sigmask
))
1511 p
->p_proc_flag
|= P_PR_TRACE
;
1512 else if (prisempty(&p
->p_fltmask
)) {
1513 user_t
*up
= PTOU(p
);
1514 if (up
->u_systrap
== 0)
1515 p
->p_proc_flag
&= ~P_PR_TRACE
;
1520 pr_setsig(prnode_t
*pnp
, siginfo_t
*sip
)
1522 int nsig
= PROC_IS_BRANDED(curproc
)? BROP(curproc
)->b_nsig
: NSIG
;
1523 int sig
= sip
->si_signo
;
1524 prcommon_t
*pcp
= pnp
->pr_common
;
1525 proc_t
*p
= pcp
->prc_proc
;
1530 t
= pr_thread(pnp
); /* returns locked thread */
1533 if (sig
< 0 || sig
>= nsig
)
1534 /* Zero allowed here */
1536 else if (lwp
->lwp_cursig
== SIGKILL
)
1537 /* "can't happen", but just in case */
1539 else if ((lwp
->lwp_cursig
= (uchar_t
)sig
) == 0) {
1540 lwp
->lwp_extsig
= 0;
1542 * Discard current siginfo_t, if any.
1544 if (lwp
->lwp_curinfo
) {
1545 siginfofree(lwp
->lwp_curinfo
);
1546 lwp
->lwp_curinfo
= NULL
;
1552 /* drop p_lock to do kmem_alloc(KM_SLEEP) */
1553 mutex_exit(&p
->p_lock
);
1554 sqp
= kmem_zalloc(sizeof (sigqueue_t
), KM_SLEEP
);
1555 mutex_enter(&p
->p_lock
);
1557 if (lwp
->lwp_curinfo
== NULL
)
1558 lwp
->lwp_curinfo
= sqp
;
1560 kmem_free(sqp
, sizeof (sigqueue_t
));
1562 * Copy contents of info to current siginfo_t.
1564 bcopy(sip
, &lwp
->lwp_curinfo
->sq_info
,
1565 sizeof (lwp
->lwp_curinfo
->sq_info
));
1567 * Prevent contents published by si_zoneid-unaware /proc
1568 * consumers from being incorrectly filtered. Because
1569 * an uninitialized si_zoneid is the same as
1570 * GLOBAL_ZONEID, this means that you can't pr_setsig a
1571 * process in a non-global zone with a siginfo which
1572 * appears to come from the global zone.
1574 if (SI_FROMUSER(sip
) && sip
->si_zoneid
== 0)
1575 lwp
->lwp_curinfo
->sq_info
.si_zoneid
=
1578 * Side-effects for SIGKILL and jobcontrol signals.
1580 if (sig
== SIGKILL
) {
1581 p
->p_flag
|= SKILLED
;
1582 p
->p_flag
&= ~SEXTKILLED
;
1583 } else if (sig
== SIGCONT
) {
1584 p
->p_flag
|= SSCONT
;
1585 sigdelq(p
, NULL
, SIGSTOP
);
1586 sigdelq(p
, NULL
, SIGTSTP
);
1587 sigdelq(p
, NULL
, SIGTTOU
);
1588 sigdelq(p
, NULL
, SIGTTIN
);
1589 sigdiffset(&p
->p_sig
, &stopdefault
);
1590 sigdiffset(&p
->p_extsig
, &stopdefault
);
1591 if ((tx
= p
->p_tlist
) != NULL
) {
1593 sigdelq(p
, tx
, SIGSTOP
);
1594 sigdelq(p
, tx
, SIGTSTP
);
1595 sigdelq(p
, tx
, SIGTTOU
);
1596 sigdelq(p
, tx
, SIGTTIN
);
1597 sigdiffset(&tx
->t_sig
, &stopdefault
);
1598 sigdiffset(&tx
->t_extsig
, &stopdefault
);
1599 } while ((tx
= tx
->t_forw
) != p
->p_tlist
);
1601 } else if (sigismember(&stopdefault
, sig
)) {
1602 if (PTOU(p
)->u_signal
[sig
-1] == SIG_DFL
&&
1603 (sig
== SIGSTOP
|| !p
->p_pgidp
->pid_pgorphaned
))
1604 p
->p_flag
&= ~SSCONT
;
1605 sigdelq(p
, NULL
, SIGCONT
);
1606 sigdelset(&p
->p_sig
, SIGCONT
);
1607 sigdelset(&p
->p_extsig
, SIGCONT
);
1608 if ((tx
= p
->p_tlist
) != NULL
) {
1610 sigdelq(p
, tx
, SIGCONT
);
1611 sigdelset(&tx
->t_sig
, SIGCONT
);
1612 sigdelset(&tx
->t_extsig
, SIGCONT
);
1613 } while ((tx
= tx
->t_forw
) != p
->p_tlist
);
1617 if (ISWAKEABLE(t
) || ISWAITING(t
)) {
1618 /* Set signaled sleeping/waiting lwp running */
1620 } else if (t
->t_state
== TS_STOPPED
&& sig
== SIGKILL
) {
1621 /* If SIGKILL, set stopped lwp running */
1623 t
->t_schedflag
|= TS_XSTART
| TS_PSTART
;
1624 t
->t_dtrace_stop
= 0;
1627 t
->t_sig_check
= 1; /* so ISSIG will be done */
1630 * More jobcontrol side-effects.
1632 if (sig
== SIGCONT
&& (tx
= p
->p_tlist
) != NULL
) {
1636 if (tx
->t_state
== TS_STOPPED
&&
1637 tx
->t_whystop
== PR_JOBCONTROL
) {
1638 tx
->t_schedflag
|= TS_XSTART
;
1642 } while ((tx
= tx
->t_forw
) != p
->p_tlist
);
1649 pr_kill(prnode_t
*pnp
, int sig
, cred_t
*cr
)
1651 int nsig
= PROC_IS_BRANDED(curproc
)? BROP(curproc
)->b_nsig
: NSIG
;
1652 prcommon_t
*pcp
= pnp
->pr_common
;
1653 proc_t
*p
= pcp
->prc_proc
;
1656 if (sig
<= 0 || sig
>= nsig
)
1659 bzero(&info
, sizeof (info
));
1660 info
.si_signo
= sig
;
1661 info
.si_code
= SI_USER
;
1662 info
.si_pid
= curproc
->p_pid
;
1663 info
.si_ctid
= PRCTID(curproc
);
1664 info
.si_zoneid
= getzoneid();
1665 info
.si_uid
= crgetruid(cr
);
1666 sigaddq(p
, (pcp
->prc_flags
& PRC_LWP
)?
1667 pcp
->prc_thread
: NULL
, &info
, KM_NOSLEEP
);
1673 pr_unkill(prnode_t
*pnp
, int sig
)
1675 int nsig
= PROC_IS_BRANDED(curproc
)? BROP(curproc
)->b_nsig
: NSIG
;
1676 prcommon_t
*pcp
= pnp
->pr_common
;
1677 proc_t
*p
= pcp
->prc_proc
;
1678 sigqueue_t
*infop
= NULL
;
1680 if (sig
<= 0 || sig
>= nsig
|| sig
== SIGKILL
)
1683 if (pcp
->prc_flags
& PRC_LWP
)
1684 sigdeq(p
, pcp
->prc_thread
, sig
, &infop
);
1686 sigdeq(p
, NULL
, sig
, &infop
);
1695 pr_nice(proc_t
*p
, int nice
, cred_t
*cr
)
1703 ASSERT(!(t
->t_proc_flag
& TP_LWPEXIT
));
1704 err
= CL_DONICE(t
, cr
, nice
, (int *)NULL
);
1705 schedctl_set_cidpri(t
);
1708 } while ((t
= t
->t_forw
) != p
->p_tlist
);
1714 pr_setentryexit(proc_t
*p
, sysset_t
*sysset
, int entry
)
1716 user_t
*up
= PTOU(p
);
1719 prassignset(&up
->u_entrymask
, sysset
);
1721 prassignset(&up
->u_exitmask
, sysset
);
1723 if (!prisempty(&up
->u_entrymask
) ||
1724 !prisempty(&up
->u_exitmask
)) {
1726 p
->p_proc_flag
|= P_PR_TRACE
;
1727 set_proc_sys(p
); /* set pre and post-sys flags */
1730 if (sigisempty(&p
->p_sigmask
) &&
1731 prisempty(&p
->p_fltmask
))
1732 p
->p_proc_flag
&= ~P_PR_TRACE
;
1737 (PR_FORK|PR_RLC|PR_KLC|PR_ASYNC|PR_BPTADJ|PR_MSACCT|PR_MSFORK|PR_PTRACE)
1740 pr_set(proc_t
*p
, long flags
)
1742 if ((p
->p_flag
& SSYS
) || p
->p_as
== &kas
)
1745 if (flags
& ~ALLFLAGS
)
1748 if (flags
& PR_FORK
)
1749 p
->p_proc_flag
|= P_PR_FORK
;
1751 p
->p_proc_flag
|= P_PR_RUNLCL
;
1753 p
->p_proc_flag
|= P_PR_KILLCL
;
1754 if (flags
& PR_ASYNC
)
1755 p
->p_proc_flag
|= P_PR_ASYNC
;
1756 if (flags
& PR_BPTADJ
)
1757 p
->p_proc_flag
|= P_PR_BPTADJ
;
1758 if (flags
& PR_MSACCT
)
1759 if ((p
->p_flag
& SMSACCT
) == 0)
1760 estimate_msacct(p
->p_tlist
, gethrtime());
1761 if (flags
& PR_MSFORK
)
1762 p
->p_flag
|= SMSFORK
;
1763 if (flags
& PR_PTRACE
) {
1764 p
->p_proc_flag
|= P_PR_PTRACE
;
1765 /* ptraced process must die if parent dead */
1767 sigtoproc(p
, NULL
, SIGKILL
);
1774 pr_unset(proc_t
*p
, long flags
)
1776 if ((p
->p_flag
& SSYS
) || p
->p_as
== &kas
)
1779 if (flags
& ~ALLFLAGS
)
1782 if (flags
& PR_FORK
)
1783 p
->p_proc_flag
&= ~P_PR_FORK
;
1785 p
->p_proc_flag
&= ~P_PR_RUNLCL
;
1787 p
->p_proc_flag
&= ~P_PR_KILLCL
;
1788 if (flags
& PR_ASYNC
)
1789 p
->p_proc_flag
&= ~P_PR_ASYNC
;
1790 if (flags
& PR_BPTADJ
)
1791 p
->p_proc_flag
&= ~P_PR_BPTADJ
;
1792 if (flags
& PR_MSACCT
)
1794 if (flags
& PR_MSFORK
)
1795 p
->p_flag
&= ~SMSFORK
;
1796 if (flags
& PR_PTRACE
)
1797 p
->p_proc_flag
&= ~P_PR_PTRACE
;
1803 pr_setfpregs(prnode_t
*pnp
, prfpregset_t
*prfpregset
)
1805 proc_t
*p
= pnp
->pr_common
->prc_proc
;
1806 kthread_t
*t
= pr_thread(pnp
); /* returns locked thread */
1808 if (!ISTOPPED(t
) && !VSTOPPED(t
) && !DSTOPPED(t
)) {
1814 return (EINVAL
); /* No FP support */
1817 /* drop p_lock while touching the lwp's stack */
1819 mutex_exit(&p
->p_lock
);
1820 prsetprfpregs(ttolwp(t
), prfpregset
);
1821 mutex_enter(&p
->p_lock
);
1826 #ifdef _SYSCALL32_IMPL
1828 pr_setfpregs32(prnode_t
*pnp
, prfpregset32_t
*prfpregset
)
1830 proc_t
*p
= pnp
->pr_common
->prc_proc
;
1831 kthread_t
*t
= pr_thread(pnp
); /* returns locked thread */
1833 if (!ISTOPPED(t
) && !VSTOPPED(t
) && !DSTOPPED(t
)) {
1839 return (EINVAL
); /* No FP support */
1842 /* drop p_lock while touching the lwp's stack */
1844 mutex_exit(&p
->p_lock
);
1845 prsetprfpregs32(ttolwp(t
), prfpregset
);
1846 mutex_enter(&p
->p_lock
);
1850 #endif /* _SYSCALL32_IMPL */
1854 pr_setxregs(prnode_t
*pnp
, prxregset_t
*prxregset
)
1857 proc_t
*p
= pnp
->pr_common
->prc_proc
;
1858 kthread_t
*t
= pr_thread(pnp
); /* returns locked thread */
1860 if (!ISTOPPED(t
) && !VSTOPPED(t
) && !DSTOPPED(t
)) {
1867 return (EINVAL
); /* No extra register support */
1869 /* drop p_lock while touching the lwp's stack */
1870 mutex_exit(&p
->p_lock
);
1871 error
= prsetprxregs(ttolwp(t
), prxregset
);
1872 mutex_enter(&p
->p_lock
);
1878 pr_setvaddr(prnode_t
*pnp
, caddr_t vaddr
)
1880 proc_t
*p
= pnp
->pr_common
->prc_proc
;
1881 kthread_t
*t
= pr_thread(pnp
); /* returns locked thread */
1883 if (!ISTOPPED(t
) && !VSTOPPED(t
) && !DSTOPPED(t
)) {
1888 /* drop p_lock while touching the lwp's stack */
1890 mutex_exit(&p
->p_lock
);
1891 prsvaddr(ttolwp(t
), vaddr
);
1892 mutex_enter(&p
->p_lock
);
1898 pr_sethold(prnode_t
*pnp
, sigset_t
*sp
)
1900 proc_t
*p
= pnp
->pr_common
->prc_proc
;
1901 kthread_t
*t
= pr_thread(pnp
); /* returns locked thread */
1903 schedctl_finish_sigblock(t
);
1904 sigutok(sp
, &t
->t_hold
);
1905 if (ISWAKEABLE(t
) &&
1906 (fsig(&p
->p_sig
, t
) || fsig(&t
->t_sig
, t
)))
1908 t
->t_sig_check
= 1; /* so thread will see new holdmask */
1913 pr_setfault(proc_t
*p
, fltset_t
*fltp
)
1915 prassignset(&p
->p_fltmask
, fltp
);
1916 if (!prisempty(&p
->p_fltmask
))
1917 p
->p_proc_flag
|= P_PR_TRACE
;
1918 else if (sigisempty(&p
->p_sigmask
)) {
1919 user_t
*up
= PTOU(p
);
1920 if (up
->u_systrap
== 0)
1921 p
->p_proc_flag
&= ~P_PR_TRACE
;
1926 pr_clearsig(prnode_t
*pnp
)
1928 kthread_t
*t
= pr_thread(pnp
); /* returns locked thread */
1929 klwp_t
*lwp
= ttolwp(t
);
1932 if (lwp
->lwp_cursig
== SIGKILL
)
1936 * Discard current siginfo_t, if any.
1938 lwp
->lwp_cursig
= 0;
1939 lwp
->lwp_extsig
= 0;
1940 if (lwp
->lwp_curinfo
) {
1941 siginfofree(lwp
->lwp_curinfo
);
1942 lwp
->lwp_curinfo
= NULL
;
1949 pr_clearflt(prnode_t
*pnp
)
1951 kthread_t
*t
= pr_thread(pnp
); /* returns locked thread */
1954 ttolwp(t
)->lwp_curflt
= 0;
1960 pr_watch(prnode_t
*pnp
, prwatch_t
*pwp
, int *unlocked
)
1962 proc_t
*p
= pnp
->pr_common
->prc_proc
;
1963 struct as
*as
= p
->p_as
;
1964 uintptr_t vaddr
= pwp
->pr_vaddr
;
1965 size_t size
= pwp
->pr_size
;
1966 int wflags
= pwp
->pr_wflags
;
1967 ulong_t newpage
= 0;
1968 struct watched_area
*pwa
;
1974 * Can't apply to a system process.
1976 if ((p
->p_flag
& SSYS
) || p
->p_as
== &kas
)
1980 * Verify that the address range does not wrap
1981 * and that only the proper flags were specified.
1983 if ((wflags
& ~WA_TRAPAFTER
) == 0)
1985 if (vaddr
+ size
< vaddr
||
1986 (wflags
& ~(WA_READ
|WA_WRITE
|WA_EXEC
|WA_TRAPAFTER
)) != 0 ||
1987 ((wflags
& ~WA_TRAPAFTER
) != 0 && size
== 0))
1991 * Don't let the address range go above as->a_userlimit.
1992 * There is no error here, just a limitation.
1994 if (vaddr
>= (uintptr_t)as
->a_userlimit
)
1996 if (vaddr
+ size
> (uintptr_t)as
->a_userlimit
)
1997 size
= (uintptr_t)as
->a_userlimit
- vaddr
;
2000 * Compute maximum number of pages this will add.
2002 if ((wflags
& ~WA_TRAPAFTER
) != 0) {
2003 ulong_t pagespan
= (vaddr
+ size
) - (vaddr
& PAGEMASK
);
2004 newpage
= btopr(pagespan
);
2005 if (newpage
> 2 * prnwatch
)
2010 * Force the process to be fully stopped.
2014 while (holdwatch() != 0)
2016 if ((error
= prlock(pnp
, ZNO
)) != 0) {
2023 while (pr_allstopped(p
, 0) > 0) {
2025 * This cv/mutex pair is persistent even
2026 * if the process disappears after we
2027 * unmark it and drop p->p_lock.
2029 kcondvar_t
*cv
= &pr_pid_cv
[p
->p_slot
];
2030 kmutex_t
*mp
= &p
->p_lock
;
2033 (void) cv_wait(cv
, mp
);
2035 if ((error
= prlock(pnp
, ZNO
)) != 0) {
2037 * Unpause the process if it exists.
2040 mutex_exit(&pr_pidlock
);
2052 * Drop p->p_lock in order to perform the rest of this.
2053 * The process is still locked with the P_PR_LOCK flag.
2055 mutex_exit(&p
->p_lock
);
2057 pwa
= kmem_alloc(sizeof (struct watched_area
), KM_SLEEP
);
2058 pwa
->wa_vaddr
= (caddr_t
)vaddr
;
2059 pwa
->wa_eaddr
= (caddr_t
)vaddr
+ size
;
2060 pwa
->wa_flags
= (ulong_t
)wflags
;
2062 error
= ((pwa
->wa_flags
& ~WA_TRAPAFTER
) == 0)?
2063 clear_watched_area(p
, pwa
) : set_watched_area(p
, pwa
);
2067 mutex_enter(&p
->p_lock
);
2070 mutex_enter(&p
->p_lock
);
2077 /* jobcontrol stopped, but with a /proc directed stop in effect */
2078 #define JDSTOPPED(t) \
2079 ((t)->t_state == TS_STOPPED && \
2080 (t)->t_whystop == PR_JOBCONTROL && \
2081 ((t)->t_proc_flag & TP_PRSTOP))
2084 * pr_agent() creates the agent lwp. If the process is exiting while
2085 * we are creating an agent lwp, then exitlwps() waits until the
2086 * agent has been created using prbarrier().
2089 pr_agent(prnode_t
*pnp
, prgregset_t prgregset
, int *unlocked
)
2091 proc_t
*p
= pnp
->pr_common
->prc_proc
;
2104 * Cannot create the /proc agent lwp if :-
2105 * - the process is not fully stopped or directed to stop.
2106 * - there is an agent lwp already.
2107 * - the process has been killed.
2108 * - the process is exiting.
2109 * - it's a vfork(2) parent.
2111 t
= prchoose(p
); /* returns locked thread */
2114 if ((!ISTOPPED(t
) && !VSTOPPED(t
) && !SUSPENDED(t
) && !JDSTOPPED(t
)) ||
2115 p
->p_agenttp
!= NULL
||
2116 (p
->p_flag
& (SKILLED
| SEXITING
| SVFWAIT
))) {
2122 mutex_exit(&p
->p_lock
);
2125 sigdiffset(&smask
, &cantmask
);
2126 clwp
= lwp_create(lwp_rtt
, NULL
, 0, p
, TS_STOPPED
,
2127 t
->t_pri
, &smask
, NOCLASS
, 0);
2129 mutex_enter(&p
->p_lock
);
2132 prsetprregs(clwp
, prgregset
, 1);
2135 * Because abandoning the agent inside the target process leads to
2136 * a state that is essentially undebuggable, we record the psinfo of
2137 * the process creating the agent and hang that off of the lwp.
2139 clwp
->lwp_spymaster
= kmem_zalloc(sizeof (psinfo_t
), KM_SLEEP
);
2140 mutex_enter(&curproc
->p_lock
);
2141 prgetpsinfo(curproc
, clwp
->lwp_spymaster
);
2142 mutex_exit(&curproc
->p_lock
);
2145 * We overload pr_time in the spymaster to denote the time at which the
2146 * agent was created.
2148 gethrestime(&clwp
->lwp_spymaster
->pr_time
);
2152 (void) CL_ALLOC(&bufp
, cid
, KM_SLEEP
);
2153 mutex_enter(&p
->p_lock
);
2154 if (cid
!= t
->t_cid
) {
2156 * Someone just changed this thread's scheduling class,
2157 * so try pre-allocating the buffer again. Hopefully we
2158 * don't hit this often.
2160 mutex_exit(&p
->p_lock
);
2165 clwp
->lwp_ap
= clwp
->lwp_arg
;
2166 clwp
->lwp_eosys
= NORMALRETURN
;
2168 ct
->t_clfuncs
= t
->t_clfuncs
;
2169 CL_FORK(t
, ct
, bufp
);
2170 ct
->t_cid
= t
->t_cid
;
2171 ct
->t_proc_flag
|= TP_PRSTOP
;
2173 * Setting t_sysnum to zero causes post_syscall()
2174 * to bypass all syscall checks and go directly to
2175 * if (issig()) psig();
2176 * so that the agent lwp will stop in issig_forreal()
2177 * showing PR_REQUESTED.
2181 ct
->t_sig_check
= 1;
2183 ct
->t_proc_flag
&= ~TP_HOLDLWP
;
2185 pcp
= pnp
->pr_pcommon
;
2186 mutex_enter(&pcp
->prc_mutex
);
2188 lwp_create_done(ct
);
2191 * Don't return until the agent is stopped on PR_REQUESTED.
2199 * Wait for the agent to stop and notify us.
2200 * If we've been interrupted, return that information.
2202 error
= pr_wait(pcp
, NULL
, 0);
2203 if (error
== EINTR
) {
2209 * Confirm that the agent LWP has stopped.
2212 if ((error
= prlock(pnp
, ZNO
)) != 0)
2217 * Since we dropped the lock on the process, the agent
2218 * may have disappeared or changed. Grab the current
2219 * agent and check fail if it has disappeared.
2221 if ((ct
= p
->p_agenttp
) == NULL
) {
2226 mutex_enter(&pcp
->prc_mutex
);
2231 mutex_exit(&pcp
->prc_mutex
);
2238 return (error
? error
: -1);
2242 pr_rdwr(proc_t
*p
, enum uio_rw rw
, priovec_t
*pio
)
2244 caddr_t base
= (caddr_t
)pio
->pio_base
;
2245 size_t cnt
= pio
->pio_len
;
2246 uintptr_t offset
= (uintptr_t)pio
->pio_offset
;
2251 if ((p
->p_flag
& SSYS
) || p
->p_as
== &kas
)
2253 else if ((base
+ cnt
) < base
|| (offset
+ cnt
) < offset
)
2255 else if (cnt
!= 0) {
2256 aiov
.iov_base
= base
;
2259 auio
.uio_loffset
= offset
;
2260 auio
.uio_iov
= &aiov
;
2261 auio
.uio_iovcnt
= 1;
2262 auio
.uio_resid
= cnt
;
2263 auio
.uio_segflg
= UIO_USERSPACE
;
2264 auio
.uio_llimit
= (longlong_t
)MAXOFFSET_T
;
2265 auio
.uio_fmode
= FREAD
|FWRITE
;
2266 auio
.uio_extflg
= UIO_COPY_DEFAULT
;
2268 mutex_exit(&p
->p_lock
);
2269 error
= prusrio(p
, rw
, &auio
, 0);
2270 mutex_enter(&p
->p_lock
);
2273 * We have no way to return the i/o count,
2274 * like read() or write() would do, so we
2275 * return an error if the i/o was truncated.
2277 if (auio
.uio_resid
!= 0 && error
== 0)
2285 pr_scred(proc_t
*p
, prcred_t
*prcred
, cred_t
*cr
, boolean_t dogrps
)
2292 zone_t
*zone
= crgetzone(cr
);
2294 if (!VALID_UID(prcred
->pr_euid
, zone
) ||
2295 !VALID_UID(prcred
->pr_ruid
, zone
) ||
2296 !VALID_UID(prcred
->pr_suid
, zone
) ||
2297 !VALID_GID(prcred
->pr_egid
, zone
) ||
2298 !VALID_GID(prcred
->pr_rgid
, zone
) ||
2299 !VALID_GID(prcred
->pr_sgid
, zone
))
2303 int ngrp
= prcred
->pr_ngroups
;
2306 if (ngrp
< 0 || ngrp
> ngroups_max
)
2309 for (i
= 0; i
< ngrp
; i
++) {
2310 if (!VALID_GID(prcred
->pr_groups
[i
], zone
))
2315 error
= secpolicy_allow_setid(cr
, prcred
->pr_euid
, B_FALSE
);
2317 if (error
== 0 && prcred
->pr_ruid
!= prcred
->pr_euid
)
2318 error
= secpolicy_allow_setid(cr
, prcred
->pr_ruid
, B_FALSE
);
2320 if (error
== 0 && prcred
->pr_suid
!= prcred
->pr_euid
&&
2321 prcred
->pr_suid
!= prcred
->pr_ruid
)
2322 error
= secpolicy_allow_setid(cr
, prcred
->pr_suid
, B_FALSE
);
2327 mutex_exit(&p
->p_lock
);
2329 /* hold old cred so it doesn't disappear while we dup it */
2330 mutex_enter(&p
->p_crlock
);
2331 crhold(oldcred
= p
->p_cred
);
2332 mutex_exit(&p
->p_crlock
);
2333 newcred
= crdup(oldcred
);
2334 oldruid
= crgetruid(oldcred
);
2337 /* Error checking done above */
2338 (void) crsetresuid(newcred
, prcred
->pr_ruid
, prcred
->pr_euid
,
2340 (void) crsetresgid(newcred
, prcred
->pr_rgid
, prcred
->pr_egid
,
2344 (void) crsetgroups(newcred
, prcred
->pr_ngroups
,
2349 mutex_enter(&p
->p_crlock
);
2350 oldcred
= p
->p_cred
;
2351 p
->p_cred
= newcred
;
2352 mutex_exit(&p
->p_crlock
);
2356 * Keep count of processes per uid consistent.
2358 if (oldruid
!= prcred
->pr_ruid
) {
2359 zoneid_t zoneid
= crgetzoneid(newcred
);
2361 mutex_enter(&pidlock
);
2362 upcount_dec(oldruid
, zoneid
);
2363 upcount_inc(prcred
->pr_ruid
, zoneid
);
2364 mutex_exit(&pidlock
);
2368 * Broadcast the cred change to the threads.
2370 mutex_enter(&p
->p_lock
);
2373 t
->t_pre_sys
= 1; /* so syscall will get new cred */
2374 } while ((t
= t
->t_forw
) != p
->p_tlist
);
2380 * Change process credentials to specified zone. Used to temporarily
2381 * set a process to run in the global zone; only transitions between
2382 * the process's actual zone and the global zone are allowed.
2385 pr_szoneid(proc_t
*p
, zoneid_t zoneid
, cred_t
*cr
)
2393 if (secpolicy_zone_config(cr
) != 0)
2395 if (zoneid
!= GLOBAL_ZONEID
&& zoneid
!= p
->p_zone
->zone_id
)
2397 if ((zptr
= zone_find_by_id(zoneid
)) == NULL
)
2399 mutex_exit(&p
->p_lock
);
2400 mutex_enter(&p
->p_crlock
);
2401 oldcred
= p
->p_cred
;
2403 mutex_exit(&p
->p_crlock
);
2404 newcred
= crdup(oldcred
);
2405 oldzoneid
= crgetzoneid(oldcred
);
2408 crsetzone(newcred
, zptr
);
2411 mutex_enter(&p
->p_crlock
);
2412 oldcred
= p
->p_cred
;
2413 p
->p_cred
= newcred
;
2414 mutex_exit(&p
->p_crlock
);
2418 * The target process is changing zones (according to its cred), so
2419 * update the per-zone upcounts, which are based on process creds.
2421 if (oldzoneid
!= zoneid
) {
2422 uid_t ruid
= crgetruid(newcred
);
2424 mutex_enter(&pidlock
);
2425 upcount_dec(ruid
, oldzoneid
);
2426 upcount_inc(ruid
, zoneid
);
2427 mutex_exit(&pidlock
);
2430 * Broadcast the cred change to the threads.
2432 mutex_enter(&p
->p_lock
);
2435 t
->t_pre_sys
= 1; /* so syscall will get new cred */
2436 } while ((t
= t
->t_forw
) != p
->p_tlist
);
2442 pr_spriv(proc_t
*p
, prpriv_t
*prpriv
, cred_t
*cr
)
2447 ASSERT(MUTEX_HELD(&p
->p_lock
));
2449 if ((err
= priv_pr_spriv(p
, prpriv
, cr
)) == 0) {
2451 * Broadcast the cred change to the threads.
2455 t
->t_pre_sys
= 1; /* so syscall will get new cred */
2456 } while ((t
= t
->t_forw
) != p
->p_tlist
);
2463 * Return -1 if the process is the parent of a vfork(1) whose child has yet to
2464 * terminate or perform an exec(2).
2466 * Returns 0 if the process is fully stopped except for the current thread (if
2467 * we are operating on our own process), 1 otherwise.
2469 * If the watchstop flag is set, then we ignore threads with TP_WATCHSTOP set.
2470 * See holdwatch() for details.
2473 pr_allstopped(proc_t
*p
, int watchstop
)
2478 ASSERT(MUTEX_HELD(&p
->p_lock
));
2480 if (p
->p_flag
& SVFWAIT
) /* waiting for vfork'd child to exec */
2483 if ((t
= p
->p_tlist
) != NULL
) {
2485 if (t
== curthread
|| VSTOPPED(t
) ||
2486 (watchstop
&& (t
->t_proc_flag
& TP_WATCHSTOP
)))
2489 switch (t
->t_state
) {
2494 if (!(t
->t_flag
& T_WAKEABLE
) ||
2495 t
->t_wchan0
== NULL
)
2503 } while (rv
== 0 && (t
= t
->t_forw
) != p
->p_tlist
);
2510 * Cause all lwps in the process to pause (for watchpoint operations).
2513 pauselwps(proc_t
*p
)
2517 ASSERT(MUTEX_HELD(&p
->p_lock
));
2518 ASSERT(p
!= curproc
);
2520 if ((t
= p
->p_tlist
) != NULL
) {
2523 t
->t_proc_flag
|= TP_PAUSE
;
2525 if ((ISWAKEABLE(t
) && (t
->t_wchan0
== NULL
)) ||
2531 } while ((t
= t
->t_forw
) != p
->p_tlist
);
2536 * undo the effects of pauselwps()
2539 unpauselwps(proc_t
*p
)
2543 ASSERT(MUTEX_HELD(&p
->p_lock
));
2544 ASSERT(p
!= curproc
);
2546 if ((t
= p
->p_tlist
) != NULL
) {
2549 t
->t_proc_flag
&= ~TP_PAUSE
;
2550 if (t
->t_state
== TS_STOPPED
) {
2551 t
->t_schedflag
|= TS_UNPAUSE
;
2552 t
->t_dtrace_stop
= 0;
2556 } while ((t
= t
->t_forw
) != p
->p_tlist
);
2561 * Cancel all watched areas. Called from prclose().
2564 pr_cancel_watch(prnode_t
*pnp
)
2566 proc_t
*p
= pnp
->pr_pcommon
->prc_proc
;
2570 ASSERT(MUTEX_HELD(&p
->p_lock
) && (p
->p_proc_flag
& P_PR_LOCK
));
2572 if (!pr_watch_active(p
))
2576 * Pause the process before dealing with the watchpoints.
2580 while (holdwatch() != 0)
2583 mutex_exit(&pr_pidlock
);
2584 ASSERT(p
== curproc
);
2587 while (p
!= NULL
&& pr_allstopped(p
, 0) > 0) {
2589 * This cv/mutex pair is persistent even
2590 * if the process disappears after we
2591 * unmark it and drop p->p_lock.
2593 kcondvar_t
*cv
= &pr_pid_cv
[p
->p_slot
];
2594 kmutex_t
*mp
= &p
->p_lock
;
2597 (void) cv_wait(cv
, mp
);
2599 p
= pr_p_lock(pnp
); /* NULL if process disappeared */
2600 mutex_exit(&pr_pidlock
);
2604 if (p
== NULL
) /* the process disappeared */
2607 ASSERT(p
== pnp
->pr_pcommon
->prc_proc
);
2608 ASSERT(MUTEX_HELD(&p
->p_lock
) && (p
->p_proc_flag
& P_PR_LOCK
));
2610 if (pr_watch_active(p
)) {
2611 pr_free_watchpoints(p
);
2612 if ((t
= p
->p_tlist
) != NULL
) {
2616 } while ((t
= t
->t_forw
) != p
->p_tlist
);
2620 if ((as
= p
->p_as
) != NULL
) {
2622 struct watched_page
*pwp
;
2625 * If this is the parent of a vfork, the watched page
2626 * list has been moved temporarily to p->p_wpage.
2628 if (avl_numnodes(&p
->p_wpage
) != 0)
2631 tree
= &as
->a_wpage
;
2633 mutex_exit(&p
->p_lock
);
2634 AS_LOCK_ENTER(as
, RW_WRITER
);
2636 for (pwp
= avl_first(tree
); pwp
!= NULL
;
2637 pwp
= AVL_NEXT(tree
, pwp
)) {
2641 if ((pwp
->wp_flags
& WP_SETPROT
) == 0) {
2642 pwp
->wp_flags
|= WP_SETPROT
;
2643 pwp
->wp_prot
= pwp
->wp_oprot
;
2644 pwp
->wp_list
= p
->p_wprot
;
2650 mutex_enter(&p
->p_lock
);
2654 * Unpause the process now.