glibc/sysdeps/mach/hurd/i386/trampoline.c
Roland McGrath 0e3426bbcf Tue May 7 19:00:01 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* string/argz-extract.c: Remove const from decl.
	* string/argz.h: Here too.

	* Makeconfig (version.mk): Fix regexp in sed cmd.
	Depend on $(..)Makeconfig.

	* GMP code updated from gmp-2.0 release.
	* stdlib/Makefile (mpn-routines): Removed add_1, added inlines.
	* sysdeps/generic/add_1.c: File removed.
	* stdlib/strtod.c: mp_limb is now mp_limb_t.
	* stdlib/fpioconst.c, stdlib/fpioconst.h: Likewise.
	* stdio-common/_itoa.c: Likewise.
	* stdio-common/printf_fp.c: Likewise.
	Don't include ansidecl.h.

	* sysdeps/mach/hurd/getcwd.c: Use io_identity instead of io_stat.

	* shlib-versions: New file.
	* Makerules (soversions.mk): New target, include file generated from
	shlib-versions.  Moved shared library rules before installation rules.
	Rewrote shared library installation rules for versioned libraries.
	* math/Makefile (libm.so-version): Variable removed.

	* sysdeps/mach/hurd/i386/exc2signal.c: Use struct hurd_signal_detail.

	* hurd/report-wait.c (_S_msg_describe_ports): New function.

	* configure.in: Add AC_PROG_LN_S check.
	* config.make.in (LN_S): New variable.

