mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
1999-08-19 Roland McGrath <roland@baalperazim.frob.com>
* sysdeps/mach/hurd/i386/intr-msg.h (INTR_MSG_TRAP): Mark OPTION and TIMEOUT as outputs of the asm to indicate that the signal thread might mutate them. * hurd/intr-msg.c (_hurd_intr_rpc_mach_msg): Short circuit to plain mach_msg if only sending or only receiving (i.e., not an RPC). When making an RPC that might get interrupted, save OPTION and the portion of the message buffer that gets clobbered by an EINTR reply message, and properly restore them before attempting to retry the request message send.
This commit is contained in:
186
hurd/intr-msg.c
186
hurd/intr-msg.c
@ -21,6 +21,7 @@
|
|||||||
#include <mach/mig_errors.h>
|
#include <mach/mig_errors.h>
|
||||||
#include <mach/mig_support.h>
|
#include <mach/mig_support.h>
|
||||||
#include <hurd/signal.h>
|
#include <hurd/signal.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "intr-msg.h"
|
#include "intr-msg.h"
|
||||||
|
|
||||||
@ -36,39 +37,75 @@ _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg,
|
|||||||
{
|
{
|
||||||
error_t err;
|
error_t err;
|
||||||
struct hurd_sigstate *ss;
|
struct hurd_sigstate *ss;
|
||||||
int user_timeout;
|
const mach_msg_option_t user_option = option;
|
||||||
|
const mach_msg_timeout_t user_timeout = timeout;
|
||||||
|
|
||||||
if (_hurd_msgport_thread == MACH_PORT_NULL)
|
struct clobber { int i[2]; };
|
||||||
|
union msg
|
||||||
|
{
|
||||||
|
mach_msg_header_t header;
|
||||||
|
mig_reply_header_t reply;
|
||||||
|
struct
|
||||||
{
|
{
|
||||||
/* The signal thread is not set up yet, so we cannot do the
|
mach_msg_header_t header;
|
||||||
normal signal magic. Do a simple uninterruptible RPC instead. */
|
int type;
|
||||||
return __mach_msg (msg, option, send_size, rcv_size, rcv_name,
|
int code;
|
||||||
|
} check;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
mach_msg_header_t header;
|
||||||
|
struct clobber data;
|
||||||
|
} request;
|
||||||
|
};
|
||||||
|
union msg *const m = (void *) msg;
|
||||||
|
mach_msg_bits_t msgh_bits;
|
||||||
|
mach_port_t remote_port;
|
||||||
|
mach_msg_id_t msgid;
|
||||||
|
struct clobber save_data;
|
||||||
|
|
||||||
|
if ((option & (MACH_SEND_MSG|MACH_RCV_MSG)) != (MACH_SEND_MSG|MACH_RCV_MSG)
|
||||||
|
|| _hurd_msgport_thread == MACH_PORT_NULL)
|
||||||
|
{
|
||||||
|
/* Either this is not an RPC (i.e., only a send or only a receive),
|
||||||
|
so it can't be interruptible; or, the signal thread is not set up
|
||||||
|
yet, so we cannot do the normal signal magic. Do a normal,
|
||||||
|
uninterruptible mach_msg call instead. */
|
||||||
|
return __mach_msg (&m->header, option, send_size, rcv_size, rcv_name,
|
||||||
timeout, notify);
|
timeout, notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
ss = _hurd_self_sigstate ();
|
ss = _hurd_self_sigstate ();
|
||||||
|
|
||||||
/* Notice now if the user requested a timeout. OPTION may have the bit
|
/* Save state that gets clobbered by an EINTR reply message.
|
||||||
added by interruption semantics, and we must distinguish. */
|
We will need to restore it if we want to retry the RPC. */
|
||||||
user_timeout = option & MACH_RCV_TIMEOUT;
|
msgh_bits = m->header.msgh_bits;
|
||||||
|
remote_port = m->header.msgh_remote_port;
|
||||||
|
msgid = m->header.msgh_id;
|
||||||
|
assert (rcv_size >= sizeof m->request);
|
||||||
|
save_data = m->request.data;
|
||||||
|
|
||||||
/* Tell the signal thread that we are doing an interruptible RPC on
|
/* Tell the signal thread that we are doing an interruptible RPC on
|
||||||
this port. If we get a signal and should return EINTR, the signal
|
this port. If we get a signal and should return EINTR, the signal
|
||||||
thread will set this variable to MACH_PORT_NULL. The RPC might
|
thread will set this variable to MACH_PORT_NULL. The RPC might
|
||||||
return EINTR when some other thread gets a signal, in which case we
|
return EINTR when some other thread gets a signal, in which case we
|
||||||
want to restart our call. */
|
want to restart our call. */
|
||||||
ss->intr_port = msg->msgh_remote_port;
|
ss->intr_port = m->header.msgh_remote_port;
|
||||||
|
|
||||||
/* A signal may arrive here, after intr_port is set, but before
|
/* A signal may arrive here, after intr_port is set, but before the
|
||||||
the mach_msg system call. The signal handler might do an
|
mach_msg system call. The signal handler might do an interruptible
|
||||||
interruptible RPC, and clobber intr_port; then it would not be
|
RPC, and clobber intr_port; then it would not be set properly when we
|
||||||
set properly when we actually did send the RPC, and a later
|
actually did send the RPC, and a later signal wouldn't interrupt that
|
||||||
signal wouldn't interrupt that RPC. So,
|
RPC. So, _hurd_setup_sighandler saves intr_port in the sigcontext,
|
||||||
_hurd_setup_sighandler saves intr_port in the sigcontext, and
|
and sigreturn restores it. */
|
||||||
sigreturn restores it. */
|
|
||||||
|
|
||||||
message:
|
message:
|
||||||
|
|
||||||
|
/* XXX
|
||||||
|
At all points here (once SS->intr_port is set), the signal thread
|
||||||
|
thinks we are "about to enter the syscall", and might mutate our
|
||||||
|
return-value register. This is bogus.
|
||||||
|
*/
|
||||||
|
|
||||||
if (ss->cancel)
|
if (ss->cancel)
|
||||||
{
|
{
|
||||||
/* We have been cancelled. Don't do an RPC at all. */
|
/* We have been cancelled. Don't do an RPC at all. */
|
||||||
@ -77,13 +114,14 @@ _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg,
|
|||||||
return EINTR;
|
return EINTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Note that the signal trampoline code might modify our OPTION! */
|
||||||
err = INTR_MSG_TRAP (msg, option, send_size,
|
err = INTR_MSG_TRAP (msg, option, send_size,
|
||||||
rcv_size, rcv_name, timeout, notify);
|
rcv_size, rcv_name, timeout, notify);
|
||||||
|
|
||||||
switch (err)
|
switch (err)
|
||||||
{
|
{
|
||||||
case MACH_RCV_TIMED_OUT:
|
case MACH_RCV_TIMED_OUT:
|
||||||
if (user_timeout)
|
if (user_option & MACH_RCV_TIMEOUT)
|
||||||
/* The real user RPC timed out. */
|
/* The real user RPC timed out. */
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
@ -92,18 +130,34 @@ _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg,
|
|||||||
goto interrupted;
|
goto interrupted;
|
||||||
|
|
||||||
case MACH_SEND_INTERRUPTED: /* RPC didn't get out. */
|
case MACH_SEND_INTERRUPTED: /* RPC didn't get out. */
|
||||||
case EINTR: /* Server not cooperating with interrupt. */
|
if (!(option & MACH_SEND_MSG))
|
||||||
|
{
|
||||||
|
/* Oh yes, it did! Since we were not doing a message send,
|
||||||
|
this return code cannot have come from the kernel!
|
||||||
|
Instead, it was the signal thread mutating our state to tell
|
||||||
|
us not to enter this RPC. However, we are already in the receive!
|
||||||
|
Since the signal thread thought we weren't in the RPC yet,
|
||||||
|
it didn't do an interrupt_operation.
|
||||||
|
XXX */
|
||||||
|
goto retry_receive;
|
||||||
|
}
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
|
||||||
|
case EINTR:
|
||||||
|
/* Either the process was stopped and continued,
|
||||||
|
or the server doesn't support interrupt_operation. */
|
||||||
if (ss->intr_port != MACH_PORT_NULL)
|
if (ss->intr_port != MACH_PORT_NULL)
|
||||||
/* If this signal was for us and it should interrupt calls, the
|
/* If this signal was for us and it should interrupt calls, the
|
||||||
signal thread will have cleared SS->intr_port.
|
signal thread will have cleared SS->intr_port.
|
||||||
Since it's not cleared, the signal was for another thread,
|
Since it's not cleared, the signal was for another thread,
|
||||||
or SA_RESTART is set. Restart the interrupted call. */
|
or SA_RESTART is set. Restart the interrupted call. */
|
||||||
{
|
{
|
||||||
restart:
|
/* Make sure we have a valid reply port. The one we were using
|
||||||
if (rcv_name != MACH_PORT_NULL)
|
may have been destroyed by interruption. */
|
||||||
/* Make sure we have a valid reply port. The one we were using
|
m->header.msgh_local_port = rcv_name = __mig_get_reply_port ();
|
||||||
may have been destroyed by interruption. */
|
m->header.msgh_bits = msgh_bits;
|
||||||
msg->msgh_local_port = rcv_name = __mig_get_reply_port ();
|
option = user_option;
|
||||||
|
timeout = user_timeout;
|
||||||
goto message;
|
goto message;
|
||||||
}
|
}
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
@ -122,52 +176,74 @@ _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg,
|
|||||||
|
|
||||||
case MACH_RCV_INTERRUPTED: /* RPC sent; no reply. */
|
case MACH_RCV_INTERRUPTED: /* RPC sent; no reply. */
|
||||||
option &= ~MACH_SEND_MSG; /* Don't send again. */
|
option &= ~MACH_SEND_MSG; /* Don't send again. */
|
||||||
|
retry_receive:
|
||||||
if (ss->intr_port == MACH_PORT_NULL)
|
if (ss->intr_port == MACH_PORT_NULL)
|
||||||
{
|
{
|
||||||
/* This signal or cancellation was for us. We need to wait for
|
/* This signal or cancellation was for us. We need to wait for
|
||||||
the reply, but not hang forever. */
|
the reply, but not hang forever. */
|
||||||
option |= MACH_RCV_TIMEOUT;
|
option |= MACH_RCV_TIMEOUT;
|
||||||
/* Never decrease the user's timeout. */
|
/* Never decrease the user's timeout. */
|
||||||
if (!user_timeout || timeout > _hurd_interrupted_rpc_timeout)
|
if (!(user_option & MACH_RCV_TIMEOUT)
|
||||||
|
|| timeout > _hurd_interrupted_rpc_timeout)
|
||||||
timeout = _hurd_interrupted_rpc_timeout;
|
timeout = _hurd_interrupted_rpc_timeout;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
option = user_option;
|
||||||
|
timeout = user_timeout;
|
||||||
|
}
|
||||||
goto message; /* Retry the receive. */
|
goto message; /* Retry the receive. */
|
||||||
|
|
||||||
case MACH_MSG_SUCCESS:
|
case MACH_MSG_SUCCESS:
|
||||||
if (option & MACH_RCV_MSG)
|
{
|
||||||
|
/* We got a reply. Was it EINTR? */
|
||||||
|
const union
|
||||||
{
|
{
|
||||||
/* We got a reply. Was it EINTR? */
|
mach_msg_type_t t;
|
||||||
mig_reply_header_t *const reply = (void *) msg;
|
int i;
|
||||||
const union
|
} check =
|
||||||
{
|
{ t: { MACH_MSG_TYPE_INTEGER_T, sizeof (integer_t) * 8,
|
||||||
mach_msg_type_t t;
|
1, TRUE, FALSE, FALSE, 0 } };
|
||||||
integer_t i;
|
|
||||||
} check =
|
if (m->reply.RetCode == EINTR &&
|
||||||
{ t: {
|
m->header.msgh_size == sizeof m->reply &&
|
||||||
MACH_MSG_TYPE_INTEGER_T,
|
m->check.type == check.i &&
|
||||||
sizeof (integer_t) * 8,
|
!(m->header.msgh_bits & MACH_MSGH_BITS_COMPLEX))
|
||||||
1,
|
{
|
||||||
TRUE,
|
/* It is indeed EINTR. Is the interrupt for us? */
|
||||||
FALSE,
|
if (ss->intr_port != MACH_PORT_NULL)
|
||||||
FALSE,
|
{
|
||||||
0
|
|
||||||
} };
|
|
||||||
if (msg->msgh_size == sizeof *reply &&
|
|
||||||
!(msg->msgh_bits & MACH_MSGH_BITS_COMPLEX) &&
|
|
||||||
*(int *) &reply->RetCodeType == check.i &&
|
|
||||||
reply->RetCode == EINTR)
|
|
||||||
{
|
|
||||||
/* It is indeed EINTR. Is the interrupt for us? */
|
|
||||||
if (ss->intr_port != MACH_PORT_NULL)
|
|
||||||
/* Nope; repeat the RPC.
|
/* Nope; repeat the RPC.
|
||||||
XXX Resources moved? */
|
XXX Resources moved? */
|
||||||
goto restart;
|
|
||||||
else
|
assert (m->header.msgh_id == msgid + 100);
|
||||||
/* The EINTR return indicates cancellation, so clear the
|
|
||||||
flag. */
|
/* We know we have a valid reply port, because we just
|
||||||
ss->cancel = 0;
|
received the EINTR reply on it. Restore it and the
|
||||||
}
|
other fields in the message header needed for send,
|
||||||
}
|
since the header now reflects receipt of the reply. */
|
||||||
|
m->header.msgh_local_port = rcv_name;
|
||||||
|
m->header.msgh_remote_port = remote_port;
|
||||||
|
m->header.msgh_id = msgid;
|
||||||
|
m->header.msgh_bits = msgh_bits;
|
||||||
|
/* Restore the two words clobbered by the reply data. */
|
||||||
|
m->request.data = save_data;
|
||||||
|
|
||||||
|
/* Restore the original mach_msg options.
|
||||||
|
OPTION may have had MACH_RCV_TIMEOUT added,
|
||||||
|
and/or MACH_SEND_MSG removed. */
|
||||||
|
option = user_option;
|
||||||
|
timeout = user_timeout;
|
||||||
|
|
||||||
|
/* Now we are ready to repeat the original message send. */
|
||||||
|
goto message;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* The EINTR return indicates cancellation,
|
||||||
|
so clear the flag. */
|
||||||
|
ss->cancel = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: /* Quiet -Wswitch-enum. */
|
default: /* Quiet -Wswitch-enum. */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* Machine-dependent details of interruptible RPC messaging. i386 version.
|
/* Machine-dependent details of interruptible RPC messaging. i386 version.
|
||||||
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
Copyright (C) 1995, 1996, 1997, 1999 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -18,6 +18,9 @@
|
|||||||
Boston, MA 02111-1307, USA. */
|
Boston, MA 02111-1307, USA. */
|
||||||
|
|
||||||
|
|
||||||
|
/* Note that we must mark OPTION and TIMEOUT as outputs of this operation,
|
||||||
|
to indicate that the signal thread might mutate them as part
|
||||||
|
of sending us to a signal handler. */
|
||||||
#define INTR_MSG_TRAP(msg, option, send_size, rcv_size, rcv_name, timeout, notify) \
|
#define INTR_MSG_TRAP(msg, option, send_size, rcv_size, rcv_name, timeout, notify) \
|
||||||
({ \
|
({ \
|
||||||
error_t err; \
|
error_t err; \
|
||||||
@ -26,12 +29,14 @@
|
|||||||
".globl _hurd_intr_rpc_msg_cx_sp\n" \
|
".globl _hurd_intr_rpc_msg_cx_sp\n" \
|
||||||
".globl _hurd_intr_rpc_msg_sp_restored\n" \
|
".globl _hurd_intr_rpc_msg_sp_restored\n" \
|
||||||
" movl %%esp, %%ecx\n" \
|
" movl %%esp, %%ecx\n" \
|
||||||
" leal %1, %%esp\n" \
|
" leal %3, %%esp\n" \
|
||||||
"_hurd_intr_rpc_msg_cx_sp: movl $-25, %%eax\n" \
|
"_hurd_intr_rpc_msg_cx_sp: movl $-25, %%eax\n" \
|
||||||
"_hurd_intr_rpc_msg_do_trap: lcall $7, $0 # status in %0\n" \
|
"_hurd_intr_rpc_msg_do_trap: lcall $7, $0 # status in %0\n" \
|
||||||
"_hurd_intr_rpc_msg_in_trap: movl %%ecx, %%esp\n" \
|
"_hurd_intr_rpc_msg_in_trap: movl %%ecx, %%esp\n" \
|
||||||
"_hurd_intr_rpc_msg_sp_restored:" \
|
"_hurd_intr_rpc_msg_sp_restored:" \
|
||||||
: "=a" (err) : "m" ((&msg)[-1]) : "%ecx"); \
|
: "=a" (err), "=m" (option), "=m" (timeout) \
|
||||||
|
: "m" ((&msg)[-1]), "1" (option), "2" (timeout) \
|
||||||
|
: "%ecx"); \
|
||||||
err; \
|
err; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user