1. 12 Feb, 2013 1 commit
  2. 11 Feb, 2013 4 commits
    • Elliott Hughes's avatar
      More pthreads cleanup. · 2a1bb4e6
      Elliott Hughes authored
      POSIX says pthread_create returns EAGAIN, not ENOMEM.
      
      Also pull pthread_attr_t functions into their own file.
      
      Also pull pthread_setname_np into its own file.
      
      Also remove unnecessary #includes from pthread_key.cpp.
      
      Also account for those pthread keys used internally by bionic,
      so they don't count against the number of keys available to user
      code. (They do with glibc, but glibc's limit is the much more
      generous 1024.)
      
      Also factor out the common errno-restoring idiom to reduce gotos.
      
      Bug: 6702535
      Change-Id: I555e66efffcf2c1b5a2873569e91489156efca42
      2a1bb4e6
    • Elliott Hughes's avatar
      Revert "Revert "Pull the pthread_key_t functions out of pthread.c."" · 44b53ad6
      Elliott Hughes authored
      This reverts commit 6260553d
      
      (Removing the accidental libm/Android.mk change.)
      
      Change-Id: I6cddd9857c31facc05636e8221505b3d2344cb75
      44b53ad6
    • Elliott Hughes's avatar
      Revert "Pull the pthread_key_t functions out of pthread.c." · 6260553d
      Elliott Hughes authored
      This reverts commit ad59322a
      
      somehow my unfinished libm/Android.mk change got into here.
      
      Change-Id: I46be626c5269d60fb1ced9862f2ebaa380b4e0af
      6260553d
    • Elliott Hughes's avatar
      Pull the pthread_key_t functions out of pthread.c. · ad59322a
      Elliott Hughes authored
      This was originally motivated by noticing that we were setting the
      wrong bits for the well-known tls entries. That was a harmless bug
      because none of the well-known tls entries has a destructor, but
      it's best not to leave land mines lying around.
      
      Also add some missing POSIX constants, a new test, and fix
      pthread_key_create's return value when we hit the limit.
      
      Change-Id: Ife26ea2f4b40865308e8410ec803b20bcc3e0ed1
      ad59322a
  3. 08 Feb, 2013 1 commit
  4. 07 Feb, 2013 1 commit
    • Elliott Hughes's avatar
      Clean up the argc/argv/envp/auxv handling. · 42b2c6a5
      Elliott Hughes authored
      There's now only one place where we deal with this stuff, it only needs to
      be parsed once by the dynamic linker (rather than by each recipient), and it's
      now easier for us to get hold of auxv data early on.
      
      Change-Id: I6314224257c736547aac2e2a650e66f2ea53bef5
      42b2c6a5
  5. 22 Jan, 2013 1 commit
    • Nick Kralevich's avatar
      bionic_auxv.h: fix #define conflict · abc21c80
      Nick Kralevich authored
      Both libc/include/sys/auxv.h and libc/private/bionic_auxv.h
      use _SYS_AUXV_H_ to see if a header file has already been included.
      This prevents both of these files from being included at the same
      time.
      
      Fix this name conflict.
      
      Change-Id: Ifaec88aa9779d784b95f8e75145117acf3d5cfc5
      abc21c80
  6. 19 Jan, 2013 1 commit
    • Elliott Hughes's avatar
      Fix the duplication in the debugging code. · 1e980b6b
      Elliott Hughes authored
      We had two copies of the backtrace code, and two copies of the
      libcorkscrew /proc/pid/maps code. This patch gets us down to one.
      
      We also had hacks so we could log in the malloc debugging code.
      This patch pulls the non-allocating "printf" code out of the
      dynamic linker so everyone can share.
      
      This patch also makes the leak diagnostics easier to read, and
      makes it possible to paste them directly into the 'stack' tool (by
      using relative PCs).
      
      This patch also fixes the stdio standard stream leak that was
      causing a leak warning every time tf_daemon ran.
      
      Bug: 7291287
      Change-Id: I66e4083ac2c5606c8d2737cb45c8ac8a32c7cfe8
      1e980b6b
  7. 16 Jan, 2013 2 commits
    • Nick Kralevich's avatar
      Revert "stack protector: use AT_RANDOM" · 36bd371e
      Nick Kralevich authored
      The AT_RANDOM changes broke setuid / setgid executables
      such as "ping". When the linker executes a setuid program,
      it cleans the environment, removing any invalid environment
      entries, and adding "NULL"s to the end of the environment
      array for each removed variable. Later on, we try to determine
      the location of the aux environment variable, and get tripped
      up by these extra NULLs.
      
      Reverting this patch will get setuid executables working again,
      but getauxval() is still broken for setuid programs because of
      this bug.
      
      This reverts commit e3a49a86.
      
      Change-Id: I05c58a896b1fe32cfb5d95d43b096045cda0aa4a
      36bd371e
    • Nick Kralevich's avatar
      stack protector: use AT_RANDOM · e3a49a86
      Nick Kralevich authored
      Populate the stack canaries from the kernel supplied
      AT_RANDOM value, which doesn't involve any system calls.
      This is slightly faster (6 fewer syscalls) and avoids
      unnecessarily reading /dev/urandom, which depletes entropy.
      
      Bug: 7959813
      
      Change-Id: If2b43100a2a9929666df3de56b6139fed969e0f1
      e3a49a86
  8. 15 Jan, 2013 1 commit
  9. 11 Jan, 2013 1 commit
  10. 10 Jan, 2013 1 commit
  11. 04 Dec, 2012 1 commit
  12. 30 Nov, 2012 1 commit
  13. 25 Oct, 2012 1 commit
  14. 23 Oct, 2012 1 commit
  15. 16 Oct, 2012 1 commit
    • Elliott Hughes's avatar
      Make dlerror(3) thread-safe. · 5419b947
      Elliott Hughes authored
      I gave up trying to use the usual thread-local buffer idiom; calls to
      calloc(3) and free(3) from any of the "dl" functions -- which live in
      the dynamic linker -- end up resolving to the dynamic linker's stubs.
      I tried to work around that, but was just making things more complicated.
      This alternative costs us a well-known TLS slot (instead of the
      dynamically-allocated TLS slot we'd have used otherwise, so no difference
      there), plus an extra buffer inside every pthread_internal_t.
      
      Bug: 5404023
      Change-Id: Ie9614edd05b6d1eeaf7bf9172792d616c6361767
      5419b947
  16. 11 Oct, 2012 1 commit
  17. 01 Oct, 2012 1 commit
  18. 24 Sep, 2012 1 commit
  19. 11 Sep, 2012 1 commit
  20. 07 Sep, 2012 1 commit
  21. 28 Aug, 2012 1 commit
    • Ard Biesheuvel's avatar
      ARM: make CRT_LEGACY_WORKAROUND work as intended · f3cfcd86
      Ard Biesheuvel authored
      
      To properly support legacy ARM shared libraries, libc.so needs
      to export the symbols __dso_handle and atexit, even though
      these are now supplied by the crt startup code.
      
      This patch reshuffles the existing CRT_LEGACY_WORKAROUND
      conditionally compiled code slightly so it works as the
      original author likely intended.
      
      Change-Id: Id6c0e94dc65b7928324a5f0bad7eba6eb2f464b9
      Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@gmail.com>
      f3cfcd86
  22. 07 Aug, 2012 1 commit
    • Elliott Hughes's avatar
      Clean up the linker a bit, remove prelinking support. · 4688279d
      Elliott Hughes authored
      Also make the errors more readable, since none of us seemed to know
      what they actually meant. The new style is still as verbose as the
      old, but that's probably necessary in the absence of chained exceptions
      in C. Here's what you'd see if you try to boot after removing
      libsurfaceflinger.so:
      
        32267 32267 E AndroidRuntime: java.lang.UnsatisfiedLinkError: Cannot load library: (linker.c:1629, pid 32259) soinfo_link_image: could not load library "libsystem_server.so" needed by "libandroid_servers.so"; caused by (linker.c:1629, pid 32259) soinfo_link_image: could not load library "libsurfaceflinger.so" needed by "libsystem_server.so"; caused by (linker.c:709, pid 32259) load_library: library "libsurfaceflinger.so" not found
      
      This patch also fixes almost all of the compiler warnings.
      
      Change-Id: I64bb59aed6d4e039c15ea45be2367f319ef879f8
      4688279d
  23. 02 Aug, 2012 1 commit
  24. 27 Jul, 2012 1 commit
    • Elliott Hughes's avatar
      Report errors to the log, not just stderr. · 52d62332
      Elliott Hughes authored
      In particular this affects assert(3) and __cxa_pure_virtual, both of
      which have managed to confuse people this week by apparently aborting
      without reason. (Because stderr goes nowhere, normally.)
      
      Bug: 6852995
      Bug: 6840813
      Change-Id: I7f5d17d5ddda439e217b7932096702dc013b9142
      52d62332
  25. 24 Jul, 2012 2 commits
  26. 11 Jun, 2012 1 commit
  27. 08 Jun, 2012 1 commit
    • Geremy Condra's avatar
      Adding event logging to libc. · 8b11c4ce
      Geremy Condra authored
      I've basically just copied the relevant bits out of liblog and
      EventLog.cpp. While this will let us do the uid logging we want
      to address the concerns in 245c07027f78565858dd489eb0d94c3d48743e9d
      it doesn't give us much else.
      
      Change-Id: Icac6ff20bc0a3ade5927f6f76fedffe1ae6f8522
      8b11c4ce
  28. 01 Jun, 2012 1 commit
    • Nick Kralevich's avatar
      arm: rewrite crtbegin* as C files. · 9d403268
      Nick Kralevich authored
      Rewrite
       crtbegin.S     -> crtbegin.c
       crtbegin_so.S  -> crtbegin_so.c
      
      This change allows us to generate PIC code without relying
      on text relocations.
      
      As a consequence of this rewrite, also rewrite
        __dso_handle.S    -> __dso_handle.c
        __dso_handle_so.S -> __dso_handle_so.c
        atexit.S          -> atexit.c
      
      In crtbegin.c _start, place the __PREINIT_ARRAY__, __INIT_ARRAY__,
      __FINI_ARRAY__, and __CTOR_LIST__ variables onto the stack, instead of
      passing a pointer to the text section of the binary.
      
      This change appears sorta wonky, as I attempted to preserve,
      as much as possible, the structure of the original assembly.
      As a result, you have C files including other C files, and other
      programming uglyness.
      
      Result: This change reduces the number of files with text-relocations
      from 315 to 19 on my Android build.
      
      Before:
        $ scanelf -aR $OUT/system | grep TEXTREL | wc -l
        315
      
      After:
        $ scanelf -aR $OUT/system | grep TEXTREL | wc -l
        19
      
      Change-Id: Ib9f98107c0eeabcb606e1ddc7ed7fc4eba01c9c4
      9d403268
  29. 07 May, 2012 1 commit
    • Mattias Falk's avatar
      Avoid multiple dns lookups for the same query · a59cfcfd
      Mattias Falk authored
      If two or more rapid dns requests for the same server are done
      from different threads it turns into separate dns reques, if
      the response of the request isn't found in the cache.
      
      This patch avoid multiple request for the same server by
      letting subsequents request wait until the first request
      has finished.
      
      Change-Id: Ic72ea0e7d3964a4164eddf866feb4357ec4dfe54
      a59cfcfd
  30. 12 Apr, 2012 1 commit
    • Evgeniy Stepanov's avatar
      Initialize TLS before any application code is run. · 1a78fbb5
      Evgeniy Stepanov authored
      Since e19d702b, dlsym and friends use recursive mutexes that
      require the current thread id, which is not available before the libc
      constructor. This prevents us from using dlsym() in .preinit_array.
      
      This change moves TLS initialization from libc constructor to the earliest
      possible point - immediately after linker itself is relocated. As a result,
      pthread_internal_t for the initial thread is available from the start.
      
      As a bonus, values stored in TLS in .preinit_array are not lost when libc is
      initialized.
      
      Change-Id: Iee5a710ee000173bff63e924adeb4a4c600c1e2d
      1a78fbb5
  31. 26 Mar, 2012 1 commit
    • Jean-Baptiste Queru's avatar
      Handle pthread-related changes (mutex/atfork) · faca92f2
      Jean-Baptiste Queru authored
      First commit:
      
      Revert "Revert "am be741d47: am 2f460fbe: am 73b5cad9: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()"""
      
      This reverts commit 06823da2.
      
      Second commit:
      
      bionic: fix atfork hanlder_mutex deadlock
      
      This cherry-picks commit 34e89c23
      
      
      
      After applying the kernel_id fix, the system refused to boot up and we
      got following crash log:
      I/DEBUG   (  113): pid: 618, tid: 618  >>> org.simalliance.openmobileapi.service:remote <<<
      I/DEBUG   (  113): signal 16 (SIGSTKFLT), code -6 (?), fault addr --------
      I/DEBUG   (  113):  eax fffffe00  ebx b77de994  ecx 00000080  edx 00724002
      I/DEBUG   (  113):  esi 00000000  edi 00004000
      I/DEBUG   (  113):  xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000000 xss 0000007b
      I/DEBUG   (  113):  eip b7761351  ebp bfdf3de8  esp bfdf3dc4  flags 00000202
      I/DEBUG   (  113):     #00  eip: 00015351  /system/lib/libc.so
      I/DEBUG   (  113):     #01  eip: 0000d13c  /system/lib/libc.so (pthread_mutex_lock)
      I/DEBUG   (  113):     #02  eip: 00077b48  /system/lib/libc.so (__bionic_atfork_run_prepare)
      I/DEBUG   (  113):     #03  eip: 00052cdb  /system/lib/libc.so (fork)
      I/DEBUG   (  113):     #04  eip: 0009ae91  /system/lib/libdvm.so (_Z18dvmOptimizeDexFileillPKcjjb)
      I/DEBUG   (  113):     #05  eip: 000819d6  /system/lib/libdvm.so (_Z14dvmJarFileOpenPKcS0_PP7JarFileb)
      I/DEBUG   (  113):     #06  eip: 000b175e  /system/lib/libdvm.so (_ZL40Dalvik_dalvik_system_DexFile_openDexFilePKjP6JValue)
      I/DEBUG   (  113):     #07  eip: 0011fb94  /system/lib/libdvm.so
      
      Root cause:
      The atfork uses the mutex handler_mutex to protect the atfork_head. The
      parent will call __bionic_atfork_run_prepare() to lock the handler_mutex,
      and need both the parent and child to unlock their own copy of handler_mutex
      after fork. At that time, the owner of hanlder_mutex is set as the parent.
      If we apply the kernel_id fix, then the child's kernel_id will be set as
      child's tid.
      The handler_mutex is a recursive lock, and pthread_mutex_unlock(&hander_mutex)
      will fail because the mutex owner is the parent, while the current tid
      (__get_thread()->kernel_id) is child, not matched with the mutex owner.
      At that time, the handler_mutex is left in lock state.If the child wants to
      fork other process after than, then it will try to lock handler_mutex, and
      then be deadlocked.
      
      Fix:
      Since the child has its own copy of vm space from the the parent, the
      child space's handler_mutex should be reset to the initialized state.
      
      Change-Id: I3907dd9a153418fb78862f2aa6d0302c375d9e27
      Signed-off-by: default avatarJack Ren <jack.ren@intel.com>
      Signed-off-by: default avatarChenyang Du <chenyang.du@intel.com>
      Signed-off-by: default avatarBruce Beare <bruce.j.beare@intel.com>
      
      Change-Id: Ic8072f366a877443a60fe215f3c00b3df5a259c8
      faca92f2
  32. 13 Mar, 2012 1 commit
  33. 12 Mar, 2012 1 commit
    • Jack Ren's avatar
      bionic: Fix wrong kernel_id in pthread descriptor after fork() · d8bc6e71
      Jack Ren authored
      
      After forking, the kernel_id field in the phtread_internal_t returned by pthread_self()
      is incorrect --- it's the tid from the parent, not the new tid of the
      child.
      
      The root cause is that: currently the kernel_id is set by
      _init_thread(), which is called in 2 cases:
      (1) called by __libc_init_common(). That happens when the execv( ) is
      called after fork( ). But when the zygote tries to fork the android
      application, the child application doesn't call execv( ), instread, it
      tries to call the Java main method directly.
      (2) called by pthread_create(). That happens when a new thread is
      created.
      
      For the lead thread which is the thread created by fork(), it should
      call execv() but it doesn't, as described in (1) above. So its kernel_id
      will inherit the parent's kernel_id.
      
      Fixed it in this patch.
      
      Change-Id: I63513e82af40ec5fe51fbb69456b1843e4bc0fc7
      Signed-off-by: default avatarChenyang Du <chenyang.du@intel.com>
      Signed-off-by: default avatarJack Ren <jack.ren@intel.com>
      Signed-off-by: default avatarBruce Beare <bruce.j.beare@intel.com>
      d8bc6e71
  34. 13 Jan, 2012 1 commit
    • David 'Digit' Turner's avatar
      libc: Copy private C library declarations to private/ · 11f3d5a4
      David 'Digit' Turner authored
      This patch is the first in a series that aims at cleaning up the
      public C library headers (which end up being distributed with the NDK).
      
      <resolv.h> and <time.h> contain declarations that should not be public.
      They are used by other parts of the platform, but NDK applications should
      not use or rely on them.
      
      So copy them to private <bionic_time.h> and <resolv_iface.h> headers
      and use a guard macro to avoid conflicts when both headers are included
      at the same time.
      
      The idea is that we're going to fix the other platform modules to
      include these private headers. After this is done, we will remove the
      duplicate definitions from <resolv.h> and <time.h>
      
      Change-Id: I121c11936951c98ca7165e811126ed8a4a3a394d
      11f3d5a4
  35. 16 Nov, 2011 1 commit
    • David 'Digit' Turner's avatar
      bionic: Do not use <sys/atomics.h> for platform code. · e31bfae2
      David 'Digit' Turner authored
      We're going to modify the __atomic_xxx implementation to provide
      full memory barriers, to avoid problems for NDK machine code that
      link to these functions.
      
      First step is to remove their usage from our platform code.
      We now use inlined versions of the same functions for a slight
      performance boost.
      
      + remove obsolete atomics_x86.c (was never compiled)
      
      NOTE: This improvement was benchmarked on various devices.
            Comparing a pthread mutex lock + atomic increment + unlock
            we get:
      
        - ARMv7 emulator, running on a 2.4 GHz Xeon:
             before: 396 ns    after: 288 ns
      
        - x86 emulator in KVM mode on same machine:
             before: 27 ns     after: 27 ns
      
        - Google Nexus S, in ARMv7 mode (single-core):
             before: 82 ns     after: 76 ns
      
        - Motorola Xoom, in ARMv7 mode (multi-core):
             before: 121 ns    after: 120 ns
      
      The code has also been rebuilt in ARMv5TE mode for correctness.
      
      Change-Id: Ic1dc72b173d59b2e7af901dd70d6a72fb2f64b17
      e31bfae2