linux_machdep.c revision 65506
1130812Smarcel/*- 2130812Smarcel * Copyright (c) 2000 Marcel Moolenaar 3130812Smarcel * All rights reserved. 4130812Smarcel * 5130812Smarcel * Redistribution and use in source and binary forms, with or without 6130812Smarcel * modification, are permitted provided that the following conditions 7130812Smarcel * are met: 8130812Smarcel * 1. Redistributions of source code must retain the above copyright 9130812Smarcel * notice, this list of conditions and the following disclaimer 10130812Smarcel * in this position and unchanged. 11130812Smarcel * 2. Redistributions in binary form must reproduce the above copyright 12130812Smarcel * notice, this list of conditions and the following disclaimer in the 13130812Smarcel * documentation and/or other materials provided with the distribution. 14130812Smarcel * 3. The name of the author may not be used to endorse or promote products 15130812Smarcel * derived from this software without specific prior written permission. 16130812Smarcel * 17130812Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18130812Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19130812Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20130812Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21130812Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22130812Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23130812Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24130812Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25130812Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26130812Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27130812Smarcel * 28130812Smarcel * $FreeBSD: head/sys/i386/linux/linux_machdep.c 65506 2000-09-06 06:08:54Z marcel $ 29130812Smarcel */ 30130812Smarcel 31130812Smarcel#include <sys/param.h> 32130812Smarcel#include <sys/mman.h> 33130812Smarcel#include <sys/proc.h> 34130812Smarcel#include <sys/sysproto.h> 35130812Smarcel#include <sys/systm.h> 36130812Smarcel#include <sys/unistd.h> 37130812Smarcel 38130812Smarcel#include <machine/frame.h> 39130812Smarcel#include <machine/psl.h> 40130812Smarcel#include <machine/segments.h> 41130812Smarcel#include <machine/sysarch.h> 42130812Smarcel 43130812Smarcel#include <i386/linux/linux.h> 44130812Smarcel#include <i386/linux/linux_proto.h> 45130812Smarcel#include <compat/linux/linux_ipc.h> 46130812Smarcel#include <compat/linux/linux_signal.h> 47130812Smarcel#include <compat/linux/linux_util.h> 48130812Smarcel 49130812Smarcelstruct linux_descriptor { 50130812Smarcel unsigned int entry_number; 51130812Smarcel unsigned long base_addr; 52130812Smarcel unsigned int limit; 53130812Smarcel unsigned int seg_32bit:1; 54130812Smarcel unsigned int contents:2; 55130812Smarcel unsigned int read_exec_only:1; 56130812Smarcel unsigned int limit_in_pages:1; 57130812Smarcel unsigned int seg_not_present:1; 58130812Smarcel unsigned int useable:1; 59130812Smarcel}; 60130812Smarcel 61130812Smarcelstruct linux_select_argv { 62130812Smarcel int nfds; 63130812Smarcel fd_set *readfds; 64130812Smarcel fd_set *writefds; 65130812Smarcel fd_set *exceptfds; 66130812Smarcel struct timeval *timeout; 67130812Smarcel}; 68130812Smarcel 69130812Smarcelint 70130812Smarcellinux_execve(struct proc *p, struct linux_execve_args *args) 71130812Smarcel{ 72130812Smarcel struct execve_args bsd; 73130812Smarcel caddr_t sg; 74130812Smarcel 75130812Smarcel sg = stackgap_init(); 76130812Smarcel CHECKALTEXIST(p, &sg, args->path); 77130812Smarcel 78130812Smarcel#ifdef DEBUG 79130812Smarcel printf("Linux-emul(%d): execve(%s)\n", 80130812Smarcel p->p_pid, args->path); 81130812Smarcel#endif 82130812Smarcel 83130812Smarcel bsd.fname = args->path; 84130812Smarcel bsd.argv = args->argp; 85130812Smarcel bsd.envv = args->envp; 86130812Smarcel return (execve(p, &bsd)); 87130812Smarcel} 88130812Smarcel 89130812Smarcelint 90130812Smarcellinux_ipc(struct proc *p, struct linux_ipc_args *args) 91130812Smarcel{ 92130812Smarcel switch (args->what) { 93130812Smarcel case LINUX_SEMOP: 94130812Smarcel return (linux_semop(p, args)); 95130812Smarcel case LINUX_SEMGET: 96130812Smarcel return (linux_semget(p, args)); 97130812Smarcel case LINUX_SEMCTL: 98130812Smarcel return (linux_semctl(p, args)); 99130812Smarcel case LINUX_MSGSND: 100130812Smarcel return (linux_msgsnd(p, args)); 101130812Smarcel case LINUX_MSGRCV: 102130812Smarcel return (linux_msgrcv(p, args)); 103130812Smarcel case LINUX_MSGGET: 104130812Smarcel return (linux_msgget(p, args)); 105130812Smarcel case LINUX_MSGCTL: 106130812Smarcel return (linux_msgctl(p, args)); 107130812Smarcel case LINUX_SHMAT: 108130812Smarcel return (linux_shmat(p, args)); 109130812Smarcel case LINUX_SHMDT: 110130812Smarcel return (linux_shmdt(p, args)); 111130812Smarcel case LINUX_SHMGET: 112130812Smarcel return (linux_shmget(p, args)); 113130812Smarcel case LINUX_SHMCTL: 114130812Smarcel return (linux_shmctl(p, args)); 115130812Smarcel } 116130812Smarcel 117130812Smarcel uprintf("LINUX: 'ipc' typ=%d not implemented\n", args->what); 118130812Smarcel return (ENOSYS); 119130812Smarcel} 120130812Smarcel 121130812Smarcelint 122130812Smarcellinux_select(struct proc *p, struct linux_select_args *args) 123130812Smarcel{ 124130812Smarcel struct linux_select_argv linux_args; 125130812Smarcel struct linux_newselect_args newsel; 126130812Smarcel int error; 127130812Smarcel 128130812Smarcel#ifdef SELECT_DEBUG 129130812Smarcel printf("Linux-emul(%ld): select(%x)\n", (long)p->p_pid, args->ptr); 130130812Smarcel#endif 131130812Smarcel 132130812Smarcel error = copyin(args->ptr, &linux_args, sizeof(linux_args)); 133130812Smarcel if (error) 134130812Smarcel return (error); 135130812Smarcel 136130812Smarcel newsel.nfds = linux_args.nfds; 137130812Smarcel newsel.readfds = linux_args.readfds; 138130812Smarcel newsel.writefds = linux_args.writefds; 139130812Smarcel newsel.exceptfds = linux_args.exceptfds; 140130812Smarcel newsel.timeout = linux_args.timeout; 141130812Smarcel return (linux_newselect(p, &newsel)); 142130812Smarcel} 143130812Smarcel 144130812Smarcelint 145130812Smarcellinux_fork(struct proc *p, struct linux_fork_args *args) 146130812Smarcel{ 147130812Smarcel int error; 148130812Smarcel 149130812Smarcel#ifdef DEBUG 150130812Smarcel printf("Linux-emul(%ld): fork()\n", (long)p->p_pid); 151130812Smarcel#endif 152130812Smarcel 153130812Smarcel if ((error = fork(p, (struct fork_args *)args)) != 0) 154130812Smarcel return (error); 155130812Smarcel 156130812Smarcel if (p->p_retval[1] == 1) 157130812Smarcel p->p_retval[0] = 0; 158130812Smarcel return (0); 159130812Smarcel} 160130812Smarcel 161130812Smarcelint 162130812Smarcellinux_vfork(struct proc *p, struct linux_vfork_args *args) 163130812Smarcel{ 164130812Smarcel int error; 165130812Smarcel 166130812Smarcel#ifdef DEBUG 167130812Smarcel printf("Linux-emul(%ld): vfork()\n", (long)p->p_pid); 168130812Smarcel#endif 169130812Smarcel 170130812Smarcel if ((error = vfork(p, (struct vfork_args *)args)) != 0) 171130812Smarcel return (error); 172130812Smarcel /* Are we the child? */ 173130812Smarcel if (p->p_retval[1] == 1) 174130812Smarcel p->p_retval[0] = 0; 175130812Smarcel return (0); 176130812Smarcel} 177130812Smarcel 178130812Smarcel#define CLONE_VM 0x100 179130812Smarcel#define CLONE_FS 0x200 180130812Smarcel#define CLONE_FILES 0x400 181130812Smarcel#define CLONE_SIGHAND 0x800 182#define CLONE_PID 0x1000 183 184int 185linux_clone(struct proc *p, struct linux_clone_args *args) 186{ 187 int error, ff = RFPROC; 188 struct proc *p2; 189 int exit_signal; 190 vm_offset_t start; 191 struct rfork_args rf_args; 192 193#ifdef DEBUG 194 if (args->flags & CLONE_PID) 195 printf("linux_clone(%ld): CLONE_PID not yet supported\n", 196 (long)p->p_pid); 197 printf("linux_clone(%ld): invoked with flags %x and stack %x\n", 198 (long)p->p_pid, (unsigned int)args->flags, 199 (unsigned int)args->stack); 200#endif 201 202 if (!args->stack) 203 return (EINVAL); 204 205 exit_signal = args->flags & 0x000000ff; 206 if (exit_signal >= LINUX_NSIG) 207 return (EINVAL); 208 209 if (exit_signal <= LINUX_SIGTBLSZ) 210 exit_signal = linux_to_bsd_signal[_SIG_IDX(exit_signal)]; 211 212 /* RFTHREAD probably not necessary here, but it shouldn't hurt */ 213 ff |= RFTHREAD; 214 215 if (args->flags & CLONE_VM) 216 ff |= RFMEM; 217 if (args->flags & CLONE_SIGHAND) 218 ff |= RFSIGSHARE; 219 if (!(args->flags & CLONE_FILES)) 220 ff |= RFFDG; 221 222 error = 0; 223 start = 0; 224 225 rf_args.flags = ff; 226 if ((error = rfork(p, &rf_args)) != 0) 227 return (error); 228 229 p2 = pfind(p->p_retval[0]); 230 if (p2 == 0) 231 return (ESRCH); 232 233 p2->p_sigparent = exit_signal; 234 p2->p_md.md_regs->tf_esp = (unsigned int)args->stack; 235 236#ifdef DEBUG 237 printf ("linux_clone(%ld): successful rfork to %ld\n", (long)p->p_pid, 238 (long)p2->p_pid); 239#endif 240 241 return (0); 242} 243 244/* XXX move */ 245struct linux_mmap_argv { 246 linux_caddr_t addr; 247 int len; 248 int prot; 249 int flags; 250 int fd; 251 int pos; 252}; 253 254#define STACK_SIZE (2 * 1024 * 1024) 255#define GUARD_SIZE (4 * PAGE_SIZE) 256 257int 258linux_mmap(struct proc *p, struct linux_mmap_args *args) 259{ 260 struct mmap_args /* { 261 caddr_t addr; 262 size_t len; 263 int prot; 264 int flags; 265 int fd; 266 long pad; 267 off_t pos; 268 } */ bsd_args; 269 int error; 270 struct linux_mmap_argv linux_args; 271 272 error = copyin(args->ptr, &linux_args, sizeof(linux_args)); 273 if (error) 274 return (error); 275 276#ifdef DEBUG 277 printf("Linux-emul(%ld): mmap(%p, %d, %d, 0x%08x, %d, %d)", 278 (long)p->p_pid, (void *)linux_args.addr, linux_args.len, 279 linux_args.prot, linux_args.flags, linux_args.fd, linux_args.pos); 280#endif 281 282 bsd_args.flags = 0; 283 if (linux_args.flags & LINUX_MAP_SHARED) 284 bsd_args.flags |= MAP_SHARED; 285 if (linux_args.flags & LINUX_MAP_PRIVATE) 286 bsd_args.flags |= MAP_PRIVATE; 287 if (linux_args.flags & LINUX_MAP_FIXED) 288 bsd_args.flags |= MAP_FIXED; 289 if (linux_args.flags & LINUX_MAP_ANON) 290 bsd_args.flags |= MAP_ANON; 291 if (linux_args.flags & LINUX_MAP_GROWSDOWN) { 292 bsd_args.flags |= MAP_STACK; 293 294 /* The linux MAP_GROWSDOWN option does not limit auto 295 * growth of the region. Linux mmap with this option 296 * takes as addr the inital BOS, and as len, the initial 297 * region size. It can then grow down from addr without 298 * limit. However, linux threads has an implicit internal 299 * limit to stack size of STACK_SIZE. Its just not 300 * enforced explicitly in linux. But, here we impose 301 * a limit of (STACK_SIZE - GUARD_SIZE) on the stack 302 * region, since we can do this with our mmap. 303 * 304 * Our mmap with MAP_STACK takes addr as the maximum 305 * downsize limit on BOS, and as len the max size of 306 * the region. It them maps the top SGROWSIZ bytes, 307 * and autgrows the region down, up to the limit 308 * in addr. 309 * 310 * If we don't use the MAP_STACK option, the effect 311 * of this code is to allocate a stack region of a 312 * fixed size of (STACK_SIZE - GUARD_SIZE). 313 */ 314 315 /* This gives us TOS */ 316 bsd_args.addr = linux_args.addr + linux_args.len; 317 318 /* This gives us our maximum stack size */ 319 if (linux_args.len > STACK_SIZE - GUARD_SIZE) 320 bsd_args.len = linux_args.len; 321 else 322 bsd_args.len = STACK_SIZE - GUARD_SIZE; 323 324 /* This gives us a new BOS. If we're using VM_STACK, then 325 * mmap will just map the top SGROWSIZ bytes, and let 326 * the stack grow down to the limit at BOS. If we're 327 * not using VM_STACK we map the full stack, since we 328 * don't have a way to autogrow it. 329 */ 330 bsd_args.addr -= bsd_args.len; 331 } else { 332 bsd_args.addr = linux_args.addr; 333 bsd_args.len = linux_args.len; 334 } 335 336 bsd_args.prot = linux_args.prot | PROT_READ; /* always required */ 337 if (linux_args.flags & LINUX_MAP_ANON) 338 bsd_args.fd = -1; 339 else 340 bsd_args.fd = linux_args.fd; 341 bsd_args.pos = linux_args.pos; 342 bsd_args.pad = 0; 343 344#ifdef DEBUG 345 printf("-> (%p, %d, %d, 0x%08x, %d, %d)\n", (void *)bsd_args.addr, 346 bsd_args.len, bsd_args.prot, bsd_args.flags, bsd_args.fd, 347 (int)bsd_args.pos); 348#endif 349 350 return (mmap(p, &bsd_args)); 351} 352 353int 354linux_pipe(struct proc *p, struct linux_pipe_args *args) 355{ 356 int error; 357 int reg_edx; 358 359#ifdef DEBUG 360 printf("Linux-emul(%ld): pipe(*)\n", (long)p->p_pid); 361#endif 362 363 reg_edx = p->p_retval[1]; 364 error = pipe(p, 0); 365 if (error) { 366 p->p_retval[1] = reg_edx; 367 return (error); 368 } 369 370 error = copyout(p->p_retval, args->pipefds, 2*sizeof(int)); 371 if (error) { 372 p->p_retval[1] = reg_edx; 373 return (error); 374 } 375 376 p->p_retval[1] = reg_edx; 377 p->p_retval[0] = 0; 378 return (0); 379} 380 381int 382linux_ioperm(struct proc *p, struct linux_ioperm_args *args) 383{ 384 struct sysarch_args sa; 385 struct i386_ioperm_args *iia; 386 caddr_t sg; 387 388 sg = stackgap_init(); 389 iia = stackgap_alloc(&sg, sizeof(struct i386_ioperm_args)); 390 iia->start = args->start; 391 iia->length = args->length; 392 iia->enable = args->enable; 393 sa.op = I386_SET_IOPERM; 394 sa.parms = (char *)iia; 395 return (sysarch(p, &sa)); 396} 397 398int 399linux_iopl(struct proc *p, struct linux_iopl_args *args) 400{ 401 int error; 402 403 if (args->level < 0 || args->level > 3) 404 return (EINVAL); 405 if ((error = suser(p)) != 0) 406 return (error); 407 if (securelevel > 0) 408 return (EPERM); 409 p->p_md.md_regs->tf_eflags = (p->p_md.md_regs->tf_eflags & ~PSL_IOPL) | 410 (args->level * (PSL_IOPL / 3)); 411 return (0); 412} 413 414int 415linux_modify_ldt(p, uap) 416 struct proc *p; 417 struct linux_modify_ldt_args *uap; 418{ 419 int error; 420 caddr_t sg; 421 struct sysarch_args args; 422 struct i386_ldt_args *ldt; 423 struct linux_descriptor ld; 424 union descriptor *desc; 425 426 sg = stackgap_init(); 427 428 if (uap->ptr == NULL) 429 return (EINVAL); 430 431 switch (uap->func) { 432 case 0x00: /* read_ldt */ 433 ldt = stackgap_alloc(&sg, sizeof(*ldt)); 434 ldt->start = 0; 435 ldt->descs = uap->ptr; 436 ldt->num = uap->bytecount / sizeof(union descriptor); 437 args.op = I386_GET_LDT; 438 args.parms = (char*)ldt; 439 error = sysarch(p, &args); 440 p->p_retval[0] *= sizeof(union descriptor); 441 break; 442 case 0x01: /* write_ldt */ 443 case 0x11: /* write_ldt */ 444 if (uap->bytecount != sizeof(ld)) 445 return (EINVAL); 446 447 error = copyin(uap->ptr, &ld, sizeof(ld)); 448 if (error) 449 return (error); 450 451 ldt = stackgap_alloc(&sg, sizeof(*ldt)); 452 desc = stackgap_alloc(&sg, sizeof(*desc)); 453 ldt->start = ld.entry_number; 454 ldt->descs = desc; 455 ldt->num = 1; 456 desc->sd.sd_lolimit = (ld.limit & 0x0000ffff); 457 desc->sd.sd_hilimit = (ld.limit & 0x000f0000) >> 16; 458 desc->sd.sd_lobase = (ld.base_addr & 0x00ffffff); 459 desc->sd.sd_hibase = (ld.base_addr & 0xff000000) >> 24; 460 desc->sd.sd_type = SDT_MEMRO | ((ld.read_exec_only ^ 1) << 1) | 461 (ld.contents << 2); 462 desc->sd.sd_dpl = 3; 463 desc->sd.sd_p = (ld.seg_not_present ^ 1); 464 desc->sd.sd_xx = 0; 465 desc->sd.sd_def32 = ld.seg_32bit; 466 desc->sd.sd_gran = ld.limit_in_pages; 467 args.op = I386_SET_LDT; 468 args.parms = (char*)ldt; 469 error = sysarch(p, &args); 470 break; 471 default: 472 error = EINVAL; 473 break; 474 } 475 476 if (error == EOPNOTSUPP) { 477 printf("linux: modify_ldt needs kernel option USER_LDT\n"); 478 error = ENOSYS; 479 } 480 481 return (error); 482} 483 484int 485linux_sigaction(struct proc *p, struct linux_sigaction_args *args) 486{ 487 linux_osigaction_t osa; 488 linux_sigaction_t act, oact; 489 int error; 490 491#ifdef DEBUG 492 printf("Linux-emul(%ld): sigaction(%d, %p, %p)\n", (long)p->p_pid, 493 args->sig, (void *)args->nsa, (void *)args->osa); 494#endif 495 496 if (args->nsa != NULL) { 497 error = copyin(args->nsa, &osa, sizeof(linux_osigaction_t)); 498 if (error) 499 return (error); 500 act.lsa_handler = osa.lsa_handler; 501 act.lsa_flags = osa.lsa_flags; 502 act.lsa_restorer = osa.lsa_restorer; 503 LINUX_SIGEMPTYSET(act.lsa_mask); 504 act.lsa_mask.__bits[0] = osa.lsa_mask; 505 } 506 507 error = linux_do_sigaction(p, args->sig, args->nsa ? &act : NULL, 508 args->osa ? &oact : NULL); 509 510 if (args->osa != NULL && !error) { 511 osa.lsa_handler = oact.lsa_handler; 512 osa.lsa_flags = oact.lsa_flags; 513 osa.lsa_restorer = oact.lsa_restorer; 514 osa.lsa_mask = oact.lsa_mask.__bits[0]; 515 error = copyout(&osa, args->osa, sizeof(linux_osigaction_t)); 516 } 517 518 return (error); 519} 520 521/* 522 * Linux has two extra args, restart and oldmask. We dont use these, 523 * but it seems that "restart" is actually a context pointer that 524 * enables the signal to happen with a different register set. 525 */ 526int 527linux_sigsuspend(struct proc *p, struct linux_sigsuspend_args *args) 528{ 529 struct sigsuspend_args bsd; 530 sigset_t *sigmask; 531 linux_sigset_t mask; 532 caddr_t sg = stackgap_init(); 533 534#ifdef DEBUG 535 printf("Linux-emul(%ld): sigsuspend(%08lx)\n", 536 (long)p->p_pid, (unsigned long)args->mask); 537#endif 538 539 sigmask = stackgap_alloc(&sg, sizeof(sigset_t)); 540 LINUX_SIGEMPTYSET(mask); 541 mask.__bits[0] = args->mask; 542 linux_to_bsd_sigset(&mask, sigmask); 543 bsd.sigmask = sigmask; 544 return (sigsuspend(p, &bsd)); 545} 546 547int 548linux_rt_sigsuspend(p, uap) 549 struct proc *p; 550 struct linux_rt_sigsuspend_args *uap; 551{ 552 linux_sigset_t lmask; 553 sigset_t *bmask; 554 struct sigsuspend_args bsd; 555 caddr_t sg = stackgap_init(); 556 int error; 557 558#ifdef DEBUG 559 printf("Linux-emul(%ld): rt_sigsuspend(%p, %d)\n", (long)p->p_pid, 560 (void *)uap->newset, uap->sigsetsize); 561#endif 562 563 if (uap->sigsetsize != sizeof(linux_sigset_t)) 564 return (EINVAL); 565 566 error = copyin(uap->newset, &lmask, sizeof(linux_sigset_t)); 567 if (error) 568 return (error); 569 570 bmask = stackgap_alloc(&sg, sizeof(sigset_t)); 571 linux_to_bsd_sigset(&lmask, bmask); 572 bsd.sigmask = bmask; 573 return (sigsuspend(p, &bsd)); 574} 575 576int 577linux_pause(struct proc *p, struct linux_pause_args *args) 578{ 579 struct sigsuspend_args bsd; 580 sigset_t *sigmask; 581 caddr_t sg = stackgap_init(); 582 583#ifdef DEBUG 584 printf("Linux-emul(%d): pause()\n", p->p_pid); 585#endif 586 587 sigmask = stackgap_alloc(&sg, sizeof(sigset_t)); 588 *sigmask = p->p_sigmask; 589 bsd.sigmask = sigmask; 590 return (sigsuspend(p, &bsd)); 591} 592 593int 594linux_sigaltstack(p, uap) 595 struct proc *p; 596 struct linux_sigaltstack_args *uap; 597{ 598 struct sigaltstack_args bsd; 599 stack_t *ss, *oss; 600 linux_stack_t lss; 601 int error; 602 caddr_t sg = stackgap_init(); 603 604#ifdef DEBUG 605 printf("Linux-emul(%ld): sigaltstack(%p, %p)\n", 606 (long)p->p_pid, uap->uss, uap->uoss); 607#endif 608 609 error = copyin(uap->uss, &lss, sizeof(linux_stack_t)); 610 if (error) 611 return (error); 612 613 ss = stackgap_alloc(&sg, sizeof(stack_t)); 614 ss->ss_sp = lss.ss_sp; 615 ss->ss_size = (lss.ss_size >= LINUX_MINSIGSTKSZ && 616 lss.ss_size < MINSIGSTKSZ) ? MINSIGSTKSZ : lss.ss_size; 617 ss->ss_flags = lss.ss_flags; 618 619 oss = (uap->uoss != NULL) 620 ? stackgap_alloc(&sg, sizeof(stack_t)) 621 : NULL; 622 623 bsd.ss = ss; 624 bsd.oss = oss; 625 error = sigaltstack(p, &bsd); 626 627 if (!error && oss != NULL) { 628 lss.ss_sp = oss->ss_sp; 629 lss.ss_size = oss->ss_size; 630 lss.ss_flags = oss->ss_flags; 631 error = copyout(&lss, uap->uoss, sizeof(linux_stack_t)); 632 } 633 634 return (error); 635} 636