Commit graph

1431 commits

Author SHA1 Message Date
Elliott Hughes
470631ed79 Give the timer_create SIGEV_THREAD helper threads sensible names.
Bug: 6609676
Change-Id: I286b197c75beee4d9930b0973f2d7dd47c14e91c
2012-06-06 10:32:56 -07:00
Nick Kralevich
204c6e5ff3 Merge "arm: rewrite crtbegin* as C files." 2012-06-06 08:54:22 -07:00
Nick Kralevich
0a2301598c libc: implement some FORTIFY_SOURCE functions
Add initial support for -D_FORTIFY_SOURCE to bionic for the
following functions:

* memcpy
* memmove
* strcpy
* strcat
* strncpy
* strncat

This change adds a new version of the above functions which passes
the size of the destination buffer to __builtin___*_chk.

If the compiler can determine, at compile time, that the destination
buffer is large enough, or the destination buffer can point to an object
of unknown size, then the check call is bypassed.

If the compiler can't make a compile time decision, then it calls
the __*_chk() function, which does a runtime buffer size check

These options are only enabled if the code is compiled with
-D_FORTIFY_SOURCE=1 or 2, and only when optimizations are enabled.

Please see
* http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
* http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html

for additional details on FORTIFY_SOURCE.

Testing: Compiled the entire Android tree with -D_FORTIFY_SOURCE=1,
and verified that everything appears to be working properly.
Also created a test buffer overflow, and verified that it was
caught by this change.

Change-Id: I4fddb445bafe92b16845b22458d72e6dedd24fbc
2012-06-05 15:44:31 -07:00
Iliyan Malchev
31431f454a am 252a5c85: resolved conflicts for merge of e1dd3c28 to jb-dev-plus-aosp
* commit '252a5c854a08e89fc7337ea679220161fe4ea98f':
  bionic: import heaptracker as chk_malloc
2012-06-02 08:35:07 -07:00
Iliyan Malchev
143ad4cf31 am f0ddaa2f: am 7d2e24eb: bionic: introduce libc.debug.malloc.program
* commit 'f0ddaa2fac00ac20059c0b2c142da9de2838a7b6':
  bionic: introduce libc.debug.malloc.program
2012-06-02 08:20:09 -07:00
Iliyan Malchev
252a5c854a resolved conflicts for merge of e1dd3c28 to jb-dev-plus-aosp
Change-Id: I58b9c13d20771aa39b703ec05cbff8aeaad38fe8
2012-06-02 08:14:36 -07:00
Iliyan Malchev
f0ddaa2fac am 7d2e24eb: bionic: introduce libc.debug.malloc.program
* commit '7d2e24eb167b6257f7935c7bd2023a708704ca1a':
  bionic: introduce libc.debug.malloc.program
2012-06-01 19:03:06 -07:00
Iliyan Malchev
e1dd3c287b bionic: import heaptracker as chk_malloc
This patch is a rewrite of libc.debug.malloc = 10 (chk_malloc).  It provides
the same features as the original (poison freed memory, detect heap overruns
and underruns), except that it provides more debugging information whenever it
detects a problem.

In addition to the original features, the new chk_malloc() implementation
detects multiple frees within a given range of the last N allocations, N being
configurable via the system property libc.debug.malloc.backlog.

Finally, this patch keeps track of all outstanding memory allocations.  On
program exit, we walk that list and report each outstanding allocation.

(There is support (not enabled) for a scanner thread periodically walks over
the list of outstanding allocations as well as the backlog of recently-freed
allocations, checking for heap-usage errors.)

Feature overview:

  1) memory leaks
  2) multiple frees
  3) use after free
  4) overrun

Implementation:

-- for each allocation, there is a:
  1) stack trace at the time the allocation is made
  2) if the memory is freed, there is also a stack trace at the point
  3) a front and rear guard (fence)
  4) the stack traces are kept together with the allocation

-- the following lists and maintained

  1) all outstanding memory allocations
  3) a backlog of allocations what are freed; when you call free(), instead of
     actually freed, the allocation is moved to this backlog;
  4) when the backlog of allocations gets full, the oldest entry gets evicted
     from it; at that point, the allocation is checked for overruns or
     use-after-free errors, and then actually freed.
  5) when the program exits, the list of outstanding allocations and the
     backlog are inspected for errors, then freed;

To use this, set the following system properties before running the process or
processes you want to inspect:

libc.malloc.debug.backlog # defaults to 100
libc.malloc.debug 10

When a problem is detected, you will see the following on logcat for a multiple
free:

E/libc    ( 7233): +++ ALLOCATION 0x404b9278 SIZE 10 BYTES MULTIPLY FREED!
E/libc    ( 7233): +++ ALLOCATION 0x404b9278 SIZE 10 ALLOCATED HERE:
E/libc    ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc    ( 7233):      #00  pc 0000c35a  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #01  pc 0000c658  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #02  pc 00016d80  /system/lib/libc.so
E/libc    ( 7233):      #03  pc 4009647c  /system/bin/malloctest
E/libc    ( 7233):      #04  pc 00016f24  /system/lib/libc.so
E/libc    ( 7233): +++ ALLOCATION 0x404b9278 SIZE 10 FIRST FREED HERE:
E/libc    ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc    ( 7233):      #00  pc 0000c35a  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #01  pc 0000c7d2  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #02  pc 00016d94  /system/lib/libc.so
E/libc    ( 7233):      #03  pc 40096490  /system/bin/malloctest
E/libc    ( 7233):      #04  pc 00016f24  /system/lib/libc.so
E/libc    ( 7233): +++ ALLOCATION 0x404b9278 SIZE 10 NOW BEING FREED HERE:
E/libc    ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc    ( 7233):      #00  pc 0000c35a  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #01  pc 0000c6ac  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #02  pc 00016d94  /system/lib/libc.so
E/libc    ( 7233):      #03  pc 400964a0  /system/bin/malloctest
E/libc    ( 7233):      #04  pc 00016f24  /system/lib/libc.so

The following for a heap overrun and underrun:

E/libc    ( 7233): +++ REAR GUARD MISMATCH [10, 11)
E/libc    ( 7233): +++ ALLOCATION 0x404b9198 SIZE 10 HAS A CORRUPTED REAR GUARD
E/libc    ( 7233): +++ ALLOCATION 0x404b9198 SIZE 10 ALLOCATED HERE:
E/libc    ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc    ( 7233):      #00  pc 0000c35a  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #01  pc 0000c658  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #02  pc 00016d80  /system/lib/libc.so
E/libc    ( 7233):      #03  pc 40096438  /system/bin/malloctest
E/libc    ( 7233):      #04  pc 00016f24  /system/lib/libc.so
E/libc    ( 7233): +++ ALLOCATION 0x404b9198 SIZE 10 FREED HERE:
E/libc    ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc    ( 7233):      #00  pc 0000c35a  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #01  pc 0000c7d2  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #02  pc 00016d94  /system/lib/libc.so
E/libc    ( 7233):      #03  pc 40096462  /system/bin/malloctest
E/libc    ( 7233):      #04  pc 00016f24  /system/lib/libc.so
E/libc    ( 7233): +++ ALLOCATION 0x404b9358 SIZE 10 HAS A CORRUPTED FRONT GUARD
E/libc    ( 7233): +++ ALLOCATION 0x404b9358 SIZE 10 ALLOCATED HERE:
E/libc    ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc    ( 7233):      #00  pc 0000c35a  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #01  pc 0000c658  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #02  pc 00016d80  /system/lib/libc.so
E/libc    ( 7233):      #03  pc 400964ba  /system/bin/malloctest
E/libc    ( 7233):      #04  pc 00016f24  /system/lib/libc.so
E/libc    ( 7233): +++ ALLOCATION 0x404b9358 SIZE 10 FREED HERE:
E/libc    ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc    ( 7233):      #00  pc 0000c35a  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #01  pc 0000c7d2  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #02  pc 00016d94  /system/lib/libc.so
E/libc    ( 7233):      #03  pc 400964e4  /system/bin/malloctest
E/libc    ( 7233):      #04  pc 00016f24  /system/lib/libc.so

The following for a memory leak:

E/libc    ( 7233): +++ THERE ARE 1 LEAKED ALLOCATIONS
E/libc    ( 7233): +++ DELETING 4096 BYTES OF LEAKED MEMORY AT 0x404b95e8 (1 REMAINING)
E/libc    ( 7233): +++ ALLOCATION 0x404b95e8 SIZE 4096 ALLOCATED HERE:
E/libc    ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc    ( 7233):      #00  pc 0000c35a  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #01  pc 0000c658  /system/lib/libc_malloc_debug_leak.so
E/libc    ( 7233):      #02  pc 00016d80  /system/lib/libc.so
E/libc    ( 7233):      #03  pc 0001bc94  /system/lib/libc.so
E/libc    ( 7233):      #04  pc 0001edf6  /system/lib/libc.so
E/libc    ( 7233):      #05  pc 0001b80a  /system/lib/libc.so
E/libc    ( 7233):      #06  pc 0001c086  /system/lib/libc.so
E/libc    ( 7233):      #07  pc 40096402  /system/bin/malloctest
E/libc    ( 7233):      #08  pc 00016f24  /system/lib/libc.so

Change-Id: Ic440e9d05a01e2ea86b25e8998714e88bc2d16e0
Signed-off-by: Iliyan Malchev <malchev@google.com>
2012-06-01 15:54:34 -07:00
Nick Kralevich
9d40326830 arm: rewrite crtbegin* as C files.
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
2012-06-01 14:41:27 -07:00
Iliyan Malchev
7d2e24eb16 bionic: introduce libc.debug.malloc.program
libc.debug.malloc.program  provides an additional level of control over which
processes to enable libc.debug.malloc functionality for.  The string value of
libc.debug.malloc.program is matched against the program name; if the value of
libc.debug.malloc.program is a substring of the program name, then malloc debug
is applied to that program at whatever level libc.debug.malloc specifies.

If lib.debug.malloc.program is not specified, then libc.debug.malloc has the
same effect as before.

For example, to enable libc.deubug.malloc = 10 only to the mediaserver, do the
following:

   adb root # necessary for setprop
   adb setprop libc.debug.malloc.program mediaserver
   adb setprop libc.debug.malloc 10
   adb kill -9 $(pid mediaserver)

Change-Id: I6f01c12f033c8e2e015d73025369d7f1685ba200
Signed-off-by: Iliyan Malchev <malchev@google.com>
2012-05-30 20:03:47 -07:00
Nick Kralevich
857fc9eab9 Merge "crtbegin: eliminate duplicate code" 2012-05-30 13:29:58 -07:00
Nick Kralevich
83a73d1afe crtbegin: eliminate duplicate code
crtbegin_dynamic and crtbegin_static are essentially identical,
minus a few trivial differences (comments and whitespace).

Eliminate duplicates.

Change-Id: Ic9fae6bc9695004974493b53bfc07cd3bb904480
2012-05-30 11:45:12 -07:00
Geremy Condra
207d7673e5 am 5a095ef2: am 03539a36: Merge "Ensure that the port number and TXID are properly randomized." into jb-dev
* commit '5a095ef28716b54f86d9c1727b9a2493ba775255':
  Ensure that the port number and TXID are properly randomized.
2012-05-30 11:11:33 -07:00
Geremy Condra
5a095ef287 am 03539a36: Merge "Ensure that the port number and TXID are properly randomized." into jb-dev
* commit '03539a36b634bdfa61c06277cf25e0ca8e3105ba':
  Ensure that the port number and TXID are properly randomized.
2012-05-30 11:09:05 -07:00
Geremy Condra
03539a36b6 Merge "Ensure that the port number and TXID are properly randomized." into jb-dev 2012-05-30 11:06:54 -07:00
Ben Cheng
41c2a112c2 am d7b60b20: am c84ff11d: Print the corrupted address passed to free().
* commit 'd7b60b207be79513b99faf2ef576db333f9c7a78':
  Print the corrupted address passed to free().
2012-05-24 17:23:43 -07:00
Ben Cheng
d7b60b207b am c84ff11d: Print the corrupted address passed to free().
* commit 'c84ff11dad26435dc5760bceda18e8f1175a6061':
  Print the corrupted address passed to free().
2012-05-24 17:21:03 -07:00
Ben Cheng
c84ff11dad Print the corrupted address passed to free().
For example:

@@@ ABORTING: INVALID HEAP ADDRESS IN dlfree addr=0x5c3bfbd0
Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 2942

The addr=0x5c3bfbd0 part is new.

Change-Id: I8670144b2b0a3a6182384150d762c97dfee5452f
2012-05-24 17:06:43 -07:00
Geremy Condra
b23f193dcc Ensure that the port number and TXID are properly randomized.
This fix reads from /dev/urandom to get the required entropy.

Bug: 6535492
Change-Id: Ibc2fec3f71a67607b608ad9b767b0b6504993c1d
2012-05-24 15:26:12 -07:00
Jean-Baptiste Queru
15ed08d065 am d155ba57: am c7882ab2: Merge "bionic: add clean kernel header ucontext.h"
* commit 'd155ba57a32ce3182d8a5b79ff27bc5e7fa55df9':
  bionic: add clean kernel header ucontext.h
2012-05-21 12:41:30 -07:00
Elliott Hughes
7cce04381a resolved conflicts for merge of dc6c2b77 to master
Change-Id: Ifab4573a825cf5caa7158d8888243bb8d5d01148
2012-05-17 17:15:01 -07:00
Jean-Baptiste Queru
d155ba57a3 am c7882ab2: Merge "bionic: add clean kernel header ucontext.h"
* commit 'c7882ab2a99a74c8f772ab03fdfd9a3b53515e46':
  bionic: add clean kernel header ucontext.h
2012-05-17 13:28:10 -07:00
Jean-Baptiste Queru
c7882ab2a9 Merge "bionic: add clean kernel header ucontext.h" 2012-05-17 12:25:02 -07:00
Elliott Hughes
dc6c2b779b am 70cf0bc0: Merge "Remove the last references to SuperH."
* commit '70cf0bc0496a1d4c0e83fe3f1933f667ab66c148':
  Remove the last references to SuperH.
2012-05-16 17:18:23 -07:00
Elliott Hughes
e33af61c70 Remove the last references to SuperH.
Change-Id: Icb44c1f94cb178d90b4c2b1e8f6d175586aec4e1
2012-05-15 17:08:41 -07:00
Ying Wang
fc9e525fe0 Rename the misleading var name TARGET_OUT_STATIC_LIBRARIES
TARGET_OUT_STATIC_LIBRARIES is actually the same as
TARGET_OUT_INTERMEDIATE_LIBRARIES.

Change-Id: I11ac35256031d461d20156cd4c19ed7eae781d22
2012-05-15 15:15:11 -07:00
Nick Kralevich
6cdefd06c0 Add linker support for PIE
Modify the dynamic linker so that executables can be loaded
at locations other than 0x00000000.

Modify crtbegin* so that non-PIC compilant "thumb interwork
veneers" are not created by the linker.

Bug: 5323301
Change-Id: Iece0272e2b708c79034f302c20160e1fe9029588
2012-05-15 09:56:32 -07:00
Kito Cheng
c425bc0532 bionic: add clean kernel header ucontext.h
Change-Id: I34fd0b0147fa33fd74c13480bc11827634233a41
2012-05-14 01:42:12 +08:00
Elliott Hughes
1b56aaa659 am f2f7bf76: am 4f05d1c7: Merge "bionic/x86: Optimization for memcpy"
* commit 'f2f7bf76dfd1d6014ed3baa1e27b221388e70a09':
  bionic/x86: Optimization for memcpy
2012-05-10 23:15:00 -07:00
Elliott Hughes
f2f7bf76df am 4f05d1c7: Merge "bionic/x86: Optimization for memcpy"
* commit '4f05d1c758ba141c617f25251a661ecb66627e9e':
  bionic/x86: Optimization for memcpy
2012-05-10 21:31:48 -07:00
Elliott Hughes
4f05d1c758 Merge "bionic/x86: Optimization for memcpy" 2012-05-10 10:14:44 -07:00
Iliyan Malchev
83a38b8c44 am 8034415d: resolved conflicts for merge of 08e72d01 to jb-dev-plus-aosp
* commit '8034415ddd8404f8788199ed993af89692235dc5':
  bionic: add support for non-NEON memcpy() on NEON SoCs
2012-05-10 09:24:46 -07:00
Iliyan Malchev
8034415ddd resolved conflicts for merge of 08e72d01 to jb-dev-plus-aosp
Change-Id: If00e354a5953ed54b31963d4f8ea77e1603c321e
2012-05-10 09:19:59 -07:00
Elliott Hughes
537867aed8 am 804147cb: am edb7cad9: Merge "Actually set the header guard in "linux-syscalls.h"."
* commit '804147cb7d533f5635da6adc28fbca1467a3078b':
  Actually set the header guard in "linux-syscalls.h".
2012-05-09 20:12:40 -07:00
Elliott Hughes
804147cb7d am edb7cad9: Merge "Actually set the header guard in "linux-syscalls.h"."
* commit 'edb7cad9b764f029c5faac2750f749d3d84bd86a':
  Actually set the header guard in "linux-syscalls.h".
2012-05-09 20:10:14 -07:00
Elliott Hughes
1928523c87 Actually set the header guard in "linux-syscalls.h".
Spotted while merging a MIPS change.

Change-Id: I36fb5a07d0bba0c117e9fe9733957bd37ca4b4c0
2012-05-09 16:34:11 -07:00
Elliott Hughes
2a5fab9a5f am dbd5ecad: resolved conflicts for merge of e5408907 to jb-dev-plus-aosp
* commit 'dbd5ecad26e39281bb83f97664bc32555c5c071a':
  [MIPS] Add support for MIPS syscalls
2012-05-09 13:57:12 -07:00
Elliott Hughes
dbd5ecad26 resolved conflicts for merge of e5408907 to jb-dev-plus-aosp
Change-Id: If4c3f51bf87b28da8074be2e46ae772a374b266f
2012-05-09 13:53:37 -07:00
Prajakta Gudadhe
08e72d0161 bionic: add support for non-NEON memcpy() on NEON SoCs
Some SoCs that support NEON nevertheless perform better with a non-NEON than a
NEON memcpy().  This patch adds build variable ARCH_ARM_USE_NON_NEON_MEMCPY,
which can be set in BoardConfig.mk.  When ARCH_ARM_USE_NON_NEON_MEMCPY is
defined, we compile in the non-NEON optimized memcpy() even if the SoC supports
NEON.

Change-Id: Ia0e5bee6bad5880ffc5ff8f34a1382d567546cf9
2012-05-09 13:34:31 -07:00
Elliott Hughes
fd8bd2c432 am 58a00b49: am 7eb1cc23: Merge "bionic: allow the board to customize MALLOC_ALIGNMENT"
* commit '58a00b4977b6fa073a8f56d94d741b1e4cb49856':
  bionic: allow the board to customize MALLOC_ALIGNMENT
2012-05-09 12:56:15 -07:00
Elliott Hughes
22167aafba am eab2889e: am fd955033: Merge "pthread: Invalidate stale stack pointers on pthread_exit()"
* commit 'eab2889e66d4fe03f3c5590d7e8b14e3777179ec':
  pthread: Invalidate stale stack pointers on pthread_exit()
2012-05-09 12:56:15 -07:00
Elliott Hughes
58a00b4977 am 7eb1cc23: Merge "bionic: allow the board to customize MALLOC_ALIGNMENT"
* commit '7eb1cc23f8976a2062ba0cf92f030216a8e64e60':
  bionic: allow the board to customize MALLOC_ALIGNMENT
2012-05-09 12:53:16 -07:00
Elliott Hughes
eab2889e66 am fd955033: Merge "pthread: Invalidate stale stack pointers on pthread_exit()"
* commit 'fd95503347acba5c52d669a186ad2b161338a8a7':
  pthread: Invalidate stale stack pointers on pthread_exit()
2012-05-09 12:53:16 -07:00
Raghu Gandham
1fa0d84957 [MIPS] Add support for MIPS syscalls
Change-Id: I4deba67e15c865c4c2db03064c04098a09828ea6
Signed-off-by: Raghu Gandham <raghu@mips.com>
Signed-off-by: Chris Dearman <chris@mips.com>
2012-05-09 11:46:28 -07:00
Jack Ren
2fd81ef71c bionic: allow the board to customize MALLOC_ALIGNMENT
Currently the dlmalloc allocates the memory with 8-byte alignment.
According to the com.aurorasoftworks.quadrant.ui.professional benchmark data:
We can get much better memory performance if we change it to be 16-byte aligned.
For example, On Nexus-S:
8-byte aligned :
    1378 1070  1142 1665 1765  1163 1179  1263  1404 avg: 1336.555555556
16-byte aligned:
    1691 1731  1780 1691 1671  1678 1802  1758  1780 avg: 1731.333333333
                                                    gain: 29.53%

That patch provides flexibity to customize the MALLOC_ALIGNMENT from the
board config.The macro MALLOC_ALIGNMENT defaults to 8.
To change it, please define BOARD_MALLOC_ALIGNMENT in the BoardConfig.mk:
BOARD_MALLOC_ALIGNMENT := <whatever>

Change-Id: I8da0376944a0bbcef1d0fc026bfb6d9125db9739
Signed-off-by: Jin Wei <wei.a.jin@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Beare, Bruce J <bruce.j.beare@intel.com>
2012-05-09 09:52:22 -07:00
Ben Cheng
da0d8534f1 am 08b51e2c: Implement the "abort" stub in assembly for ARM.
* commit '08b51e2c091d036c124259ae59eb7be6bbe346af':
  Implement the "abort" stub in assembly for ARM.
2012-05-09 01:48:40 -07:00
Bjorn Andersson
0753dc653e pthread: Invalidate stale stack pointers on pthread_exit()
A call to pthread_key_delete() after pthread_exit() have unmapped the stack of a thread
but before the ongoing pthread_join() have finished executing will result in an access
to unmapped memory.
Avoid this by invalidating the stack_base and tls pointers during pthread_exit().

This is based on the investigation and proprosed solution by
Srinavasa Nagaraju <srinavasa.x.nagaraju@sonyericsson.com>

Change-Id: I145fb5d57930e91b00f1609d7b2cd16a55d5b3a9
2012-05-08 17:43:57 -07:00
Elliott Hughes
a4e84d285c am 9c3eca7b: resolved conflicts for merge of 6cf3c7c5 to jb-dev-plus-aosp
* commit '9c3eca7bcee694e6a477a7d50065f11cf1e805bb':
  Let pthread_create fail if schedparam can't be set
2012-05-08 15:13:20 -07:00
Ben Cheng
eda7be454d Implement the "abort" stub in assembly for ARM.
So that we can always get the full stack trace regardless of gcc's handling
of the "noreturn" attribute associated with abort().

(Cherry pick of Id264a5167e7cabbf11515fbc48f5469c527e34d4.)

Bug: 6455193

Conflicts:

	libc/Android.mk

Change-Id: I568fc5303fd1d747075ca933355f914122f94dac
2012-05-08 14:47:20 -07:00
Ben Cheng
08b51e2c09 Implement the "abort" stub in assembly for ARM.
So that we can always get the full stack trace regardless of gcc's handling
of the "noreturn" attribute associated with abort().

[cherry-picked from master]

BUG:6455193
Change-Id: I0102355f5bf20e636d3feab9d1424495f38e39e2
2012-05-08 14:39:35 -07:00
Ben Cheng
12cbf0605e Merge "Implement the "abort" stub in assembly for ARM." 2012-05-08 14:01:22 -07:00
Ben Cheng
017f438534 Implement the "abort" stub in assembly for ARM.
So that we can always get the full stack trace regardless of gcc's handling
of the "noreturn" attribute associated with abort().

BUG:6455193
Change-Id: Id264a5167e7cabbf11515fbc48f5469c527e34d4
2012-05-08 13:43:12 -07:00
Elliott Hughes
9c3eca7bce resolved conflicts for merge of 6cf3c7c5 to jb-dev-plus-aosp
Change-Id: Ib22a8ae1ef63bf9b9c82ce6e22afd188ba7c2806
2012-05-08 13:26:28 -07:00
Jack Ren
c47703a521 bionic/x86: Optimization for memcpy
Signed-off-by: Liubov Dmitrieva <liubov.dmitrieva@intel.com>
Signed-off-by: H.J. Lu <hongjiu.lu@intel.com>
Signed-off-by: Wei A Jin <wei.a.jin@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>

Conflicts:

	libc/arch-x86/string/ssse3-memcpy5.S

Change-Id: I41e70d1d19d5457e65c89b64da452fbdaf3a00a7
2012-05-08 12:18:25 -07:00
Nick Kralevich
5982e33aca Cherry-pick "generate PIC code".
Change-Id: I7d5f2e5663df263493f65e364c959e663fc4d13a
2012-05-08 11:53:28 -07:00
Elliott Hughes
2eef0ca111 am ff0d1ce4: am e3bc7192: Merge "bionic: fix integer overflows in chk_malloc(), leak_malloc(), and leak_memalign()"
* commit 'ff0d1ce4dfceb35a65440259c3f325106fc9e39b':
  bionic: fix integer overflows in chk_malloc(), leak_malloc(), and leak_memalign()
2012-05-08 11:32:58 -07:00
Elliott Hughes
9b25457498 am 53daf475: am 73a6566d: Merge "Remove expired dns cache entries before removing oldest"
* commit '53daf4757d36522c132006e2f74ed81bb4ed717a':
  Remove expired dns cache entries before removing oldest
2012-05-08 11:32:57 -07:00
Elliott Hughes
e34c7ffc57 am e636e1f2: am 8657eafc: Merge "Adjust memcpy for ARM Cortex A9 cache line size"
* commit 'e636e1f2c17d7097b6638cb4ae2b4857765b502d':
  Adjust memcpy for ARM Cortex A9 cache line size
2012-05-08 11:32:55 -07:00
Pierre Peiffer
d0c884d359 Let pthread_create fail if schedparam can't be set
The creation of a thread succeeds even if the requested scheduling
parameters can not be set. This is not POSIX compliant, and even
worse, it leads to a wrong behavior. Let pthread_create() fail in this
case.

Change-Id: Ice66e2a720975c6bde9fe86c2cf8f649533a169c
Signed-off-by: Christian Bejram <christian.bejram@stericsson.com>
2012-05-08 10:54:51 -07:00
Mattias Falk
a59cfcfd08 Avoid multiple dns lookups for the same query
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
2012-05-07 18:04:25 -07:00
Nick Kralevich
a2758f19ce libc: stop using the custom linker script
stop using the custom linker script. It prevents relro from
working on libc.

This reverts commit b091dd9bf2.
2012-05-07 14:33:32 -07:00
Elliott Hughes
ff0d1ce4df am e3bc7192: Merge "bionic: fix integer overflows in chk_malloc(), leak_malloc(), and leak_memalign()"
* commit 'e3bc7192ec4254bed00eb8b352735665c6072995':
  bionic: fix integer overflows in chk_malloc(), leak_malloc(), and leak_memalign()
2012-05-07 14:00:01 -07:00
Elliott Hughes
53daf4757d am 73a6566d: Merge "Remove expired dns cache entries before removing oldest"
* commit '73a6566da337db50cfc73c369d774ac1905a30c2':
  Remove expired dns cache entries before removing oldest
2012-05-07 13:59:59 -07:00
Elliott Hughes
e636e1f2c1 am 8657eafc: Merge "Adjust memcpy for ARM Cortex A9 cache line size"
* commit '8657eafc3552f36c176667c1591beab255308da6':
  Adjust memcpy for ARM Cortex A9 cache line size
2012-05-07 13:59:58 -07:00
Xi Wang
7f5aa4f35e bionic: fix integer overflows in chk_malloc(), leak_malloc(), and leak_memalign()
The allocation size in chk_malloc(), leak_malloc(), and leak_memalign()
functions may be rounded up to a small value, leading to buffer overflows.
The code only runs in debugging mode.

This patch complements commit 6f04a0f4 (CVE-2009-0607).

