Print this page
remove whole-process swapping
Long before Unix supported paging, it used process swapping to reclaim
memory. The code is there and in theory it runs when we get *extremely* low
on memory. In practice, it never runs since the definition of low-on-memory
is antiquated. (XXX: define what antiquated means)
You can check the number of swapout/swapin events with kstats:
$ kstat -p ::vm:swapin ::vm:swapout
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/ia32/os/syscall.c
+++ new/usr/src/uts/intel/ia32/os/syscall.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 #include <sys/param.h>
27 27 #include <sys/vmparam.h>
28 28 #include <sys/types.h>
29 29 #include <sys/sysmacros.h>
30 30 #include <sys/systm.h>
31 31 #include <sys/signal.h>
32 32 #include <sys/stack.h>
33 33 #include <sys/cred.h>
34 34 #include <sys/cmn_err.h>
35 35 #include <sys/user.h>
36 36 #include <sys/privregs.h>
37 37 #include <sys/psw.h>
38 38 #include <sys/debug.h>
39 39 #include <sys/errno.h>
40 40 #include <sys/proc.h>
41 41 #include <sys/modctl.h>
42 42 #include <sys/var.h>
43 43 #include <sys/inline.h>
44 44 #include <sys/syscall.h>
45 45 #include <sys/ucontext.h>
46 46 #include <sys/cpuvar.h>
47 47 #include <sys/siginfo.h>
48 48 #include <sys/trap.h>
49 49 #include <sys/vtrace.h>
50 50 #include <sys/sysinfo.h>
51 51 #include <sys/procfs.h>
52 52 #include <sys/prsystm.h>
53 53 #include <c2/audit.h>
54 54 #include <sys/modctl.h>
55 55 #include <sys/aio_impl.h>
56 56 #include <sys/tnf.h>
57 57 #include <sys/tnf_probe.h>
58 58 #include <sys/copyops.h>
59 59 #include <sys/priv.h>
60 60 #include <sys/msacct.h>
61 61
62 62 int syscalltrace = 0;
63 63 #ifdef SYSCALLTRACE
64 64 static kmutex_t systrace_lock; /* syscall tracing lock */
65 65 #else
66 66 #define syscalltrace 0
67 67 #endif /* SYSCALLTRACE */
68 68
69 69 typedef int64_t (*llfcn_t)(); /* function returning long long */
70 70
71 71 int pre_syscall(void);
72 72 void post_syscall(long rval1, long rval2);
73 73 static krwlock_t *lock_syscall(struct sysent *, uint_t);
74 74 void deferred_singlestep_trap(caddr_t);
75 75
76 76 #ifdef _SYSCALL32_IMPL
77 77 #define LWP_GETSYSENT(lwp) \
78 78 (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE ? sysent : sysent32)
79 79 #else
80 80 #define LWP_GETSYSENT(lwp) (sysent)
81 81 #endif
82 82
83 83 /*
84 84 * If watchpoints are active, don't make copying in of
85 85 * system call arguments take a read watchpoint trap.
86 86 */
87 87 static int
88 88 copyin_args(struct regs *rp, long *ap, uint_t nargs)
89 89 {
90 90 greg_t *sp = 1 + (greg_t *)rp->r_sp; /* skip ret addr */
91 91
92 92 ASSERT(nargs <= MAXSYSARGS);
93 93
94 94 return (copyin_nowatch(sp, ap, nargs * sizeof (*sp)));
95 95 }
96 96
97 97 #if defined(_SYSCALL32_IMPL)
98 98 static int
99 99 copyin_args32(struct regs *rp, long *ap, uint_t nargs)
100 100 {
101 101 greg32_t *sp = 1 + (greg32_t *)rp->r_sp; /* skip ret addr */
102 102 uint32_t a32[MAXSYSARGS];
103 103 int rc;
104 104
105 105 ASSERT(nargs <= MAXSYSARGS);
106 106
107 107 if ((rc = copyin_nowatch(sp, a32, nargs * sizeof (*sp))) == 0) {
108 108 uint32_t *a32p = &a32[0];
109 109
110 110 while (nargs--)
111 111 *ap++ = (ulong_t)*a32p++;
112 112 }
113 113 return (rc);
114 114 }
115 115 #define COPYIN_ARGS32 copyin_args32
116 116 #else
117 117 #define COPYIN_ARGS32 copyin_args
118 118 #endif
119 119
120 120 /*
121 121 * Error handler for system calls where arg copy gets fault.
122 122 */
123 123 static longlong_t
124 124 syscall_err()
125 125 {
126 126 return (0);
127 127 }
128 128
129 129 /*
130 130 * Corresponding sysent entry to allow syscall_entry caller
131 131 * to invoke syscall_err.
132 132 */
133 133 static struct sysent sysent_err = {
134 134 0, SE_32RVAL1, NULL, NULL, (llfcn_t)syscall_err
135 135 };
136 136
137 137 /*
138 138 * Called from syscall() when a non-trivial 32-bit system call occurs.
139 139 * Sets up the args and returns a pointer to the handler.
140 140 */
141 141 struct sysent *
↓ open down ↓ |
141 lines elided |
↑ open up ↑ |
142 142 syscall_entry(kthread_t *t, long *argp)
143 143 {
144 144 klwp_t *lwp = ttolwp(t);
145 145 struct regs *rp = lwptoregs(lwp);
146 146 unsigned int code;
147 147 struct sysent *callp;
148 148 struct sysent *se = LWP_GETSYSENT(lwp);
149 149 int error = 0;
150 150 uint_t nargs;
151 151
152 - ASSERT(t == curthread && curthread->t_schedflag & TS_DONT_SWAP);
152 + ASSERT(t == curthread);
153 153
154 154 lwp->lwp_ru.sysc++;
155 155 lwp->lwp_eosys = NORMALRETURN; /* assume this will be normal */
156 156
157 157 /*
158 158 * Set lwp_ap to point to the args, even if none are needed for this
159 159 * system call. This is for the loadable-syscall case where the
160 160 * number of args won't be known until the system call is loaded, and
161 161 * also maintains a non-NULL lwp_ap setup for get_syscall_args(). Note
162 162 * that lwp_ap MUST be set to a non-NULL value _BEFORE_ t_sysnum is
163 163 * set to non-zero; otherwise get_syscall_args(), seeing a non-zero
164 164 * t_sysnum for this thread, will charge ahead and dereference lwp_ap.
165 165 */
166 166 lwp->lwp_ap = argp; /* for get_syscall_args */
167 167
168 168 code = rp->r_r0;
169 169 t->t_sysnum = (short)code;
170 170 callp = code >= NSYSCALL ? &nosys_ent : se + code;
171 171
172 172 if ((t->t_pre_sys | syscalltrace) != 0) {
173 173 error = pre_syscall();
174 174
175 175 /*
176 176 * pre_syscall() has taken care so that lwp_ap is current;
177 177 * it either points to syscall-entry-saved amd64 regs,
178 178 * or it points to lwp_arg[], which has been re-copied from
179 179 * the ia32 ustack, but either way, it's a current copy after
180 180 * /proc has possibly mucked with the syscall args.
181 181 */
182 182
183 183 if (error)
184 184 return (&sysent_err); /* use dummy handler */
185 185 }
186 186
187 187 /*
188 188 * Fetch the system call arguments to the kernel stack copy used
189 189 * for syscall handling.
190 190 * Note: for loadable system calls the number of arguments required
191 191 * may not be known at this point, and will be zero if the system call
192 192 * was never loaded. Once the system call has been loaded, the number
193 193 * of args is not allowed to be changed.
194 194 */
195 195 if ((nargs = (uint_t)callp->sy_narg) != 0 &&
196 196 COPYIN_ARGS32(rp, argp, nargs)) {
197 197 (void) set_errno(EFAULT);
198 198 return (&sysent_err); /* use dummy handler */
199 199 }
200 200
201 201 return (callp); /* return sysent entry for caller */
202 202 }
203 203
204 204 void
205 205 syscall_exit(kthread_t *t, long rval1, long rval2)
206 206 {
207 207 /*
208 208 * Handle signals and other post-call events if necessary.
209 209 */
210 210 if ((t->t_post_sys_ast | syscalltrace) == 0) {
211 211 klwp_t *lwp = ttolwp(t);
212 212 struct regs *rp = lwptoregs(lwp);
213 213
214 214 /*
215 215 * Normal return.
216 216 * Clear error indication and set return values.
217 217 */
218 218 rp->r_ps &= ~PS_C; /* reset carry bit */
219 219 rp->r_r0 = rval1;
220 220 rp->r_r1 = rval2;
221 221 lwp->lwp_state = LWP_USER;
222 222 } else
223 223 post_syscall(rval1, rval2);
224 224 t->t_sysnum = 0; /* invalidate args */
225 225 }
226 226
227 227 /*
228 228 * Perform pre-system-call processing, including stopping for tracing,
229 229 * auditing, etc.
230 230 *
231 231 * This routine is called only if the t_pre_sys flag is set. Any condition
232 232 * requiring pre-syscall handling must set the t_pre_sys flag. If the
233 233 * condition is persistent, this routine will repost t_pre_sys.
234 234 */
↓ open down ↓ |
72 lines elided |
↑ open up ↑ |
235 235 int
236 236 pre_syscall()
237 237 {
238 238 kthread_t *t = curthread;
239 239 unsigned code = t->t_sysnum;
240 240 klwp_t *lwp = ttolwp(t);
241 241 proc_t *p = ttoproc(t);
242 242 int repost;
243 243
244 244 t->t_pre_sys = repost = 0; /* clear pre-syscall processing flag */
245 -
246 - ASSERT(t->t_schedflag & TS_DONT_SWAP);
247 245
248 246 #if defined(DEBUG)
249 247 /*
250 248 * On the i386 kernel, lwp_ap points at the piece of the thread
251 249 * stack that we copy the users arguments into.
252 250 *
253 251 * On the amd64 kernel, the syscall arguments in the rdi..r9
254 252 * registers should be pointed at by lwp_ap. If the args need to
255 253 * be copied so that those registers can be changed without losing
256 254 * the ability to get the args for /proc, they can be saved by
257 255 * save_syscall_args(), and lwp_ap will be restored by post_syscall().
258 256 */
259 257 if (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE) {
260 258 #if defined(_LP64)
261 259 ASSERT(lwp->lwp_ap == (long *)&lwptoregs(lwp)->r_rdi);
262 260 } else {
263 261 #endif
264 262 ASSERT((caddr_t)lwp->lwp_ap > t->t_stkbase &&
265 263 (caddr_t)lwp->lwp_ap < t->t_stk);
266 264 }
267 265 #endif /* DEBUG */
268 266
269 267 /*
270 268 * Make sure the thread is holding the latest credentials for the
271 269 * process. The credentials in the process right now apply to this
272 270 * thread for the entire system call.
273 271 */
274 272 if (t->t_cred != p->p_cred) {
275 273 cred_t *oldcred = t->t_cred;
276 274 /*
277 275 * DTrace accesses t_cred in probe context. t_cred must
278 276 * always be either NULL, or point to a valid, allocated cred
279 277 * structure.
280 278 */
281 279 t->t_cred = crgetcred();
282 280 crfree(oldcred);
283 281 }
284 282
285 283 /*
286 284 * From the proc(4) manual page:
287 285 * When entry to a system call is being traced, the traced process
288 286 * stops after having begun the call to the system but before the
289 287 * system call arguments have been fetched from the process.
290 288 */
291 289 if (PTOU(p)->u_systrap) {
292 290 if (prismember(&PTOU(p)->u_entrymask, code)) {
293 291 mutex_enter(&p->p_lock);
294 292 /*
295 293 * Recheck stop condition, now that lock is held.
296 294 */
297 295 if (PTOU(p)->u_systrap &&
298 296 prismember(&PTOU(p)->u_entrymask, code)) {
299 297 stop(PR_SYSENTRY, code);
300 298
301 299 /*
302 300 * /proc may have modified syscall args,
303 301 * either in regs for amd64 or on ustack
304 302 * for ia32. Either way, arrange to
305 303 * copy them again, both for the syscall
306 304 * handler and for other consumers in
307 305 * post_syscall (like audit). Here, we
308 306 * only do amd64, and just set lwp_ap
309 307 * back to the kernel-entry stack copy;
310 308 * the syscall ml code redoes
311 309 * move-from-regs to set up for the
312 310 * syscall handler after we return. For
313 311 * ia32, save_syscall_args() below makes
314 312 * an lwp_ap-accessible copy.
315 313 */
316 314 #if defined(_LP64)
317 315 if (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE) {
318 316 lwp->lwp_argsaved = 0;
319 317 lwp->lwp_ap =
320 318 (long *)&lwptoregs(lwp)->r_rdi;
321 319 }
322 320 #endif
323 321 }
324 322 mutex_exit(&p->p_lock);
325 323 }
326 324 repost = 1;
327 325 }
328 326
329 327 /*
330 328 * ia32 kernel, or ia32 proc on amd64 kernel: keep args in
331 329 * lwp_arg for post-syscall processing, regardless of whether
332 330 * they might have been changed in /proc above.
333 331 */
334 332 #if defined(_LP64)
335 333 if (lwp_getdatamodel(lwp) != DATAMODEL_NATIVE)
336 334 #endif
337 335 (void) save_syscall_args();
338 336
339 337 if (lwp->lwp_sysabort) {
340 338 /*
341 339 * lwp_sysabort may have been set via /proc while the process
342 340 * was stopped on PR_SYSENTRY. If so, abort the system call.
343 341 * Override any error from the copyin() of the arguments.
344 342 */
345 343 lwp->lwp_sysabort = 0;
346 344 (void) set_errno(EINTR); /* forces post_sys */
347 345 t->t_pre_sys = 1; /* repost anyway */
348 346 return (1); /* don't do system call, return EINTR */
349 347 }
350 348
351 349 /*
352 350 * begin auditing for this syscall if the c2audit module is loaded
353 351 * and auditing is enabled
354 352 */
355 353 if (audit_active == C2AUDIT_LOADED) {
356 354 uint32_t auditing = au_zone_getstate(NULL);
357 355
358 356 if (auditing & AU_AUDIT_MASK) {
359 357 int error;
360 358 if (error = audit_start(T_SYSCALL, code, auditing, \
361 359 0, lwp)) {
362 360 t->t_pre_sys = 1; /* repost anyway */
363 361 (void) set_errno(error);
364 362 return (1);
365 363 }
366 364 repost = 1;
367 365 }
368 366 }
369 367
370 368 #ifndef NPROBE
371 369 /* Kernel probe */
372 370 if (tnf_tracing_active) {
373 371 TNF_PROBE_1(syscall_start, "syscall thread", /* CSTYLED */,
374 372 tnf_sysnum, sysnum, t->t_sysnum);
375 373 t->t_post_sys = 1; /* make sure post_syscall runs */
376 374 repost = 1;
377 375 }
378 376 #endif /* NPROBE */
379 377
380 378 #ifdef SYSCALLTRACE
381 379 if (syscalltrace) {
382 380 int i;
383 381 long *ap;
384 382 char *cp;
385 383 char *sysname;
386 384 struct sysent *callp;
387 385
388 386 if (code >= NSYSCALL)
389 387 callp = &nosys_ent; /* nosys has no args */
390 388 else
391 389 callp = LWP_GETSYSENT(lwp) + code;
392 390 (void) save_syscall_args();
393 391 mutex_enter(&systrace_lock);
394 392 printf("%d: ", p->p_pid);
395 393 if (code >= NSYSCALL)
396 394 printf("0x%x", code);
397 395 else {
398 396 sysname = mod_getsysname(code);
399 397 printf("%s[0x%x/0x%p]", sysname == NULL ? "NULL" :
400 398 sysname, code, callp->sy_callc);
401 399 }
402 400 cp = "(";
403 401 for (i = 0, ap = lwp->lwp_ap; i < callp->sy_narg; i++, ap++) {
404 402 printf("%s%lx", cp, *ap);
405 403 cp = ", ";
406 404 }
407 405 if (i)
408 406 printf(")");
409 407 printf(" %s id=0x%p\n", PTOU(p)->u_comm, curthread);
410 408 mutex_exit(&systrace_lock);
411 409 }
412 410 #endif /* SYSCALLTRACE */
413 411
414 412 /*
415 413 * If there was a continuing reason for pre-syscall processing,
416 414 * set the t_pre_sys flag for the next system call.
417 415 */
418 416 if (repost)
419 417 t->t_pre_sys = 1;
420 418 lwp->lwp_error = 0; /* for old drivers */
421 419 lwp->lwp_badpriv = PRIV_NONE;
422 420 return (0);
423 421 }
424 422
425 423
426 424 /*
427 425 * Post-syscall processing. Perform abnormal system call completion
428 426 * actions such as /proc tracing, profiling, signals, preemption, etc.
429 427 *
430 428 * This routine is called only if t_post_sys, t_sig_check, or t_astflag is set.
431 429 * Any condition requiring pre-syscall handling must set one of these.
432 430 * If the condition is persistent, this routine will repost t_post_sys.
433 431 */
434 432 void
435 433 post_syscall(long rval1, long rval2)
436 434 {
437 435 kthread_t *t = curthread;
438 436 klwp_t *lwp = ttolwp(t);
439 437 proc_t *p = ttoproc(t);
440 438 struct regs *rp = lwptoregs(lwp);
441 439 uint_t error;
442 440 uint_t code = t->t_sysnum;
443 441 int repost = 0;
444 442 int proc_stop = 0; /* non-zero if stopping */
445 443 int sigprof = 0; /* non-zero if sending SIGPROF */
446 444
447 445 t->t_post_sys = 0;
448 446
449 447 error = lwp->lwp_errno;
450 448
451 449 /*
452 450 * Code can be zero if this is a new LWP returning after a forkall(),
453 451 * other than the one which matches the one in the parent which called
454 452 * forkall(). In these LWPs, skip most of post-syscall activity.
455 453 */
456 454 if (code == 0)
457 455 goto sig_check;
458 456 /*
459 457 * If the trace flag is set, mark the lwp to take a single-step trap
460 458 * on return to user level (below). The x86 lcall interface and
461 459 * sysenter has already done this, and turned off the flag, but
462 460 * amd64 syscall interface has not.
463 461 */
464 462 if (rp->r_ps & PS_T) {
465 463 lwp->lwp_pcb.pcb_flags |= DEBUG_PENDING;
466 464 rp->r_ps &= ~PS_T;
467 465 aston(curthread);
468 466 }
469 467
470 468 /* put out audit record for this syscall */
471 469 if (AU_AUDITING()) {
472 470 rval_t rval;
473 471
474 472 /* XX64 -- truncation of 64-bit return values? */
475 473 rval.r_val1 = (int)rval1;
476 474 rval.r_val2 = (int)rval2;
477 475 audit_finish(T_SYSCALL, code, error, &rval);
478 476 repost = 1;
479 477 }
480 478
481 479 if (curthread->t_pdmsg != NULL) {
482 480 char *m = curthread->t_pdmsg;
483 481
484 482 uprintf("%s", m);
485 483 kmem_free(m, strlen(m) + 1);
486 484 curthread->t_pdmsg = NULL;
487 485 }
488 486
489 487 /*
490 488 * If we're going to stop for /proc tracing, set the flag and
491 489 * save the arguments so that the return values don't smash them.
492 490 */
493 491 if (PTOU(p)->u_systrap) {
494 492 if (prismember(&PTOU(p)->u_exitmask, code)) {
495 493 if (lwp_getdatamodel(lwp) == DATAMODEL_LP64)
496 494 (void) save_syscall_args();
497 495 proc_stop = 1;
498 496 }
499 497 repost = 1;
500 498 }
501 499
502 500 /*
503 501 * Similarly check to see if SIGPROF might be sent.
504 502 */
505 503 if (curthread->t_rprof != NULL &&
506 504 curthread->t_rprof->rp_anystate != 0) {
507 505 if (lwp_getdatamodel(lwp) == DATAMODEL_LP64)
508 506 (void) save_syscall_args();
509 507 sigprof = 1;
510 508 }
511 509
512 510 if (lwp->lwp_eosys == NORMALRETURN) {
513 511 if (error == 0) {
514 512 #ifdef SYSCALLTRACE
515 513 if (syscalltrace) {
516 514 mutex_enter(&systrace_lock);
517 515 printf(
518 516 "%d: r_val1=0x%lx, r_val2=0x%lx, id 0x%p\n",
519 517 p->p_pid, rval1, rval2, curthread);
520 518 mutex_exit(&systrace_lock);
521 519 }
522 520 #endif /* SYSCALLTRACE */
523 521 rp->r_ps &= ~PS_C;
524 522 rp->r_r0 = rval1;
525 523 rp->r_r1 = rval2;
526 524 } else {
527 525 int sig;
528 526 #ifdef SYSCALLTRACE
529 527 if (syscalltrace) {
530 528 mutex_enter(&systrace_lock);
531 529 printf("%d: error=%d, id 0x%p\n",
532 530 p->p_pid, error, curthread);
533 531 mutex_exit(&systrace_lock);
534 532 }
535 533 #endif /* SYSCALLTRACE */
536 534 if (error == EINTR && t->t_activefd.a_stale)
537 535 error = EBADF;
538 536 if (error == EINTR &&
539 537 (sig = lwp->lwp_cursig) != 0 &&
540 538 sigismember(&PTOU(p)->u_sigrestart, sig) &&
541 539 PTOU(p)->u_signal[sig - 1] != SIG_DFL &&
542 540 PTOU(p)->u_signal[sig - 1] != SIG_IGN)
543 541 error = ERESTART;
544 542 rp->r_r0 = error;
545 543 rp->r_ps |= PS_C;
546 544 }
547 545 }
548 546
549 547 /*
550 548 * From the proc(4) manual page:
551 549 * When exit from a system call is being traced, the traced process
552 550 * stops on completion of the system call just prior to checking for
553 551 * signals and returning to user level. At this point all return
554 552 * values have been stored into the traced process's saved registers.
555 553 */
556 554 if (proc_stop) {
557 555 mutex_enter(&p->p_lock);
558 556 if (PTOU(p)->u_systrap &&
559 557 prismember(&PTOU(p)->u_exitmask, code))
560 558 stop(PR_SYSEXIT, code);
561 559 mutex_exit(&p->p_lock);
562 560 }
563 561
564 562 /*
565 563 * If we are the parent returning from a successful
566 564 * vfork, wait for the child to exec or exit.
567 565 * This code must be here and not in the bowels of the system
568 566 * so that /proc can intercept exit from vfork in a timely way.
569 567 */
570 568 if (t->t_flag & T_VFPARENT) {
571 569 ASSERT(code == SYS_vfork || code == SYS_forksys);
572 570 ASSERT(rp->r_r1 == 0 && error == 0);
573 571 vfwait((pid_t)rval1);
574 572 t->t_flag &= ~T_VFPARENT;
575 573 }
576 574
577 575 /*
578 576 * If profiling is active, bill the current PC in user-land
579 577 * and keep reposting until profiling is disabled.
580 578 */
581 579 if (p->p_prof.pr_scale) {
582 580 if (lwp->lwp_oweupc)
583 581 profil_tick(rp->r_pc);
584 582 repost = 1;
585 583 }
586 584
587 585 sig_check:
588 586 /*
589 587 * Reset flag for next time.
590 588 * We must do this after stopping on PR_SYSEXIT
591 589 * because /proc uses the information in lwp_eosys.
592 590 */
593 591 lwp->lwp_eosys = NORMALRETURN;
594 592 clear_stale_fd();
595 593 t->t_flag &= ~T_FORKALL;
596 594
597 595 if (t->t_astflag | t->t_sig_check) {
598 596 /*
599 597 * Turn off the AST flag before checking all the conditions that
600 598 * may have caused an AST. This flag is on whenever a signal or
601 599 * unusual condition should be handled after the next trap or
602 600 * syscall.
603 601 */
604 602 astoff(t);
605 603 /*
606 604 * If a single-step trap occurred on a syscall (see trap())
607 605 * recognize it now. Do this before checking for signals
608 606 * because deferred_singlestep_trap() may generate a SIGTRAP to
609 607 * the LWP or may otherwise mark the LWP to call issig(FORREAL).
610 608 */
611 609 if (lwp->lwp_pcb.pcb_flags & DEBUG_PENDING)
612 610 deferred_singlestep_trap((caddr_t)rp->r_pc);
613 611
614 612 t->t_sig_check = 0;
615 613
616 614 /*
617 615 * The following check is legal for the following reasons:
618 616 * 1) The thread we are checking, is ourselves, so there is
619 617 * no way the proc can go away.
620 618 * 2) The only time we need to be protected by the
621 619 * lock is if the binding is changed.
622 620 *
623 621 * Note we will still take the lock and check the binding
624 622 * if the condition was true without the lock held. This
625 623 * prevents lock contention among threads owned by the
626 624 * same proc.
627 625 */
628 626
629 627 if (curthread->t_proc_flag & TP_CHANGEBIND) {
630 628 mutex_enter(&p->p_lock);
631 629 if (curthread->t_proc_flag & TP_CHANGEBIND) {
632 630 timer_lwpbind();
633 631 curthread->t_proc_flag &= ~TP_CHANGEBIND;
634 632 }
635 633 mutex_exit(&p->p_lock);
636 634 }
637 635
638 636 /*
639 637 * for kaio requests on the special kaio poll queue,
640 638 * copyout their results to user memory.
641 639 */
642 640 if (p->p_aio)
643 641 aio_cleanup(0);
644 642 /*
645 643 * If this LWP was asked to hold, call holdlwp(), which will
646 644 * stop. holdlwps() sets this up and calls pokelwps() which
647 645 * sets the AST flag.
648 646 *
649 647 * Also check TP_EXITLWP, since this is used by fresh new LWPs
650 648 * through lwp_rtt(). That flag is set if the lwp_create(2)
651 649 * syscall failed after creating the LWP.
652 650 */
653 651 if (ISHOLD(p) || (t->t_proc_flag & TP_EXITLWP))
654 652 holdlwp();
655 653
656 654 /*
657 655 * All code that sets signals and makes ISSIG_PENDING
658 656 * evaluate true must set t_sig_check afterwards.
659 657 */
660 658 if (ISSIG_PENDING(t, lwp, p)) {
661 659 if (issig(FORREAL))
662 660 psig();
663 661 t->t_sig_check = 1; /* recheck next time */
664 662 }
665 663
666 664 if (sigprof) {
667 665 int nargs = (code > 0 && code < NSYSCALL)?
668 666 LWP_GETSYSENT(lwp)[code].sy_narg : 0;
669 667 realsigprof(code, nargs, error);
670 668 t->t_sig_check = 1; /* recheck next time */
671 669 }
672 670
673 671 /*
674 672 * If a performance counter overflow interrupt was
675 673 * delivered *during* the syscall, then re-enable the
676 674 * AST so that we take a trip through trap() to cause
677 675 * the SIGEMT to be delivered.
678 676 */
679 677 if (lwp->lwp_pcb.pcb_flags & CPC_OVERFLOW)
680 678 aston(t);
681 679
682 680 /*
683 681 * /proc can't enable/disable the trace bit itself
684 682 * because that could race with the call gate used by
685 683 * system calls via "lcall". If that happened, an
686 684 * invalid EFLAGS would result. prstep()/prnostep()
687 685 * therefore schedule an AST for the purpose.
688 686 */
689 687 if (lwp->lwp_pcb.pcb_flags & REQUEST_STEP) {
690 688 lwp->lwp_pcb.pcb_flags &= ~REQUEST_STEP;
691 689 rp->r_ps |= PS_T;
692 690 }
693 691 if (lwp->lwp_pcb.pcb_flags & REQUEST_NOSTEP) {
694 692 lwp->lwp_pcb.pcb_flags &= ~REQUEST_NOSTEP;
695 693 rp->r_ps &= ~PS_T;
696 694 }
697 695 }
698 696
699 697 lwp->lwp_errno = 0; /* clear error for next time */
700 698
701 699 #ifndef NPROBE
702 700 /* Kernel probe */
703 701 if (tnf_tracing_active) {
704 702 TNF_PROBE_3(syscall_end, "syscall thread", /* CSTYLED */,
705 703 tnf_long, rval1, rval1,
706 704 tnf_long, rval2, rval2,
707 705 tnf_long, errno, (long)error);
708 706 repost = 1;
709 707 }
710 708 #endif /* NPROBE */
711 709
712 710 /*
713 711 * Set state to LWP_USER here so preempt won't give us a kernel
714 712 * priority if it occurs after this point. Call CL_TRAPRET() to
715 713 * restore the user-level priority.
716 714 *
717 715 * It is important that no locks (other than spinlocks) be entered
718 716 * after this point before returning to user mode (unless lwp_state
719 717 * is set back to LWP_SYS).
720 718 *
721 719 * XXX Sampled times past this point are charged to the user.
722 720 */
723 721 lwp->lwp_state = LWP_USER;
724 722
725 723 if (t->t_trapret) {
726 724 t->t_trapret = 0;
727 725 thread_lock(t);
728 726 CL_TRAPRET(t);
729 727 thread_unlock(t);
730 728 }
731 729 if (CPU->cpu_runrun || t->t_schedflag & TS_ANYWAITQ)
732 730 preempt();
733 731 prunstop();
734 732
735 733 lwp->lwp_errno = 0; /* clear error for next time */
736 734
737 735 /*
738 736 * The thread lock must be held in order to clear sysnum and reset
739 737 * lwp_ap atomically with respect to other threads in the system that
740 738 * may be looking at the args via lwp_ap from get_syscall_args().
741 739 */
742 740
743 741 thread_lock(t);
744 742 t->t_sysnum = 0; /* no longer in a system call */
745 743
746 744 if (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE) {
747 745 #if defined(_LP64)
748 746 /*
749 747 * In case the args were copied to the lwp, reset the
750 748 * pointer so the next syscall will have the right
751 749 * lwp_ap pointer.
752 750 */
753 751 lwp->lwp_ap = (long *)&rp->r_rdi;
754 752 } else {
755 753 #endif
756 754 lwp->lwp_ap = NULL; /* reset on every syscall entry */
757 755 }
758 756 thread_unlock(t);
759 757
760 758 lwp->lwp_argsaved = 0;
761 759
762 760 /*
763 761 * If there was a continuing reason for post-syscall processing,
764 762 * set the t_post_sys flag for the next system call.
765 763 */
766 764 if (repost)
767 765 t->t_post_sys = 1;
768 766
769 767 /*
770 768 * If there is a ustack registered for this lwp, and the stack rlimit
771 769 * has been altered, read in the ustack. If the saved stack rlimit
772 770 * matches the bounds of the ustack, update the ustack to reflect
773 771 * the new rlimit. If the new stack rlimit is RLIM_INFINITY, disable
774 772 * stack checking by setting the size to 0.
775 773 */
776 774 if (lwp->lwp_ustack != 0 && lwp->lwp_old_stk_ctl != 0) {
777 775 rlim64_t new_size;
778 776 caddr_t top;
779 777 stack_t stk;
780 778 struct rlimit64 rl;
781 779
782 780 mutex_enter(&p->p_lock);
783 781 new_size = p->p_stk_ctl;
784 782 top = p->p_usrstack;
785 783 (void) rctl_rlimit_get(rctlproc_legacy[RLIMIT_STACK], p, &rl);
786 784 mutex_exit(&p->p_lock);
787 785
788 786 if (rl.rlim_cur == RLIM64_INFINITY)
789 787 new_size = 0;
790 788
791 789 if (copyin((stack_t *)lwp->lwp_ustack, &stk,
792 790 sizeof (stack_t)) == 0 &&
793 791 (stk.ss_size == lwp->lwp_old_stk_ctl ||
794 792 stk.ss_size == 0) &&
795 793 stk.ss_sp == top - stk.ss_size) {
796 794 stk.ss_sp = (void *)((uintptr_t)stk.ss_sp +
797 795 stk.ss_size - (uintptr_t)new_size);
798 796 stk.ss_size = new_size;
799 797
800 798 (void) copyout(&stk, (stack_t *)lwp->lwp_ustack,
801 799 sizeof (stack_t));
802 800 }
803 801
804 802 lwp->lwp_old_stk_ctl = 0;
805 803 }
806 804 }
807 805
808 806 /*
809 807 * Called from post_syscall() when a deferred singlestep is to be taken.
810 808 */
811 809 void
812 810 deferred_singlestep_trap(caddr_t pc)
813 811 {
814 812 proc_t *p = ttoproc(curthread);
815 813 klwp_t *lwp = ttolwp(curthread);
816 814 pcb_t *pcb = &lwp->lwp_pcb;
817 815 uint_t fault = 0;
818 816 k_siginfo_t siginfo;
819 817
820 818 bzero(&siginfo, sizeof (siginfo));
821 819
822 820 /*
823 821 * If both NORMAL_STEP and WATCH_STEP are in
824 822 * effect, give precedence to WATCH_STEP.
825 823 * If neither is set, user must have set the
826 824 * PS_T bit in %efl; treat this as NORMAL_STEP.
827 825 */
828 826 if ((fault = undo_watch_step(&siginfo)) == 0 &&
829 827 ((pcb->pcb_flags & NORMAL_STEP) ||
830 828 !(pcb->pcb_flags & WATCH_STEP))) {
831 829 siginfo.si_signo = SIGTRAP;
832 830 siginfo.si_code = TRAP_TRACE;
833 831 siginfo.si_addr = pc;
834 832 fault = FLTTRACE;
835 833 }
836 834 pcb->pcb_flags &= ~(DEBUG_PENDING|NORMAL_STEP|WATCH_STEP);
837 835
838 836 if (fault) {
839 837 /*
840 838 * Remember the fault and fault adddress
841 839 * for real-time (SIGPROF) profiling.
842 840 */
843 841 lwp->lwp_lastfault = fault;
844 842 lwp->lwp_lastfaddr = siginfo.si_addr;
845 843 /*
846 844 * If a debugger has declared this fault to be an
847 845 * event of interest, stop the lwp. Otherwise just
848 846 * deliver the associated signal.
849 847 */
850 848 if (prismember(&p->p_fltmask, fault) &&
851 849 stop_on_fault(fault, &siginfo) == 0)
852 850 siginfo.si_signo = 0;
853 851 }
854 852
855 853 if (siginfo.si_signo)
856 854 trapsig(&siginfo, 1);
857 855 }
858 856
859 857 /*
860 858 * nonexistent system call-- signal lwp (may want to handle it)
861 859 * flag error if lwp won't see signal immediately
862 860 */
863 861 int64_t
864 862 nosys()
865 863 {
866 864 tsignal(curthread, SIGSYS);
867 865 return (set_errno(ENOSYS));
868 866 }
869 867
870 868 /*
871 869 * Execute a 32-bit system call on behalf of the current thread.
872 870 */
873 871 void
874 872 dosyscall(void)
875 873 {
876 874 /*
877 875 * Need space on the stack to store syscall arguments.
878 876 */
879 877 long syscall_args[MAXSYSARGS];
880 878 struct sysent *se;
881 879 int64_t ret;
882 880
883 881 syscall_mstate(LMS_TRAP, LMS_SYSTEM);
884 882
885 883 ASSERT(curproc->p_model == DATAMODEL_ILP32);
886 884
887 885 CPU_STATS_ENTER_K();
888 886 CPU_STATS_ADDQ(CPU, sys, syscall, 1);
889 887 CPU_STATS_EXIT_K();
890 888
891 889 se = syscall_entry(curthread, syscall_args);
892 890
893 891 /*
894 892 * syscall_entry() copied all 8 arguments into syscall_args.
895 893 */
896 894 ret = se->sy_callc(syscall_args[0], syscall_args[1], syscall_args[2],
897 895 syscall_args[3], syscall_args[4], syscall_args[5], syscall_args[6],
898 896 syscall_args[7]);
899 897
900 898 syscall_exit(curthread, (int)ret & 0xffffffffu, (int)(ret >> 32));
901 899 syscall_mstate(LMS_SYSTEM, LMS_TRAP);
902 900 }
903 901
904 902 /*
905 903 * Get the arguments to the current system call. See comment atop
906 904 * save_syscall_args() regarding lwp_ap usage.
907 905 */
908 906
909 907 uint_t
910 908 get_syscall_args(klwp_t *lwp, long *argp, int *nargsp)
911 909 {
912 910 kthread_t *t = lwptot(lwp);
913 911 ulong_t mask = 0xfffffffful;
914 912 uint_t code;
915 913 long *ap;
916 914 int nargs;
917 915
918 916 #if defined(_LP64)
919 917 if (lwp_getdatamodel(lwp) == DATAMODEL_LP64)
920 918 mask = 0xfffffffffffffffful;
921 919 #endif
922 920
923 921 /*
924 922 * The thread lock must be held while looking at the arguments to ensure
925 923 * they don't go away via post_syscall().
926 924 * get_syscall_args() is the only routine to read them which is callable
927 925 * outside the LWP in question and hence the only one that must be
928 926 * synchronized in this manner.
929 927 */
930 928 thread_lock(t);
931 929
932 930 code = t->t_sysnum;
933 931 ap = lwp->lwp_ap;
934 932
935 933 thread_unlock(t);
936 934
937 935 if (code != 0 && code < NSYSCALL) {
938 936 nargs = LWP_GETSYSENT(lwp)[code].sy_narg;
939 937
940 938 ASSERT(nargs <= MAXSYSARGS);
941 939
942 940 *nargsp = nargs;
943 941 while (nargs-- > 0)
944 942 *argp++ = *ap++ & mask;
945 943 } else {
946 944 *nargsp = 0;
947 945 }
948 946
949 947 return (code);
950 948 }
951 949
952 950 #ifdef _SYSCALL32_IMPL
953 951 /*
954 952 * Get the arguments to the current 32-bit system call.
955 953 */
956 954 uint_t
957 955 get_syscall32_args(klwp_t *lwp, int *argp, int *nargsp)
958 956 {
959 957 long args[MAXSYSARGS];
960 958 uint_t i, code;
961 959
962 960 code = get_syscall_args(lwp, args, nargsp);
963 961
964 962 for (i = 0; i != *nargsp; i++)
965 963 *argp++ = (int)args[i];
966 964 return (code);
967 965 }
968 966 #endif
969 967
970 968 /*
971 969 * Save the system call arguments in a safe place.
972 970 *
973 971 * On the i386 kernel:
974 972 *
975 973 * Copy the users args prior to changing the stack or stack pointer.
976 974 * This is so /proc will be able to get a valid copy of the
977 975 * args from the user stack even after the user stack has been changed.
978 976 * Note that the kernel stack copy of the args may also have been
979 977 * changed by a system call handler which takes C-style arguments.
980 978 *
981 979 * Note that this may be called by stop() from trap(). In that case
982 980 * t_sysnum will be zero (syscall_exit clears it), so no args will be
983 981 * copied.
984 982 *
985 983 * On the amd64 kernel:
986 984 *
987 985 * For 64-bit applications, lwp->lwp_ap normally points to %rdi..%r9
988 986 * in the reg structure. If the user is going to change the argument
989 987 * registers, rax, or the stack and might want to get the args (for
990 988 * /proc tracing), it must copy the args elsewhere via save_syscall_args().
991 989 *
992 990 * For 32-bit applications, lwp->lwp_ap normally points to a copy of
993 991 * the system call arguments on the kernel stack made from the user
994 992 * stack. Copy the args prior to change the stack or stack pointer.
995 993 * This is so /proc will be able to get a valid copy of the args
996 994 * from the user stack even after that stack has been changed.
997 995 *
998 996 * This may be called from stop() even when we're not in a system call.
999 997 * Since there's no easy way to tell, this must be safe (not panic).
1000 998 * If the copyins get data faults, return non-zero.
1001 999 */
1002 1000 int
1003 1001 save_syscall_args()
1004 1002 {
1005 1003 kthread_t *t = curthread;
1006 1004 klwp_t *lwp = ttolwp(t);
1007 1005 uint_t code = t->t_sysnum;
1008 1006 uint_t nargs;
1009 1007
1010 1008 if (lwp->lwp_argsaved || code == 0)
1011 1009 return (0); /* args already saved or not needed */
1012 1010
1013 1011 if (code >= NSYSCALL) {
1014 1012 nargs = 0; /* illegal syscall */
1015 1013 } else {
1016 1014 struct sysent *se = LWP_GETSYSENT(lwp);
1017 1015 struct sysent *callp = se + code;
1018 1016
1019 1017 nargs = callp->sy_narg;
1020 1018 if (LOADABLE_SYSCALL(callp) && nargs == 0) {
1021 1019 krwlock_t *module_lock;
1022 1020
1023 1021 /*
1024 1022 * Find out how many arguments the system
1025 1023 * call uses.
1026 1024 *
1027 1025 * We have the property that loaded syscalls
1028 1026 * never change the number of arguments they
1029 1027 * use after they've been loaded once. This
1030 1028 * allows us to stop for /proc tracing without
1031 1029 * holding the module lock.
1032 1030 * /proc is assured that sy_narg is valid.
1033 1031 */
1034 1032 module_lock = lock_syscall(se, code);
1035 1033 nargs = callp->sy_narg;
1036 1034 rw_exit(module_lock);
1037 1035 }
1038 1036 }
1039 1037
1040 1038 /*
1041 1039 * Fetch the system call arguments.
1042 1040 */
1043 1041 if (nargs == 0)
1044 1042 goto out;
1045 1043
1046 1044 ASSERT(nargs <= MAXSYSARGS);
1047 1045
1048 1046 if (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE) {
1049 1047 #if defined(_LP64)
1050 1048 struct regs *rp = lwptoregs(lwp);
1051 1049
1052 1050 lwp->lwp_arg[0] = rp->r_rdi;
1053 1051 lwp->lwp_arg[1] = rp->r_rsi;
1054 1052 lwp->lwp_arg[2] = rp->r_rdx;
1055 1053 lwp->lwp_arg[3] = rp->r_rcx;
1056 1054 lwp->lwp_arg[4] = rp->r_r8;
1057 1055 lwp->lwp_arg[5] = rp->r_r9;
1058 1056 if (nargs > 6 && copyin_args(rp, &lwp->lwp_arg[6], nargs - 6))
1059 1057 return (-1);
1060 1058 } else {
1061 1059 #endif
1062 1060 if (COPYIN_ARGS32(lwptoregs(lwp), lwp->lwp_arg, nargs))
1063 1061 return (-1);
1064 1062 }
1065 1063 out:
1066 1064 lwp->lwp_ap = lwp->lwp_arg;
1067 1065 lwp->lwp_argsaved = 1;
1068 1066 t->t_post_sys = 1; /* so lwp_ap will be reset */
1069 1067 return (0);
1070 1068 }
1071 1069
1072 1070 void
1073 1071 reset_syscall_args(void)
1074 1072 {
1075 1073 ttolwp(curthread)->lwp_argsaved = 0;
1076 1074 }
1077 1075
1078 1076 /*
1079 1077 * Call a system call which takes a pointer to the user args struct and
1080 1078 * a pointer to the return values. This is a bit slower than the standard
1081 1079 * C arg-passing method in some cases.
1082 1080 */
1083 1081 int64_t
1084 1082 syscall_ap(void)
1085 1083 {
1086 1084 uint_t error;
1087 1085 struct sysent *callp;
1088 1086 rval_t rval;
1089 1087 kthread_t *t = curthread;
1090 1088 klwp_t *lwp = ttolwp(t);
1091 1089 struct regs *rp = lwptoregs(lwp);
1092 1090
1093 1091 callp = LWP_GETSYSENT(lwp) + t->t_sysnum;
1094 1092
1095 1093 #if defined(__amd64)
1096 1094 /*
1097 1095 * If the arguments don't fit in registers %rdi-%r9, make sure they
1098 1096 * have been copied to the lwp_arg array.
1099 1097 */
1100 1098 if (callp->sy_narg > 6 && save_syscall_args())
1101 1099 return ((int64_t)set_errno(EFAULT));
1102 1100 #endif
1103 1101
1104 1102 rval.r_val1 = 0;
1105 1103 rval.r_val2 = rp->r_r1;
1106 1104 lwp->lwp_error = 0; /* for old drivers */
1107 1105 error = (*(callp->sy_call))(lwp->lwp_ap, &rval);
1108 1106 if (error)
1109 1107 return ((longlong_t)set_errno(error));
1110 1108 return (rval.r_vals);
1111 1109 }
1112 1110
1113 1111 /*
1114 1112 * Load system call module.
1115 1113 * Returns with pointer to held read lock for module.
1116 1114 */
1117 1115 static krwlock_t *
1118 1116 lock_syscall(struct sysent *table, uint_t code)
1119 1117 {
1120 1118 krwlock_t *module_lock;
1121 1119 struct modctl *modp;
1122 1120 int id;
1123 1121 struct sysent *callp;
1124 1122
1125 1123 callp = table + code;
1126 1124 module_lock = callp->sy_lock;
1127 1125
1128 1126 /*
1129 1127 * Optimization to only call modload if we don't have a loaded
1130 1128 * syscall.
1131 1129 */
1132 1130 rw_enter(module_lock, RW_READER);
1133 1131 if (LOADED_SYSCALL(callp))
1134 1132 return (module_lock);
1135 1133 rw_exit(module_lock);
1136 1134
1137 1135 for (;;) {
1138 1136 if ((id = modload("sys", syscallnames[code])) == -1)
1139 1137 break;
1140 1138
1141 1139 /*
1142 1140 * If we loaded successfully at least once, the modctl
1143 1141 * will still be valid, so we try to grab it by filename.
1144 1142 * If this call fails, it's because the mod_filename
1145 1143 * was changed after the call to modload() (mod_hold_by_name()
1146 1144 * is the likely culprit). We can safely just take
1147 1145 * another lap if this is the case; the modload() will
1148 1146 * change the mod_filename back to one by which we can
1149 1147 * find the modctl.
1150 1148 */
1151 1149 modp = mod_find_by_filename("sys", syscallnames[code]);
1152 1150
1153 1151 if (modp == NULL)
1154 1152 continue;
1155 1153
1156 1154 mutex_enter(&mod_lock);
1157 1155
1158 1156 if (!modp->mod_installed) {
1159 1157 mutex_exit(&mod_lock);
1160 1158 continue;
1161 1159 }
1162 1160 break;
1163 1161 }
1164 1162 rw_enter(module_lock, RW_READER);
1165 1163
1166 1164 if (id != -1)
1167 1165 mutex_exit(&mod_lock);
1168 1166
1169 1167 return (module_lock);
1170 1168 }
1171 1169
1172 1170 /*
1173 1171 * Loadable syscall support.
1174 1172 * If needed, load the module, then reserve it by holding a read
1175 1173 * lock for the duration of the call.
1176 1174 * Later, if the syscall is not unloadable, it could patch the vector.
1177 1175 */
1178 1176 /*ARGSUSED*/
1179 1177 int64_t
1180 1178 loadable_syscall(
1181 1179 long a0, long a1, long a2, long a3,
1182 1180 long a4, long a5, long a6, long a7)
1183 1181 {
1184 1182 klwp_t *lwp = ttolwp(curthread);
1185 1183 int64_t rval;
1186 1184 struct sysent *callp;
1187 1185 struct sysent *se = LWP_GETSYSENT(lwp);
1188 1186 krwlock_t *module_lock;
1189 1187 int code, error = 0;
1190 1188 int64_t (*sy_call)();
1191 1189
1192 1190 code = curthread->t_sysnum;
1193 1191 callp = se + code;
1194 1192
1195 1193 /*
1196 1194 * Try to autoload the system call if necessary
1197 1195 */
1198 1196 module_lock = lock_syscall(se, code);
1199 1197 THREAD_KPRI_RELEASE(); /* drop priority given by rw_enter */
1200 1198
1201 1199 /*
1202 1200 * we've locked either the loaded syscall or nosys
1203 1201 */
1204 1202
1205 1203 if (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE) {
1206 1204 #if defined(_LP64)
1207 1205 if (callp->sy_flags & SE_ARGC) {
1208 1206 sy_call = (int64_t (*)())callp->sy_call;
1209 1207 rval = (*sy_call)(a0, a1, a2, a3, a4, a5);
1210 1208 } else
1211 1209 rval = syscall_ap();
1212 1210 } else {
1213 1211 #endif
1214 1212 /*
1215 1213 * Now that it's loaded, make sure enough args were copied.
1216 1214 */
1217 1215 if (COPYIN_ARGS32(lwptoregs(lwp), lwp->lwp_ap, callp->sy_narg))
1218 1216 error = EFAULT;
1219 1217 if (error) {
1220 1218 rval = set_errno(error);
1221 1219 } else if (callp->sy_flags & SE_ARGC) {
1222 1220 sy_call = (int64_t (*)())callp->sy_call;
1223 1221 rval = (*sy_call)(lwp->lwp_ap[0], lwp->lwp_ap[1],
1224 1222 lwp->lwp_ap[2], lwp->lwp_ap[3], lwp->lwp_ap[4],
1225 1223 lwp->lwp_ap[5]);
1226 1224 } else
1227 1225 rval = syscall_ap();
1228 1226 }
1229 1227
1230 1228 THREAD_KPRI_REQUEST(); /* regain priority from read lock */
1231 1229 rw_exit(module_lock);
1232 1230 return (rval);
1233 1231 }
1234 1232
1235 1233 /*
1236 1234 * Indirect syscall handled in libc on x86 architectures
1237 1235 */
1238 1236 int64_t
1239 1237 indir()
1240 1238 {
1241 1239 return (nosys());
1242 1240 }
1243 1241
1244 1242 /*
1245 1243 * set_errno - set an error return from the current system call.
1246 1244 * This could be a macro.
1247 1245 * This returns the value it is passed, so that the caller can
1248 1246 * use tail-recursion-elimination and do return (set_errno(ERRNO));
1249 1247 */
1250 1248 uint_t
1251 1249 set_errno(uint_t error)
1252 1250 {
1253 1251 ASSERT(error != 0); /* must not be used to clear errno */
1254 1252
1255 1253 curthread->t_post_sys = 1; /* have post_syscall do error return */
1256 1254 return (ttolwp(curthread)->lwp_errno = error);
1257 1255 }
1258 1256
1259 1257 /*
1260 1258 * set_proc_pre_sys - Set pre-syscall processing for entire process.
1261 1259 */
1262 1260 void
1263 1261 set_proc_pre_sys(proc_t *p)
1264 1262 {
1265 1263 kthread_t *t;
1266 1264 kthread_t *first;
1267 1265
1268 1266 ASSERT(MUTEX_HELD(&p->p_lock));
1269 1267
1270 1268 t = first = p->p_tlist;
1271 1269 do {
1272 1270 t->t_pre_sys = 1;
1273 1271 } while ((t = t->t_forw) != first);
1274 1272 }
1275 1273
1276 1274 /*
1277 1275 * set_proc_post_sys - Set post-syscall processing for entire process.
1278 1276 */
1279 1277 void
1280 1278 set_proc_post_sys(proc_t *p)
1281 1279 {
1282 1280 kthread_t *t;
1283 1281 kthread_t *first;
1284 1282
1285 1283 ASSERT(MUTEX_HELD(&p->p_lock));
1286 1284
1287 1285 t = first = p->p_tlist;
1288 1286 do {
1289 1287 t->t_post_sys = 1;
1290 1288 } while ((t = t->t_forw) != first);
1291 1289 }
1292 1290
1293 1291 /*
1294 1292 * set_proc_sys - Set pre- and post-syscall processing for entire process.
1295 1293 */
1296 1294 void
1297 1295 set_proc_sys(proc_t *p)
1298 1296 {
1299 1297 kthread_t *t;
1300 1298 kthread_t *first;
1301 1299
1302 1300 ASSERT(MUTEX_HELD(&p->p_lock));
1303 1301
1304 1302 t = first = p->p_tlist;
1305 1303 do {
1306 1304 t->t_pre_sys = 1;
1307 1305 t->t_post_sys = 1;
1308 1306 } while ((t = t->t_forw) != first);
1309 1307 }
1310 1308
1311 1309 /*
1312 1310 * set_all_proc_sys - set pre- and post-syscall processing flags for all
1313 1311 * user processes.
1314 1312 *
1315 1313 * This is needed when auditing, tracing, or other facilities which affect
1316 1314 * all processes are turned on.
1317 1315 */
1318 1316 void
1319 1317 set_all_proc_sys()
1320 1318 {
1321 1319 kthread_t *t;
1322 1320 kthread_t *first;
1323 1321
1324 1322 mutex_enter(&pidlock);
1325 1323 t = first = curthread;
1326 1324 do {
1327 1325 t->t_pre_sys = 1;
1328 1326 t->t_post_sys = 1;
1329 1327 } while ((t = t->t_next) != first);
1330 1328 mutex_exit(&pidlock);
1331 1329 }
1332 1330
1333 1331 /*
1334 1332 * set_all_zone_usr_proc_sys - set pre- and post-syscall processing flags for
1335 1333 * all user processes running in the zone of the current process
1336 1334 *
1337 1335 * This is needed when auditing, tracing, or other facilities which affect
1338 1336 * all processes are turned on.
1339 1337 */
1340 1338 void
1341 1339 set_all_zone_usr_proc_sys(zoneid_t zoneid)
1342 1340 {
1343 1341 proc_t *p;
1344 1342 kthread_t *t;
1345 1343
1346 1344 mutex_enter(&pidlock);
1347 1345 for (p = practive; p != NULL; p = p->p_next) {
1348 1346 /* skip kernel and incomplete processes */
1349 1347 if (p->p_exec == NULLVP || p->p_as == &kas ||
1350 1348 p->p_stat == SIDL || p->p_stat == SZOMB ||
1351 1349 (p->p_flag & (SSYS | SEXITING | SEXITLWPS)))
1352 1350 continue;
1353 1351 /*
1354 1352 * Only processes in the given zone (eventually in
1355 1353 * all zones) are taken into account
1356 1354 */
1357 1355 if (zoneid == ALL_ZONES || p->p_zone->zone_id == zoneid) {
1358 1356 mutex_enter(&p->p_lock);
1359 1357 if ((t = p->p_tlist) == NULL) {
1360 1358 mutex_exit(&p->p_lock);
1361 1359 continue;
1362 1360 }
1363 1361 /*
1364 1362 * Set pre- and post-syscall processing flags
1365 1363 * for all threads of the process
1366 1364 */
1367 1365 do {
1368 1366 t->t_pre_sys = 1;
1369 1367 t->t_post_sys = 1;
1370 1368 } while (p->p_tlist != (t = t->t_forw));
1371 1369 mutex_exit(&p->p_lock);
1372 1370 }
1373 1371 }
1374 1372 mutex_exit(&pidlock);
1375 1373 }
1376 1374
1377 1375 /*
1378 1376 * set_proc_ast - Set asynchronous service trap (AST) flag for all
1379 1377 * threads in process.
1380 1378 */
1381 1379 void
1382 1380 set_proc_ast(proc_t *p)
1383 1381 {
1384 1382 kthread_t *t;
1385 1383 kthread_t *first;
1386 1384
1387 1385 ASSERT(MUTEX_HELD(&p->p_lock));
1388 1386
1389 1387 t = first = p->p_tlist;
1390 1388 do {
1391 1389 aston(t);
1392 1390 } while ((t = t->t_forw) != first);
1393 1391 }
↓ open down ↓ |
1137 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX