diff options
author | Christopher Faylor <me@cgf.cx> | 2011-12-17 00:03:31 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2011-12-17 00:03:31 +0000 |
commit | ca35d41cec77e095bf08cc48109210295b28cc08 (patch) | |
tree | 81c690e5f58612aaa763757d22ada427ff511900 /winsup/cygwin/syscalls.cc | |
parent | 6eee66418c285caaf32187332f9e9fb0d7c008ab (diff) | |
download | cygnal-ca35d41cec77e095bf08cc48109210295b28cc08.tar.gz cygnal-ca35d41cec77e095bf08cc48109210295b28cc08.tar.bz2 cygnal-ca35d41cec77e095bf08cc48109210295b28cc08.zip |
Implement fhandler reference counting.
* cygheap.h
(cygheap_fdmanip::release): Make virtual.
(cygheap_fdnew::~cygheap_fdnew): New destructor increments reference count when
fd has been allocated.
(cygheap_fdget::fh): New (old?) field.
(cygheap_fdget::cygheap_fdget): Increment reference count when we've found an
active fd. Set fh appropriately.
(cygheap_fdget::~cygheap_fdget): Decrement reference count when appropriate.
Delete fh if reference count goes to zero.
(cygheap_fdget::release): New function. Do more bookkeping on release.
* dtable.cc (dtable::release): Change from void to boolean return. Only delete
the fhandler when its reference count is <= 0 (this should be a fairly unusual
case). Return true if fhandler has been deleted.
(cygwin_attach_handle_to_fd): Increment reference count when fh is assigned.
(dtable::init_std_file_from_handle): Ditto.
* dtable.h (dtable::release): Change return to boolean.
* fhandler.cc (fhandler_base::fhandler_base): Set new isclosed flag to false.
Set _refcnt to zero.
(fhandler_base::close): Simplify paranoid debugging output. Set new isclosed()
flag.
(fhandler_base_overlapped::wait_overlapped): Use isclosed() flag to avoid
querying the exception handle.
* fhandler.h (fhandler_base::_refcnt): New field.
(fhandler_base::refcnt): New function.
(fhandler_base::isclosed): Implement.
(fhandler_base::fhandler_base): Set isclosed to false.
* syscalls.cc: Remove space after function before parentheses for several
strace printfs.
(dup): Add standard strace "leaver" code.
(dup2): Ditto.
(dup3): Ditto.
(remove): Ditto.
(getpid): Ditto.
(getppid): Ditto.
(lseek64): Fix strace debugging to correctly use %R.
* fhandler_termios.cc (fhandler_termios::tcsetpgrp): Avoid sending signals to
other processes if we're debugging since it can cause a deadlock with the
calling debugger.
* exceptions.cc (_cygtls::call_signal_handler): Add debugging-only strace
output.
Diffstat (limited to 'winsup/cygwin/syscalls.cc')
-rw-r--r-- | winsup/cygwin/syscalls.cc | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 6ac4b1c97..f77c451bf 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -120,51 +120,51 @@ close_all_files (bool norelease) extern "C" int dup (int fd) { - return cygheap->fdtab.dup3 (fd, cygheap_fdnew (), 0); + int res = cygheap->fdtab.dup3 (fd, cygheap_fdnew (), 0); + syscall_printf ("%R = dup(%d)", res, fd); + return res; } extern "C" int dup2 (int oldfd, int newfd) { + int res; if (newfd >= OPEN_MAX_MAX) { - syscall_printf ("-1 = dup2 (%d, %d) (%d too large)", oldfd, newfd, newfd); set_errno (EBADF); - return -1; + res = -1; } - if (newfd == oldfd) + else if (newfd == oldfd) { cygheap_fdget cfd (oldfd); - if (cfd < 0) - { - syscall_printf ("%R = dup2(%d,%d) (oldfd not open)", -1, oldfd, newfd); - return -1; - } - syscall_printf ("%R = dup2(%d, %d) (newfd==oldfd)", oldfd, oldfd, newfd); - return oldfd; + res = (cfd >= 0) ? oldfd : -1; } - return cygheap->fdtab.dup3 (oldfd, newfd, 0); + else + res = cygheap->fdtab.dup3 (oldfd, newfd, 0); + + syscall_printf ("%R = dup2(%d, %d)", res, oldfd, newfd); + return res; } extern "C" int dup3 (int oldfd, int newfd, int flags) { + int res; if (newfd >= OPEN_MAX_MAX) { - syscall_printf ("-1 = dup3 (%d, %d, %p) (%d too large)", - oldfd, newfd, flags, newfd); set_errno (EBADF); - return -1; + res = -1; } - if (newfd == oldfd) + else if (newfd == oldfd) { cygheap_fdget cfd (oldfd, false, false); set_errno (cfd < 0 ? EBADF : EINVAL); - syscall_printf ("-1 = dup3 (%d, %d, %p) (newfd==oldfd)", - oldfd, newfd, flags); - return -1; + res = -1; } - return cygheap->fdtab.dup3 (oldfd, newfd, flags); + else + res = cygheap->fdtab.dup3 (oldfd, newfd, flags); + syscall_printf ("%R = dup2(%d, %d, %p)", res, oldfd, newfd, flags); + return res; } static inline void @@ -965,12 +965,15 @@ remove (const char *ourname) return -1; } - return win32_name.isdir () ? rmdir (ourname) : unlink (ourname); + int res = win32_name.isdir () ? rmdir (ourname) : unlink (ourname); + syscall_printf ("%R = remove(%s)", res, ourname); + return res; } extern "C" pid_t getpid () { + syscall_printf ("%d = getpid()", myself->pid); return myself->pid; } @@ -984,6 +987,7 @@ _getpid_r (struct _reent *) extern "C" pid_t getppid () { + syscall_printf ("%d = getppid()", myself->ppid); return myself->ppid; } @@ -1041,6 +1045,7 @@ getsid (pid_t pid) res = -1; } } + syscall_printf ("%R = getsid(%d)", pid); return res; } @@ -1066,7 +1071,7 @@ read (int fd, void *ptr, size_t len) } /* Could block, so let user know we at least got here. */ - syscall_printf ("read (%d, %p, %d) %sblocking", + syscall_printf ("read(%d, %p, %d) %sblocking", fd, ptr, len, cfd->is_nonblocking () ? "non" : ""); cfd->read (ptr, res = len); @@ -1108,7 +1113,7 @@ readv (int fd, const struct iovec *const iov, const int iovcnt) } /* Could block, so let user know we at least got here. */ - syscall_printf ("readv (%d, %p, %d) %sblocking", + syscall_printf ("readv(%d, %p, %d) %sblocking", fd, iov, iovcnt, cfd->is_nonblocking () ? "non" : ""); res = cfd->readv (iov, iovcnt, tot); @@ -1158,9 +1163,9 @@ write (int fd, const void *ptr, size_t len) /* Could block, so let user know we at least got here. */ if (fd == 1 || fd == 2) - paranoid_printf ("write (%d, %p, %d)", fd, ptr, len); + paranoid_printf ("write(%d, %p, %d)", fd, ptr, len); else - syscall_printf ("write (%d, %p, %d)", fd, ptr, len); + syscall_printf ("write(%d, %p, %d)", fd, ptr, len); res = cfd->write (ptr, len); @@ -1206,9 +1211,9 @@ writev (const int fd, const struct iovec *const iov, const int iovcnt) /* Could block, so let user know we at least got here. */ if (fd == 1 || fd == 2) - paranoid_printf ("writev (%d, %p, %d)", fd, iov, iovcnt); + paranoid_printf ("writev(%d, %p, %d)", fd, iov, iovcnt); else - syscall_printf ("writev (%d, %p, %d)", fd, iov, iovcnt); + syscall_printf ("writev(%d, %p, %d)", fd, iov, iovcnt); res = cfd->writev (iov, iovcnt, tot); @@ -1248,7 +1253,7 @@ open (const char *unix_path, int flags, ...) va_list ap; mode_t mode = 0; - syscall_printf ("open (%s, %p)", unix_path, flags); + syscall_printf ("open(%s, %p)", unix_path, flags); pthread_testcancel (); myfault efault; if (efault.faulted (EFAULT)) @@ -1341,7 +1346,7 @@ lseek64 (int fd, _off64_t pos, int dir) else res = -1; } - syscall_printf ("%D = lseek (%d, %D, %d)", res, fd, pos, dir); + syscall_printf ("%R = lseek(%d, %D, %d)", res, fd, pos, dir); return res; } @@ -1361,7 +1366,7 @@ close (int fd) { int res; - syscall_printf ("close (%d)", fd); + syscall_printf ("close(%d)", fd); pthread_testcancel (); |