Change-Id: Id899bcd2bcd2ea2205e5753c433390710032dc83
Signed-off-by: Xi Wang <xi.wang@gmail.com>
2012-05-07 10:50:21 -07:00
Elliott Hughes
73a6566da3 Merge "Remove expired dns cache entries before removing oldest" 2012-05-07 10:41:53 -07:00
Henrik Smiding
fe6338da91 Adjust memcpy for ARM Cortex A9 cache line size
ARM Cortex A8 use 64 bytes and ARM Cortex A9 use 32 bytes cache line
size.

The following patch:
  Adds code to adjust memcpy cache line size to match A9 cache line
  size.
  Adds a flag to select between 32 bytes and 64 bytes cache line
  size.

  Copyright (C) ST-Ericsson SA 2010
    Modified neon implementation to fit Cortex A9 cache line size
    Author: Henrik Smiding henrik.smiding@stericsson.com for
            ST-Ericsson.

Change-Id: I8a55946bfb074e6ec0a14805ed65f73fcd0984a3
Signed-off-by: Christian Bejram <christian.bejram@stericsson.com>
2012-05-07 14:18:02 +02:00
Ken Sumrall
6baffed252 Add the posix_memalign(3) function to bionic
The posix_memalign(3) function is very similar to the traditional
memalign(3) function, but with better error reporting and a guarantee
that the memory it allocates can be freed.  In bionic, memalign(3)
allocated memory can be freed, so posix_memalign(3) is just a wrapper
around memalign(3).

Change-Id: I62ee908aa5ba6b887d8446a00d8298d080a6a299
2012-04-27 09:34:53 -07:00
Mike Lockwood
4fab6f901c am efcf8893: Merge "Update f_accessory.h kernel header" into jb-dev
* commit 'efcf8893a97df2eb2ecb7aab305998878771d2f2':
  Update f_accessory.h kernel header
2012-04-26 13:12:54 -07:00
Mike Lockwood
efcf8893a9 Merge "Update f_accessory.h kernel header" into jb-dev 2012-04-26 13:10:25 -07:00
Nick Kralevich
2cc0894992 am b091dd9b: libc: continue to use Android\'s custom linker script
* commit 'b091dd9bf27a9132c4ac9da55f2f4a87ffe3b59f':
  libc: continue to use Android's custom linker script
2012-04-26 11:58:48 -07:00
Nick Kralevich
b091dd9bf2 libc: continue to use Android's custom linker script
By default, Android no longer compiles code using it's custom
linker script /build/core/armelf.xsc. However, this causes
problems for libc. Certain programs linked using older versions
of GOLD expect libc.so to export __exidx_start and __exidx_end.
Removing the custom linker script causes libc.so not to export
those symbols.

For now, continue using the old linker script, until we can
figure out a better solution.

Change-Id: Iaf002afd63a58b848818da24e5a4525620dc4d74
2012-04-26 11:04:44 -07:00
Mike Lockwood
ed87404c44 Update f_accessory.h kernel header
Change-Id: I29ec4aa4843b9308cbfa412df88e026e8475b715
Signed-off-by: Mike Lockwood <lockwood@google.com>
2012-04-25 09:57:32 -07:00
Jean-Baptiste Queru
203aae7d79 Merge from AOSP
Change-Id: If2e8e4305d10df738cc4ebcf226077f273a48cbf
2012-04-25 09:29:40 -07:00
Raghu Gandham
e328ce6c55 [MIPS] Fix the warning originating from the kernel header signal.h.
This is a clean header generated from the corresponding change in
external/kernel-headers repository. (CL 35760)
2012-04-23 18:59:41 -07:00
Erik Gilling
baeacba04d add linux/sw_sync.h
Change-Id: I79de18d04b950c21b985d5ebc01cd3306a43d318
Signed-off-by: Erik Gilling <konkers@android.com>
2012-04-18 15:37:01 -07:00
Erik Gilling
6b99103c31 add linux/sync.h
Change-Id: I38bb9498e18cb2b2e84a97487d4ad1e15fabd9d4
Signed-off-by: Erik Gilling <konkers@android.com>
2012-04-18 14:23:04 -07:00
Evgeniy Stepanov
4a9d6e50bb Fix segv when unwinding stack past __libc_init.
This change mirrors cd15bac for statically-linked binaries.

Change-Id: Id870832a50b37f0ef3e79e1ed03ed31390bfc9ef
2012-04-18 12:59:38 +04:00
Elliott Hughes
f848321c4f resolved conflicts for merge of ef987656 to master
Change-Id: I3854de8f4cddaf344444efa6f9da027642a237d9
2012-04-16 14:26:43 -07:00
Elliott Hughes
8ecb4770a0 resolved conflicts for merge of 6b8fd054 to master
Change-Id: Ifc5a10d9c2f7764ad80d64cc552aad81d5fbf5eb
2012-04-16 14:16:42 -07:00
Elliott Hughes
8266cf94d3 am ff219e57: am 6435d27f: Merge "bionic: fix NULL parameter failure in getcwd()"
* commit 'ff219e57c0ffe5ac2816f79677ce4f1afa677277':
  bionic: fix NULL parameter failure in getcwd()
2012-04-16 13:15:13 -07:00
Elliott Hughes
4994deaef5 Merge "Bionic: Fix wrong prototype of system call clock_nanosleep" 2012-04-16 09:09:05 -07:00
Elliott Hughes
7b8666e683 Merge "bionic: Fix wrong prototype of system call getresuid/getresgid" 2012-04-16 09:06:22 -07:00
Jack Ren
d515ce465b Bionic: Fix wrong prototype of system call clock_nanosleep
In bionic/libc/SYSCALLS.TXT, the prototype of system call
clock_nanosleep is incorrect.

According to man page:
int clock_nanosleep(clockid_t clock_id, int flags,
                    const struct timespec *request,
                    struct timespec *remain);

Change-Id: Ic44c6db3d632293aa17998035554eacd664c2d57
Signed-off-by: Jin Wei <wei.a.jin@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2012-04-16 23:53:05 +08:00
Jack Ren
41070dd15f bionic: Fix wrong prototype of system call getresuid/getresgid
In bionic/libc/SYSCALLS.TXT, the prototypes of system call
getresuid/getresgid are incorrect.

According to man page, they should be:
    int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
    int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid);

Change-Id: I676098868bb05a9e1fe45419b234cf397626fdad
Signed-off-by: Jin Wei <wei.a.jin@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2012-04-16 23:45:36 +08:00
Jack Ren
e5bf068147 bionic: fix NULL parameter failure in getcwd()
LTP: getcwd01 failed in LTP

Need to check getcwd parameters, otherwise it will lead to
posix test case to fail.

Change-Id: Ieb673b6dd4ca6481da81c5339dbf7ec0a463f263
Signed-off-by: Jin Wei <wei.a.jin@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2012-04-16 23:35:05 +08:00
Kenny Root
a401160cee Merge changes I427a1881,I959b6428
* changes:
  Add faccessat to syscall list
  Update unistd.h for new syscalls
