1/*-
2 * Copyright (c) 1994-1996 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 11 unchanged lines hidden (view full) ---
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/i386/linux/linux_sysvec.c 71497 2001-01-24 00:27:28Z jhb $
29 */
30
31/* XXX we use functions that might not exist. */
32#include "opt_compat.h"
33
34#ifndef COMPAT_43
35#error "Unable to compile Linux-emulator due to missing COMPAT_43 option!"
36#endif
--- 140 unchanged lines hidden (view full) ---
177 }
178 AUXARGS_ENTRY(pos, AT_PHDR, args->phdr);
179 AUXARGS_ENTRY(pos, AT_PHENT, args->phent);
180 AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum);
181 AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz);
182 AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
183 AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
184 AUXARGS_ENTRY(pos, AT_BASE, args->base);
185 PROC_LOCK(imgp->proc);
186 AUXARGS_ENTRY(pos, AT_UID, imgp->proc->p_cred->p_ruid);
187 AUXARGS_ENTRY(pos, AT_EUID, imgp->proc->p_cred->p_svuid);
188 AUXARGS_ENTRY(pos, AT_GID, imgp->proc->p_cred->p_rgid);
189 AUXARGS_ENTRY(pos, AT_EGID, imgp->proc->p_cred->p_svgid);
190 PROC_UNLOCK(imgp->proc);
191 AUXARGS_ENTRY(pos, AT_NULL, 0);
192
193 free(imgp->auxargs, M_TEMP);
194 imgp->auxargs = NULL;
195
196 (*stack_base)--;
197 **stack_base = (long)imgp->argc;
198 return 0;
--- 15 unchanged lines hidden (view full) ---
214
215#ifdef DEBUG
216 printf("Linux-emul(%ld): linux_rt_sendsig(%p, %d, %p, %lu)\n",
217 (long)p->p_pid, catcher, sig, (void*)mask, code);
218#endif
219 /*
220 * Allocate space for the signal handler context.
221 */
222 PROC_LOCK(p);
223 if ((p->p_flag & P_ALTSTACK) && !oonstack &&
224 SIGISMEMBER(p->p_sigacts->ps_sigonstack, sig)) {
225 fp = (struct linux_rt_sigframe *)(p->p_sigstk.ss_sp +
226 p->p_sigstk.ss_size - sizeof(struct linux_rt_sigframe));
227 } else
228 fp = (struct linux_rt_sigframe *)regs->tf_esp - 1;
229 PROC_UNLOCK(p);
230
231 /*
232 * grow() will return FALSE if the fp will not fit inside the stack
233 * and the stack can not be grown. useracc will return FALSE
234 * if access is denied.
235 */
236 if ((grow_stack (p, (int)fp) == FALSE) ||
237 !useracc((caddr_t)fp, sizeof (struct linux_rt_sigframe),
238 VM_PROT_WRITE)) {
239 /*
240 * Process has trashed its stack; give it an illegal
241 * instruction to halt it in its tracks.
242 */
243 PROC_LOCK(p);
244 SIGACTION(p, SIGILL) = SIG_DFL;
245 SIGDELSET(p->p_sigignore, SIGILL);
246 SIGDELSET(p->p_sigcatch, SIGILL);
247 SIGDELSET(p->p_sigmask, SIGILL);
248 PROC_UNLOCK(p);
249#ifdef DEBUG
250 printf("Linux-emul(%ld): linux_rt_sendsig -- bad stack %p, "
251 "oonstack=%x\n", (long)p->p_pid, fp, oonstack);
252#endif
253 psignal(p, SIGILL);
254 return;
255 }
256
--- 15 unchanged lines hidden (view full) ---
272 frame.sf_si.lsi_addr = (void *)regs->tf_err;
273
274 /*
275 * Build the signal context to be used by sigreturn.
276 */
277 frame.sf_sc.uc_flags = 0; /* XXX ??? */
278 frame.sf_sc.uc_link = NULL; /* XXX ??? */
279
280 PROC_LOCK(p);
281 frame.sf_sc.uc_stack.ss_sp = p->p_sigstk.ss_sp;
282 frame.sf_sc.uc_stack.ss_size = p->p_sigstk.ss_size;
283 frame.sf_sc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
284 ? ((oonstack) ? LINUX_SS_ONSTACK : 0) : LINUX_SS_DISABLE;
285 PROC_UNLOCK(p);
286
287 bsd_to_linux_sigset(mask, &frame.sf_sc.uc_sigmask);
288
289 frame.sf_sc.uc_mcontext.sc_mask = frame.sf_sc.uc_sigmask.__bits[0];
290 frame.sf_sc.uc_mcontext.sc_gs = rgs();
291 frame.sf_sc.uc_mcontext.sc_fs = regs->tf_fs;
292 frame.sf_sc.uc_mcontext.sc_es = regs->tf_es;
293 frame.sf_sc.uc_mcontext.sc_ds = regs->tf_ds;
--- 76 unchanged lines hidden (view full) ---
370#ifdef DEBUG
371 printf("Linux-emul(%ld): linux_sendsig(%p, %d, %p, %lu)\n",
372 (long)p->p_pid, catcher, sig, (void*)mask, code);
373#endif
374
375 /*
376 * Allocate space for the signal handler context.
377 */
378 PROC_LOCK(p);
379 if ((p->p_flag & P_ALTSTACK) && !oonstack &&
380 SIGISMEMBER(p->p_sigacts->ps_sigonstack, sig)) {
381 fp = (struct linux_sigframe *)(p->p_sigstk.ss_sp +
382 p->p_sigstk.ss_size - sizeof(struct linux_sigframe));
383 } else
384 fp = (struct linux_sigframe *)regs->tf_esp - 1;
385 PROC_UNLOCK(p);
386
387 /*
388 * grow() will return FALSE if the fp will not fit inside the stack
389 * and the stack can not be grown. useracc will return FALSE
390 * if access is denied.
391 */
392 if ((grow_stack (p, (int)fp) == FALSE) ||
393 !useracc((caddr_t)fp, sizeof (struct linux_sigframe),
394 VM_PROT_WRITE)) {
395 /*
396 * Process has trashed its stack; give it an illegal
397 * instruction to halt it in its tracks.
398 */
399 PROC_LOCK(p);
400 SIGACTION(p, SIGILL) = SIG_DFL;
401 SIGDELSET(p->p_sigignore, SIGILL);
402 SIGDELSET(p->p_sigcatch, SIGILL);
403 SIGDELSET(p->p_sigmask, SIGILL);
404 PROC_UNLOCK(p);
405 psignal(p, SIGILL);
406 return;
407 }
408
409 /*
410 * Build the argument list for the signal handler.
411 */
412 if (p->p_sysent->sv_sigtbl)
--- 118 unchanged lines hidden (view full) ---
531 if (!CS_SECURE(frame.sf_sc.sc_cs)) {
532 trapsignal(p, SIGBUS, T_PROTFLT);
533 return(EINVAL);
534 }
535
536 lmask.__bits[0] = frame.sf_sc.sc_mask;
537 for (i = 0; i < (LINUX_NSIG_WORDS-1); i++)
538 lmask.__bits[i+1] = frame.sf_extramask[i];
539 PROC_LOCK(p);
540 linux_to_bsd_sigset(&lmask, &p->p_sigmask);
541 SIG_CANTMASK(p->p_sigmask);
542 PROC_UNLOCK(p);
543
544 /*
545 * Restore signal context.
546 */
547 /* %gs was restored by the trampoline. */
548 regs->tf_fs = frame.sf_sc.sc_fs;
549 regs->tf_es = frame.sf_sc.sc_es;
550 regs->tf_ds = frame.sf_sc.sc_ds;
--- 78 unchanged lines hidden (view full) ---
629 * other selectors, invalid %eip's and invalid %esp's.
630 */
631#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL)
632 if (!CS_SECURE(context->sc_cs)) {
633 trapsignal(p, SIGBUS, T_PROTFLT);
634 return(EINVAL);
635 }
636
637 PROC_LOCK(p);
638 linux_to_bsd_sigset(&uc.uc_sigmask, &p->p_sigmask);
639 SIG_CANTMASK(p->p_sigmask);
640 PROC_UNLOCK(p);
641
642 /*
643 * Restore signal context
644 */
645 /* %gs was restored by the trampoline. */
646 regs->tf_fs = context->sc_fs;
647 regs->tf_es = context->sc_es;
648 regs->tf_ds = context->sc_ds;
--- 202 unchanged lines hidden ---
2 * Copyright (c) 1994-1996 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
--- 11 unchanged lines hidden (view full) ---
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/i386/linux/linux_sysvec.c 71497 2001-01-24 00:27:28Z jhb $
29 */
30
31/* XXX we use functions that might not exist. */
32#include "opt_compat.h"
33
34#ifndef COMPAT_43
35#error "Unable to compile Linux-emulator due to missing COMPAT_43 option!"
36#endif
--- 140 unchanged lines hidden (view full) ---
177 }
178 AUXARGS_ENTRY(pos, AT_PHDR, args->phdr);
179 AUXARGS_ENTRY(pos, AT_PHENT, args->phent);
180 AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum);
181 AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz);
182 AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
183 AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
184 AUXARGS_ENTRY(pos, AT_BASE, args->base);
185 PROC_LOCK(imgp->proc);
186 AUXARGS_ENTRY(pos, AT_UID, imgp->proc->p_cred->p_ruid);
187 AUXARGS_ENTRY(pos, AT_EUID, imgp->proc->p_cred->p_svuid);
188 AUXARGS_ENTRY(pos, AT_GID, imgp->proc->p_cred->p_rgid);
189 AUXARGS_ENTRY(pos, AT_EGID, imgp->proc->p_cred->p_svgid);
190 PROC_UNLOCK(imgp->proc);
191 AUXARGS_ENTRY(pos, AT_NULL, 0);
192
193 free(imgp->auxargs, M_TEMP);
194 imgp->auxargs = NULL;
195
196 (*stack_base)--;
197 **stack_base = (long)imgp->argc;
198 return 0;
--- 15 unchanged lines hidden (view full) ---
214
215#ifdef DEBUG
216 printf("Linux-emul(%ld): linux_rt_sendsig(%p, %d, %p, %lu)\n",
217 (long)p->p_pid, catcher, sig, (void*)mask, code);
218#endif
219 /*
220 * Allocate space for the signal handler context.
221 */
222 PROC_LOCK(p);
223 if ((p->p_flag & P_ALTSTACK) && !oonstack &&
224 SIGISMEMBER(p->p_sigacts->ps_sigonstack, sig)) {
225 fp = (struct linux_rt_sigframe *)(p->p_sigstk.ss_sp +
226 p->p_sigstk.ss_size - sizeof(struct linux_rt_sigframe));
227 } else
228 fp = (struct linux_rt_sigframe *)regs->tf_esp - 1;
229 PROC_UNLOCK(p);
230
231 /*
232 * grow() will return FALSE if the fp will not fit inside the stack
233 * and the stack can not be grown. useracc will return FALSE
234 * if access is denied.
235 */
236 if ((grow_stack (p, (int)fp) == FALSE) ||
237 !useracc((caddr_t)fp, sizeof (struct linux_rt_sigframe),
238 VM_PROT_WRITE)) {
239 /*
240 * Process has trashed its stack; give it an illegal
241 * instruction to halt it in its tracks.
242 */
243 PROC_LOCK(p);
244 SIGACTION(p, SIGILL) = SIG_DFL;
245 SIGDELSET(p->p_sigignore, SIGILL);
246 SIGDELSET(p->p_sigcatch, SIGILL);
247 SIGDELSET(p->p_sigmask, SIGILL);
248 PROC_UNLOCK(p);
249#ifdef DEBUG
250 printf("Linux-emul(%ld): linux_rt_sendsig -- bad stack %p, "
251 "oonstack=%x\n", (long)p->p_pid, fp, oonstack);
252#endif
253 psignal(p, SIGILL);
254 return;
255 }
256
--- 15 unchanged lines hidden (view full) ---
272 frame.sf_si.lsi_addr = (void *)regs->tf_err;
273
274 /*
275 * Build the signal context to be used by sigreturn.
276 */
277 frame.sf_sc.uc_flags = 0; /* XXX ??? */
278 frame.sf_sc.uc_link = NULL; /* XXX ??? */
279
280 PROC_LOCK(p);
281 frame.sf_sc.uc_stack.ss_sp = p->p_sigstk.ss_sp;
282 frame.sf_sc.uc_stack.ss_size = p->p_sigstk.ss_size;
283 frame.sf_sc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
284 ? ((oonstack) ? LINUX_SS_ONSTACK : 0) : LINUX_SS_DISABLE;
285 PROC_UNLOCK(p);
286
287 bsd_to_linux_sigset(mask, &frame.sf_sc.uc_sigmask);
288
289 frame.sf_sc.uc_mcontext.sc_mask = frame.sf_sc.uc_sigmask.__bits[0];
290 frame.sf_sc.uc_mcontext.sc_gs = rgs();
291 frame.sf_sc.uc_mcontext.sc_fs = regs->tf_fs;
292 frame.sf_sc.uc_mcontext.sc_es = regs->tf_es;
293 frame.sf_sc.uc_mcontext.sc_ds = regs->tf_ds;
--- 76 unchanged lines hidden (view full) ---
370#ifdef DEBUG
371 printf("Linux-emul(%ld): linux_sendsig(%p, %d, %p, %lu)\n",
372 (long)p->p_pid, catcher, sig, (void*)mask, code);
373#endif
374
375 /*
376 * Allocate space for the signal handler context.
377 */
378 PROC_LOCK(p);
379 if ((p->p_flag & P_ALTSTACK) && !oonstack &&
380 SIGISMEMBER(p->p_sigacts->ps_sigonstack, sig)) {
381 fp = (struct linux_sigframe *)(p->p_sigstk.ss_sp +
382 p->p_sigstk.ss_size - sizeof(struct linux_sigframe));
383 } else
384 fp = (struct linux_sigframe *)regs->tf_esp - 1;
385 PROC_UNLOCK(p);
386
387 /*
388 * grow() will return FALSE if the fp will not fit inside the stack
389 * and the stack can not be grown. useracc will return FALSE
390 * if access is denied.
391 */
392 if ((grow_stack (p, (int)fp) == FALSE) ||
393 !useracc((caddr_t)fp, sizeof (struct linux_sigframe),
394 VM_PROT_WRITE)) {
395 /*
396 * Process has trashed its stack; give it an illegal
397 * instruction to halt it in its tracks.
398 */
399 PROC_LOCK(p);
400 SIGACTION(p, SIGILL) = SIG_DFL;
401 SIGDELSET(p->p_sigignore, SIGILL);
402 SIGDELSET(p->p_sigcatch, SIGILL);
403 SIGDELSET(p->p_sigmask, SIGILL);
404 PROC_UNLOCK(p);
405 psignal(p, SIGILL);
406 return;
407 }
408
409 /*
410 * Build the argument list for the signal handler.
411 */
412 if (p->p_sysent->sv_sigtbl)
--- 118 unchanged lines hidden (view full) ---
531 if (!CS_SECURE(frame.sf_sc.sc_cs)) {
532 trapsignal(p, SIGBUS, T_PROTFLT);
533 return(EINVAL);
534 }
535
536 lmask.__bits[0] = frame.sf_sc.sc_mask;
537 for (i = 0; i < (LINUX_NSIG_WORDS-1); i++)
538 lmask.__bits[i+1] = frame.sf_extramask[i];
539 PROC_LOCK(p);
540 linux_to_bsd_sigset(&lmask, &p->p_sigmask);
541 SIG_CANTMASK(p->p_sigmask);
542 PROC_UNLOCK(p);
543
544 /*
545 * Restore signal context.
546 */
547 /* %gs was restored by the trampoline. */
548 regs->tf_fs = frame.sf_sc.sc_fs;
549 regs->tf_es = frame.sf_sc.sc_es;
550 regs->tf_ds = frame.sf_sc.sc_ds;
--- 78 unchanged lines hidden (view full) ---
629 * other selectors, invalid %eip's and invalid %esp's.
630 */
631#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL)
632 if (!CS_SECURE(context->sc_cs)) {
633 trapsignal(p, SIGBUS, T_PROTFLT);
634 return(EINVAL);
635 }
636
637 PROC_LOCK(p);
638 linux_to_bsd_sigset(&uc.uc_sigmask, &p->p_sigmask);
639 SIG_CANTMASK(p->p_sigmask);
640 PROC_UNLOCK(p);
641
642 /*
643 * Restore signal context
644 */
645 /* %gs was restored by the trampoline. */
646 regs->tf_fs = context->sc_fs;
647 regs->tf_es = context->sc_es;
648 regs->tf_ds = context->sc_ds;
--- 202 unchanged lines hidden ---