From 69864e48cb0ef1efd1ac29a80b34bbc9c604533b Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sat, 3 Dec 2011 23:55:21 +0000 Subject: [PATCH] * mmap.cc (mlock): Add standard syscall return value debugging output. (munlock): Ditto. (posix_madvise): Ditto. * signal.cc: Remove obsolete sigcatchers stuff throughout. (sigaction_worker): Add function name parameter and use it to show standard syscall return value debugging output. Also add fault protection. (sigaction): Accommodate extra argument to sigaction_worker. (siginterrupt): Ditto. * syscalls.cc (read): Remove obsolete sigcatchers stuff. (readv): Ditto. --- winsup/cygwin/ChangeLog | 15 +++++ winsup/cygwin/mmap.cc | 30 ++++++---- winsup/cygwin/signal.cc | 122 +++++++++++++++++--------------------- winsup/cygwin/syscalls.cc | 12 ++-- 4 files changed, 92 insertions(+), 87 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index fe4bb2e74..fc37e0d12 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,18 @@ +2011-12-03 Christopher Faylor + + * mmap.cc (mlock): Add standard syscall return value debugging output. + (munlock): Ditto. + (posix_madvise): Ditto. + + * signal.cc: Remove obsolete sigcatchers stuff throughout. + (sigaction_worker): Add function name parameter and use it to show + standard syscall return value debugging output. Also add fault + protection. + (sigaction): Accommodate extra argument to sigaction_worker. + (siginterrupt): Ditto. + * syscalls.cc (read): Remove obsolete sigcatchers stuff. + (readv): Ditto. + 2011-12-03 Corinna Vinschen * mmap.cc (mlock): Drop requesting SE_LOCK_MEMORY_PRIVILEGE. Drop diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc index 97f0dad6f..2bd72610f 100644 --- a/winsup/cygwin/mmap.cc +++ b/winsup/cygwin/mmap.cc @@ -1394,6 +1394,7 @@ mlock (const void *addr, size_t len) } while (status == STATUS_WORKING_SET_QUOTA); + syscall_printf ("%R = mlock(%p, %u)", ret, addr, len); return ret; } @@ -1413,28 +1414,37 @@ munlock (const void *addr, size_t len) else ret = 0; + syscall_printf ("%R = munlock(%p, %u)", ret, addr, len); return ret; } extern "C" int posix_madvise (void *addr, size_t len, int advice) { + int ret; /* Check parameters. */ if (advice < POSIX_MADV_NORMAL || advice > POSIX_MADV_DONTNEED || !len) - return EINVAL; - - /* Check requested memory area. */ - MEMORY_BASIC_INFORMATION m; - char *p = (char *) addr; - char *endp = p + len; - while (p < endp) + ret = EINVAL; + else { - if (!VirtualQuery (p, &m, sizeof m) || m.State == MEM_FREE) - return ENOMEM; - p = (char *) m.BaseAddress + m.RegionSize; + /* Check requested memory area. */ + MEMORY_BASIC_INFORMATION m; + char *p = (char *) addr; + char *endp = p + len; + while (p < endp) + { + if (!VirtualQuery (p, &m, sizeof m) || m.State == MEM_FREE) + { + ret = ENOMEM; + break; + } + p = (char *) m.BaseAddress + m.RegionSize; + } + ret = 0; } + syscall_printf ("%d = posix_madvise(%p, %u, %d)", ret, addr, len, advice); /* Eventually do nothing. */ return 0; } diff --git a/winsup/cygwin/signal.cc b/winsup/cygwin/signal.cc index 8a475c118..272fb366e 100644 --- a/winsup/cygwin/signal.cc +++ b/winsup/cygwin/signal.cc @@ -23,32 +23,13 @@ details. */ #include "dtable.h" #include "cygheap.h" -int sigcatchers; /* FIXME: Not thread safe. */ - #define _SA_NORESTART 0x8000 -static int sigaction_worker (int, const struct sigaction *, struct sigaction *, bool) +static int sigaction_worker (int, const struct sigaction *, struct sigaction *, bool, const char *) __attribute__ ((regparm (3))); #define sigtrapped(func) ((func) != SIG_IGN && (func) != SIG_DFL) -static inline void -set_sigcatchers (void (*oldsig) (int), void (*cursig) (int)) -{ -#ifdef DEBUGGING - int last_sigcatchers = sigcatchers; -#endif - if (!sigtrapped (oldsig) && sigtrapped (cursig)) - sigcatchers++; - else if (sigtrapped (oldsig) && !sigtrapped (cursig)) - sigcatchers--; -#ifdef DEBUGGING - if (last_sigcatchers != sigcatchers) - sigproc_printf ("last %d, old %d, cur %p, cur %p", last_sigcatchers, - sigcatchers, oldsig, cursig); -#endif -} - extern "C" _sig_func_ptr signal (int sig, _sig_func_ptr func) { @@ -74,8 +55,6 @@ signal (int sig, _sig_func_ptr func) gs.sa_handler = func; gs.sa_flags &= ~SA_SIGINFO; - set_sigcatchers (prev, func); - syscall_printf ("%p = signal (%d, %p)", prev, sig, func); return prev; } @@ -407,63 +386,68 @@ abort (void) } static int -sigaction_worker (int sig, const struct sigaction *newact, struct sigaction *oldact, bool isinternal) +sigaction_worker (int sig, const struct sigaction *newact, + struct sigaction *oldact, bool isinternal, const char *fnname) { - sig_dispatch_pending (); - /* check that sig is in right range */ - if (sig < 0 || sig >= NSIG) - { - set_errno (EINVAL); - sigproc_printf ("signal %d, newact %p, oldact %p", sig, newact, oldact); - syscall_printf ("SIG_ERR = sigaction signal %d out of range", sig); - return -1; - } - - struct sigaction oa = global_sigs[sig]; - - if (!newact) - sigproc_printf ("signal %d, newact %p, oa %p", sig, newact, oa, oa.sa_handler); - else + int res = -1; + myfault efault; + if (!efault.faulted (EFAULT)) { - sigproc_printf ("signal %d, newact %p (handler %p), oa %p", sig, newact, newact->sa_handler, oa, oa.sa_handler); - if (sig == SIGKILL || sig == SIGSTOP) - { - set_errno (EINVAL); - return -1; - } - struct sigaction na = *newact; - struct sigaction& gs = global_sigs[sig]; - if (!isinternal) - na.sa_flags &= ~_SA_INTERNAL_MASK; - gs = na; - if (!(gs.sa_flags & SA_NODEFER)) - gs.sa_mask |= SIGTOMASK(sig); - if (gs.sa_handler == SIG_IGN) - sig_clear (sig); - if (gs.sa_handler == SIG_DFL && sig == SIGCHLD) - sig_clear (sig); - set_sigcatchers (oa.sa_handler, gs.sa_handler); - if (sig == SIGCHLD) + sig_dispatch_pending (); + /* check that sig is in right range */ + if (sig < 0 || sig >= NSIG) + set_errno (EINVAL); + else { - myself->process_state &= ~PID_NOCLDSTOP; - if (gs.sa_flags & SA_NOCLDSTOP) - myself->process_state |= PID_NOCLDSTOP; + struct sigaction oa = global_sigs[sig]; + + if (!newact) + sigproc_printf ("signal %d, newact %p, oa %p", sig, newact, oa, oa.sa_handler); + else + { + sigproc_printf ("signal %d, newact %p (handler %p), oa %p", sig, newact, newact->sa_handler, oa, oa.sa_handler); + if (sig == SIGKILL || sig == SIGSTOP) + { + set_errno (EINVAL); + goto out; + } + struct sigaction na = *newact; + struct sigaction& gs = global_sigs[sig]; + if (!isinternal) + na.sa_flags &= ~_SA_INTERNAL_MASK; + gs = na; + if (!(gs.sa_flags & SA_NODEFER)) + gs.sa_mask |= SIGTOMASK(sig); + if (gs.sa_handler == SIG_IGN) + sig_clear (sig); + if (gs.sa_handler == SIG_DFL && sig == SIGCHLD) + sig_clear (sig); + if (sig == SIGCHLD) + { + myself->process_state &= ~PID_NOCLDSTOP; + if (gs.sa_flags & SA_NOCLDSTOP) + myself->process_state |= PID_NOCLDSTOP; + } + } + + if (oldact) + { + *oldact = oa; + oa.sa_flags &= ~_SA_INTERNAL_MASK; + } + res = 0; } } - if (oldact) - { - *oldact = oa; - oa.sa_flags &= ~_SA_INTERNAL_MASK; - } - - return 0; +out: + syscall_printf ("%R = %s(%d, %p, %p)", res, fnname, sig, newact, oldact); + return res; } extern "C" int sigaction (int sig, const struct sigaction *newact, struct sigaction *oldact) { - return sigaction_worker (sig, newact, oldact, false); + return sigaction_worker (sig, newact, oldact, false, "sigaction"); } extern "C" int @@ -560,7 +544,7 @@ siginterrupt (int sig, int flag) act.sa_flags &= ~_SA_NORESTART; act.sa_flags |= SA_RESTART; } - return sigaction_worker (sig, &act, NULL, true); + return sigaction_worker (sig, &act, NULL, true, "siginterrupt"); } extern "C" int diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 3a0681d92..6ac4b1c97 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1066,10 +1066,8 @@ read (int fd, void *ptr, size_t len) } /* Could block, so let user know we at least got here. */ - extern int sigcatchers; - syscall_printf ("read (%d, %p, %d) %sblocking, sigcatchers %d", - fd, ptr, len, cfd->is_nonblocking () ? "non" : "", - sigcatchers); + syscall_printf ("read (%d, %p, %d) %sblocking", + fd, ptr, len, cfd->is_nonblocking () ? "non" : ""); cfd->read (ptr, res = len); @@ -1110,10 +1108,8 @@ readv (int fd, const struct iovec *const iov, const int iovcnt) } /* Could block, so let user know we at least got here. */ - extern int sigcatchers; - syscall_printf ("readv (%d, %p, %d) %sblocking, sigcatchers %d", - fd, iov, iovcnt, cfd->is_nonblocking () ? "non" : "", - sigcatchers); + syscall_printf ("readv (%d, %p, %d) %sblocking", + fd, iov, iovcnt, cfd->is_nonblocking () ? "non" : ""); res = cfd->readv (iov, iovcnt, tot); -- 2.43.5