* cygtls.h (_cygtls::inside_kernel): Move function declaration into _cygtls

class.
* exceptions.cc (_cygtls::inside_kernel): Move function definition into _cygtls
class.
* fhandler.cc (fhandler_base::wait_overlapped): Make return tri-state to detect
when there is a EINTR situation.  Add a pointer to a length parameter.  Move
GetOverlappedResult into this function.
(fhandler_base::read_overlapped): Accommodate above changes and loop if we
receive a restartable signal.
(fhandler_base::write_overlapped): Ditto.
* fhandler.h (fhandler_base::wait_overlapped): Reflect above changes.
* fhandler_fifo.cc (fhandler_fifo::wait): Ditto.
This commit is contained in:
Christopher Faylor 2007-07-29 05:22:05 +00:00
parent 81e98baf81
commit ee2984326b
6 changed files with 61 additions and 23 deletions

View File

@ -1,3 +1,19 @@
2007-07-29 Christopher Faylor <me+cygwin@cgf.cx>
* cygtls.h (_cygtls::inside_kernel): Move function declaration into
_cygtls class.
* exceptions.cc (_cygtls::inside_kernel): Move function definition into
_cygtls class.
* fhandler.cc (fhandler_base::wait_overlapped): Make return tri-state
to detect when there is a EINTR situation. Add a pointer to a length
parameter. Move GetOverlappedResult into this function.
(fhandler_base::read_overlapped): Accommodate above changes and loop if
we receive a restartable signal.
(fhandler_base::write_overlapped): Ditto.
* fhandler.h (fhandler_base::wait_overlapped): Reflect above changes.
* fhandler_fifo.cc (fhandler_fifo::wait): Ditto.
2007-07-28 Corinna Vinschen <corinna@vinschen.de> 2007-07-28 Corinna Vinschen <corinna@vinschen.de>
* ntdll.h (RtlEqualUnicodePathPrefix): Rename from RtlEqualPathPrefix. * ntdll.h (RtlEqualUnicodePathPrefix): Rename from RtlEqualPathPrefix.

View File

@ -190,7 +190,8 @@ struct _cygtls
/* exception handling */ /* exception handling */
static int handle_exceptions (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void *); static int handle_exceptions (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void *);
static int handle_threadlist_exception (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *c, void *); static int handle_threadlist_exception (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void *);
bool inside_kernel (CONTEXT *);
void init_exception_handler (int (*) (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void*)); void init_exception_handler (int (*) (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void*));
void init_threadlist_exceptions (); void init_threadlist_exceptions ();
void signal_exit (int) __attribute__ ((noreturn, regparm(2))); void signal_exit (int) __attribute__ ((noreturn, regparm(2)));

View File

