From 9a9177720555953b8761b8f22ef7f5566db0955f Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Thu, 9 Jun 2005 22:33:57 +0000 Subject: [PATCH] * cygtls.h (_local_storage::setmode_file): New element. (_local_storage::setmode_mode): New element. * tlsoffsets.h: Regenerate. * cygwin.din (setmode): Define as cygwin_getmode. * syscalls.cc (setmode_helper): Use setmode_* variables from tls rather than using unthreadsafe static. (setmode): Break out fwalk stuff. (cygwin_setmode): New function. Put fwalk stdio stuff here. --- winsup/cygwin/ChangeLog | 11 ++++ winsup/cygwin/cygtls.h | 4 ++ winsup/cygwin/cygwin.din | 4 +- winsup/cygwin/syscalls.cc | 34 ++++++----- winsup/cygwin/thread.cc | 3 +- winsup/cygwin/tlsoffsets.h | 114 ++++++++++++++++++------------------- 6 files changed, 95 insertions(+), 75 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 1731086bb..f6c06b925 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +2005-06-09 Christopher Faylor + + * cygtls.h (_local_storage::setmode_file): New element. + (_local_storage::setmode_mode): New element. + * tlsoffsets.h: Regenerate. + * cygwin.din (setmode): Define as cygwin_getmode. + * syscalls.cc (setmode_helper): Use setmode_* variables from tls rather + than using unthreadsafe static. + (setmode): Break out fwalk stuff. + (cygwin_setmode): New function. Put fwalk stdio stuff here. + 2005-06-09 Christopher Faylor * thread.cc (pthread_mutex::_lock): Use cancelable_wait rather than diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index 257c8acf9..7ee1ddcc1 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -95,6 +95,10 @@ struct _local_storage /* cygthread.cc */ char unknown_thread_name[30]; + + /* syscalls.cc */ + int setmode_file; + int setmode_mode; }; typedef struct struct_waitq diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 30b6d2343..38786e392 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -1202,8 +1202,8 @@ _setlocale = setlocale NOSIGFE setlogmask NOSIGFE setmntent SIGFE _setmntent = setmntent SIGFE -setmode SIGFE -_setmode = setmode SIGFE +setmode = cygwin_setmode SIGFE +_setmode = cygwin_setmode SIGFE setpassent NOSIGFE _setpassent = setpassent NOSIGFE setpgid SIGFE diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index e655d3684..fa92b1b46 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1565,20 +1565,17 @@ _cygwin_istext_for_stdio (int fd) /* internal newlib function */ extern "C" int _fwalk (struct _reent *ptr, int (*function) (FILE *)); -static int setmode_mode; -static int setmode_file; - static int setmode_helper (FILE *f) { - if (fileno (f) != setmode_file) + if (fileno (f) != _my_tls.locals.setmode_file) { - syscall_printf ("improbable, but %d != %d", fileno (f), setmode_file); + syscall_printf ("improbable, but %d != %d", fileno (f), _my_tls.locals.setmode_file); return 0; } syscall_printf ("file was %s now %s", f->_flags & __SCLE ? "text" : "binary", - setmode_mode & O_TEXT ? "text" : "binary"); - if (setmode_mode & O_TEXT) + _my_tls.locals.setmode_mode & O_TEXT ? "text" : "binary"); + if (_my_tls.locals.setmode_mode & O_TEXT) f->_flags |= __SCLE; else f->_flags &= ~__SCLE; @@ -1628,18 +1625,27 @@ setmode (int fd, int mode) else cfd->set_flags ((cfd->get_flags () & ~(O_TEXT | O_BINARY)) | mode); - if (_cygwin_istext_for_stdio (fd)) - setmode_mode = O_TEXT; - else - setmode_mode = O_BINARY; - setmode_file = fd; - _fwalk (_GLOBAL_REENT, setmode_helper); - syscall_printf ("(%d<%s>, %p) returning %s", fd, cfd->get_name (), mode, res & O_TEXT ? "text" : "binary"); return res; } +extern "C" int +cygwin_setmode (int fd, int mode) +{ + int res = setmode (fd, mode); + if (res != -1) + { + _my_tls.locals.setmode_file = fd; + if (_cygwin_istext_for_stdio (fd)) + _my_tls.locals.setmode_mode = O_TEXT; + else + _my_tls.locals.setmode_mode = O_BINARY; + _fwalk (_GLOBAL_REENT, setmode_helper); + } + return res; +} + extern "C" int ftruncate64 (int fd, _off64_t length) { diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index f1714d2bb..f25878480 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -1756,8 +1756,7 @@ int semaphore::_trywait () { /* FIXME: signals should be able to interrupt semaphores... - *We probably need WaitForMultipleObjects here. - */ + We probably need WaitForMultipleObjects here. */ if (WaitForSingleObject (win32_obj_id, 0) == WAIT_TIMEOUT) { set_errno (EAGAIN); diff --git a/winsup/cygwin/tlsoffsets.h b/winsup/cygwin/tlsoffsets.h index 402ca0793..bda6bd173 100644 --- a/winsup/cygwin/tlsoffsets.h +++ b/winsup/cygwin/tlsoffsets.h @@ -1,117 +1,117 @@ //;# autogenerated: Do not edit. -//; $tls::sizeof__cygtls = 3964; -//; $tls::func = -3964; +//; $tls::sizeof__cygtls = 3972; +//; $tls::func = -3972; //; $tls::pfunc = 0; -//; $tls::saved_errno = -3960; +//; $tls::saved_errno = -3968; //; $tls::psaved_errno = 4; -//; $tls::sa_flags = -3956; +//; $tls::sa_flags = -3964; //; $tls::psa_flags = 8; -//; $tls::oldmask = -3952; +//; $tls::oldmask = -3960; //; $tls::poldmask = 12; -//; $tls::deltamask = -3948; +//; $tls::deltamask = -3956; //; $tls::pdeltamask = 16; -//; $tls::event = -3944; +//; $tls::event = -3952; //; $tls::pevent = 20; -//; $tls::errno_addr = -3940; +//; $tls::errno_addr = -3948; //; $tls::perrno_addr = 24; -//; $tls::initialized = -3936; +//; $tls::initialized = -3944; //; $tls::pinitialized = 28; -//; $tls::sigmask = -3932; +//; $tls::sigmask = -3940; //; $tls::psigmask = 32; -//; $tls::sigwait_mask = -3928; +//; $tls::sigwait_mask = -3936; //; $tls::psigwait_mask = 36; -//; $tls::sigwait_info = -3924; +//; $tls::sigwait_info = -3932; //; $tls::psigwait_info = 40; -//; $tls::threadkill = -3920; +//; $tls::threadkill = -3928; //; $tls::pthreadkill = 44; -//; $tls::infodata = -3916; +//; $tls::infodata = -3924; //; $tls::pinfodata = 48; -//; $tls::tid = -3768; +//; $tls::tid = -3776; //; $tls::ptid = 196; -//; $tls::local_clib = -3764; +//; $tls::local_clib = -3772; //; $tls::plocal_clib = 200; -//; $tls::__dontuse = -3764; +//; $tls::__dontuse = -3772; //; $tls::p__dontuse = 200; -//; $tls::locals = -2700; +//; $tls::locals = -2708; //; $tls::plocals = 1264; //; $tls::_ctinfo = -1084; -//; $tls::p_ctinfo = 2880; +//; $tls::p_ctinfo = 2888; //; $tls::wq = -1080; -//; $tls::pwq = 2884; +//; $tls::pwq = 2892; //; $tls::prev = -1052; -//; $tls::pprev = 2912; +//; $tls::pprev = 2920; //; $tls::next = -1048; -//; $tls::pnext = 2916; +//; $tls::pnext = 2924; //; $tls::stackptr = -1044; -//; $tls::pstackptr = 2920; +//; $tls::pstackptr = 2928; //; $tls::sig = -1040; -//; $tls::psig = 2924; +//; $tls::psig = 2932; //; $tls::incyg = -1036; -//; $tls::pincyg = 2928; +//; $tls::pincyg = 2936; //; $tls::spinning = -1032; -//; $tls::pspinning = 2932; +//; $tls::pspinning = 2940; //; $tls::stacklock = -1028; -//; $tls::pstacklock = 2936; +//; $tls::pstacklock = 2944; //; $tls::stack = -1024; -//; $tls::pstack = 2940; +//; $tls::pstack = 2948; //; $tls::padding = 0; -//; $tls::ppadding = 3964; +//; $tls::ppadding = 3972; //; __DATA__ -#define tls_func (-3964) +#define tls_func (-3972) #define tls_pfunc (0) -#define tls_saved_errno (-3960) +#define tls_saved_errno (-3968) #define tls_psaved_errno (4) -#define tls_sa_flags (-3956) +#define tls_sa_flags (-3964) #define tls_psa_flags (8) -#define tls_oldmask (-3952) +#define tls_oldmask (-3960) #define tls_poldmask (12) -#define tls_deltamask (-3948) +#define tls_deltamask (-3956) #define tls_pdeltamask (16) -#define tls_event (-3944) +#define tls_event (-3952) #define tls_pevent (20) -#define tls_errno_addr (-3940) +#define tls_errno_addr (-3948) #define tls_perrno_addr (24) -#define tls_initialized (-3936) +#define tls_initialized (-3944) #define tls_pinitialized (28) -#define tls_sigmask (-3932) +#define tls_sigmask (-3940) #define tls_psigmask (32) -#define tls_sigwait_mask (-3928) +#define tls_sigwait_mask (-3936) #define tls_psigwait_mask (36) -#define tls_sigwait_info (-3924) +#define tls_sigwait_info (-3932) #define tls_psigwait_info (40) -#define tls_threadkill (-3920) +#define tls_threadkill (-3928) #define tls_pthreadkill (44) -#define tls_infodata (-3916) +#define tls_infodata (-3924) #define tls_pinfodata (48) -#define tls_tid (-3768) +#define tls_tid (-3776) #define tls_ptid (196) -#define tls_local_clib (-3764) +#define tls_local_clib (-3772) #define tls_plocal_clib (200) -#define tls___dontuse (-3764) +#define tls___dontuse (-3772) #define tls_p__dontuse (200) -#define tls_locals (-2700) +#define tls_locals (-2708) #define tls_plocals (1264) #define tls__ctinfo (-1084) -#define tls_p_ctinfo (2880) +#define tls_p_ctinfo (2888) #define tls_wq (-1080) -#define tls_pwq (2884) +#define tls_pwq (2892) #define tls_prev (-1052) -#define tls_pprev (2912) +#define tls_pprev (2920) #define tls_next (-1048) -#define tls_pnext (2916) +#define tls_pnext (2924) #define tls_stackptr (-1044) -#define tls_pstackptr (2920) +#define tls_pstackptr (2928) #define tls_sig (-1040) -#define tls_psig (2924) +#define tls_psig (2932) #define tls_incyg (-1036) -#define tls_pincyg (2928) +#define tls_pincyg (2936) #define tls_spinning (-1032) -#define tls_pspinning (2932) +#define tls_pspinning (2940) #define tls_stacklock (-1028) -#define tls_pstacklock (2936) +#define tls_pstacklock (2944) #define tls_stack (-1024) -#define tls_pstack (2940) +#define tls_pstack (2948) #define tls_padding (0) -#define tls_ppadding (3964) +#define tls_ppadding (3972)