Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
/*-
|
2023-05-10 11:40:58 -04:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2017-11-27 10:08:52 -05:00
|
|
|
*
|
2012-01-15 08:23:18 -05:00
|
|
|
* Copyright (c) 1994-1996 Søren Schmidt
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
* 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
|
2018-02-16 10:00:14 -05:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
* 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.
|
|
|
|
|
*
|
2018-02-16 10:00:14 -05:00
|
|
|
* 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.
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
*/
|
|
|
|
|
|
2023-02-02 09:58:06 -05:00
|
|
|
#define __ELF_WORD_SIZE 32
|
|
|
|
|
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
#include <sys/param.h>
|
2003-12-29 01:51:10 -05:00
|
|
|
#include <sys/exec.h>
|
2008-03-31 08:01:21 -04:00
|
|
|
#include <sys/fcntl.h>
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
#include <sys/imgact.h>
|
1998-09-14 01:36:51 -04:00
|
|
|
#include <sys/imgact_aout.h>
|
1996-03-10 03:42:54 -05:00
|
|
|
#include <sys/imgact_elf.h>
|
2003-12-29 01:51:10 -05:00
|
|
|
#include <sys/kernel.h>
|
2023-02-14 09:46:32 -05:00
|
|
|
#include <sys/lock.h>
|
1996-03-10 03:42:54 -05:00
|
|
|
#include <sys/malloc.h>
|
2003-12-29 01:51:10 -05:00
|
|
|
#include <sys/module.h>
|
2023-02-14 09:46:32 -05:00
|
|
|
#include <sys/mutex.h>
|
2001-05-01 04:13:21 -04:00
|
|
|
#include <sys/proc.h>
|
2021-07-20 03:01:18 -04:00
|
|
|
#include <sys/stddef.h>
|
2002-09-01 18:30:27 -04:00
|
|
|
#include <sys/syscallsubr.h>
|
2015-05-24 11:51:18 -04:00
|
|
|
#include <sys/sysctl.h>
|
2001-05-01 04:13:21 -04:00
|
|
|
#include <sys/sysent.h>
|
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
|
|
2002-09-06 21:29:21 -04:00
|
|
|
#include <vm/pmap.h>
|
2023-02-14 09:46:32 -05:00
|
|
|
#include <vm/vm.h>
|
2002-09-06 21:29:21 -04:00
|
|
|
#include <vm/vm_map.h>
|
2003-12-29 01:51:10 -05:00
|
|
|
#include <vm/vm_page.h>
|
|
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
2009-03-04 07:14:33 -05:00
|
|
|
#include <machine/cputypes.h>
|
2003-12-29 01:51:10 -05:00
|
|
|
#include <machine/md_var.h>
|
2004-11-27 01:46:45 -05:00
|
|
|
#include <machine/pcb.h>
|
2018-03-27 16:57:51 -04:00
|
|
|
#include <machine/trap.h>
|
2002-09-06 21:29:21 -04:00
|
|
|
|
2021-07-20 03:01:18 -04:00
|
|
|
#include <x86/linux/linux_x86.h>
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
#include <i386/linux/linux.h>
|
2000-11-10 16:30:19 -05:00
|
|
|
#include <i386/linux/linux_proto.h>
|
2023-02-02 09:58:06 -05:00
|
|
|
#include <compat/linux/linux_elf.h>
|
2006-08-17 17:06:48 -04:00
|
|
|
#include <compat/linux/linux_emul.h>
|
2021-08-12 04:49:01 -04:00
|
|
|
#include <compat/linux/linux_fork.h>
|
2013-01-29 13:41:30 -05:00
|
|
|
#include <compat/linux/linux_ioctl.h>
|
2003-03-27 13:18:35 -05:00
|
|
|
#include <compat/linux/linux_mib.h>
|
2009-03-04 07:14:33 -05:00
|
|
|
#include <compat/linux/linux_misc.h>
|
2000-11-15 21:07:05 -05:00
|
|
|
#include <compat/linux/linux_signal.h>
|
2000-08-22 01:57:55 -04:00
|
|
|
#include <compat/linux/linux_util.h>
|
2015-05-24 11:28:17 -04:00
|
|
|
#include <compat/linux/linux_vdso.h>
|
1996-03-10 03:42:54 -05:00
|
|
|
|
2022-05-15 14:03:01 -04:00
|
|
|
#include <x86/linux/linux_x86_sigframe.h>
|
|
|
|
|
|
2000-05-05 21:36:04 -04:00
|
|
|
MODULE_VERSION(linux, 1);
|
|
|
|
|
|
2021-07-20 03:01:18 -04:00
|
|
|
#define LINUX_VDSOPAGE_SIZE PAGE_SIZE * 2
|
|
|
|
|
#define LINUX_VDSOPAGE (VM_MAXUSER_ADDRESS - LINUX_VDSOPAGE_SIZE)
|
|
|
|
|
#define LINUX_SHAREDPAGE (LINUX_VDSOPAGE - PAGE_SIZE)
|
|
|
|
|
/*
|
|
|
|
|
* PAGE_SIZE - the size
|
|
|
|
|
* of the native SHAREDPAGE
|
|
|
|
|
*/
|
|
|
|
|
#define LINUX_USRSTACK LINUX_SHAREDPAGE
|
2011-03-13 10:58:02 -04:00
|
|
|
#define LINUX_PS_STRINGS (LINUX_USRSTACK - sizeof(struct ps_strings))
|
|
|
|
|
|
2015-05-24 11:28:17 -04:00
|
|
|
static int linux_szsigcode;
|
2021-07-20 03:01:18 -04:00
|
|
|
static vm_object_t linux_vdso_obj;
|
|
|
|
|
static char *linux_vdso_mapping;
|
|
|
|
|
extern char _binary_linux_vdso_so_o_start;
|
|
|
|
|
extern char _binary_linux_vdso_so_o_end;
|
|
|
|
|
static vm_offset_t linux_vdso_base;
|
1999-12-04 06:10:22 -05:00
|
|
|
|
|
|
|
|
extern struct sysent linux_sysent[LINUX_SYS_MAXSYSCALL];
|
2022-10-28 17:19:39 -04:00
|
|
|
extern const char *linux_syscallnames[];
|
1999-12-04 06:10:22 -05:00
|
|
|
|
2001-06-13 06:58:39 -04:00
|
|
|
SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler);
|
1999-12-04 06:10:22 -05:00
|
|
|
|
2019-12-03 18:17:54 -05:00
|
|
|
static int linux_fixup(uintptr_t *stack_base,
|
2002-03-23 23:09:05 -05:00
|
|
|
struct image_params *iparams);
|
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 08:43:47 -04:00
|
|
|
static void linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask);
|
2018-03-19 17:26:32 -04:00
|
|
|
static void linux_exec_setregs(struct thread *td,
|
2019-12-03 18:17:54 -05:00
|
|
|
struct image_params *imgp, uintptr_t stack);
|
2021-07-20 03:01:18 -04:00
|
|
|
static void linux_exec_sysvec_init(void *param);
|
2021-07-20 02:56:25 -04:00
|
|
|
static int linux_on_exec_vmspace(struct proc *p,
|
|
|
|
|
struct image_params *imgp);
|
2021-08-12 04:45:25 -04:00
|
|
|
static void linux_set_fork_retval(struct thread *td);
|
2021-07-20 03:01:47 -04:00
|
|
|
static void linux_vdso_install(const void *param);
|
|
|
|
|
static void linux_vdso_deinstall(const void *param);
|
2021-07-20 03:01:18 -04:00
|
|
|
static void linux_vdso_reloc(char *mapping, Elf_Addr offset);
|
2009-03-04 07:14:33 -05:00
|
|
|
|
2021-06-22 01:36:21 -04:00
|
|
|
LINUX_VDSO_SYM_CHAR(linux_platform);
|
2021-07-20 03:01:18 -04:00
|
|
|
LINUX_VDSO_SYM_INTPTR(__kernel_vsyscall);
|
2022-05-15 14:08:12 -04:00
|
|
|
LINUX_VDSO_SYM_INTPTR(linux_vdso_sigcode);
|
|
|
|
|
LINUX_VDSO_SYM_INTPTR(linux_vdso_rt_sigcode);
|
2021-07-20 03:01:18 -04:00
|
|
|
LINUX_VDSO_SYM_INTPTR(kern_timekeep_base);
|
|
|
|
|
LINUX_VDSO_SYM_INTPTR(kern_tsc_selector);
|
2022-05-08 10:20:52 -04:00
|
|
|
LINUX_VDSO_SYM_INTPTR(kern_cpu_selector);
|
2015-05-24 11:28:17 -04:00
|
|
|
|
1998-02-09 01:11:36 -05:00
|
|
|
static int
|
2019-12-03 18:17:54 -05:00
|
|
|
linux_fixup(uintptr_t *stack_base, struct image_params *imgp)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
{
|
2019-12-03 18:17:54 -05:00
|
|
|
register_t *base, *argv, *envp;
|
|
|
|
|
|
|
|
|
|
base = (register_t *)*stack_base;
|
|
|
|
|
argv = base;
|
|
|
|
|
envp = base + (imgp->args->argc + 1);
|
|
|
|
|
base--;
|
2023-12-25 20:40:05 -05:00
|
|
|
if (suword(base, (intptr_t)envp) != 0)
|
|
|
|
|
return (EFAULT);
|
2019-12-03 18:17:54 -05:00
|
|
|
base--;
|
2023-12-25 20:40:05 -05:00
|
|
|
if (suword(base, (intptr_t)argv) != 0)
|
|
|
|
|
return (EFAULT);
|
2019-12-03 18:17:54 -05:00
|
|
|
base--;
|
2023-12-25 20:40:05 -05:00
|
|
|
if (suword(base, imgp->args->argc) != 0)
|
|
|
|
|
return (EFAULT);
|
2019-12-03 18:17:54 -05:00
|
|
|
*stack_base = (uintptr_t)base;
|
2009-03-04 07:14:33 -05:00
|
|
|
return (0);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
}
|
|
|
|
|
|
2023-04-22 15:16:02 -04:00
|
|
|
void
|
|
|
|
|
linux32_arch_copyout_auxargs(struct image_params *imgp, Elf_Auxinfo **pos)
|
1996-03-10 03:42:54 -05:00
|
|
|
{
|
2009-05-10 14:43:43 -04:00
|
|
|
|
2023-04-22 15:16:02 -04:00
|
|
|
AUXARGS_ENTRY((*pos), LINUX_AT_SYSINFO_EHDR, linux_vdso_base);
|
|
|
|
|
AUXARGS_ENTRY((*pos), LINUX_AT_SYSINFO, __kernel_vsyscall);
|
|
|
|
|
AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP, cpu_feature);
|
2023-07-28 04:56:59 -04:00
|
|
|
AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP2, linux_x86_elf_hwcap2());
|
2023-04-22 15:16:02 -04:00
|
|
|
AUXARGS_ENTRY((*pos), LINUX_AT_PLATFORM, PTROUT(linux_platform));
|
2019-11-15 18:01:43 -05:00
|
|
|
}
|
|
|
|
|
|
2000-10-16 20:00:20 -04:00
|
|
|
static 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 08:43:47 -04:00
|
|
|
linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
|
2000-10-16 20:00:20 -04:00
|
|
|
{
|
2003-03-03 04:17:12 -05:00
|
|
|
struct thread *td = curthread;
|
|
|
|
|
struct proc *p = td->td_proc;
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 16:36:02 -04:00
|
|
|
struct sigacts *psp;
|
2003-03-03 04:17:12 -05:00
|
|
|
struct trapframe *regs;
|
2001-09-08 15:07:04 -04:00
|
|
|
struct l_rt_sigframe *fp, frame;
|
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 08:43:47 -04:00
|
|
|
int sig, code;
|
2000-10-16 20:00:20 -04:00
|
|
|
int oonstack;
|
|
|
|
|
|
2022-05-20 07:54:03 -04:00
|
|
|
sig = linux_translate_traps(ksi->ksi_signo, ksi->ksi_trapno);
|
2018-02-05 12:29:12 -05:00
|
|
|
code = ksi->ksi_code;
|
2001-09-06 18:20:41 -04:00
|
|
|
PROC_LOCK_ASSERT(p, MA_OWNED);
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 16:36:02 -04:00
|
|
|
psp = p->p_sigacts;
|
|
|
|
|
mtx_assert(&psp->ps_mtx, MA_OWNED);
|
2001-09-12 04:38:13 -04:00
|
|
|
regs = td->td_frame;
|
2000-11-30 00:23:49 -05:00
|
|
|
oonstack = sigonstack(regs->tf_esp);
|
2000-10-16 20:00:20 -04:00
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Allocate space for the signal handler context. */
|
2004-01-02 21:02:26 -05:00
|
|
|
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 16:36:02 -04:00
|
|
|
SIGISMEMBER(psp->ps_sigonstack, sig)) {
|
2016-01-27 12:55:01 -05:00
|
|
|
fp = (struct l_rt_sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
|
2004-01-02 21:02:26 -05:00
|
|
|
td->td_sigstk.ss_size - sizeof(struct l_rt_sigframe));
|
2000-11-30 00:23:49 -05:00
|
|
|
} else
|
2001-09-08 15:07:04 -04:00
|
|
|
fp = (struct l_rt_sigframe *)regs->tf_esp - 1;
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 16:36:02 -04:00
|
|
|
mtx_unlock(&psp->ps_mtx);
|
2000-10-16 20:00:20 -04:00
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Build the argument list for the signal handler. */
|
2015-05-24 13:47:20 -04:00
|
|
|
sig = bsd_to_linux_signal(sig);
|
2000-10-16 20:00:20 -04:00
|
|
|
|
2002-11-02 02:41:04 -05:00
|
|
|
bzero(&frame, sizeof(frame));
|
|
|
|
|
|
2000-10-16 20:00:20 -04:00
|
|
|
frame.sf_sig = sig;
|
2022-05-15 14:03:01 -04:00
|
|
|
frame.sf_siginfo = PTROUT(&fp->sf_si);
|
2022-05-15 14:06:47 -04:00
|
|
|
frame.sf_ucontext = PTROUT(&fp->sf_uc);
|
2000-11-23 03:55:30 -05:00
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Fill in POSIX parts. */
|
2021-06-06 23:06:17 -04:00
|
|
|
siginfo_to_lsiginfo(&ksi->ksi_info, &frame.sf_si, sig);
|
2000-11-23 03:55:30 -05:00
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Build the signal context to be used by sigreturn. */
|
2022-05-15 14:06:47 -04:00
|
|
|
frame.sf_uc.uc_stack.ss_sp = PTROUT(td->td_sigstk.ss_sp);
|
|
|
|
|
frame.sf_uc.uc_stack.ss_size = td->td_sigstk.ss_size;
|
|
|
|
|
frame.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
|
2000-11-30 00:23:49 -05:00
|
|
|
? ((oonstack) ? LINUX_SS_ONSTACK : 0) : LINUX_SS_DISABLE;
|
2001-01-23 19:27:28 -05:00
|
|
|
PROC_UNLOCK(p);
|
2000-11-23 03:55:30 -05:00
|
|
|
|
2022-05-15 14:06:47 -04:00
|
|
|
bsd_to_linux_sigset(mask, &frame.sf_uc.uc_sigmask);
|
|
|
|
|
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_mask = frame.sf_uc.uc_sigmask.__mask;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_gs = rgs();
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_fs = regs->tf_fs;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_es = regs->tf_es;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_ds = regs->tf_ds;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_edi = regs->tf_edi;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_esi = regs->tf_esi;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_ebp = regs->tf_ebp;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_ebx = regs->tf_ebx;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_esp = regs->tf_esp;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_edx = regs->tf_edx;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_ecx = regs->tf_ecx;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_eax = regs->tf_eax;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_eip = regs->tf_eip;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_cs = regs->tf_cs;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_eflags = regs->tf_eflags;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_esp_at_signal = regs->tf_esp;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_ss = regs->tf_ss;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_err = regs->tf_err;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_cr2 = (register_t)ksi->ksi_addr;
|
|
|
|
|
frame.sf_uc.uc_mcontext.sc_trapno = bsd_to_linux_trapcode(code);
|
2000-10-16 20:00:20 -04:00
|
|
|
|
|
|
|
|
if (copyout(&frame, fp, sizeof(frame)) != 0) {
|
|
|
|
|
/*
|
|
|
|
|
* Process has trashed its stack; give it an illegal
|
|
|
|
|
* instruction to halt it in its tracks.
|
|
|
|
|
*/
|
2001-03-06 22:37:06 -05:00
|
|
|
PROC_LOCK(p);
|
2001-09-12 04:38:13 -04:00
|
|
|
sigexit(td, SIGILL);
|
2000-10-16 20:00:20 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Build context to run handler in. */
|
2022-05-15 14:03:01 -04:00
|
|
|
regs->tf_esp = PTROUT(fp);
|
2022-05-15 14:08:12 -04:00
|
|
|
regs->tf_eip = linux_vdso_rt_sigcode;
|
2022-05-15 14:03:01 -04:00
|
|
|
regs->tf_edi = PTROUT(catcher);
|
2008-03-13 06:54:38 -04:00
|
|
|
regs->tf_eflags &= ~(PSL_T | PSL_VM | PSL_D);
|
2000-10-16 20:00:20 -04:00
|
|
|
regs->tf_cs = _ucodesel;
|
|
|
|
|
regs->tf_ds = _udatasel;
|
|
|
|
|
regs->tf_es = _udatasel;
|
|
|
|
|
regs->tf_fs = _udatasel;
|
|
|
|
|
regs->tf_ss = _udatasel;
|
2001-09-06 18:20:41 -04:00
|
|
|
PROC_LOCK(p);
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 16:36:02 -04:00
|
|
|
mtx_lock(&psp->ps_mtx);
|
2000-10-16 20:00:20 -04:00
|
|
|
}
|
|
|
|
|
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
/*
|
|
|
|
|
* Send an interrupt to process.
|
|
|
|
|
*
|
|
|
|
|
* Stack is set up to allow sigcode stored
|
|
|
|
|
* in u. to call routine, followed by kcall
|
|
|
|
|
* to sigreturn routine below. After sigreturn
|
|
|
|
|
* resets the signal mask, the stack, and the
|
|
|
|
|
* frame pointer, it returns to the user
|
|
|
|
|
* specified pc, psl.
|
|
|
|
|
*/
|
1998-02-09 01:11:36 -05:00
|
|
|
static 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 08:43:47 -04:00
|
|
|
linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
{
|
2003-03-03 04:17:12 -05:00
|
|
|
struct thread *td = curthread;
|
|
|
|
|
struct proc *p = td->td_proc;
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 16:36:02 -04:00
|
|
|
struct sigacts *psp;
|
2003-03-03 04:17:12 -05:00
|
|
|
struct trapframe *regs;
|
2001-09-08 15:07:04 -04:00
|
|
|
struct l_sigframe *fp, frame;
|
|
|
|
|
l_sigset_t lmask;
|
2022-04-08 20:25:14 -04:00
|
|
|
int sig;
|
2015-05-24 13:47:20 -04:00
|
|
|
int oonstack;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
|
2001-09-17 13:22:31 -04:00
|
|
|
PROC_LOCK_ASSERT(p, MA_OWNED);
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 16:36:02 -04:00
|
|
|
psp = p->p_sigacts;
|
2022-05-20 07:54:03 -04:00
|
|
|
sig = linux_translate_traps(ksi->ksi_signo, ksi->ksi_trapno);
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 16:36:02 -04:00
|
|
|
mtx_assert(&psp->ps_mtx, MA_OWNED);
|
|
|
|
|
if (SIGISMEMBER(psp->ps_siginfo, sig)) {
|
2000-11-23 03:55:30 -05:00
|
|
|
/* Signal handler installed with SA_SIGINFO. */
|
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 08:43:47 -04:00
|
|
|
linux_rt_sendsig(catcher, ksi, mask);
|
2000-11-23 03:55:30 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2001-09-12 04:38:13 -04:00
|
|
|
regs = td->td_frame;
|
2000-11-30 00:23:49 -05:00
|
|
|
oonstack = sigonstack(regs->tf_esp);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Allocate space for the signal handler context. */
|
2004-01-02 21:02:26 -05:00
|
|
|
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 16:36:02 -04:00
|
|
|
SIGISMEMBER(psp->ps_sigonstack, sig)) {
|
2016-01-27 12:55:01 -05:00
|
|
|
fp = (struct l_sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
|
2004-01-02 21:02:26 -05:00
|
|
|
td->td_sigstk.ss_size - sizeof(struct l_sigframe));
|
2000-11-30 00:23:49 -05:00
|
|
|
} else
|
2001-09-08 15:07:04 -04:00
|
|
|
fp = (struct l_sigframe *)regs->tf_esp - 1;
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 16:36:02 -04:00
|
|
|
mtx_unlock(&psp->ps_mtx);
|
2001-01-23 19:27:28 -05:00
|
|
|
PROC_UNLOCK(p);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Build the argument list for the signal handler. */
|
2015-05-24 13:47:20 -04:00
|
|
|
sig = bsd_to_linux_signal(sig);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
|
2002-11-02 02:41:04 -05:00
|
|
|
bzero(&frame, sizeof(frame));
|
|
|
|
|
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
frame.sf_sig = sig;
|
2022-05-30 13:03:49 -04:00
|
|
|
frame.sf_sigmask = *mask;
|
2000-11-23 03:55:30 -05:00
|
|
|
bsd_to_linux_sigset(mask, &lmask);
|
|
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Build the signal context to be used by sigreturn. */
|
2015-05-24 13:47:20 -04:00
|
|
|
frame.sf_sc.sc_mask = lmask.__mask;
|
1999-04-27 21:04:33 -04:00
|
|
|
frame.sf_sc.sc_gs = rgs();
|
|
|
|
|
frame.sf_sc.sc_fs = regs->tf_fs;
|
1997-05-07 16:05:45 -04:00
|
|
|
frame.sf_sc.sc_es = regs->tf_es;
|
|
|
|
|
frame.sf_sc.sc_ds = regs->tf_ds;
|
|
|
|
|
frame.sf_sc.sc_edi = regs->tf_edi;
|
|
|
|
|
frame.sf_sc.sc_esi = regs->tf_esi;
|
|
|
|
|
frame.sf_sc.sc_ebp = regs->tf_ebp;
|
|
|
|
|
frame.sf_sc.sc_ebx = regs->tf_ebx;
|
2015-05-24 11:28:17 -04:00
|
|
|
frame.sf_sc.sc_esp = regs->tf_esp;
|
1997-05-07 16:05:45 -04:00
|
|
|
frame.sf_sc.sc_edx = regs->tf_edx;
|
|
|
|
|
frame.sf_sc.sc_ecx = regs->tf_ecx;
|
|
|
|
|
frame.sf_sc.sc_eax = regs->tf_eax;
|
|
|
|
|
frame.sf_sc.sc_eip = regs->tf_eip;
|
|
|
|
|
frame.sf_sc.sc_cs = regs->tf_cs;
|
|
|
|
|
frame.sf_sc.sc_eflags = regs->tf_eflags;
|
|
|
|
|
frame.sf_sc.sc_esp_at_signal = regs->tf_esp;
|
|
|
|
|
frame.sf_sc.sc_ss = regs->tf_ss;
|
|
|
|
|
frame.sf_sc.sc_err = regs->tf_err;
|
2007-09-20 09:46:26 -04:00
|
|
|
frame.sf_sc.sc_cr2 = (register_t)ksi->ksi_addr;
|
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 08:43:47 -04:00
|
|
|
frame.sf_sc.sc_trapno = bsd_to_linux_trapcode(ksi->ksi_trapno);
|
2000-11-23 03:55:30 -05:00
|
|
|
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
if (copyout(&frame, fp, sizeof(frame)) != 0) {
|
|
|
|
|
/*
|
|
|
|
|
* Process has trashed its stack; give it an illegal
|
|
|
|
|
* instruction to halt it in its tracks.
|
|
|
|
|
*/
|
2001-03-06 22:37:06 -05:00
|
|
|
PROC_LOCK(p);
|
2001-09-12 04:38:13 -04:00
|
|
|
sigexit(td, SIGILL);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
}
|
|
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Build context to run handler in. */
|
2022-05-15 14:03:01 -04:00
|
|
|
regs->tf_esp = PTROUT(fp);
|
2022-05-15 14:08:12 -04:00
|
|
|
regs->tf_eip = linux_vdso_sigcode;
|
2022-05-15 14:03:01 -04:00
|
|
|
regs->tf_edi = PTROUT(catcher);
|
2008-03-13 06:54:38 -04:00
|
|
|
regs->tf_eflags &= ~(PSL_T | PSL_VM | PSL_D);
|
1997-05-07 16:05:45 -04:00
|
|
|
regs->tf_cs = _ucodesel;
|
|
|
|
|
regs->tf_ds = _udatasel;
|
|
|
|
|
regs->tf_es = _udatasel;
|
1999-04-27 21:04:33 -04:00
|
|
|
regs->tf_fs = _udatasel;
|
1997-05-07 16:05:45 -04:00
|
|
|
regs->tf_ss = _udatasel;
|
2001-09-08 15:07:04 -04:00
|
|
|
PROC_LOCK(p);
|
- Merge struct procsig with struct sigacts.
- Move struct sigacts out of the u-area and malloc() it using the
M_SUBPROC malloc bucket.
- Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(),
sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared().
- Remove the p_sigignore, p_sigacts, and p_sigcatch macros.
- Add a mutex to struct sigacts that protects all the members of the struct.
- Add sigacts locking.
- Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now
that sigacts is locked.
- Several in-kernel functions such as psignal(), tdsignal(), trapsignal(),
and thread_stopped() are now MP safe.
Reviewed by: arch@
Approved by: re (rwatson)
2003-05-13 16:36:02 -04:00
|
|
|
mtx_lock(&psp->ps_mtx);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* System call to cleanup state after a signal
|
|
|
|
|
* has been taken. Reset signal mask and
|
|
|
|
|
* stack state from context left by sendsig (above).
|
|
|
|
|
* Return to previous pc and psl as specified by
|
|
|
|
|
* context left by sendsig. Check carefully to
|
|
|
|
|
* make sure that the user has not modified the
|
|
|
|
|
* psl to gain improper privileges or to cause
|
|
|
|
|
* a machine fault.
|
|
|
|
|
*/
|
|
|
|
|
int
|
2002-10-19 07:57:38 -04:00
|
|
|
linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
{
|
2001-09-08 15:07:04 -04:00
|
|
|
struct l_sigframe frame;
|
2003-03-03 04:17:12 -05:00
|
|
|
struct trapframe *regs;
|
2015-05-24 13:47:20 -04:00
|
|
|
int eflags;
|
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 08:43:47 -04:00
|
|
|
ksiginfo_t ksi;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
|
2001-09-12 04:38:13 -04:00
|
|
|
regs = td->td_frame;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
|
|
|
|
|
/*
|
2000-11-23 03:55:30 -05:00
|
|
|
* The trampoline code hands us the sigframe.
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
* It is unsafe to keep track of it ourselves, in the event that a
|
|
|
|
|
* program jumps out of a signal handler.
|
|
|
|
|
*/
|
2003-03-03 04:14:26 -05:00
|
|
|
if (copyin(args->sfp, &frame, sizeof(frame)) != 0)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
return (EFAULT);
|
|
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Check for security violations. */
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
#define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0)
|
2000-11-23 03:55:30 -05:00
|
|
|
eflags = frame.sf_sc.sc_eflags;
|
2013-11-14 10:37:20 -05:00
|
|
|
if (!EFLAGS_SECURE(eflags, regs->tf_eflags))
|
2015-05-24 10:55:12 -04:00
|
|
|
return (EINVAL);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Don't allow users to load a valid privileged %cs. Let the
|
|
|
|
|
* hardware check for invalid selectors, excess privilege in
|
|
|
|
|
* other selectors, invalid %eip's and invalid %esp's.
|
|
|
|
|
*/
|
1997-08-21 02:33:04 -04:00
|
|
|
#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL)
|
2000-11-23 03:55:30 -05:00
|
|
|
if (!CS_SECURE(frame.sf_sc.sc_cs)) {
|
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 08:43:47 -04:00
|
|
|
ksiginfo_init_trap(&ksi);
|
|
|
|
|
ksi.ksi_signo = SIGBUS;
|
|
|
|
|
ksi.ksi_code = BUS_OBJERR;
|
|
|
|
|
ksi.ksi_trapno = T_PROTFLT;
|
|
|
|
|
ksi.ksi_addr = (void *)regs->tf_eip;
|
|
|
|
|
trapsignal(td, &ksi);
|
2015-05-24 10:55:12 -04:00
|
|
|
return (EINVAL);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
}
|
|
|
|
|
|
2022-05-30 13:03:49 -04:00
|
|
|
kern_sigprocmask(td, SIG_SETMASK, &frame.sf_sigmask, NULL, 0);
|
1999-09-29 11:12:18 -04:00
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Restore signal context. */
|
1999-04-27 21:04:33 -04:00
|
|
|
/* %gs was restored by the trampoline. */
|
2000-11-23 03:55:30 -05:00
|
|
|
regs->tf_fs = frame.sf_sc.sc_fs;
|
|
|
|
|
regs->tf_es = frame.sf_sc.sc_es;
|
|
|
|
|
regs->tf_ds = frame.sf_sc.sc_ds;
|
|
|
|
|
regs->tf_edi = frame.sf_sc.sc_edi;
|
|
|
|
|
regs->tf_esi = frame.sf_sc.sc_esi;
|
|
|
|
|
regs->tf_ebp = frame.sf_sc.sc_ebp;
|
|
|
|
|
regs->tf_ebx = frame.sf_sc.sc_ebx;
|
|
|
|
|
regs->tf_edx = frame.sf_sc.sc_edx;
|
|
|
|
|
regs->tf_ecx = frame.sf_sc.sc_ecx;
|
|
|
|
|
regs->tf_eax = frame.sf_sc.sc_eax;
|
|
|
|
|
regs->tf_eip = frame.sf_sc.sc_eip;
|
|
|
|
|
regs->tf_cs = frame.sf_sc.sc_cs;
|
1997-05-07 16:05:45 -04:00
|
|
|
regs->tf_eflags = eflags;
|
2000-11-23 03:55:30 -05:00
|
|
|
regs->tf_esp = frame.sf_sc.sc_esp_at_signal;
|
|
|
|
|
regs->tf_ss = frame.sf_sc.sc_ss;
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
|
|
|
|
|
return (EJUSTRETURN);
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-16 20:00:20 -04:00
|
|
|
/*
|
|
|
|
|
* System call to cleanup state after a signal
|
|
|
|
|
* has been taken. Reset signal mask and
|
|
|
|
|
* stack state from context left by rt_sendsig (above).
|
|
|
|
|
* Return to previous pc and psl as specified by
|
|
|
|
|
* context left by sendsig. Check carefully to
|
|
|
|
|
* make sure that the user has not modified the
|
|
|
|
|
* psl to gain improper privileges or to cause
|
|
|
|
|
* a machine fault.
|
|
|
|
|
*/
|
|
|
|
|
int
|
2002-10-19 07:57:38 -04:00
|
|
|
linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args)
|
2000-10-16 20:00:20 -04:00
|
|
|
{
|
2001-09-08 15:07:04 -04:00
|
|
|
struct l_ucontext uc;
|
|
|
|
|
struct l_sigcontext *context;
|
2009-10-27 06:47:58 -04:00
|
|
|
sigset_t bmask;
|
2001-09-08 15:07:04 -04:00
|
|
|
l_stack_t *lss;
|
2002-09-01 18:30:27 -04:00
|
|
|
stack_t ss;
|
2003-03-03 04:17:12 -05:00
|
|
|
struct trapframe *regs;
|
2000-10-16 20:00:20 -04:00
|
|
|
int eflags;
|
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 08:43:47 -04:00
|
|
|
ksiginfo_t ksi;
|
2000-10-16 20:00:20 -04:00
|
|
|
|
2001-09-12 04:38:13 -04:00
|
|
|
regs = td->td_frame;
|
2000-10-16 20:00:20 -04:00
|
|
|
|
|
|
|
|
/*
|
2000-11-23 03:55:30 -05:00
|
|
|
* The trampoline code hands us the ucontext.
|
2000-10-16 20:00:20 -04:00
|
|
|
* It is unsafe to keep track of it ourselves, in the event that a
|
|
|
|
|
* program jumps out of a signal handler.
|
|
|
|
|
*/
|
2003-03-03 04:14:26 -05:00
|
|
|
if (copyin(args->ucp, &uc, sizeof(uc)) != 0)
|
2000-10-16 20:00:20 -04:00
|
|
|
return (EFAULT);
|
|
|
|
|
|
|
|
|
|
context = &uc.uc_mcontext;
|
|
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Check for security violations. */
|
2000-10-16 20:00:20 -04:00
|
|
|
#define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0)
|
|
|
|
|
eflags = context->sc_eflags;
|
2013-11-14 10:37:20 -05:00
|
|
|
if (!EFLAGS_SECURE(eflags, regs->tf_eflags))
|
2015-05-24 10:55:12 -04:00
|
|
|
return (EINVAL);
|
2000-10-16 20:00:20 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Don't allow users to load a valid privileged %cs. Let the
|
|
|
|
|
* hardware check for invalid selectors, excess privilege in
|
|
|
|
|
* other selectors, invalid %eip's and invalid %esp's.
|
|
|
|
|
*/
|
|
|
|
|
#define CS_SECURE(cs) (ISPL(cs) == SEL_UPL)
|
|
|
|
|
if (!CS_SECURE(context->sc_cs)) {
|
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 08:43:47 -04:00
|
|
|
ksiginfo_init_trap(&ksi);
|
|
|
|
|
ksi.ksi_signo = SIGBUS;
|
|
|
|
|
ksi.ksi_code = BUS_OBJERR;
|
|
|
|
|
ksi.ksi_trapno = T_PROTFLT;
|
|
|
|
|
ksi.ksi_addr = (void *)regs->tf_eip;
|
|
|
|
|
trapsignal(td, &ksi);
|
2015-05-24 10:55:12 -04:00
|
|
|
return (EINVAL);
|
2000-10-16 20:00:20 -04:00
|
|
|
}
|
|
|
|
|
|
2009-10-27 06:47:58 -04:00
|
|
|
linux_to_bsd_sigset(&uc.uc_sigmask, &bmask);
|
|
|
|
|
kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0);
|
2000-10-16 20:00:20 -04:00
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Restore signal context. */
|
2000-10-16 20:00:20 -04:00
|
|
|
/* %gs was restored by the trampoline. */
|
|
|
|
|
regs->tf_fs = context->sc_fs;
|
|
|
|
|
regs->tf_es = context->sc_es;
|
|
|
|
|
regs->tf_ds = context->sc_ds;
|
|
|
|
|
regs->tf_edi = context->sc_edi;
|
|
|
|
|
regs->tf_esi = context->sc_esi;
|
|
|
|
|
regs->tf_ebp = context->sc_ebp;
|
|
|
|
|
regs->tf_ebx = context->sc_ebx;
|
|
|
|
|
regs->tf_edx = context->sc_edx;
|
|
|
|
|
regs->tf_ecx = context->sc_ecx;
|
|
|
|
|
regs->tf_eax = context->sc_eax;
|
|
|
|
|
regs->tf_eip = context->sc_eip;
|
|
|
|
|
regs->tf_cs = context->sc_cs;
|
|
|
|
|
regs->tf_eflags = eflags;
|
|
|
|
|
regs->tf_esp = context->sc_esp_at_signal;
|
|
|
|
|
regs->tf_ss = context->sc_ss;
|
|
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Call sigaltstack & ignore results. */
|
2000-10-16 20:00:20 -04:00
|
|
|
lss = &uc.uc_stack;
|
2021-07-26 19:43:09 -04:00
|
|
|
ss.ss_sp = PTRIN(lss->ss_sp);
|
2002-09-01 18:30:27 -04:00
|
|
|
ss.ss_size = lss->ss_size;
|
|
|
|
|
ss.ss_flags = linux_to_bsd_sigaltstack(lss->ss_flags);
|
2000-10-16 20:00:20 -04:00
|
|
|
|
2002-09-01 18:30:27 -04:00
|
|
|
(void)kern_sigaltstack(td, &ss, NULL);
|
2000-10-16 20:00:20 -04:00
|
|
|
|
|
|
|
|
return (EJUSTRETURN);
|
|
|
|
|
}
|
|
|
|
|
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 14:32:02 -04:00
|
|
|
static int
|
2017-06-12 17:03:23 -04:00
|
|
|
linux_fetch_syscall_args(struct thread *td)
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
{
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 14:32:02 -04:00
|
|
|
struct proc *p;
|
|
|
|
|
struct trapframe *frame;
|
2017-06-12 17:03:23 -04:00
|
|
|
struct syscall_args *sa;
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 14:32:02 -04:00
|
|
|
|
|
|
|
|
p = td->td_proc;
|
|
|
|
|
frame = td->td_frame;
|
2017-06-12 17:03:23 -04:00
|
|
|
sa = &td->td_sa;
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 14:32:02 -04:00
|
|
|
|
|
|
|
|
sa->code = frame->tf_eax;
|
2021-07-10 12:19:52 -04:00
|
|
|
sa->original_code = sa->code;
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 14:32:02 -04:00
|
|
|
sa->args[0] = frame->tf_ebx;
|
|
|
|
|
sa->args[1] = frame->tf_ecx;
|
|
|
|
|
sa->args[2] = frame->tf_edx;
|
|
|
|
|
sa->args[3] = frame->tf_esi;
|
|
|
|
|
sa->args[4] = frame->tf_edi;
|
2023-10-10 05:33:22 -04:00
|
|
|
sa->args[5] = frame->tf_ebp;
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 14:32:02 -04:00
|
|
|
|
|
|
|
|
if (sa->code >= p->p_sysent->sv_size)
|
2015-05-24 13:38:02 -04:00
|
|
|
/* nosys */
|
2023-09-25 12:32:52 -04:00
|
|
|
sa->callp = &nosys_sysent;
|
2018-02-05 12:29:12 -05:00
|
|
|
else
|
|
|
|
|
sa->callp = &p->p_sysent->sv_table[sa->code];
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 14:32:02 -04:00
|
|
|
|
|
|
|
|
td->td_retval[0] = 0;
|
|
|
|
|
td->td_retval[1] = frame->tf_edx;
|
|
|
|
|
|
|
|
|
|
return (0);
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
}
|
|
|
|
|
|
2020-09-15 12:41:21 -04:00
|
|
|
static void
|
|
|
|
|
linux_set_syscall_retval(struct thread *td, int error)
|
|
|
|
|
{
|
|
|
|
|
struct trapframe *frame = td->td_frame;
|
|
|
|
|
|
|
|
|
|
cpu_set_syscall_retval(td, error);
|
|
|
|
|
|
|
|
|
|
if (__predict_false(error != 0)) {
|
|
|
|
|
if (error != ERESTART && error != EJUSTRETURN)
|
2020-10-27 08:49:40 -04:00
|
|
|
frame->tf_eax = bsd_to_linux_errno(error);
|
2020-09-15 12:41:21 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-12 04:45:25 -04:00
|
|
|
static void
|
|
|
|
|
linux_set_fork_retval(struct thread *td)
|
|
|
|
|
{
|
|
|
|
|
struct trapframe *frame = td->td_frame;
|
|
|
|
|
|
|
|
|
|
frame->tf_eax = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-11 17:51:11 -04:00
|
|
|
/*
|
|
|
|
|
* exec_setregs may initialize some registers differently than Linux
|
|
|
|
|
* does, thus potentially confusing Linux binaries. If necessary, we
|
|
|
|
|
* override the exec_setregs default(s) here.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2019-12-03 18:17:54 -05:00
|
|
|
linux_exec_setregs(struct thread *td, struct image_params *imgp,
|
|
|
|
|
uintptr_t stack)
|
2003-05-11 17:51:11 -04:00
|
|
|
{
|
|
|
|
|
struct pcb *pcb = td->td_pcb;
|
|
|
|
|
|
2010-03-25 10:24:00 -04:00
|
|
|
exec_setregs(td, imgp, stack);
|
2003-05-11 17:51:11 -04:00
|
|
|
|
2018-03-12 20:40:05 -04:00
|
|
|
/* Linux sets %gs to 0, we default to _udatasel. */
|
2009-03-05 14:42:11 -05:00
|
|
|
pcb->pcb_gs = 0;
|
|
|
|
|
load_gs(0);
|
2005-02-06 12:29:20 -05:00
|
|
|
|
2009-03-05 14:42:11 -05:00
|
|
|
pcb->pcb_initial_npxcw = __LINUX_NPXCW__;
|
2003-05-11 17:51:11 -04:00
|
|
|
}
|
|
|
|
|
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
struct sysentvec linux_sysvec = {
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_size = LINUX_SYS_MAXSYSCALL,
|
|
|
|
|
.sv_table = linux_sysent,
|
|
|
|
|
.sv_fixup = linux_fixup,
|
|
|
|
|
.sv_sendsig = linux_sendsig,
|
2021-07-20 03:01:18 -04:00
|
|
|
.sv_sigcode = &_binary_linux_vdso_so_o_start,
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_szsigcode = &linux_szsigcode,
|
|
|
|
|
.sv_name = "Linux a.out",
|
|
|
|
|
.sv_coredump = NULL,
|
|
|
|
|
.sv_minsigstksz = LINUX_MINSIGSTKSZ,
|
|
|
|
|
.sv_minuser = VM_MIN_ADDRESS,
|
|
|
|
|
.sv_maxuser = VM_MAXUSER_ADDRESS,
|
2011-03-13 10:58:02 -04:00
|
|
|
.sv_usrstack = LINUX_USRSTACK,
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_psstrings = PS_STRINGS,
|
2022-01-17 11:42:07 -05:00
|
|
|
.sv_psstringssz = sizeof(struct ps_strings),
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_stackprot = VM_PROT_ALL,
|
|
|
|
|
.sv_copyout_strings = exec_copyout_strings,
|
2018-03-19 17:26:32 -04:00
|
|
|
.sv_setregs = linux_exec_setregs,
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_fixlimit = NULL,
|
2008-11-22 07:36:15 -05:00
|
|
|
.sv_maxssiz = NULL,
|
2021-06-05 14:18:21 -04:00
|
|
|
.sv_flags = SV_ABI_LINUX | SV_AOUT | SV_IA32 | SV_ILP32 |
|
|
|
|
|
SV_SIG_DISCIGN | SV_SIG_WAITNDQ,
|
2020-09-15 12:41:21 -04:00
|
|
|
.sv_set_syscall_retval = linux_set_syscall_retval,
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 14:32:02 -04:00
|
|
|
.sv_fetch_syscall_args = linux_fetch_syscall_args,
|
2022-10-28 17:19:39 -04:00
|
|
|
.sv_syscallnames = linux_syscallnames,
|
2011-03-08 14:01:45 -05:00
|
|
|
.sv_schedtail = linux_schedtail,
|
2015-05-24 10:53:16 -04:00
|
|
|
.sv_thread_detach = linux_thread_detach,
|
2016-01-09 15:18:53 -05:00
|
|
|
.sv_trap = NULL,
|
2023-04-22 15:16:02 -04:00
|
|
|
.sv_hwcap = NULL,
|
|
|
|
|
.sv_hwcap2 = NULL,
|
2021-07-20 02:56:25 -04:00
|
|
|
.sv_onexec = linux_on_exec_vmspace,
|
2020-11-23 13:18:16 -05:00
|
|
|
.sv_onexit = linux_on_exit,
|
|
|
|
|
.sv_ontdexit = linux_thread_dtor,
|
2021-01-14 08:51:52 -05:00
|
|
|
.sv_setid_allowed = &linux_setid_allowed_query,
|
2021-08-12 04:45:25 -04:00
|
|
|
.sv_set_fork_retval = linux_set_fork_retval,
|
1996-03-10 03:42:54 -05:00
|
|
|
};
|
2011-03-13 10:58:02 -04:00
|
|
|
INIT_SYSENTVEC(aout_sysvec, &linux_sysvec);
|
1996-03-10 03:42:54 -05:00
|
|
|
|
|
|
|
|
struct sysentvec elf_linux_sysvec = {
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_size = LINUX_SYS_MAXSYSCALL,
|
|
|
|
|
.sv_table = linux_sysent,
|
2023-02-02 09:58:07 -05:00
|
|
|
.sv_fixup = __elfN(freebsd_fixup),
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_sendsig = linux_sendsig,
|
2021-07-20 03:01:18 -04:00
|
|
|
.sv_sigcode = &_binary_linux_vdso_so_o_start,
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_szsigcode = &linux_szsigcode,
|
2021-01-20 20:54:12 -05:00
|
|
|
.sv_name = "Linux ELF32",
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_coredump = elf32_coredump,
|
2023-02-02 09:58:06 -05:00
|
|
|
.sv_elf_core_osabi = ELFOSABI_NONE,
|
|
|
|
|
.sv_elf_core_abi_vendor = LINUX_ABI_VENDOR,
|
|
|
|
|
.sv_elf_core_prepare_notes = __linuxN(prepare_notes),
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_minsigstksz = LINUX_MINSIGSTKSZ,
|
|
|
|
|
.sv_minuser = VM_MIN_ADDRESS,
|
|
|
|
|
.sv_maxuser = VM_MAXUSER_ADDRESS,
|
2011-03-13 10:58:02 -04:00
|
|
|
.sv_usrstack = LINUX_USRSTACK,
|
|
|
|
|
.sv_psstrings = LINUX_PS_STRINGS,
|
2022-01-17 11:42:07 -05:00
|
|
|
.sv_psstringssz = sizeof(struct ps_strings),
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_stackprot = VM_PROT_ALL,
|
2023-04-22 15:16:02 -04:00
|
|
|
.sv_copyout_auxargs = __linuxN(copyout_auxargs),
|
2023-02-02 09:58:07 -05:00
|
|
|
.sv_copyout_strings = __linuxN(copyout_strings),
|
2018-03-19 17:26:32 -04:00
|
|
|
.sv_setregs = linux_exec_setregs,
|
2008-09-24 06:14:37 -04:00
|
|
|
.sv_fixlimit = NULL,
|
2008-11-22 07:36:15 -05:00
|
|
|
.sv_maxssiz = NULL,
|
2021-06-05 14:18:21 -04:00
|
|
|
.sv_flags = SV_ABI_LINUX | SV_IA32 | SV_ILP32 | SV_SHP |
|
2021-07-20 03:01:18 -04:00
|
|
|
SV_SIG_DISCIGN | SV_SIG_WAITNDQ | SV_TIMEKEEP,
|
2020-09-15 12:41:21 -04:00
|
|
|
.sv_set_syscall_retval = linux_set_syscall_retval,
|
Reorganize syscall entry and leave handling.
Extend struct sysvec with three new elements:
sv_fetch_syscall_args - the method to fetch syscall arguments from
usermode into struct syscall_args. The structure is machine-depended
(this might be reconsidered after all architectures are converted).
sv_set_syscall_retval - the method to set a return value for usermode
from the syscall. It is a generalization of
cpu_set_syscall_retval(9) to allow ABIs to override the way to set a
return value.
sv_syscallnames - the table of syscall names.
Use sv_set_syscall_retval in kern_sigsuspend() instead of hardcoding
the call to cpu_set_syscall_retval().
The new functions syscallenter(9) and syscallret(9) are provided that
use sv_*syscall* pointers and contain the common repeated code from
the syscall() implementations for the architecture-specific syscall
trap handlers.
Syscallenter() fetches arguments, calls syscall implementation from
ABI sysent table, and set up return frame. The end of syscall
bookkeeping is done by syscallret().
Take advantage of single place for MI syscall handling code and
implement ptrace_lwpinfo pl_flags PL_FLAG_SCE, PL_FLAG_SCX and
PL_FLAG_EXEC. The SCE and SCX flags notify the debugger that the
thread is stopped at syscall entry or return point respectively. The
EXEC flag augments SCX and notifies debugger that the process address
space was changed by one of exec(2)-family syscalls.
The i386, amd64, sparc64, sun4v, powerpc and ia64 syscall()s are
changed to use syscallenter()/syscallret(). MIPS and arm are not
converted and use the mostly unchanged syscall() implementation.
Reviewed by: jhb, marcel, marius, nwhitehorn, stas
Tested by: marcel (ia64), marius (sparc64), nwhitehorn (powerpc),
stas (mips)
MFC after: 1 month
2010-05-23 14:32:02 -04:00
|
|
|
.sv_fetch_syscall_args = linux_fetch_syscall_args,
|
|
|
|
|
.sv_syscallnames = NULL,
|
2011-03-13 10:58:02 -04:00
|
|
|
.sv_shared_page_base = LINUX_SHAREDPAGE,
|
|
|
|
|
.sv_shared_page_len = PAGE_SIZE,
|
2011-03-08 14:01:45 -05:00
|
|
|
.sv_schedtail = linux_schedtail,
|
2015-05-24 10:53:16 -04:00
|
|
|
.sv_thread_detach = linux_thread_detach,
|
2016-01-09 15:18:53 -05:00
|
|
|
.sv_trap = NULL,
|
2023-04-22 15:16:02 -04:00
|
|
|
.sv_hwcap = NULL,
|
|
|
|
|
.sv_hwcap2 = NULL,
|
2021-07-20 02:56:25 -04:00
|
|
|
.sv_onexec = linux_on_exec_vmspace,
|
2020-11-23 13:18:16 -05:00
|
|
|
.sv_onexit = linux_on_exit,
|
|
|
|
|
.sv_ontdexit = linux_thread_dtor,
|
2021-01-14 08:51:52 -05:00
|
|
|
.sv_setid_allowed = &linux_setid_allowed_query,
|
2021-08-12 04:45:25 -04:00
|
|
|
.sv_set_fork_retval = linux_set_fork_retval,
|
Mega-commit for Linux emulator update.. This has been stress tested under
netscape-2.0 for Linux running all the Java stuff. The scrollbars are now
working, at least on my machine. (whew! :-)
I'm uncomfortable with the size of this commit, but it's too
inter-dependant to easily seperate out.
The main changes:
COMPAT_LINUX is *GONE*. Most of the code has been moved out of the i386
machine dependent section into the linux emulator itself. The int 0x80
syscall code was almost identical to the lcall 7,0 code and a minor tweak
allows them to both be used with the same C code. All kernels can now
just modload the lkm and it'll DTRT without having to rebuild the kernel
first. Like IBCS2, you can statically compile it in with "options LINUX".
A pile of new syscalls implemented, including getdents(), llseek(),
readv(), writev(), msync(), personality(). The Linux-ELF libraries want
to use some of these.
linux_select() now obeys Linux semantics, ie: returns the time remaining
of the timeout value rather than leaving it the original value.
Quite a few bugs removed, including incorrect arguments being used in
syscalls.. eg: mixups between passing the sigset as an int, vs passing
it as a pointer and doing a copyin(), missing return values, unhandled
cases, SIOC* ioctls, etc.
The build for the code has changed. i386/conf/files now knows how
to build linux_genassym and generate linux_assym.h on the fly.
Supporting changes elsewhere in the kernel:
The user-mode signal trampoline has moved from the U area to immediately
below the top of the stack (below PS_STRINGS). This allows the different
binary emulations to have their own signal trampoline code (which gets rid
of the hardwired syscall 103 (sigreturn on BSD, syslog on Linux)) and so
that the emulator can provide the exact "struct sigcontext *" argument to
the program's signal handlers.
The sigstack's "ss_flags" now uses SS_DISABLE and SS_ONSTACK flags, which
have the same values as the re-used SA_DISABLE and SA_ONSTACK which are
intended for sigaction only. This enables the support of a SA_RESETHAND
flag to sigaction to implement the gross SYSV and Linux SA_ONESHOT signal
semantics where the signal handler is reset when it's triggered.
makesyscalls.sh no longer appends the struct sysentvec on the end of the
generated init_sysent.c code. It's a lot saner to have it in a seperate
file rather than trying to update the structure inside the awk script. :-)
At exec time, the dozen bytes or so of signal trampoline code are copied
to the top of the user's stack, rather than obtaining the trampoline code
the old way by getting a clone of the parent's user area. This allows
Linux and native binaries to freely exec each other without getting
trampolines mixed up.
1996-03-02 14:38:20 -05:00
|
|
|
};
|
2015-05-24 11:28:17 -04:00
|
|
|
|
2021-07-20 02:56:25 -04:00
|
|
|
static int
|
|
|
|
|
linux_on_exec_vmspace(struct proc *p, struct image_params *imgp)
|
|
|
|
|
{
|
2021-07-20 03:01:18 -04:00
|
|
|
int error = 0;
|
2021-07-20 02:56:25 -04:00
|
|
|
|
2021-07-20 03:01:18 -04:00
|
|
|
if (SV_PROC_FLAG(p, SV_SHP) != 0)
|
|
|
|
|
error = linux_map_vdso(p, linux_vdso_obj,
|
|
|
|
|
linux_vdso_base, LINUX_VDSOPAGE_SIZE, imgp);
|
|
|
|
|
if (error == 0)
|
2023-05-29 04:16:46 -04:00
|
|
|
error = linux_on_exec(p, imgp);
|
2021-07-20 03:01:18 -04:00
|
|
|
return (error);
|
2021-07-20 02:56:25 -04:00
|
|
|
}
|
|
|
|
|
|
2021-07-20 03:02:34 -04:00
|
|
|
/*
|
|
|
|
|
* linux_vdso_install() and linux_exec_sysvec_init() must be called
|
|
|
|
|
* after exec_sysvec_init() which is SI_SUB_EXEC (SI_ORDER_ANY).
|
|
|
|
|
*/
|
2015-05-24 11:28:17 -04:00
|
|
|
static void
|
2021-07-20 03:01:18 -04:00
|
|
|
linux_exec_sysvec_init(void *param)
|
2015-05-24 11:28:17 -04:00
|
|
|
{
|
2021-07-20 03:01:18 -04:00
|
|
|
l_uintptr_t *ktimekeep_base, *ktsc_selector;
|
|
|
|
|
struct sysentvec *sv;
|
|
|
|
|
ptrdiff_t tkoff;
|
|
|
|
|
|
|
|
|
|
sv = param;
|
|
|
|
|
/* Fill timekeep_base */
|
|
|
|
|
exec_sysvec_init(sv);
|
|
|
|
|
|
|
|
|
|
tkoff = kern_timekeep_base - linux_vdso_base;
|
|
|
|
|
ktimekeep_base = (l_uintptr_t *)(linux_vdso_mapping + tkoff);
|
2022-06-02 03:58:12 -04:00
|
|
|
*ktimekeep_base = sv->sv_shared_page_base + sv->sv_timekeep_offset;
|
2021-07-20 03:01:18 -04:00
|
|
|
|
|
|
|
|
tkoff = kern_tsc_selector - linux_vdso_base;
|
|
|
|
|
ktsc_selector = (l_uintptr_t *)(linux_vdso_mapping + tkoff);
|
|
|
|
|
*ktsc_selector = linux_vdso_tsc_selector_idx();
|
|
|
|
|
if (bootverbose)
|
|
|
|
|
printf("Linux i386 vDSO tsc_selector: %u\n", *ktsc_selector);
|
2022-05-08 10:20:52 -04:00
|
|
|
|
|
|
|
|
tkoff = kern_cpu_selector - linux_vdso_base;
|
|
|
|
|
ktsc_selector = (l_uintptr_t *)(linux_vdso_mapping + tkoff);
|
|
|
|
|
*ktsc_selector = linux_vdso_cpu_selector_idx();
|
|
|
|
|
if (bootverbose)
|
|
|
|
|
printf("Linux i386 vDSO cpu_selector: %u\n", *ktsc_selector);
|
2021-07-20 03:01:18 -04:00
|
|
|
}
|
2021-07-20 03:02:34 -04:00
|
|
|
SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC + 1, SI_ORDER_ANY,
|
2021-07-20 03:01:18 -04:00
|
|
|
linux_exec_sysvec_init, &elf_linux_sysvec);
|
2015-05-24 11:28:17 -04:00
|
|
|
|
2021-07-20 03:01:18 -04:00
|
|
|
static void
|
2021-07-20 03:01:47 -04:00
|
|
|
linux_vdso_install(const void *param)
|
2021-07-20 03:01:18 -04:00
|
|
|
{
|
|
|
|
|
char *vdso_start = &_binary_linux_vdso_so_o_start;
|
|
|
|
|
char *vdso_end = &_binary_linux_vdso_so_o_end;
|
2015-05-24 11:28:17 -04:00
|
|
|
|
2021-07-20 03:01:18 -04:00
|
|
|
linux_szsigcode = vdso_end - vdso_start;
|
|
|
|
|
MPASS(linux_szsigcode <= LINUX_VDSOPAGE_SIZE);
|
2015-05-24 11:28:17 -04:00
|
|
|
|
2021-07-20 03:01:18 -04:00
|
|
|
linux_vdso_base = LINUX_VDSOPAGE;
|
2015-05-24 11:28:17 -04:00
|
|
|
|
2021-07-20 03:01:18 -04:00
|
|
|
__elfN(linux_vdso_fixup)(vdso_start, linux_vdso_base);
|
2015-05-24 11:28:17 -04:00
|
|
|
|
2021-07-20 03:01:18 -04:00
|
|
|
linux_vdso_obj = __elfN(linux_shared_page_init)
|
|
|
|
|
(&linux_vdso_mapping, LINUX_VDSOPAGE_SIZE);
|
|
|
|
|
bcopy(vdso_start, linux_vdso_mapping, linux_szsigcode);
|
2015-05-24 11:28:17 -04:00
|
|
|
|
2021-07-20 03:01:18 -04:00
|
|
|
linux_vdso_reloc(linux_vdso_mapping, linux_vdso_base);
|
2015-05-24 11:28:17 -04:00
|
|
|
}
|
2021-07-20 03:02:34 -04:00
|
|
|
SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC + 1, SI_ORDER_FIRST,
|
2018-03-23 16:32:54 -04:00
|
|
|
linux_vdso_install, NULL);
|
2015-05-24 11:28:17 -04:00
|
|
|
|
|
|
|
|
static void
|
2021-07-20 03:01:47 -04:00
|
|
|
linux_vdso_deinstall(const void *param)
|
2015-05-24 11:28:17 -04:00
|
|
|
{
|
|
|
|
|
|
2021-07-20 03:01:18 -04:00
|
|
|
__elfN(linux_shared_page_fini)(linux_vdso_obj,
|
|
|
|
|
linux_vdso_mapping, LINUX_VDSOPAGE_SIZE);
|
2018-03-14 09:20:36 -04:00
|
|
|
}
|
2015-05-24 11:28:17 -04:00
|
|
|
SYSUNINIT(elf_linux_vdso_uninit, SI_SUB_EXEC, SI_ORDER_FIRST,
|
2018-03-23 16:32:54 -04:00
|
|
|
linux_vdso_deinstall, NULL);
|
1996-03-10 03:42:54 -05:00
|
|
|
|
2021-07-20 03:01:18 -04:00
|
|
|
static void
|
|
|
|
|
linux_vdso_reloc(char *mapping, Elf_Addr offset)
|
|
|
|
|
{
|
|
|
|
|
const Elf_Shdr *shdr;
|
|
|
|
|
const Elf_Rel *rel;
|
|
|
|
|
const Elf_Ehdr *ehdr;
|
|
|
|
|
Elf_Addr *where;
|
|
|
|
|
Elf_Size rtype, symidx;
|
|
|
|
|
Elf_Addr addr, addend;
|
|
|
|
|
int i, relcnt;
|
|
|
|
|
|
|
|
|
|
MPASS(offset != 0);
|
|
|
|
|
|
|
|
|
|
relcnt = 0;
|
|
|
|
|
ehdr = (const Elf_Ehdr *)mapping;
|
|
|
|
|
shdr = (const Elf_Shdr *)(mapping + ehdr->e_shoff);
|
|
|
|
|
for (i = 0; i < ehdr->e_shnum; i++)
|
|
|
|
|
{
|
|
|
|
|
switch (shdr[i].sh_type) {
|
|
|
|
|
case SHT_REL:
|
|
|
|
|
rel = (const Elf_Rel *)(mapping + shdr[i].sh_offset);
|
|
|
|
|
relcnt = shdr[i].sh_size / sizeof(*rel);
|
|
|
|
|
break;
|
|
|
|
|
case SHT_RELA:
|
|
|
|
|
printf("Linux i386 vDSO: unexpected Rela section\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < relcnt; i++, rel++) {
|
|
|
|
|
where = (Elf_Addr *)(mapping + rel->r_offset);
|
|
|
|
|
addend = *where;
|
|
|
|
|
rtype = ELF_R_TYPE(rel->r_info);
|
|
|
|
|
symidx = ELF_R_SYM(rel->r_info);
|
|
|
|
|
|
|
|
|
|
switch (rtype) {
|
|
|
|
|
case R_386_NONE: /* none */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_386_RELATIVE: /* B + A */
|
|
|
|
|
addr = (Elf_Addr)PTROUT(offset + addend);
|
|
|
|
|
if (*where != addr)
|
|
|
|
|
*where = addr;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case R_386_IRELATIVE:
|
|
|
|
|
printf("Linux i386 vDSO: unexpected ifunc relocation, "
|
|
|
|
|
"symbol index %d\n", symidx);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("Linux i386 vDSO: unexpected relocation type %d, "
|
|
|
|
|
"symbol index %d\n", rtype, symidx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-13 12:40:51 -04:00
|
|
|
static Elf_Brandnote linux_brandnote = {
|
Fix handling of .note.ABI-tag section for GNU systems [1].
Handle GNU/Linux according to LSB Core Specification 4.0,
Chapter 11. Object Format, 11.8. ABI note tag.
Also check the first word of desc, not only name, according to
glibc abi-tags specification to distinguish between Linux and
kFreeBSD.
Add explicit handling for Debian GNU/kFreeBSD, which runs
on our kernels as well [2].
In {amd64,i386}/trap.c, when checking osrel of the current process,
also check the ABI to not change the signal behaviour for Linux
binary processes, now that we save an osrel version for all three
from the lists above in struct proc [2].
These changes make it possible to run FreeBSD, Debian GNU/kFreeBSD
and Linux binaries on the same machine again for at least i386 and
amd64, and no longer break kFreeBSD which was detected as GNU(/Linux).
PR: kern/135468
Submitted by: dchagin [1] (initial patch)
Suggested by: kib [2]
Tested by: Petr Salinger (Petr.Salinger seznam.cz) for kFreeBSD
Reviewed by: kib
MFC after: 3 days
2009-08-24 12:19:47 -04:00
|
|
|
.hdr.n_namesz = sizeof(GNU_ABI_VENDOR),
|
|
|
|
|
.hdr.n_descsz = 16, /* XXX at least 16 */
|
2009-03-13 12:40:51 -04:00
|
|
|
.hdr.n_type = 1,
|
Fix handling of .note.ABI-tag section for GNU systems [1].
Handle GNU/Linux according to LSB Core Specification 4.0,
Chapter 11. Object Format, 11.8. ABI note tag.
Also check the first word of desc, not only name, according to
glibc abi-tags specification to distinguish between Linux and
kFreeBSD.
Add explicit handling for Debian GNU/kFreeBSD, which runs
on our kernels as well [2].
In {amd64,i386}/trap.c, when checking osrel of the current process,
also check the ABI to not change the signal behaviour for Linux
binary processes, now that we save an osrel version for all three
from the lists above in struct proc [2].
These changes make it possible to run FreeBSD, Debian GNU/kFreeBSD
and Linux binaries on the same machine again for at least i386 and
amd64, and no longer break kFreeBSD which was detected as GNU(/Linux).
PR: kern/135468
Submitted by: dchagin [1] (initial patch)
Suggested by: kib [2]
Tested by: Petr Salinger (Petr.Salinger seznam.cz) for kFreeBSD
Reviewed by: kib
MFC after: 3 days
2009-08-24 12:19:47 -04:00
|
|
|
.vendor = GNU_ABI_VENDOR,
|
|
|
|
|
.flags = BN_TRANSLATE_OSREL,
|
|
|
|
|
.trans_osrel = linux_trans_osrel
|
2009-03-13 12:40:51 -04:00
|
|
|
};
|
|
|
|
|
|
1998-10-11 17:08:02 -04:00
|
|
|
static Elf32_Brandinfo linux_brand = {
|
2008-09-24 06:14:37 -04:00
|
|
|
.brand = ELFOSABI_LINUX,
|
|
|
|
|
.machine = EM_386,
|
|
|
|
|
.compat_3_brand = "Linux",
|
|
|
|
|
.interp_path = "/lib/ld-linux.so.1",
|
|
|
|
|
.sysvec = &elf_linux_sysvec,
|
|
|
|
|
.interp_newpath = NULL,
|
2009-03-13 12:40:51 -04:00
|
|
|
.brand_note = &linux_brandnote,
|
2014-06-17 01:29:18 -04:00
|
|
|
.flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
|
2008-09-24 06:14:37 -04:00
|
|
|
};
|
1996-03-10 17:42:16 -05:00
|
|
|
|
1998-10-11 17:08:02 -04:00
|
|
|
static Elf32_Brandinfo linux_glibc2brand = {
|
2008-09-24 06:14:37 -04:00
|
|
|
.brand = ELFOSABI_LINUX,
|
|
|
|
|
.machine = EM_386,
|
|
|
|
|
.compat_3_brand = "Linux",
|
|
|
|
|
.interp_path = "/lib/ld-linux.so.2",
|
|
|
|
|
.sysvec = &elf_linux_sysvec,
|
|
|
|
|
.interp_newpath = NULL,
|
2009-03-13 12:40:51 -04:00
|
|
|
.brand_note = &linux_brandnote,
|
2014-06-17 01:29:18 -04:00
|
|
|
.flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
|
2008-09-24 06:14:37 -04:00
|
|
|
};
|
1998-09-17 18:08:34 -04:00
|
|
|
|
2017-07-03 06:24:49 -04:00
|
|
|
static Elf32_Brandinfo linux_muslbrand = {
|
|
|
|
|
.brand = ELFOSABI_LINUX,
|
|
|
|
|
.machine = EM_386,
|
|
|
|
|
.compat_3_brand = "Linux",
|
|
|
|
|
.interp_path = "/lib/ld-musl-i386.so.1",
|
|
|
|
|
.sysvec = &elf_linux_sysvec,
|
|
|
|
|
.interp_newpath = NULL,
|
|
|
|
|
.brand_note = &linux_brandnote,
|
2021-07-20 07:39:20 -04:00
|
|
|
.flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE |
|
|
|
|
|
LINUX_BI_FUTEX_REQUEUE
|
2017-07-03 06:24:49 -04:00
|
|
|
};
|
|
|
|
|
|
1998-10-11 17:08:02 -04:00
|
|
|
Elf32_Brandinfo *linux_brandlist[] = {
|
2008-09-24 06:14:37 -04:00
|
|
|
&linux_brand,
|
|
|
|
|
&linux_glibc2brand,
|
2017-07-03 06:24:49 -04:00
|
|
|
&linux_muslbrand,
|
2008-09-24 06:14:37 -04:00
|
|
|
NULL
|
|
|
|
|
};
|
1998-10-11 17:08:02 -04:00
|
|
|
|
1998-10-15 23:55:01 -04:00
|
|
|
static int
|
1998-11-15 10:33:52 -05:00
|
|
|
linux_elf_modevent(module_t mod, int type, void *data)
|
1997-03-29 05:50:27 -05:00
|
|
|
{
|
1998-10-11 17:08:02 -04:00
|
|
|
Elf32_Brandinfo **brandinfo;
|
|
|
|
|
int error;
|
2001-06-13 06:58:39 -04:00
|
|
|
struct linux_ioctl_handler **lihp;
|
1998-10-11 17:08:02 -04:00
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
1998-10-15 23:55:01 -04:00
|
|
|
switch(type) {
|
|
|
|
|
case MOD_LOAD:
|
|
|
|
|
for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL;
|
1999-12-04 06:10:22 -05:00
|
|
|
++brandinfo)
|
2002-07-19 22:56:12 -04:00
|
|
|
if (elf32_insert_brand_entry(*brandinfo) < 0)
|
1998-10-15 23:55:01 -04:00
|
|
|
error = EINVAL;
|
2000-11-22 22:21:58 -05:00
|
|
|
if (error == 0) {
|
2001-06-13 06:58:39 -04:00
|
|
|
SET_FOREACH(lihp, linux_ioctl_handler_set)
|
|
|
|
|
linux_ioctl_register_handler(*lihp);
|
2019-11-06 15:53:33 -05:00
|
|
|
linux_dev_shm_create();
|
2009-05-07 14:36:47 -04:00
|
|
|
linux_osd_jail_register();
|
2023-02-06 09:00:44 -05:00
|
|
|
linux_netlink_register();
|
2009-05-10 14:16:07 -04:00
|
|
|
stclohz = (stathz ? stathz : hz);
|
1999-12-04 06:10:22 -05:00
|
|
|
if (bootverbose)
|
2000-11-22 22:21:58 -05:00
|
|
|
printf("Linux ELF exec handler installed\n");
|
|
|
|
|
} else
|
|
|
|
|
printf("cannot insert Linux ELF brand handler\n");
|
1998-10-15 23:55:01 -04:00
|
|
|
break;
|
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
|
for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL;
|
1999-12-04 06:10:22 -05:00
|
|
|
++brandinfo)
|
2002-07-19 22:56:12 -04:00
|
|
|
if (elf32_brand_inuse(*brandinfo))
|
1999-02-04 16:20:13 -05:00
|
|
|
error = EBUSY;
|
|
|
|
|
if (error == 0) {
|
|
|
|
|
for (brandinfo = &linux_brandlist[0];
|
1999-12-04 06:10:22 -05:00
|
|
|
*brandinfo != NULL; ++brandinfo)
|
2002-07-19 22:56:12 -04:00
|
|
|
if (elf32_remove_brand_entry(*brandinfo) < 0)
|
1999-02-04 16:20:13 -05:00
|
|
|
error = EINVAL;
|
|
|
|
|
}
|
2000-11-22 22:21:58 -05:00
|
|
|
if (error == 0) {
|
2001-06-13 06:58:39 -04:00
|
|
|
SET_FOREACH(lihp, linux_ioctl_handler_set)
|
|
|
|
|
linux_ioctl_unregister_handler(*lihp);
|
2023-02-06 09:00:44 -05:00
|
|
|
linux_netlink_deregister();
|
2019-11-06 15:53:33 -05:00
|
|
|
linux_dev_shm_destroy();
|
2009-05-07 14:36:47 -04:00
|
|
|
linux_osd_jail_deregister();
|
2000-11-22 22:21:58 -05:00
|
|
|
if (bootverbose)
|
|
|
|
|
printf("Linux ELF exec handler removed\n");
|
|
|
|
|
} else
|
1998-10-15 23:55:01 -04:00
|
|
|
printf("Could not deinstall ELF interpreter entry\n");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2015-05-24 10:55:12 -04:00
|
|
|
return (EOPNOTSUPP);
|
1998-10-15 23:55:01 -04:00
|
|
|
}
|
2015-05-24 10:55:12 -04:00
|
|
|
return (error);
|
1997-03-29 05:50:27 -05:00
|
|
|
}
|
2000-11-22 22:21:58 -05:00
|
|
|
|
1998-10-15 23:55:01 -04:00
|
|
|
static moduledata_t linux_elf_mod = {
|
|
|
|
|
"linuxelf",
|
|
|
|
|
linux_elf_modevent,
|
2012-10-10 04:36:38 -04:00
|
|
|
0
|
1998-10-15 23:55:01 -04:00
|
|
|
};
|
2000-11-22 22:21:58 -05:00
|
|
|
|
2010-10-12 05:18:17 -04:00
|
|
|
DECLARE_MODULE_TIED(linuxelf, linux_elf_mod, SI_SUB_EXEC, SI_ORDER_ANY);
|
2023-02-06 09:00:44 -05:00
|
|
|
MODULE_DEPEND(linuxelf, netlink, 1, 1, 1);
|
2016-04-05 18:36:48 -04:00
|
|
|
FEATURE(linux, "Linux 32bit support");
|