From 54da5be39c868b55c234c23bb38eb42babc084d7 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Mon, 14 Aug 1995 22:49:23 +0000 Subject: Mon Aug 14 16:51:13 1995 Roland McGrath * hurd/thread-cancel.c: New file. * sysdeps/mach/hurd/i386/trampoline.c (_hurd_setup_sighandler): In rpc_wait case, frob mach_msg args to set timeout on receive. (_hurdsig_rcv_interrupted_p): Function removed. * sysdeps/mach/hurd/alpha/trampoline.c: Likewise. * sysdeps/mach/hurd/hppa/trampoline.c: Likewise. * sysdeps/mach/hurd/mips/trampoline.c: Likewise. * hurd/intr-msg.c: New file. * hurd/hurd/signal.h (struct hurd_sigstate): New member `cancel'. (_hurdsig_rcv_interrupted_p): Declaration removed. (HURD_EINTR_RPC): Macro removed. (_hurd_longjmp_thread_state, _hurd_interrupted_rpc_timeout): Declare these. * hurd/intr-rpc.h: New file. * hurd/intr-rpc.defs: Just import intr-rpc.h. * hurd/hurdsig.c (_hurd_interrupted_rpc_timeout): New variable. (interrupted_reply_port_location): Take new flag arg; only catch faults if it's set. (abort_rpcs): Rename to _hurdsig_abort_rpcs; take same new flag arg. No longer use _hurdsig_rcv_interrupted_p; instead compare PC to &_hurd_intr_rpc_msg_in_trap. If before it, mutate state to simulate MACH_SEND_INTERRUPTED return; on it, interrupt the operation. All callers changed. * hurd/hurd.h (hurd_thread_cancel, hurd_check_cancel): Declare these. * hurd/Makefile (distribute): Remove intr-rpc.awk. (sig): Add thread-cancel. (transform-user-stub, transform-user-stub-output): Variables removed. * sysdeps/mach/hurd/dl-sysdep.c: Change all RPCs from `__hurd_intr_rpc_*' to `__*'. (_hurd_intr_rpc_mach_msg): New function. (_hurd_thread_sigstate): Function removed. * sysdeps/mach/hurd/ioctl.c: Use _hurd_intr_rpc_mach_msg function, instead of __mach_msg inside HURD_EINTR_RPC macro. * sysdeps/generic/morecore.c [__GNU_LIBRARY__]: Declare `__sbrk' to take ptrdiff_t arg. * sysdeps/mach/hurd/fork.c: Remove _hurd_longjmp_thread_state decl. * sysdeps/mach/hurd/kill.c (kill_pid): Don't make `inline'. * libc-symbols.h [GCC >= 2.7] (strong_alias, weak_symbol, weak_alias): Use `extern' storage class. --- sysdeps/mach/hurd/alpha/trampoline.c | 47 ++++++----------------------------- sysdeps/mach/hurd/dl-sysdep.c | 48 +++++++++++++++++++----------------- sysdeps/mach/hurd/fork.c | 3 --- sysdeps/mach/hurd/hppa/trampoline.c | 40 +++++------------------------- sysdeps/mach/hurd/i386/trampoline.c | 42 +++++-------------------------- sysdeps/mach/hurd/ioctl.c | 10 ++++---- sysdeps/mach/hurd/kill.c | 2 -- sysdeps/mach/hurd/mips/trampoline.c | 37 +++++---------------------- 8 files changed, 56 insertions(+), 173 deletions(-) (limited to 'sysdeps/mach') diff --git a/sysdeps/mach/hurd/alpha/trampoline.c b/sysdeps/mach/hurd/alpha/trampoline.c index 85f4964..f3872fc 100644 --- a/sysdeps/mach/hurd/alpha/trampoline.c +++ b/sysdeps/mach/hurd/alpha/trampoline.c @@ -1,5 +1,5 @@ /* Set thread_state for sighandler, and sigcontext to recover. Alpha version. -Copyright (C) 1994 Free Software Foundation, Inc. +Copyright (C) 1994, 1995 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 @@ -160,6 +160,12 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, 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; + state->basic.pc = (long int) &&rpc_wait_trampoline; /* After doing the message receive, the trampoline code will need to update the v0 ($0) value to be restored by sigreturn. To simplify @@ -245,42 +251,3 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, /* NOTREACHED */ return NULL; } - -/* STATE describes a thread that had intr_port set (meaning it was inside - HURD_EINTR_RPC), after it has been thread_abort'd. If it looks to have - just completed a mach_msg_trap system call that returned - MACH_RCV_INTERRUPTED, return nonzero and set *PORT to the receive right - being waited on. */ -int -_hurdsig_rcv_interrupted_p (struct machine_thread_all_state *state, - mach_port_t *port) -{ - if (state->basic.r0 == MACH_RCV_INTERRUPTED) - { - const unsigned int *pc = (void *) state->basic.pc; - struct mach_msg_trap_args *args = (void *) &state->basic.r16; - - if (_hurdsig_catch_fault (SIGSEGV)) - { - assert (_hurdsig_fault_sigcode == (long int) (pc - 1) || - _hurdsig_fault_sigcode == (long int) &args->rcv_name); - /* We got a fault trying to read the PC or stack. */ - return 0; - } - else - { - if (pc[-1] == ((alpha_instruction) { pal_format: - { opcode: op_pal, - function: op_chmk } }).bits) - { - /* We did just return from a mach_msg_trap system call - doing a message receive that was interrupted. - Examine the parameters to find the receive right. */ - *port = args->rcv_name; - return 1; - } - } - } - - return 0; -} diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index 8f303bf..e55a615 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -125,6 +125,7 @@ fmh(); /* XXX */ _hurd_startup (start_argptr, &go); LOSE; + abort (); } int @@ -137,7 +138,6 @@ _dl_sysdep_open_zero_fill (void) void _dl_sysdep_fatal (const char *msg, ...) { - extern __typeof (__io_write) __hurd_intr_rpc_io_write; va_list ap; va_start (ap, msg); @@ -147,8 +147,7 @@ _dl_sysdep_fatal (const char *msg, ...) mach_msg_type_number_t nwrote; do { - if (__hurd_intr_rpc_io_write (_hurd_init_dtable[2], - msg, len, -1, &nwrote)) + if (__io_write (_hurd_init_dtable[2], msg, len, -1, &nwrote)) break; len -= nwrote; msg += nwrote; @@ -169,8 +168,6 @@ _dl_sysdep_fatal (const char *msg, ...) int open (const char *file_name, int mode, ...) { - extern __typeof (__dir_lookup) __hurd_intr_rpc_dir_lookup; - extern __typeof (__io_reauthenticate) __hurd_intr_rpc_io_reauthenticate; enum retry_type doretry; char retryname[1024]; /* XXX string_t LOSES! */ file_t startdir, newpt, fileport; @@ -187,7 +184,7 @@ open (const char *file_name, int mode, ...) while (file_name[0] == '/') file_name++; - if (errno = __hurd_intr_rpc_dir_lookup (startdir, file_name, mode, 0, + if (errno = __dir_lookup (startdir, file_name, mode, 0, &doretry, retryname, &fileport)) return -1; @@ -207,7 +204,7 @@ open (const char *file_name, int mode, ...) case FS_RETRY_REAUTH: { mach_port_t ref = __mach_reply_port (); - errno = __hurd_intr_rpc_io_reauthenticate + errno = __io_reauthenticate (fileport, ref, MACH_MSG_TYPE_MAKE_SEND); if (! errno) errno = __auth_user_authenticate @@ -236,14 +233,12 @@ open (const char *file_name, int mode, ...) if (retryname[0] == '\0') { mach_port_t memobj_rd, memobj_wr; - extern __typeof (__io_map) __hurd_intr_rpc_io_map; dealloc_dir = 1; opened: /* We have the file open. Now map it. */ - errno = __hurd_intr_rpc_io_map (fileport, - &memobj_rd, &memobj_wr); + errno = __io_map (fileport, &memobj_rd, &memobj_wr); if (dealloc_dir) __mach_port_deallocate (__mach_task_self (), fileport); if (errno) @@ -359,7 +354,7 @@ open (const char *file_name, int mode, ...) if (! err) { mach_port_t ref = __mach_reply_port (); - err = __hurd_intr_rpc_io_reauthenticate + err = __io_reauthenticate (unauth, ref, MACH_MSG_TYPE_MAKE_SEND); if (! err) err = __auth_user_authenticate @@ -404,8 +399,8 @@ open (const char *file_name, int mode, ...) return -1; } - errno = __hurd_intr_rpc_dir_lookup (startdir, file_name, mode, 0, - &doretry, retryname, &fileport); + errno = __dir_lookup (startdir, file_name, mode, 0, + &doretry, retryname, &fileport); } } @@ -445,9 +440,8 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset) void _exit (int status) { - extern __typeof (__proc_mark_exit) __hurd_intr_rpc_proc_mark_exit; - __hurd_intr_rpc_proc_mark_exit (_dl_hurd_data->portarray[INIT_PORT_PROC], - W_EXITCODE (status, 0)); + __proc_mark_exit (_dl_hurd_data->portarray[INIT_PORT_PROC], + W_EXITCODE (status, 0)); while (__task_terminate (__mach_task_self ())) __mach_task_self_ = (__mach_task_self) (); } @@ -513,11 +507,21 @@ longjmp (jmp_buf env, int val) { __longjmp (env[0].__jmpbuf, val); } weak_symbol (longjmp) -/* Stub out this function that is called by interruptible RPC stubs. It - should never get called during initial dynamic linking, because we use - only the raw MiG stub functions __hurd_intr_rpc_*. Since this defn is +/* This function is called by interruptible RPC stubs. For initial + dynamic linking, just use the normal mach_msg. Since this defn is weak, the real defn in libc.so will override it if we are linked into the user program (-ldl). */ -struct hurd_sigstate * -_hurd_thread_sigstate (thread_t thread) { thread = thread; abort (); } -weak_symbol (_hurd_thread_sigstate) + +error_t +_hurd_intr_rpc_mach_msg (mach_msg_header_t *msg, + mach_msg_option_t option, + mach_msg_size_t send_size, + mach_msg_size_t rcv_size, + mach_port_t rcv_name, + mach_msg_timeout_t timeout, + mach_port_t notify) +{ + return __mach_msg (msg, option, send_size, rcv_size, rcv_name, + timeout, notify); +} +weak_symbol (_hurd_intr_rpc_mach_msg) diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c index 8e625b8..b8b1574 100644 --- a/sysdeps/mach/hurd/fork.c +++ b/sysdeps/mach/hurd/fork.c @@ -27,9 +27,6 @@ Cambridge, MA 02139, USA. */ #include #include "hurdmalloc.h" /* XXX */ -extern void _hurd_longjmp_thread_state (struct machine_thread_state *, - jmp_buf env, int value); - /* Things that want to be locked while forking. */ struct diff --git a/sysdeps/mach/hurd/hppa/trampoline.c b/sysdeps/mach/hurd/hppa/trampoline.c index 09ab71e..1dbbe6d 100644 --- a/sysdeps/mach/hurd/hppa/trampoline.c +++ b/sysdeps/mach/hurd/hppa/trampoline.c @@ -144,6 +144,12 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, 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 (); MACHINE_THREAD_STATE_SET_PC (&state->basic, &&rpc_wait_trampoline); @@ -222,37 +228,3 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, /* NOTREACHED */ return NULL; } - -/* STATE describes a thread that had intr_port set (meaning it was inside - HURD_EINTR_RPC), after it has been thread_abort'd. It it looks to have - just completed a mach_msg_trap system call that returned - MACH_RCV_INTERRUPTED, return nonzero and set *PORT to the receive right - being waited on. */ -int -_hurdsig_rcv_interrupted_p (struct machine_thread_all_state *state, - mach_port_t *port) -{ - const unsigned int *volatile pc - = MACHINE_THREAD_STATE_PC (&state->basic); - const mach_port_t *rcv_name - = (void *) state->r30 -32-20; /* VA_ARG4 from . */ - - if (_hurdsig_catch_fault (SIGSEGV)) - assert (_hurdsig_fault_sigcode == (long int) pc || - _hurdsig_fault_sigcode == (long int) rcv_name); - else - { - int rcving = (state->basic.r28 == MACH_RCV_INTERRUPTED && - pc == ???unfinished???); - if (rcving) - /* We did just return from a mach_msg_trap system call - doing a message receive that was interrupted. - Examine the parameters to find the receive right. */ - *port = *rcv_name; - _hurdsig_end_catch_fault (); - if (rcving) - return 1; - } - - return 0; -} diff --git a/sysdeps/mach/hurd/i386/trampoline.c b/sysdeps/mach/hurd/i386/trampoline.c index 2a31588..7adffc4 100644 --- a/sysdeps/mach/hurd/i386/trampoline.c +++ b/sysdeps/mach/hurd/i386/trampoline.c @@ -181,6 +181,12 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, 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; @@ -250,39 +256,3 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, /* NOTREACHED */ return NULL; } - -/* STATE describes a thread that had intr_port set (meaning it was inside - HURD_EINTR_RPC), after it has been thread_abort'd. It it looks to have - just completed a mach_msg_trap system call that returned - MACH_RCV_INTERRUPTED, return nonzero and set *PORT to the receive right - being waited on. */ -int -_hurdsig_rcv_interrupted_p (struct machine_thread_all_state *state, - mach_port_t *port) -{ - static const unsigned char syscall[] = { 0x9a, 0, 0, 0, 0, 7, 0 }; - const unsigned char *volatile pc - = (void *) state->basic.eip - sizeof syscall; - - if (_hurdsig_catch_fault (SIGSEGV)) - assert (_hurdsig_fault_sigcode >= (long int) pc && - _hurdsig_fault_sigcode < (long int) (pc + sizeof syscall)); - else - { - int rcving = (state->basic.eax == MACH_RCV_INTERRUPTED && - !memcmp (pc, &syscall, sizeof syscall)); - _hurdsig_end_catch_fault (); - if (rcving) - { - /* We did just return from a mach_msg_trap system call - doing a message receive that was interrupted. - Examine the parameters to find the receive right. */ - struct mach_msg_trap_args *args = (void *) state->basic.uesp; - - *port = args->rcv_name; - return 1; - } - } - - return 0; -} diff --git a/sysdeps/mach/hurd/ioctl.c b/sysdeps/mach/hurd/ioctl.c index 4aad0bb..a1523c6 100644 --- a/sysdeps/mach/hurd/ioctl.c +++ b/sysdeps/mach/hurd/ioctl.c @@ -79,11 +79,11 @@ DEFUN(__ioctl, (fd, request), m->msgh_id = msgid; m->msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE); - err = HURD_EINTR_RPC (ioport, __mach_msg (m, MACH_SEND_MSG|MACH_RCV_MSG, - m->msgh_size, sizeof (msg), - m->msgh_local_port, - MACH_MSG_TIMEOUT_NONE, - MACH_PORT_NULL)); + err = _hurd_intr_rpc_mach_msg (m, MACH_SEND_MSG|MACH_RCV_MSG, + m->msgh_size, sizeof (msg), + m->msgh_local_port, + MACH_MSG_TIMEOUT_NONE, + MACH_PORT_NULL); switch (err) { case MACH_MSG_SUCCESS: diff --git a/sysdeps/mach/hurd/kill.c b/sysdeps/mach/hurd/kill.c index a6abdc5..bedc137 100644 --- a/sysdeps/mach/hurd/kill.c +++ b/sysdeps/mach/hurd/kill.c @@ -37,8 +37,6 @@ __kill (pid_t pid, int sig) inline void kill_pid (pid_t pid) /* Kill one PID. */ { - - /* SIGKILL is not delivered as a normal signal. Sending SIGKILL to a process means to terminate its task. */ if (sig == SIGKILL) diff --git a/sysdeps/mach/hurd/mips/trampoline.c b/sysdeps/mach/hurd/mips/trampoline.c index f03ad58..03e3d1d 100644 --- a/sysdeps/mach/hurd/mips/trampoline.c +++ b/sysdeps/mach/hurd/mips/trampoline.c @@ -150,6 +150,12 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, 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; + state->basic.pc = (int) &&rpc_wait_trampoline; state->basic.r29 = (int) sigsp; /* $29 is the stack pointer register. */ /* After doing the message receive, the trampoline code will need to @@ -227,34 +233,3 @@ _hurd_setup_sighandler (struct hurd_sigstate *ss, __sighandler_t handler, return NULL; } - -/* STATE describes a thread that had intr_port set (meaning it was inside - HURD_EINTR_RPC), after it has been thread_abort'd. It it looks to have - just completed a mach_msg_trap system call that returned - MACH_RCV_INTERRUPTED, return nonzero and set *PORT to the receive right - being waited on. */ -int -_hurdsig_rcv_interrupted_p (struct machine_thread_all_state *state, - mach_port_t *port) -{ - const unsigned int *const pc = (void *) state->basic.pc; - - if (_hurdsig_catch_fault (SIGSEGV)) - assert (_hurdsig_fault_sigcode == (long int) pc); - else - { - if (state->basic.r2 == MACH_RCV_INTERRUPTED && - pc[-1] == 0xc) /* syscall */ - { - /* We did just return from a mach_msg_trap system call - doing a message receive that was interrupted. - Examine the parameters to find the receive right. */ - struct mach_msg_trap_args *args = (void *) &state->basic.r4; - - *port = args->rcv_name; - return 1; - } - } - - return 0; -} -- cgit v1.1