1. 15 9月, 2018 5 次提交
    • R
      fix undefined behavior in strto* via FILE buffer pointer abuse · d6c855ca
      Rich Felker 提交于
      in order to produce FILE objects to pass to the intscan/floatscan
      backends without any (prohibitively costly) extra buffering layer, the
      strto* functions set the FILE's rend (read end) buffer pointer to an
      invalid value at the end of the address space, or SIZE_MAX/2 past the
      beginning of the string. this led to undefined behavior comparing and
      subtracting the end pointer with the buffer position pointer (rpos).
      
      the comparison issue is easily eliminated by using != instead of <.
      however the subtractions require nontrivial changes:
      
      previously, f->shcnt stored the count that would have been read if
      consuming the whole buffer, which required an end pointer for the
      buffer. the purpose for this was that it allowed reading it and adding
      rpos-rend at any time to get the actual count so far, and required no
      adjustment at the time of __shgetc (actual function call) since the
      call would only happen when reaching the end of the buffer.
      
      to get rid of the dependency on rend, instead offset shcnt by buf-rpos
      (start of buffer) at the time of last __shlim/__shgetc call. this
      makes for slightly more work in __shgetc the function, but for the
      inline macro it's still just as easy to compute the current count.
      
      since the scan helper interfaces used here are a big hack, comments
      are added to document their contracts and what's going on with their
      implementations.
      d6c855ca
    • B
      improve error handling of ttyname_r and isatty · c8497199
      Benjamin Peterson 提交于
      POSIX allows ttyname(_r) and isatty to return EBADF if passed file
      descriptor is invalid.
      
      maintainer's note: these are optional ("may fail") errors, but it's
      non-conforming for ttyname_r to return ENOTTY when it failed for a
      different reason.
      c8497199
    • R
      add hidden version of &errno accessor function · e13063aa
      Rich Felker 提交于
      this significantly improves codegen in functions that need to access
      errno but otherwise have no need for a GOT pointer.
      
      we could probably improve it much more by including an inline version
      of the &errno accessor function, but that depends on having the
      definitions of struct __pthread and __pthread_self(), which at present
      would expose a lot more than is appropriate. moving them to a small
      tls.h later might make this more reasonable.
      e13063aa
    • R
      fix build regression in sysconf for archs with variable page size · da55d488
      Rich Felker 提交于
      commit 5ce37379 removed the inclusion
      of libc.h from this file as spurious, but it's needed to get PAGE_SIZE
      on archs where PAGE_SIZE is not a constant defined by limits.h.
      da55d488
    • R
      drop lazy plural forms init in dcngettext · 017e67dd
      Rich Felker 提交于
      there is no good reason to wait to find and process the plural rules
      for a translated message file until a gettext form requesting plural
      rule processing is used. it just imposes additional synchronization,
      here in the form of clunky use of atomics.
      
      it looks like there may also have been a race condition where nplurals
      could be seen without plural_rule being seen, possibly leading to null
      pointer dereference. if so, this commit fixes it.
      017e67dd
  2. 14 9月, 2018 1 次提交
    • R
      fix broken atomic store on powerpc[64] · 12817793
      Rich Felker 提交于
      in our memory model, all atomics are supposed to be full barriers;
      stores are not release-only. this is important because store is used
      as an unlock operation in places where it needs to acquire the waiter
      count to determine if a futex wake is needed. at least in the
      malloc-internal locks, but possibly elsewhere, soft deadlocks from
      missing futex wake (breakable by poking the threads to restart the
      syscall, e.g. by attaching a tracer) were reported to occur.
      
      once the malloc lock is replaced with Jens Gustedt's new lock
      implementation (see commit 47d0bcd4),
      malloc will not be affected by the issue, but it's not clear that
      other uses won't be. reducing the strength of the ordering properties
      required from a_store would require a thorough analysis of how it's
      used.
      
      to fix the problem, I'm removing the powerpc[64]-specific a_store
      definition; now, the top-level atomic.h will implement a_store using
      a_barrier on both sides of the store.
      
      it's not clear to me yet whether there might be issues with the other
      atomics. it's possible that a_post_llsc needs to be replaced with a
      full barrier to guarantee the formal semanics we want, but either way
      I think the difference is unlikely to impact the way we use them.
      12817793
  3. 13 9月, 2018 34 次提交