diff options
author | Christopher Faylor <me@cgf.cx> | 2005-07-03 02:40:30 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2005-07-03 02:40:30 +0000 |
commit | 893ac8e03c21d246bbfc8d575a227d8c65cfae76 (patch) | |
tree | 4cee09d3d2a99f1eba1deeecb2c4e1b5710d1efc /winsup/cygwin/miscfuncs.cc | |
parent | 766bda71333f106a6ec5279477cd5bdf25672e14 (diff) | |
download | cygnal-893ac8e03c21d246bbfc8d575a227d8c65cfae76.tar.gz cygnal-893ac8e03c21d246bbfc8d575a227d8c65cfae76.tar.bz2 cygnal-893ac8e03c21d246bbfc8d575a227d8c65cfae76.zip |
Replace valid memory checks with new myfault class "exception handling", almost
everywhere. Leave some thread.cc stuff alone for now.
* cygtls.h: Kludge some definitions to avoid including a problematic windows
header.
(_cygtls::_myfault): New entry.
(_cygtls::_myfault_errno): Ditto.
(_cygtls::fault_guarded): New function.
(_cygtls::setup_fault): Ditto.
(_cygtls::return_from_fault): Ditto.
(_cygtls::clear_fault): Ditto.
(myfault): New class.
* exceptions.cc (handle_exceptions): Handle case of guarded fault in system
routine.
* gendef: Add another entry point for setjmp that the compiler doesn't know
about and won't complain about.
* gentls_offsets: Just include windows.h rather than kludging a HANDLE def.
* miscfuncs.cc (check_null_str): Delete.
(check_null_empty_str): Ditto.
(check_null_empty_str_errno): Ditto.
(check_null_str_errno): Ditto.
(__check_null_invalid_struct): Ditto.
(__check_null_invalid_struct_errno): Ditto.
(__check_invalid_read_ptr): Ditto.
(__check_invalid_read_ptr_errno): Ditto.
(dummytest): New function.
(check_iovec_for_read): Delete.
(chec_iovec): Rename from check_iovec_for_write. Take a read/write parameter.
* tlsoffsets.h: Regenerate.
* winsup.h: Remove check_* declarations.
(check_iovec_for_read): Delete declaration. Turn into a define instead.
(check_iovec_for_write): Ditto.
(check_iovec): New declaration.
* thread.h: Use ifdef guard name consistent with other header files.
Diffstat (limited to 'winsup/cygwin/miscfuncs.cc')
-rw-r--r-- | winsup/cygwin/miscfuncs.cc | 126 |
1 files changed, 16 insertions, 110 deletions
diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index 79ad5c312..531d2b1f2 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -19,6 +19,7 @@ details. */ #include <winbase.h> #include <winnls.h> #include "cygthread.h" +#include "cygtls.h" long tls_ix = -1; @@ -146,76 +147,6 @@ strcasestr (const char *searchee, const char *lookfor) } int __stdcall -check_null_str (const char *name) -{ - if (name && !IsBadStringPtr (name, CYG_MAX_PATH)) - return 0; - - return EFAULT; -} - -int __stdcall -check_null_empty_str (const char *name) -{ - if (name && !IsBadStringPtr (name, CYG_MAX_PATH)) - return !*name ? ENOENT : 0; - - return EFAULT; -} - -int __stdcall -check_null_empty_str_errno (const char *name) -{ - int __err; - if ((__err = check_null_empty_str (name))) - set_errno (__err); - return __err; -} - -int __stdcall -check_null_str_errno (const char *name) -{ - int __err; - if ((__err = check_null_str (name))) - set_errno (__err); - return __err; -} - -int __stdcall -__check_null_invalid_struct (void *s, unsigned sz) -{ - if (s && !IsBadWritePtr (s, sz)) - return 0; - - return EFAULT; -} - -int __stdcall -__check_null_invalid_struct_errno (void *s, unsigned sz) -{ - int err; - if ((err = __check_null_invalid_struct (s, sz))) - set_errno (err); - return err; -} - -int __stdcall -__check_invalid_read_ptr (const void *s, unsigned sz) -{ - if (s && !IsBadReadPtr (s, sz)) - return 0; - return EFAULT; -} - -int __stdcall -__check_invalid_read_ptr_errno (const void *s, unsigned sz) -{ - if (s && !IsBadReadPtr (s, sz)) - return 0; - return set_errno (EFAULT); -} - -int __stdcall check_invalid_virtual_addr (const void *s, unsigned sz) { MEMORY_BASIC_INFORMATION mbuf; @@ -228,43 +159,13 @@ check_invalid_virtual_addr (const void *s, unsigned sz) return 0; } -ssize_t -check_iovec_for_read (const struct iovec *iov, int iovcnt) +static char __attribute__ ((noinline)) +dummytest (volatile char *p) { - if (iovcnt <= 0 || iovcnt > IOV_MAX) - { - set_errno (EINVAL); - return -1; - } - - if (__check_invalid_read_ptr_errno (iov, iovcnt * sizeof (*iov))) - return -1; - - size_t tot = 0; - - while (iovcnt != 0) - { - if (iov->iov_len > SSIZE_MAX || (tot += iov->iov_len) > SSIZE_MAX) - { - set_errno (EINVAL); - return -1; - } - - if (iov->iov_len - && __check_null_invalid_struct_errno (iov->iov_base, iov->iov_len)) - return -1; - - iov += 1; - iovcnt -= 1; - } - - assert (tot <= SSIZE_MAX); - - return (ssize_t) tot; + return *p; } - ssize_t -check_iovec_for_write (const struct iovec *iov, int iovcnt) +check_iovec (const struct iovec *iov, int iovcnt, bool forwrite) { if (iovcnt <= 0 || iovcnt > IOV_MAX) { @@ -272,7 +173,8 @@ check_iovec_for_write (const struct iovec *iov, int iovcnt) return -1; } - if (__check_invalid_read_ptr_errno (iov, iovcnt * sizeof (*iov))) + myfault efault; + if (efault.faulted (EFAULT)) return -1; size_t tot = 0; @@ -285,12 +187,16 @@ check_iovec_for_write (const struct iovec *iov, int iovcnt) return -1; } - if (iov->iov_len - && __check_invalid_read_ptr_errno (iov->iov_base, iov->iov_len)) - return -1; + volatile char *p = ((char *) iov->iov_base) + iov->iov_len - 1; + if (!iov->iov_len) + /* nothing to do */; + else if (!forwrite) + *p = dummytest (p); + else + (void) dummytest (p); - iov += 1; - iovcnt -= 1; + iov++; + iovcnt--; } assert (tot <= SSIZE_MAX); |