2002-07-20 02:56:12 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002 Doug Rabson
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2005-09-10 02:12:49 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2003-12-18 06:59:18 +00:00
|
|
|
#include "opt_compat.h"
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
#define __ELF_WORD_SIZE 32
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/exec.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/imgact.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/pioctl.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/procfs.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/sx.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/sysent.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/imgact_elf.h>
|
2003-12-11 01:05:09 +00:00
|
|
|
#include <sys/sysproto.h>
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2003-05-16 21:26:42 +00:00
|
|
|
#include <machine/frame.h>
|
|
|
|
#include <machine/md_var.h>
|
|
|
|
#include <machine/pcb.h>
|
|
|
|
|
2002-07-20 02:56:12 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_kern.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
#include <vm/vm_map.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
|
2006-10-06 19:33:44 +00:00
|
|
|
#include <compat/freebsd32/freebsd32_signal.h>
|
2003-12-11 01:05:09 +00:00
|
|
|
#include <compat/freebsd32/freebsd32_util.h>
|
|
|
|
#include <compat/freebsd32/freebsd32_proto.h>
|
|
|
|
#include <compat/ia32/ia32_signal.h>
|
2012-03-19 21:29:57 +00:00
|
|
|
#include <x86/include/psl.h>
|
2012-03-19 21:24:50 +00:00
|
|
|
#include <x86/include/segments.h>
|
2012-03-19 21:34:11 +00:00
|
|
|
#include <x86/include/specialreg.h>
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2005-09-10 02:12:49 +00:00
|
|
|
char ia32_sigcode[] = {
|
|
|
|
0xff, 0x54, 0x24, 0x10, /* call *SIGF_HANDLER(%esp) */
|
|
|
|
0x8d, 0x44, 0x24, 0x14, /* lea SIGF_UC(%esp),%eax */
|
|
|
|
0x50, /* pushl %eax */
|
|
|
|
0xf7, 0x40, 0x54, 0x00, 0x00, 0x02, 0x02, /* testl $PSL_VM,UC_EFLAGS(%ea
|
|
|
|
x) */
|
|
|
|
0x75, 0x03, /* jne 9f */
|
|
|
|
0x8e, 0x68, 0x14, /* movl UC_GS(%eax),%gs */
|
|
|
|
0xb8, 0x57, 0x01, 0x00, 0x00, /* 9: movl $SYS_sigreturn,%eax */
|
|
|
|
0x50, /* pushl %eax */
|
|
|
|
0xcd, 0x80, /* int $0x80 */
|
|
|
|
0xeb, 0xfe, /* 0: jmp 0b */
|
|
|
|
0
|
|
|
|
};
|
|
|
|
int sz_ia32_sigcode = sizeof(ia32_sigcode);
|
|
|
|
|
2011-04-01 11:16:29 +00:00
|
|
|
#ifdef COMPAT_43
|
|
|
|
int
|
|
|
|
ofreebsd32_sigreturn(struct thread *td, struct ofreebsd32_sigreturn_args *uap)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-12-11 01:05:09 +00:00
|
|
|
/*
|
|
|
|
* Signal sending has not been implemented on ia64. This causes
|
|
|
|
* the sigtramp code to not understand the arguments and the application
|
|
|
|
* will generally crash if it tries to handle a signal. Calling
|
|
|
|
* sendsig() means that at least untrapped signals will work.
|
|
|
|
*/
|
|
|
|
void
|
1. Change prototype of trapsignal and sendsig to use ksiginfo_t *, most
changes in MD code are trivial, before this change, trapsignal and
sendsig use discrete parameters, now they uses member fields of
ksiginfo_t structure. For sendsig, this change allows us to pass
POSIX realtime signal value to user code.
2. Remove cpu_thread_siginfo, it is no longer needed because we now always
generate ksiginfo_t data and feed it to libpthread.
3. Add p_sigqueue to proc structure to hold shared signals which were
blocked by all threads in the proc.
4. Add td_sigqueue to thread structure to hold all signals delivered to
thread.
5. i386 and amd64 now return POSIX standard si_code, other arches will
be fixed.
6. In this sigqueue implementation, pending signal set is kept as before,
an extra siginfo list holds additional siginfo_t data for signals.
kernel code uses psignal() still behavior as before, it won't be failed
even under memory pressure, only exception is when deleting a signal,
we should call sigqueue_delete to remove signal from sigqueue but
not SIGDELSET. Current there is no kernel code will deliver a signal
with additional data, so kernel should be as stable as before,
a ksiginfo can carry more information, for example, allow signal to
be delivered but throw away siginfo data if memory is not enough.
SIGKILL and SIGSTOP have fast path in sigqueue_add, because they can
not be caught or masked.
The sigqueue() syscall allows user code to queue a signal to target
process, if resource is unavailable, EAGAIN will be returned as
specification said.
Just before thread exits, signal queue memory will be freed by
sigqueue_flush.
Current, all signals are allowed to be queued, not only realtime signals.
Earlier patch reviewed by: jhb, deischen
Tested on: i386, amd64
2005-10-14 12:43:47 +00:00
|
|
|
ia32_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
1. Change prototype of trapsignal and sendsig to use ksiginfo_t *, most
changes in MD code are trivial, before this change, trapsignal and
sendsig use discrete parameters, now they uses member fields of
ksiginfo_t structure. For sendsig, this change allows us to pass
POSIX realtime signal value to user code.
2. Remove cpu_thread_siginfo, it is no longer needed because we now always
generate ksiginfo_t data and feed it to libpthread.
3. Add p_sigqueue to proc structure to hold shared signals which were
blocked by all threads in the proc.
4. Add td_sigqueue to thread structure to hold all signals delivered to
thread.
5. i386 and amd64 now return POSIX standard si_code, other arches will
be fixed.
6. In this sigqueue implementation, pending signal set is kept as before,
an extra siginfo list holds additional siginfo_t data for signals.
kernel code uses psignal() still behavior as before, it won't be failed
even under memory pressure, only exception is when deleting a signal,
we should call sigqueue_delete to remove signal from sigqueue but
not SIGDELSET. Current there is no kernel code will deliver a signal
with additional data, so kernel should be as stable as before,
a ksiginfo can carry more information, for example, allow signal to
be delivered but throw away siginfo data if memory is not enough.
SIGKILL and SIGSTOP have fast path in sigqueue_add, because they can
not be caught or masked.
The sigqueue() syscall allows user code to queue a signal to target
process, if resource is unavailable, EAGAIN will be returned as
specification said.
Just before thread exits, signal queue memory will be freed by
sigqueue_flush.
Current, all signals are allowed to be queued, not only realtime signals.
Earlier patch reviewed by: jhb, deischen
Tested on: i386, amd64
2005-10-14 12:43:47 +00:00
|
|
|
sendsig(catcher, ksi, mask);
|
2003-12-11 01:05:09 +00:00
|
|
|
}
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2003-12-11 01:05:09 +00:00
|
|
|
#ifdef COMPAT_FREEBSD4
|
|
|
|
int
|
|
|
|
freebsd4_freebsd32_sigreturn(struct thread *td, struct freebsd4_freebsd32_sigreturn_args *uap)
|
|
|
|
{
|
2011-09-16 13:58:51 +00:00
|
|
|
return (sys_sigreturn(td, (struct sigreturn_args *)uap));
|
2003-12-11 01:05:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2003-12-11 01:05:09 +00:00
|
|
|
int
|
|
|
|
freebsd32_sigreturn(struct thread *td, struct freebsd32_sigreturn_args *uap)
|
|
|
|
{
|
2011-09-16 13:58:51 +00:00
|
|
|
return (sys_sigreturn(td, (struct sigreturn_args *)uap));
|
2002-07-20 02:56:12 +00:00
|
|
|
}
|
|
|
|
|
2003-12-11 01:05:09 +00:00
|
|
|
|
|
|
|
void
|
2010-03-25 14:24:00 +00:00
|
|
|
ia32_setregs(struct thread *td, struct image_params *imgp, u_long stack)
|
2002-07-20 02:56:12 +00:00
|
|
|
{
|
2003-05-16 21:26:42 +00:00
|
|
|
struct trapframe *tf = td->td_frame;
|
2002-07-20 02:56:12 +00:00
|
|
|
vm_offset_t gdt, ldt;
|
|
|
|
u_int64_t codesel, datasel, ldtsel;
|
|
|
|
u_int64_t codeseg, dataseg, gdtseg, ldtseg;
|
|
|
|
struct segment_descriptor desc;
|
|
|
|
struct vmspace *vmspace = td->td_proc->p_vmspace;
|
2010-08-07 11:57:13 +00:00
|
|
|
struct sysentvec *sv;
|
2002-07-20 02:56:12 +00:00
|
|
|
|
2010-08-07 11:57:13 +00:00
|
|
|
sv = td->td_proc->p_sysent;
|
2010-03-25 14:24:00 +00:00
|
|
|
exec_setregs(td, imgp, stack);
|
2003-05-16 21:26:42 +00:00
|
|
|
|
|
|
|
/* Non-syscall frames are cleared by exec_setregs() */
|
|
|
|
if (tf->tf_flags & FRAME_SYSCALL) {
|
|
|
|
bzero(&tf->tf_scratch, sizeof(tf->tf_scratch));
|
|
|
|
bzero(&tf->tf_scratch_fp, sizeof(tf->tf_scratch_fp));
|
|
|
|
} else
|
|
|
|
tf->tf_special.ndirty = 0;
|
|
|
|
|
|
|
|
tf->tf_special.psr |= IA64_PSR_IS;
|
|
|
|
tf->tf_special.sp = stack;
|
|
|
|
|
|
|
|
/* Point the RSE backstore to something harmless. */
|
2010-08-07 11:57:13 +00:00
|
|
|
tf->tf_special.bspstore = (sv->sv_psstrings - sz_ia32_sigcode -
|
2003-12-11 01:05:09 +00:00
|
|
|
SPARE_USRSPACE + 15) & ~15;
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
codesel = LSEL(LUCODE_SEL, SEL_UPL);
|
|
|
|
datasel = LSEL(LUDATA_SEL, SEL_UPL);
|
|
|
|
ldtsel = GSEL(GLDT_SEL, SEL_UPL);
|
|
|
|
|
2003-05-16 21:26:42 +00:00
|
|
|
/* Setup ia32 segment registers. */
|
|
|
|
tf->tf_scratch.gr16 = (datasel << 48) | (datasel << 32) |
|
|
|
|
(datasel << 16) | datasel;
|
|
|
|
tf->tf_scratch.gr17 = (ldtsel << 32) | (datasel << 16) | codesel;
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Build the GDT and LDT.
|
|
|
|
*/
|
2010-08-07 11:57:13 +00:00
|
|
|
gdt = sv->sv_usrstack;
|
2003-05-16 21:26:42 +00:00
|
|
|
vm_map_find(&vmspace->vm_map, 0, 0, &gdt, IA32_PAGE_SIZE << 1, 0,
|
|
|
|
VM_PROT_ALL, VM_PROT_ALL, 0);
|
|
|
|
ldt = gdt + IA32_PAGE_SIZE;
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
desc.sd_lolimit = 8*NLDT-1;
|
|
|
|
desc.sd_lobase = ldt & 0xffffff;
|
|
|
|
desc.sd_type = SDT_SYSLDT;
|
|
|
|
desc.sd_dpl = SEL_UPL;
|
|
|
|
desc.sd_p = 1;
|
|
|
|
desc.sd_hilimit = 0;
|
|
|
|
desc.sd_def32 = 0;
|
|
|
|
desc.sd_gran = 0;
|
|
|
|
desc.sd_hibase = ldt >> 24;
|
|
|
|
copyout(&desc, (caddr_t) gdt + 8*GLDT_SEL, sizeof(desc));
|
|
|
|
|
2010-08-07 11:57:13 +00:00
|
|
|
desc.sd_lolimit = ((sv->sv_usrstack >> 12) - 1) & 0xffff;
|
2002-07-20 02:56:12 +00:00
|
|
|
desc.sd_lobase = 0;
|
|
|
|
desc.sd_type = SDT_MEMERA;
|
|
|
|
desc.sd_dpl = SEL_UPL;
|
|
|
|
desc.sd_p = 1;
|
2010-08-07 11:57:13 +00:00
|
|
|
desc.sd_hilimit = ((sv->sv_usrstack >> 12) - 1) >> 16;
|
2002-07-20 02:56:12 +00:00
|
|
|
desc.sd_def32 = 1;
|
|
|
|
desc.sd_gran = 1;
|
|
|
|
desc.sd_hibase = 0;
|
|
|
|
copyout(&desc, (caddr_t) ldt + 8*LUCODE_SEL, sizeof(desc));
|
|
|
|
desc.sd_type = SDT_MEMRWA;
|
|
|
|
copyout(&desc, (caddr_t) ldt + 8*LUDATA_SEL, sizeof(desc));
|
|
|
|
|
|
|
|
codeseg = 0 /* base */
|
2010-08-07 11:57:13 +00:00
|
|
|
+ (((sv->sv_usrstack >> 12) - 1) << 32) /* limit */
|
2002-07-20 02:56:12 +00:00
|
|
|
+ ((long)SDT_MEMERA << 52)
|
|
|
|
+ ((long)SEL_UPL << 57)
|
|
|
|
+ (1L << 59) /* present */
|
|
|
|
+ (1L << 62) /* 32 bits */
|
|
|
|
+ (1L << 63); /* page granularity */
|
|
|
|
dataseg = 0 /* base */
|
2010-08-07 11:57:13 +00:00
|
|
|
+ (((sv->sv_usrstack >> 12) - 1) << 32) /* limit */
|
2002-07-20 02:56:12 +00:00
|
|
|
+ ((long)SDT_MEMRWA << 52)
|
|
|
|
+ ((long)SEL_UPL << 57)
|
|
|
|
+ (1L << 59) /* present */
|
|
|
|
+ (1L << 62) /* 32 bits */
|
|
|
|
+ (1L << 63); /* page granularity */
|
2003-05-16 21:26:42 +00:00
|
|
|
|
|
|
|
tf->tf_scratch.csd = codeseg;
|
|
|
|
tf->tf_scratch.ssd = dataseg;
|
|
|
|
tf->tf_scratch.gr24 = dataseg; /* ESD */
|
|
|
|
tf->tf_scratch.gr27 = dataseg; /* DSD */
|
|
|
|
tf->tf_scratch.gr28 = dataseg; /* FSD */
|
|
|
|
tf->tf_scratch.gr29 = dataseg; /* GSD */
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
gdtseg = gdt /* base */
|
|
|
|
+ ((8L*NGDT - 1) << 32) /* limit */
|
|
|
|
+ ((long)SDT_SYSNULL << 52)
|
|
|
|
+ ((long)SEL_UPL << 57)
|
|
|
|
+ (1L << 59) /* present */
|
|
|
|
+ (0L << 62) /* 16 bits */
|
|
|
|
+ (0L << 63); /* byte granularity */
|
|
|
|
ldtseg = ldt /* base */
|
|
|
|
+ ((8L*NLDT - 1) << 32) /* limit */
|
|
|
|
+ ((long)SDT_SYSLDT << 52)
|
|
|
|
+ ((long)SEL_UPL << 57)
|
|
|
|
+ (1L << 59) /* present */
|
|
|
|
+ (0L << 62) /* 16 bits */
|
|
|
|
+ (0L << 63); /* byte granularity */
|
|
|
|
|
2003-05-16 21:26:42 +00:00
|
|
|
tf->tf_scratch.gr30 = ldtseg; /* LDTD */
|
|
|
|
tf->tf_scratch.gr31 = gdtseg; /* GDTD */
|
|
|
|
|
|
|
|
/* Set ia32 control registers on this processor. */
|
|
|
|
ia64_set_cflg(CR0_PE | CR0_PG | ((long)(CR4_XMM | CR4_FXSR) << 32));
|
2002-07-20 02:56:12 +00:00
|
|
|
ia64_set_eflag(PSL_USER);
|
|
|
|
|
|
|
|
/* PS_STRINGS value for BSD/OS binaries. It is 0 for non-BSD/OS. */
|
2010-08-07 11:57:13 +00:00
|
|
|
tf->tf_scratch.gr11 = td->td_proc->p_sysent->sv_psstrings;
|
2002-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - Linux emulator
|
|
|
|
* Make sure sure edx is 0x0 on entry. Linux binaries depend
|
|
|
|
* on it.
|
|
|
|
*/
|
|
|
|
td->td_retval[1] = 0;
|
|
|
|
}
|
2003-05-16 21:26:42 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
ia32_restorectx(struct pcb *pcb)
|
|
|
|
{
|
|
|
|
|
|
|
|
ia64_set_cflg(pcb->pcb_ia32_cflg);
|
|
|
|
ia64_set_eflag(pcb->pcb_ia32_eflag);
|
|
|
|
ia64_set_fcr(pcb->pcb_ia32_fcr);
|
|
|
|
ia64_set_fdr(pcb->pcb_ia32_fdr);
|
|
|
|
ia64_set_fir(pcb->pcb_ia32_fir);
|
|
|
|
ia64_set_fsr(pcb->pcb_ia32_fsr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ia32_savectx(struct pcb *pcb)
|
|
|
|
{
|
|
|
|
|
|
|
|
pcb->pcb_ia32_cflg = ia64_get_cflg();
|
|
|
|
pcb->pcb_ia32_eflag = ia64_get_eflag();
|
|
|
|
pcb->pcb_ia32_fcr = ia64_get_fcr();
|
|
|
|
pcb->pcb_ia32_fdr = ia64_get_fdr();
|
|
|
|
pcb->pcb_ia32_fir = ia64_get_fir();
|
|
|
|
pcb->pcb_ia32_fsr = ia64_get_fsr();
|
|
|
|
}
|
2005-09-27 18:04:20 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
freebsd32_getcontext(struct thread *td, struct freebsd32_getcontext_args *uap)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (nosys(td, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
freebsd32_setcontext(struct thread *td, struct freebsd32_setcontext_args *uap)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (nosys(td, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
freebsd32_swapcontext(struct thread *td, struct freebsd32_swapcontext_args *uap)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (nosys(td, NULL));
|
|
|
|
}
|