1. 17 8月, 2020 1 次提交
  2. 25 2月, 2018 1 次提交
    • R
      avoid use of readv syscall in __stdio_read backend when not needed · e7eeeb9f
      Rich Felker 提交于
      formally, calling readv with a zero-length first iov component should
      behave identically to calling read on just the second component, but
      presence of a zero-length iov component has triggered bugs in some
      kernels and performs significantly worse than a simple read on some
      file types.
      e7eeeb9f
  3. 24 2月, 2018 2 次提交
    • R
      consistently return number of bytes read from stdio read backend · f9280418
      Rich Felker 提交于
      the stdio FILE read backend's return type is size_t, not ssize_t, and
      all of the special (non-fd-backed) FILE types already return the
      number of bytes read (zero) on error or eof. only __stdio_read leaked
      a syscall error return into its return value.
      
      fread had a workaround for this behavior going all the way back to the
      original check-in. remove the workaround since it's no longer needed.
      f9280418
    • R
      remove obfuscated flags bit-twiddling logic in __stdio_read · 9bf9c732
      Rich Felker 提交于
      replace with simple conditional that doesn't rely on assumption that
      cnt is either 0 or -1.
      9bf9c732
  4. 14 6月, 2015 1 次提交
    • R
      remove cancellation points in stdio · 4ef9b828
      Rich Felker 提交于
      commit 58165923 added these optional
      cancellation points on the basis that cancellable stdio could be
      useful, to unblock threads stuck on stdio operations that will never
      complete. however, the only way to ensure that cancellation can
      achieve this is to violate the rules for side effects when
      cancellation is acted upon, discarding knowledge of any partial data
      transfer already completed. our implementation exhibited this behavior
      and was thus non-conforming.
      
      in addition to improving correctness, removing these cancellation
      points moderately reduces code size, and should significantly improve
      performance on i386, where sysenter/syscall instructions can be used
      instead of "int $128" for non-cancellable syscalls.
      4ef9b828
  5. 29 5月, 2015 1 次提交
    • R
      fix failure of ungetc and ungetwc to work on files in eof status · 2b4fcfda
      Rich Felker 提交于
      these functions were written to handle clearing eof status, but failed
      to account for the __toread function's handling of eof. with this
      patch applied, __toread still returns EOF when the file is in eof
      status, so that read operations will fail, but it also sets up valid
      buffer pointers for read mode, which are set to the end of the buffer
      rather than the beginning in order to make the whole buffer available
      to ungetc/ungetwc.
      
      minor changes to __uflow were needed since it's now possible to have
      non-zero buffer pointers while in eof status. as made, these changes
      remove a 'fast path' bypassing the function call to __toread, which
      could be reintroduced with slightly different logic, but since
      ordinary files have a syscall in f->read, optimizing the code path
      does not seem worthwhile.
      
      the __stdio_read function is also updated not to zero the read buffer
      pointers on eof/error. while not necessary for correctness, this
      change avoids the overhead of calling __toread in ungetc after
      reaching eof, and it also reduces code size and increases consistency
      with the fmemopen read operation which does not zero the pointers.
      2b4fcfda
  6. 25 3月, 2014 1 次提交
    • R
      always initialize thread pointer at program start · dab441ae
      Rich Felker 提交于
      this is the first step in an overhaul aimed at greatly simplifying and
      optimizing everything dealing with thread-local state.
      
      previously, the thread pointer was initialized lazily on first access,
      or at program startup if stack protector was in use, or at certain
      random places where inconsistent state could be reached if it were not
      initialized early. while believed to be fully correct, the logic was
      fragile and non-obvious.
      
      in the first phase of the thread pointer overhaul, support is retained
      (and in some cases improved) for systems/situation where loading the
      thread pointer fails, e.g. old kernels.
      
      some notes on specific changes:
      
      - the confusing use of libc.main_thread as an indicator that the
        thread pointer is initialized is eliminated in favor of an explicit
        has_thread_pointer predicate.
      
      - sigaction no longer needs to ensure that the thread pointer is
        initialized before installing a signal handler (this was needed to
        prevent a situation where the signal handler caused the thread
        pointer to be initialized and the subsequent sigreturn cleared it
        again) but it still needs to ensure that implementation-internal
        thread-related signals are not blocked.
      
      - pthread tsd initialization for the main thread is deferred in a new
        manner to minimize bloat in the static-linked __init_tp code.
      
      - pthread_setcancelstate no longer needs special handling for the
        situation before the thread pointer is initialized. it simply fails
        on systems that cannot support a thread pointer, which are
        non-conforming anyway.
      
      - pthread_cleanup_push/pop now check for missing thread pointer and
        nop themselves out in this case, so stdio no longer needs to avoid
        the cancellable path when the thread pointer is not available.
      
      a number of cases remain where certain interfaces may crash if the
      system does not support a thread pointer. at this point, these should
      be limited to pthread interfaces, and the number of such cases should
      be fewer than before.
      dab441ae
  7. 09 11月, 2012 1 次提交
    • R
      clean up stdio_impl.h · 835f9f95
      Rich Felker 提交于
      this header evolved to facilitate the extremely lazy practice of
      omitting explicit includes of the necessary headers in individual
      stdio source files; not only was this sloppy, but it also increased
      build time.
      
      now, stdio_impl.h is only including the headers it needs for its own
      use; any further headers needed by source files are included directly
      where needed.
      835f9f95
  8. 26 5月, 2012 1 次提交
    • R
      avoid using pthread cleanup push/pop in stdio when not needed · 3f25354e
      Rich Felker 提交于
      unfortunately in dynamic-linked programs, these macros cause
      pthread_self to be initialized, which costs a couple syscalls, and
      (much worse) would necessarily fail, crash, and burn on ancient (2.4
      and earlier) kernels where setting up a thread pointer does not work.
      
      i'd like to do this in a more generic way that avoids all use of
      cleanup push/pop before pthread_self has been successfully called and
      avoids ugly if/else constructs like the one in this commit, but for
      now, this will suffice.
      3f25354e
  9. 02 2月, 2012 1 次提交
    • R
      make stdio open, read, and write operations cancellation points · 58165923
      Rich Felker 提交于
      it should be noted that only the actual underlying buffer flush and
      fill operations are cancellable, not reads from or writes to the
      buffer. this behavior is compatible with POSIX, which makes all
      cancellation points in stdio optional, and it achieves the goal of
      allowing cancellation of a thread that's "stuck" on IO (due to a
      non-responsive socket/pipe peer, slow/stuck hardware, etc.) without
      imposing any measurable performance cost.
      58165923
  10. 09 4月, 2011 1 次提交
    • R
      work around a nasty bug in linux readv syscall · 2cff36a8
      Rich Felker 提交于
      according to posix, readv "shall be equivalent to read(), except..."
      that it places the data into the buffers specified by the iov array.
      however on linux, when reading from a terminal, each iov element
      behaves almost like a separate read. this means that if the first iov
      exactly satisfied the request (e.g. a length-one read of '\n') and the
      second iov is nonzero length, the syscall will block again after
      getting the blank line from the terminal until another line is read.
      simply put, entering a single blank line becomes impossible.
      
      the solution, fortunately, is simple. whenever the buffer size is
      nonzero, reduce the length of the requested read by one byte and let
      the last byte go through the buffer. this way, readv will already be
      in the second (and last) iov, and won't re-block on the second iov.
      2cff36a8
  11. 28 3月, 2011 1 次提交
    • R
      major stdio overhaul, using readv/writev, plus other changes · e3cd6c5c
      Rich Felker 提交于
      the biggest change in this commit is that stdio now uses readv to fill
      the caller's buffer and the FILE buffer with a single syscall, and
      likewise writev to flush the FILE buffer and write out the caller's
      buffer in a single syscall.
      
      making this change required fundamental architectural changes to
      stdio, so i also made a number of other improvements in the process:
      
      - the implementation no longer assumes that further io will fail
        following errors, and no longer blocks io when the error flag is set
        (though the latter could easily be changed back if desired)
      
      - unbuffered mode is no longer implemented as a one-byte buffer. as a
        consequence, scanf unreading has to use ungetc, to the unget buffer
        has been enlarged to hold at least 2 wide characters.
      
      - the FILE structure has been rearranged to maintain the locations of
        the fields that might be used in glibc getc/putc type macros, while
        shrinking the structure to save some space.
      
      - error cases for fflush, fseek, etc. should be more correct.
      
      - library-internal macros are used for getc_unlocked and putc_unlocked
        now, eliminating some ugly code duplication. __uflow and __overflow
        are no longer used anywhere but these macros. switch to read or
        write mode is also separated so the code can be better shared, e.g.
        with ungetc.
      
      - lots of other small things.
      e3cd6c5c
  12. 20 3月, 2011 1 次提交
  13. 12 2月, 2011 1 次提交