2012-04-13 16:03:51 -07:00
Kenny Root
f0ec06ba60 Add faccessat to syscall list
Change-Id: I427a18811089cb280769ac8da3ed8adc00a65a10
2012-04-13 15:45:42 -07:00
Kenny Root
e54cc75f59 Update unistd.h for new syscalls
gensyscalls.py run from external/kernel-headers at commit
efab8f3e49f7f36ef0354b0996ecd5f3fa031e52

Change-Id: I959b64280e184655ef8c713aa79f9e23cb1f7df4
2012-04-13 14:50:14 -07:00
Travis Geiselbrecht
8565e21f4d am 0613dce0: regenerate linux/fb.h
* commit '0613dce0a7b806d48758cabfb2d638d0ba4dd2bc':
  regenerate linux/fb.h
2012-04-12 16:09:29 -07:00
Travis Geiselbrecht
0613dce0a7 regenerate linux/fb.h
Change-Id: Icd8c0f53306a48ffd513378abdf387af21e886a3
2012-04-12 14:51:43 -07:00
Evgeniy Stepanov
1a78fbb5c8 Initialize TLS before any application code is run.
Since e19d702b8e, 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
2012-04-13 00:08:11 +04:00
Elliott Hughes
d5099016f7 Merge "Fix segv when unwinding stack past __libc_init." 2012-04-12 11:52:44 -07:00
Kenny Root
470835b215 Move end of __on_dlclose up
The END macro was put too far down which made the linker complain about
it. Move up to the end of the code.

Change-Id: Ica71a9c6083b437d2213c7cefe34b0083c78f16b
2012-04-11 14:24:28 -07:00
Kenny Root
03273f8fc0 __on_dlclose should be aligned
Marking segments read-only was pushing the alignment of __on_dlclose by
2 bytes making it unaligned. This change makes sure the ARM code is
aligned to the 4 byte boundary.

Bug: 6313309
Change-Id: Ic2bf475e120dd61225ec19e5d8a9a8b1d0b7f081
2012-04-10 17:53:11 -07:00
Evgeniy Stepanov
cd15bacf33 Fix segv when unwinding stack past __libc_init.
This change fixes a segmentation fault in the libc unwinder when it goes
past __libc_init.

Unwind instructions for __libc_init direct it to grab the return address from
the stack frame. Without this change, the unwinder gets a wild address and
looks up further unwind instructions for the routine at that address. If it's
unlucky enough to hit an existing function, it will try to unwind it. Bad
things happen then.

With this change, the return address always points to the _start function,
which does not have unwind instructions associated with it. This stop the
unwind process.

__libc_init never returns, so this does not affect program execution, other
than adding 4 bytes on the main thread stack.

Change-Id: Id58612172e8825c8729cccd081541a13bff96bd0
2012-04-10 16:45:54 +04:00
Jeff Brown
d09f5a2e01 Merge "Update linux/input.h to version 3.4." 2012-04-09 11:24:27 -07:00
Jeff Brown
0fdc190cc0 Update linux/input.h to version 3.4.
Bug: 6292993
Change-Id: Ic7628068df6c8de9cb3711a4540d51365b96ebdb
2012-04-06 19:25:25 -07:00
Dima Zavin
07a387e196 libc/kernel: update cleaned v4l2 header
Change-Id: Ib3747b45eb1e4095cca3de6d7692387953e8c4a7
Signed-off-by: Dima Zavin <dima@android.com>
2012-04-06 14:11:09 -07:00
Ashish Sharma
17ed54ddcf libc/kernel-headers: Auto generated files for netfilter/xt_IDLETIMER
From Change I526b5fce: Add NETLINK_IDLETIMER msg type and include the corresponding header file.

Change-Id: I24bffc11394c8664e4d7d7f439b0600545f07536
Signed-off-by: Ashish Sharma <ashishsharma@google.com>
2012-04-05 19:52:24 -07:00
Elliott Hughes
1302f6936b am fdb11929: am b88f810d: Merge "Update to tzdata2012c."
* commit 'fdb119297ac421e2fc2ec096a6d5370b81938de8':
  Update to tzdata2012c.
2012-04-02 16:09:36 -07:00
Elliott Hughes
8f78ddb422 Update to tzdata2012c.
From the release notes:

       africa
               Summer time changes for Morocco (to start late April 2012)

       asia
               Changes for 2012 for Gaza & the West Bank (Hebron) and Syria

       northamerica
               Haiti following US/Canada rules for 2012 (and we're assuming,
               for now anyway, for the future).