@ -282,13 +282,13 @@ stackdump (DWORD ebp, int open_file, bool isexception)
i == 16 ? " (more stack frames may be present)" : ""); i == 16 ? " (more stack frames may be present)" : "");
} }
static bool bool
inside_kernel (CONTEXT *cx) _cygtls::inside_kernel (CONTEXT *cx)
{ {
int res; int res;
MEMORY_BASIC_INFORMATION m; MEMORY_BASIC_INFORMATION m;
if (!_my_tls.isinitialized ()) if (!isinitialized ())
return true; return true;
memset (&m, 0, sizeof m); memset (&m, 0, sizeof m);
@ -627,7 +627,7 @@ _cygtls::handle_exceptions (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT
error_code |= 1; error_code |= 1;
if (e->ExceptionInformation[0]) /* Write access */ if (e->ExceptionInformation[0]) /* Write access */
error_code |= 2; error_code |= 2;
if (!inside_kernel (in)) /* User space */ if (!me.inside_kernel (in)) /* User space */
error_code |= 4; error_code |= 4;
klog (LOG_INFO, "%s[%d]: segfault at %08x rip %08x rsp %08x error %d", klog (LOG_INFO, "%s[%d]: segfault at %08x rip %08x rsp %08x error %d",
__progname, myself->pid, __progname, myself->pid,

View File

@ -1694,9 +1694,11 @@ fhandler_base::destroy_overlapped ()
} }
} }
bool int
fhandler_base::wait_overlapped (bool& res, bool writing) fhandler_base::wait_overlapped (bool& res, bool writing, DWORD *bytes)
{ {
if (bytes)
*bytes = (DWORD) -1;
if (!res && GetLastError () != ERROR_IO_PENDING) if (!res && GetLastError () != ERROR_IO_PENDING)
__seterrno (); __seterrno ();
else else
@ -1712,15 +1714,27 @@ fhandler_base::wait_overlapped (bool& res, bool writing)
w4[0] = get_overlapped ()->hEvent; w4[0] = get_overlapped ()->hEvent;
if (&_my_tls == _main_tls) if (&_my_tls == _main_tls)
w4[n++] = signal_arrived; w4[n++] = signal_arrived;
HANDLE h = writing ? get_output_handle () : get_handle ();
switch (WaitForMultipleObjects (n, w4, false, INFINITE)) switch (WaitForMultipleObjects (n, w4, false, INFINITE))
{ {
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
res = true; if (!bytes ||
GetOverlappedResult (h, get_overlapped (), bytes, false))
res = 1;
else
{
__seterrno ();
res = -1;
}
break; break;
case WAIT_OBJECT_0 + 1: case WAIT_OBJECT_0 + 1:
CancelIo (writing ? get_output_handle () : get_handle ()); CancelIo (h);
set_errno (EINTR); set_errno (EINTR);
res = false; res = 0;
break;
default:
__seterrno ();
res = -1;
break; break;
} }
} }
@ -1735,11 +1749,14 @@ fhandler_base::read_overlapped (void *ptr, size_t& len)
assert (get_overlapped ()); assert (get_overlapped ());
assert (get_overlapped ()->hEvent); assert (get_overlapped ()->hEvent);
#endif #endif
bool res = ReadFile (get_handle (), ptr, len, (DWORD *) &len, while (1)
get_overlapped ()); {
if (!wait_overlapped (res, false) bool res = ReadFile (get_handle (), ptr, len, (DWORD *) &len,
|| !GetOverlappedResult (get_handle (), get_overlapped (), (DWORD *) &len, false)) get_overlapped ());
len = 0; int wres = wait_overlapped (res, false, (DWORD *) &len);
if (wres || !_my_tls.call_signal_handler ())
break;
}
} }
int int
@ -1747,11 +1764,15 @@ fhandler_base::write_overlapped (const void *ptr, size_t len)
{ {
DWORD bytes_written; DWORD bytes_written;
bool res = WriteFile (get_output_handle (), ptr, len, &bytes_written, while (1)
get_overlapped ()); {
if (!wait_overlapped (res, true) bool res = WriteFile (get_output_handle (), ptr, len, &bytes_written,
|| !GetOverlappedResult (get_handle (), get_overlapped (), get_overlapped ());
&bytes_written, false)) int wres = wait_overlapped (res, true, &bytes_written);
return -1; if (wres < 0)
return -1;
if (wres || !_my_tls.call_signal_handler ())
break;
}
return bytes_written; return bytes_written;
} }

View File

@ -139,7 +139,7 @@ class fhandler_base
DWORD fs_flags; DWORD fs_flags;
HANDLE read_state; HANDLE read_state;
path_conv pc; path_conv pc;
bool wait_overlapped (bool&, bool) __attribute__ ((regparm (2))); int wait_overlapped (bool&, bool, DWORD *) __attribute__ ((regparm (3)));
bool setup_overlapped () __attribute__ ((regparm (1))); bool setup_overlapped () __attribute__ ((regparm (1)));
void destroy_overlapped () __attribute__ ((regparm (1))); void destroy_overlapped () __attribute__ ((regparm (1)));

View File

@ -139,7 +139,7 @@ fhandler_fifo::wait (bool iswrite)
bool res = ConnectNamedPipe (get_handle (), get_overlapped ()); bool res = ConnectNamedPipe (get_handle (), get_overlapped ());
if (res || GetLastError () == ERROR_PIPE_CONNECTED) if (res || GetLastError () == ERROR_PIPE_CONNECTED)
return true; return true;
return wait_overlapped (res, iswrite); return wait_overlapped (res, iswrite, NULL);
default: default:
break; break;
} }