* 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.
This commit is contained in:
		| @@ -1,3 +1,18 @@ | ||||
| 2011-12-03  Christopher Faylor  <me.cygwin2011@cgf.cx> | ||||
|  | ||||
| 	* 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  <vinschen@redhat.com> | ||||
|  | ||||
| 	* mmap.cc (mlock): Drop requesting SE_LOCK_MEMORY_PRIVILEGE.  Drop | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|   | ||||
| @@ -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) | ||||
|   int res = -1; | ||||
|   myfault efault; | ||||
|   if (!efault.faulted (EFAULT)) | ||||
|     { | ||||
|       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 | ||||
|     { | ||||
|       sigproc_printf ("signal %d, newact %p (handler %p), oa %p", sig, newact, newact->sa_handler, oa, oa.sa_handler); | ||||
|       if (sig == SIGKILL || sig == SIGSTOP) | ||||
|       sig_dispatch_pending (); | ||||
|       /* check that sig is in right range */ | ||||
|       if (sig < 0 || sig >= NSIG) | ||||
| 	set_errno (EINVAL); | ||||
|       else | ||||
| 	{ | ||||
| 	  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) | ||||
| 	{ | ||||
| 	  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 | ||||
|   | ||||
| @@ -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); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user