Also include a change made internally to the 'generate' script as part of
the tzdata2011m update that apparently never made it to AOSP; the original
checkin comment for which was:

    Update to tzdata2011m.

    Fixes for Europe/Tiraspol (Moldova) and all four Ukrainian zones.

    Also show the MD5 of the downloaded data, for comparison against the MD5
    given in the announcement mails. (There's a plan to move to proper signing,
    but that's not implemented on their end yet.)

(I'm repeating the tzdata change for the convenience of anyone grepping the
log, since the 2012 tzdata releases also contain the 2011m changes; 2011m
is the only missing release I noticed.)

Change-Id: I9a2e530b3a8ea88e3375334a12376e3d8526f267
2012-04-02 07:43:15 -07:00
Elliott Hughes
4e362f230b am cd834618: am 63b14755: Merge "libc/x86: ensure the stack 16-byte aligned when tasks created"
* commit 'cd834618c4752b61d54ff4005a8baa8219b822e4':
  libc/x86: ensure the stack 16-byte aligned when tasks created
2012-03-30 22:16:02 -07:00
Elliott Hughes
63b1475551 Merge "libc/x86: ensure the stack 16-byte aligned when tasks created" 2012-03-30 13:42:42 -07:00
Dima Zavin
ddb2f13549 Revert "libc/kernel: Add rules to autogenerate device specific kernel headers"
This reverts commit 884147c7d0.

Change-Id: I09723858ac961f3e1155791aa5c54d5d3abfbd36
Signed-off-by: Dima Zavin <dima@android.com>
2012-03-30 10:21:25 -07:00
Elliott Hughes
8fd682f7f2 am ea76f414: am d509f9cc: am 09ce7749: Merge "[MIPS] Clean Kernel headers are generated by running libc/kernel/tools/update_all.py script. This patch ignores any changes to libc/kernel directory not related to MIPS architecture."
* commit 'ea76f4147825cc39d9aa91230cd863ed29f28e27':
  [MIPS] Clean Kernel headers are generated by running libc/kernel/tools/update_all.py script. This patch ignores any changes to libc/kernel directory not related to MIPS architecture.
2012-03-27 17:58:57 -07:00
Elliott Hughes
d509f9ccbb am 09ce7749: Merge "[MIPS] Clean Kernel headers are generated by running libc/kernel/tools/update_all.py script. This patch ignores any changes to libc/kernel directory not related to MIPS architecture."
* commit '09ce7749d74733b28d4fa7a1d36457cb366cc5da':
  [MIPS] Clean Kernel headers are generated by running libc/kernel/tools/update_all.py script. This patch ignores any changes to libc/kernel directory not related to MIPS architecture.
2012-03-27 17:53:35 -07:00
Raghu Gandham
82fa43febc [MIPS] Clean Kernel headers are generated by running
libc/kernel/tools/update_all.py script. This patch ignores
any changes to libc/kernel directory not related to MIPS
architecture.

Change-Id: I2c9e461dccb7c33eb4420be2db1a562f45137c8d
Signed-off-by: Raghu Gandham <raghu@mips.com>
Signed-off-by: Chris Dearman <chris@mips.com>
2012-03-27 11:38:00 -07:00
Jean-Baptiste Queru
d7c6147eff am 56731351: Merge "bionic: fix atfork hanlder_mutex deadlock"
* commit '56731351de7230180fc99a1a4b0afd12f881b0f7':
  bionic: fix atfork hanlder_mutex deadlock
2012-03-26 18:25:43 -07:00
Benoit Goby
8491327448 Merge "Add auto-generated headers for USB FunctionFS" 2012-03-26 17:14:24 -07:00
Jean-Baptiste Queru
faca92f2f1 Handle pthread-related changes (mutex/atfork)
First commit:

Revert "Revert "am be741d47: am 2f460fbe: am 73b5cad9: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()"""

This reverts commit 06823da2f0.

Second commit:

bionic: fix atfork hanlder_mutex deadlock

This cherry-picks commit 34e89c232d

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: Jack Ren <jack.ren@intel.com>
Signed-off-by: Chenyang Du <chenyang.du@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>

Change-Id: Ic8072f366a877443a60fe215f3c00b3df5a259c8
2012-03-26 15:38:59 -07:00
Benoit Goby
2ab5bfd43f Add auto-generated headers for USB FunctionFS
linux/usb/ch9.h and linux/usb/functionfs.h

Change-Id: I2907081aba63b32740eb9916315759692a96ab42
2012-03-26 15:10:29 -07:00
Andrew Hsieh
126601dd3f Fixed to #include correct 32-bit headers; Refreshed libc/kernel headers
This patch fixes an issue where 64-bit hreaders are incorrectly included
in kernel headers.  For example, file "libc/kernel/arch-x86/asm/io.h"
incorreclty includes "io_64.h" (missing, BTW) instead of "io_32.h".

The reason is because CONFIG_X86_32 isn't considered pre-defined in
"kernel_default_arch_macros" for x86, and clean_header.py doesn't
look at it at all anyway (ie. __i386__ is also ignored, but it's
okay since x86 cross compiler defines it back)

Fixed 2 tools/*py, README.TXT, and refreshed libc/kernel headers

Change-Id: Iac834cc8b3548f055d3f2a214af36072dd679fe8
2012-03-23 23:07:36 +08:00
Jack Ren
cb08204053 libc/x86: ensure the stack 16-byte aligned when tasks created
Currently Renderscript sample code RsBalls crashed on x86 when SSE2
enabled. The root cause is that the stack was not 16-byte aligned
from the beginning when the processes/threads were created, so the
RsBalls crashed when SSE2 instructions tried to access the variables
on the stack.

- For the thread created by fork():
Its stack alignment is determined by crtbegin_{dynamic, static}.S

- For the thread created by pthread_create():
Its stack alignment is determined by clone.S. __thread_entry( ) is
a standard C function. In order to have its stack be aligned with
16 byte properly, __thread_entry() needs the stack with following
layout when it is called:
layout #1 (correct)
--------------
|            |
-------------- <--ESP (ECX - 20)
| ret EIP    |
-------------- <--ECX - 16
| arg0       |
-------------- <--ECX - 12
| arg1       |
-------------- <--ECX - 8
| arg2       |
-------------- <--ECX - 4
| unused     |
-------------- <--ECX (16-byte boundary)

But it has following layout for now:
layout #2: (incorrect)
--------------
|            |
-------------- <--ESP (ECX - 16)
| unused     |
-------------- <--ECX - 12
| arg0       |
-------------- <--ECX - 8
| arg1       |
-------------- <--ECX - 4
| arg2       |
-------------- <--ECX (16-byte boundary)

Fixed in this patch.

Change-Id: Ibe01f64db14be14033c505d854c73033556ddaa8
Signed-off-by: Michael Liao <michael.liao@intel.com>
Signed-off-by: H.J. Lu <hongjiu.lu@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2012-03-23 20:04:04 +08:00
Ben Cheng
eaae81082c Initialize mspace->least_addr properly in the mmap path.
BUG: 6206963
Change-Id: Id2ab580246de50a4511b56a734a7bece98fb945c
2012-03-21 15:47:12 -07:00
Nick Kralevich
891966d020 Merge "string.h: add __attribute__ ((pure)) to string functions" 2012-03-21 14:40:41 -07:00
Iliyan Malchev
1ca0b9d158 Merge "bionic: pass MADV_MERGEABLE on private & anonymous mmaps" 2012-03-21 13:51:42 -07:00
JP Abgrall
16a8fcce9f Merge "Update the libc kernel includes to support the newer mman for KSM support" 2012-03-21 13:43:10 -07:00
JP Abgrall
b8e1e9685e bionic: pass MADV_MERGEABLE on private & anonymous mmaps
Change-Id: I8bc167bb33dec6417fe772172697ea6ff97da2f6
Signed-off-by: Iliyan Malchev <malchev@google.com>
2012-03-21 13:21:33 -07:00
JP Abgrall
2f33c5a8e4 Update the libc kernel includes to support the newer mman for KSM support
These are generated from the matching external/kernel-headers/original
files (from kernel/samsung android-samsung-3.0-wip).

Change-Id: I982ff6a0d522ea250c3a437f5756766fcc6c5c91
2012-03-21 13:21:33 -07:00
Nick Kralevich
f082444291 Merge "fnmatch.c: Update to version in OpenBSD HEAD" 2012-03-21 10:07:55 -07:00
Nick Kralevich
d1860ad8dd fnmatch.c: Update to version in OpenBSD HEAD
Upgrade fnmatch.c from OpenBSD version 1.13 to 1.16.
This is needed primarily to address CVE-2011-0419.

This is a straight copy from upstream's version at
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/gen/fnmatch.c and
incorporates the following changes:

Revision 1.16:
New fnmatch(3) implementation which is not recursive.
Written and provided under BSD licence by William A. Rowe Jr.
Originally released in Apache APR-1.4.5.
Merged class matching code from r1.14 and PATH_MAX check from r1.15.
ok miod millert

Revision 1.15:
Put a limit on recursion during matching, and reject input of size greater
or equal PATH_MAX. Based on similar fix made in NetBSD.
ok miod@ millert@

Revision 1.14:
POSIX character class support for fnmatch(3) and glob(3).  OK deraadt@

Version 1.14 introduced charclasses.h, which we copy unmodified
from upstream version 1.1.
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/gen/charclass.h

Bug: 3435120
Change-Id: I45133468f0c3d439fd10eb087a1c647799f9d25b
2012-03-21 09:53:05 -07:00
Ben Cheng
e80f799d89 Merge "New additions/bug fixes required/found when porting perf." 2012-03-21 09:32:24 -07:00
Nick Kralevich
a677907ee8 string.h: add __attribute__ ((pure)) to string functions
cdefs.h: Introduce the __purefunc attribute, which allows us to mark
certain functions as being "pure".

http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

  Many functions have no effects except the return value and their
  return value depends only on the parameters and/or global variables.
  Such a function can be subject to common subexpression elimination
  and loop optimization just as an arithmetic operator would be.

string.h: Mark many commently used string functions as "pure", to
allow for additional compiler optimizations.

Change-Id: I42961f90f822b6dbcbc3fd72cdbe774a7adc8785
2012-03-21 08:54:54 -07:00
Dima Zavin
884147c7d0 libc/kernel: Add rules to autogenerate device specific kernel headers
This change will automatically post-process kernel headers
specified by device, board, and product. This will allow us
to not check in each kernel header twice, at least for the
device specific headers for now.

Change-Id: I3bb144b6535504b7c26b807daa75de495554356d
Signed-off-by: Dima Zavin <dima@android.com>
2012-03-20 15:28:34 -07:00
Ben Cheng
21eab513e7 New additions/bug fixes required/found when porting perf.
New functions:
	tfind
	tsearch
	tdelete
	twalk
	tdestroy (GNU extension)

Bug fix: the current implementation for realpath would crash
	if the second argument (resolved_path) is NULL.

New headers:
	ar.h
	search.h

Change-Id: Ib6c1e42fc186a6d597a6e5a9692b16acaa155804
2012-03-20 12:54:55 -07:00
Jack Ren
34e89c232d bionic: fix atfork hanlder_mutex deadlock
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: Jack Ren <jack.ren@intel.com>
Signed-off-by: Chenyang Du <chenyang.du@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2012-03-17 17:08:54 +08:00
Kenny Root
ad812ef2a4 Add in auto-generated if_alg.h header
Change-Id: I5d0934069e74be2eafecdee43074590124db57a7
2012-03-15 21:59:01 -07:00
Ben Cheng
adb6989786 Merge "Update kernel headers and add syscall "perf_event_open"" 2012-03-13 13:04:22 -07:00
Ben Cheng
1a823691a2 Update kernel headers and add syscall "perf_event_open"
Change-Id: I43f12b727881df002a8524f2738586c043833bae
2012-03-13 12:28:40 -07:00
Guang Zhu
06823da2f0 Revert "am be741d47: am 2f460fbe: am 73b5cad9: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()""
This reverts commit 76d56cf4a9, reversing
changes made to c59ba4595b.

Bug: 6157577
2012-03-12 22:05:36 -07:00
Elliott Hughes
76d56cf4a9 am be741d47: am 2f460fbe: am 73b5cad9: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()"
* commit 'be741d472868a8ffcb455588f18cda889b0f465c':
  bionic: Fix wrong kernel_id in pthread descriptor after fork()
2012-03-12 17:12:35 -07:00
Elliott Hughes
2f460fbee9 am 73b5cad9: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()"
* commit '73b5cad989da317cc8089b57ee25f502b1cac71f':
  bionic: Fix wrong kernel_id in pthread descriptor after fork()
2012-03-12 17:06:09 -07:00
Jack Ren
d8bc6e7119 bionic: Fix wrong kernel_id in pthread descriptor after fork()
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: Chenyang Du <chenyang.du@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2012-03-12 23:14:56 +08:00
Robert Greenwalt
c59ba4595b Use new binary code format
3-digits + null.  Old was 3-digits + space + null.

Change-Id: If5fdf9ced073f432ace3a76858025ad651c74e3d
2012-03-09 11:50:46 -08:00
Ben Cheng
654325de02 Update bionic kernel headers using update_all.py
Change-Id: I9c377436e9bf158e7236b3b7dcebf3e79fa961de
2012-03-07 21:13:49 -08:00
Selim Gurun
db6d20be77 Merge "Prevent potential stall on dns proxy operations." 2012-03-07 17:05:15 -08:00
Ben Cheng
4b29af0a1b Revert "Update bionic kernel headers using update_all.py"
This reverts commit 94a85f6636

There is a smoke test failure for Prime but Crespo/Stingray are fine. Will revert the change for now until further investigation is made.
2012-03-07 16:14:53 -08:00
Selim Gurun
06e1831f19 Prevent potential stall on dns proxy operations.
Update wire protocol to return and process error code first.
This will make sure dns proxy operations do not stall when
an internal error happens.
Also fix a compiler warning.
Also fix a potential buffer overflow.
And use correct types (uint32_t) rather than int when reading from network.

Change-Id: I9f99c16d6fd5e9137491a4d1b293a7c78e31b9c3
2012-03-07 15:09:05 -08:00
Ben Cheng
94a85f6636 Update bionic kernel headers using update_all.py
Change-Id: I4da6b23cdbce89445f1ca5d2fadeb23345ce694c
2012-03-07 12:27:59 -08:00
Nick Kralevich
d027ffdd7a Merge "Add relro support" 2012-03-06 11:31:59 -08:00
Nick Kralevich
9ec0f03a0d Add relro support
Add support for PT_GNU_RELRO. This allows the static linker to
indicate that certain regions of memory should be marked as
"read-only" after dynamic linking is complete.

See:
  * http://www.akkadia.org/drepper/nonselsec.pdf (section 6)
  * http://tk-blog.blogspot.com/2009/02/relro-not-so-well-known-memory.html

Note that this change has no effect on Android right now, because
we don't compile our code with relro enabled.

Change-Id: I6541f8775367e8558b4388f7d105b1ae6e8f046b
2012-03-05 16:44:42 -08:00
Kenny Root
4597687335 Merge "Revert "Reference __dso_handle in PIC way"" 2012-03-05 10:46:01 -08:00
Kenny Root
be101bf39a Revert "Reference __dso_handle in PIC way"
This reverts commit 93cb308137
2012-03-05 10:45:31 -08:00
Kenny Root
1fe109ecf3 Merge "Reference __dso_handle in PIC way" 2012-03-02 16:05:57 -08:00
Kenny Root
93cb308137 Reference __dso_handle in PIC way
Use the same pattern in atexit.S to reference __dso_handle in a way that
doesn't require a TEXTREL flag to be set.

Change-Id: Id69d20863ee203d2b2f7ef0db230f9b548657741
2012-03-02 13:09:36 -08:00
Elliott Hughes
079989259f am 6d074bb7: am 70d1d45f: am a58c88c2: Merge "Upgrade to tzdata2012b."
* commit '6d074bb71a316f73f35f4430a71fa706c46d4b75':
  Upgrade to tzdata2012b.
2012-03-02 11:13:05 -08:00
Elliott Hughes
70d1d45f0e am a58c88c2: Merge "Upgrade to tzdata2012b."
* commit 'a58c88c235bfeeb17ac495991e66f7b906935852':
  Upgrade to tzdata2012b.
2012-03-02 11:07:03 -08:00
Elliott Hughes
da16ad11fe am a2b1bbc9: am a480cf93: resolved conflicts for merge of cfe535ef to stage-aosp-master
* commit 'a2b1bbc9a605819eb5ecd1df61d4f2a79f1a8f92':
  Upgrade to tzdata2011a.
2012-03-02 10:49:45 -08:00
Elliott Hughes
a480cf930f resolved conflicts for merge of cfe535ef to stage-aosp-master
Change-Id: I21a1dd41503518e75892180c14f1ce79102772ad
2012-03-02 10:11:18 -08:00