Sun May  5 03:10:44 1996  Ulrich Drepper  <drepper@cygnus.com>

	* misc/efgcvt_r.c (ecvt_r): Work aroung gcc bug.  gcc does
	not know about weak aliases now and optimizes necessary `if'
	statement away.

	* posix/unistd.h: Add swapoff prototype.

	* sysdeps/generic/confname.h: Add even more POSIX.4 symbols.

	* sysdeps/posix/fpathconf.c (__fpathconf): Get information
	for _PC_PATH_MAX from fstatfs function if available.

	* sysdeps/posix/sysconf.c: Add code to handle _SC_AIO_LISTIO_MAX,
	_SC_AIO_MAX, _SC_AIO_PRIO_DELTA_MAX, _SC_DELAYTIMER_MAX,
	_SC_MQ_OPEN_MAX, _SC_MQ_PRIO_MAX, _SC_RTSIG_MAX,
	_SC_SEM_NSEMS_MAX, _SC_SEM_VALUE_MAX, _SC_SIGQUEUE_MAX, and
	_SC_TIMER_MAX.
	* sysdeps/unix/sysv/sysv4/sysconf.c: Ditto.

	* sysdeps/stub/swapoff.c: New file.  Stub version for swapoff
	function.

	* sysdeps/unix/syscalls.list:  Add swapoff.

	* sysdeps/unix/sysv/linux/Dist: Add sys/acct.h.

	* sysdeps/unix/sysv/linux/Makefile [$(subdir) == misc]
	(sysdep_routines): Add mount, umount, llseek, setfsgid, setfsuid,
	sysinfo, and uselib.
	(headers): Add sys/sysinfo.h.

	* sysdeps/unix/sysv/linux/gethostid.c: Prevent warning.

	* sysdeps/unix/sysv/linux/i386/Makefile [$(subdir) == misc]
	(sysdep_routines): Add ioperm, iopl, and vm86.
	(headers): Add sys/perm.h and sys/vm86.h.

	* sysdeps/unix/sysv/linux/i386/sys/perm.h: New file.  Contains
	prototypes for iopl and ioperm.

	* sysdeps/unix/sysv/linux/i386/sys/vm86.h:  New file.  Contains
	prototype for vm86.

	* sysdeps/unix/sysv/linux/i386/syscalls.list: New file.  Add
	vm86 system call.

	* sysdeps/unix/sysv/linux/sys/acct.h: New file.  Contains
	prototypes for acct function.

	* sysdeps/unix/sysv/linux/sys/socket.h: Provide real header
	file with prototypes.

	* sysdeps/unix/sysv/linux/sys/sysinfo.h: New file.  Contains
	prototype for sysinfo function.

	* sysdeps/unix/sysv/linux/syscalls.list: Add flock, ioperm, iopl,
	llseek, setfsgid, setfsuid, sysinfo, and uselib.

	* sysdeps/unix/sysv/linux/sysconf.c: Instead of duplicating
	posix/sysconf.c now only handle cases different to that
	implementation.

Tue May  7 15:08:19 1996  Miles Bader  <miles@gnu.ai.mit.edu>

	* stdio/linewrap.c (__line_wrap_output): Renamed from lwoutput
	(all references changed).  Now exported.

	* stdio/linewrap.c (struct data): Type deleted (moved to linewrap.h).
	(wrap_stream, unwrap_stream, lwclose, lwfileno, lwoutput,
	line_wrap_stream, line_unwrap_stream): Use struct line_wrap_data
	instead of struct data.
	(lwoutput, line_wrap_stream, line_unwrap_stream): Rename various
	occurences of `wrap' and `wrapmargin' to `wmargin'.
	(line_wrapped, line_wrap_lmargin, line_wrap_set_lmargin,
	line_wrap_rmargin, line_wrap_set_rmargin, line_wrap_wmargin,
	line_wrap_set_wmargin, line_wrap_point): New functions.
	* stdio/linewrap.h: New file.
	* stdio/Makefile (headers): Add linewrap.h.

Tue May  7 14:19:12 1996  Roland McGrath  <roland@delasyd.gnu.ai.mit.edu>

	* sysdeps/unix/sysv/linux/i386/Makefile: File removed.

	* stdio/stdio.h: Remove line_wrap_stream, line_unwap_stream decls.

	* sysdeps/unix/sysv/linux/schedbits.h: New file.

Tue May  7 13:47:02 1996  Miles Bader  <miles@gnu.ai.mit.edu>

	* stdio/linewrap.c (struct data): Make margin fields not-pointers.
	(lwoutput): Adjust uses acordingly.

	* sysdeps/mach/hurd/fdatasync.c: New file.
	* sysdeps/mach/hurd/fsync.c: Pass new flag to file_sync.

	* sysdeps/mach/hurd/xmknod.c: Pass new flag to dir_link.
	* sysdeps/mach/hurd/symlink.c: Likewise.
	* sysdeps/mach/hurd/link.c: Likewise.
	* sysdeps/mach/hurd/bind.c: Likewise.
	* hurd/hurdsig.c (write_corefile): Likewise.

	* hurd/hurdsig.c (write_corefile): Pass cttyid port to crash server.

	* sysdeps/mach/hurd/fpathconf.c: RPC takes int pointer, not long int.

	* sysdeps/mach/hurd/_exit.c (_hurd_exit): Pass sigcode arg to
	proc_mark_exit.
	* sysdeps/mach/hurd/dl-sysdep.c (_exit): Likewise.

	* sysdeps/mach/hurd/wait4.c: Pass sigcode arg to proc_wait.

	* sysdeps/mach/hurd/rename.c: Pass new flag to dir_rename.

	* hurd/hurdfault.c (_hurdsig_fault_catch_exception_raise): Use struct
	hurd_signal_detail.
	* hurd/catch-exc.c (_S_catch_exception_raise): Likewise.
	* hurd/hurd-raise.c (_hurd_raise_signal): Likewise.
	* sysdeps/mach/hurd/i386/trampoline.c (_hurd_setup_sighandler):
	Likewise.
	* sysdeps/mach/hurd/setitimer.c (restart_itimer): Likewise.

	* hurd/hurd/signal.h: Fix _hurd_exception2signal prototype.

	* hurd/hurdsig.c (write_corefile): Take const struct
	hurd_signal_detail * arg.  Pass all details to crash_dump_task.
	(_hurd_internal_post_signal): Pass DETAIL to write_corefile.
	(_hurd_internal_post_signal: suspend): Pass code and error to
	proc_mark_stop.

	* hurd/hurdprio.c (_hurd_priority_which_map): Pass flags arg to
	proc_getprocinfo by reference.
1996-05-08 02:07:47 +00:00

267 lines
9.9 KiB
C

/* Set thread_state for sighandler, and sigcontext to recover. i386 version.
Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <hurd/signal.h>
#include <hurd/userlink.h>
#include "thread_state.h"
#include <assert.h>
#include <errno.h>
#include "hurdfault.h"
#include "intr-msg.h"
struct sigcontext *
_hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler,
int signo, struct hurd_signal_detail *detail,
volatile int rpc_wait,
struct machine_thread_all_state *state)
{
__label__ trampoline, rpc_wait_trampoline, firewall;
extern const void _hurd_intr_rpc_msg_in_trap;
extern const void _hurd_intr_rpc_msg_cx_sp;
extern const void _hurd_intr_rpc_msg_sp_restored;
void *volatile sigsp;
struct sigcontext *scp;
struct
{
int signo;
long int sigcode;
struct sigcontext *scp; /* Points to ctx, below. */
void *sigreturn_addr;
void *sigreturn_returns_here;
struct sigcontext *return_scp; /* Same; arg to sigreturn. */
struct sigcontext ctx;
struct hurd_userlink link;
} *stackframe;
if (ss->context)
{
/* We have a previous sigcontext that sigreturn was about
to restore when another signal arrived. We will just base
our setup on that. */
if (! _hurdsig_catch_memory_fault (ss->context))
{
memcpy (&state->basic, &ss->context->sc_i386_thread_state,
sizeof (state->basic));
memcpy (&state->fpu, &ss->context->sc_i386_float_state,
sizeof (state->fpu));
state->set |= (1 << i386_THREAD_STATE) | (1 << i386_FLOAT_STATE);
}
}
if (! machine_get_basic_state (ss->thread, state))
return NULL;
/* Save the original SP in the gratuitous `esp' slot.
We may need to reset the SP (the `uesp' slot) to avoid clobbering an
interrupted RPC frame. */
state->basic.esp = state->basic.uesp;
if ((ss->actions[signo].sa_flags & SA_ONSTACK) &&
!(ss->sigaltstack.ss_flags & (SA_DISABLE|SA_ONSTACK)))
{
sigsp = ss->sigaltstack.ss_sp + ss->sigaltstack.ss_size;
ss->sigaltstack.ss_flags |= SA_ONSTACK;
/* XXX need to set up base of new stack for
per-thread variables, cthreads. */
}
/* This code has intimate knowledge of the special mach_msg system call
done in intr-msg.c; that code does (see intr-msg.h):
movl %esp, %ecx
leal ARGS, %esp
_hurd_intr_rpc_msg_cx_sp: movl $-25, %eax
_hurd_intr_rpc_msg_do_trap: lcall $7, $0
_hurd_intr_rpc_msg_in_trap: movl %ecx, %esp
_hurd_intr_rpc_msg_sp_restored:
We must check for the window during which %esp points at the
mach_msg arguments. The space below until %ecx is used by
the _hurd_intr_rpc_mach_msg frame, and must not be clobbered. */
else if (state->basic.eip >= (int) &_hurd_intr_rpc_msg_cx_sp &&
state->basic.eip < (int) &_hurd_intr_rpc_msg_sp_restored)
/* The SP now points at the mach_msg args, but there is more stack
space used below it. The real SP is saved in %ecx; we must push the
new frame below there, and restore that value as the SP on
sigreturn. */
sigsp = (char *) (state->basic.uesp = state->basic.ecx);
else
sigsp = (char *) state->basic.uesp;
/* Push the arguments to call `trampoline' on the stack. */
sigsp -= sizeof (*stackframe);
stackframe = sigsp;
if (_hurdsig_catch_memory_fault (stackframe))
{
/* We got a fault trying to write the stack frame.
We cannot set up the signal handler.
Returning NULL tells our caller, who will nuke us with a SIGILL. */
return NULL;
}
else
{
int ok;
extern void _hurdsig_longjmp_from_handler (void *, jmp_buf, int);
/* Add a link to the thread's active-resources list. We mark this as
the only user of the "resource", so the cleanup function will be
called by any longjmp which is unwinding past the signal frame.
The cleanup function (in sigunwind.c) will make sure that all the
appropriate cleanups done by sigreturn are taken care of. */
stackframe->link.cleanup = &_hurdsig_longjmp_from_handler;
stackframe->link.cleanup_data = &stackframe->ctx;
stackframe->link.resource.next = NULL;
stackframe->link.resource.prevp = NULL;
stackframe->link.thread.next = ss->active_resources;
stackframe->link.thread.prevp = &ss->active_resources;
if (stackframe->link.thread.next)
stackframe->link.thread.next->thread.prevp
= &stackframe->link.thread.next;
ss->active_resources = &stackframe->link;
/* Set up the arguments for the signal handler. */
stackframe->signo = signo;
stackframe->sigcode = detail->code;
stackframe->scp = stackframe->return_scp = scp = &stackframe->ctx;
stackframe->sigreturn_addr = &__sigreturn;
stackframe->sigreturn_returns_here = &&firewall; /* Crash on return. */
/* Set up the sigcontext from the current state of the thread. */
scp->sc_onstack = ss->sigaltstack.ss_flags & SA_ONSTACK ? 1 : 0;
/* struct sigcontext is laid out so that starting at sc_gs mimics a
struct i386_thread_state. */
memcpy (&scp->sc_i386_thread_state,
&state->basic, sizeof (state->basic));
/* struct sigcontext is laid out so that starting at sc_fpkind mimics
a struct i386_float_state. */
ok = machine_get_state (ss->thread, state, i386_FLOAT_STATE,
&state->fpu, &scp->sc_i386_float_state,
sizeof (state->fpu));
_hurdsig_end_catch_fault ();
if (! ok)
return NULL;
}
/* Modify the thread state to call the trampoline code on the new stack. */
if (rpc_wait)
{
/* The signalee thread was blocked in a mach_msg_trap system call,
still waiting for a reply. We will have it run the special
trampoline code which retries the message receive before running
the signal handler.
To do this we change the OPTION argument on its stack to enable only
message reception, since the request message has already been
sent. */
struct mach_msg_trap_args *args = (void *) state->basic.esp;
if (_hurdsig_catch_memory_fault (args))
{
/* Faulted accessing ARGS. Bomb. */
return NULL;
}
assert (args->option & MACH_RCV_MSG);
/* Disable the message-send, since it has already completed. The
calls we retry need only wait to receive the reply message. */
args->option &= ~MACH_SEND_MSG;
/* Limit the time to receive the reply message, in case the server
claimed that `interrupt_operation' succeeded but in fact the RPC
is hung. */
args->option |= MACH_RCV_TIMEOUT;
args->timeout = _hurd_interrupted_rpc_timeout;
_hurdsig_end_catch_fault ();
state->basic.eip = (int) &&rpc_wait_trampoline;
/* The reply-receiving trampoline code runs initially on the original
user stack. We pass it the signal stack pointer in %ebx. */
state->basic.uesp = state->basic.esp; /* Restore mach_msg syscall SP. */
state->basic.ebx = (int) sigsp;
/* After doing the message receive, the trampoline code will need to
update the %eax value to be restored by sigreturn. To simplify
the assembly code, we pass the address of its slot in SCP to the
trampoline code in %ecx. */
state->basic.ecx = (int) &scp->sc_eax;
}
else
{
state->basic.eip = (int) &&trampoline;
state->basic.uesp = (int) sigsp;
}
/* We pass the handler function to the trampoline code in %edx. */
state->basic.edx = (int) handler;
return scp;
/* The trampoline code follows. This is not actually executed as part of
this function, it is just convenient to write it that way. */
rpc_wait_trampoline:
/* This is the entry point when we have an RPC reply message to receive
before running the handler. The MACH_MSG_SEND bit has already been
cleared in the OPTION argument on our stack. The interrupted user
stack pointer has not been changed, so the system call can find its
arguments; the signal stack pointer is in %ebx. For our convenience,
%ecx points to the sc_eax member of the sigcontext. */
asm volatile
(/* Retry the interrupted mach_msg system call. */
"movl $-25, %eax\n" /* mach_msg_trap */
"lcall $7, $0\n"
/* When the sigcontext was saved, %eax was MACH_RCV_INTERRUPTED. But
now the message receive has completed and the original caller of
the RPC (i.e. the code running when the signal arrived) needs to
see the final return value of the message receive in %eax. So
store the new %eax value into the sc_eax member of the sigcontext
(whose address is in %ecx to make this code simpler). */
"movl %eax, (%ecx)\n"
/* Switch to the signal stack. */
"movl %ebx, %esp\n");
trampoline:
/* Entry point for running the handler normally. The arguments to the
handler function are already on the top of the stack:
0(%esp) SIGNO
4(%esp) SIGCODE
8(%esp) SCP
*/
asm volatile
("call *%edx\n" /* Call the handler function. */
"addl $12, %esp\n" /* Pop its args. */
/* The word at the top of stack is &__sigreturn; following are a dummy
word to fill the slot for the address for __sigreturn to return to,
and a copy of SCP for __sigreturn's argument. "Return" to calling
__sigreturn (SCP); this call never returns. */
"ret");
firewall:
asm volatile ("hlt");
/* NOTREACHED */
return NULL;
}