Fix possible file descriptor leaking

Original code returns w/o closing the file descriptor
Close the descriptors and free the direct object before
return to avoid leaking

original id of the change I09204a8e989d041a12d6a6a00d1138b958f68a8f

picked from:
https://android-review.googlesource.com/#/c/23191/
bionic: fixed the race condition in dlmalloc_usable_size()

Currently there is a race condition in dlmalloc_usage_size():
    if (cinuse(p))
      return chunksize(p) - overhead_for(p);
overhead_for(p) will return 2 bytes if p is mmaped, otherwise 1 byte.
\#define is_mmapped(p)\
  (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_MMAPPED_BIT))

If p is re-allocated by other thread and filled with data, then
(p)->head and (p)->prev_foot could be arbitary value and overhead_for(p)
could return a wrong value which leads to dlmalloc_usable_size() return
a wrong value eventually.

mspace_walk_heap() has the simliar issue.

Fixed them by adding protection to prevent p from re-allocated
when accessing (p)->head and (p)->prev_foot.

original id of the change is I4e3ea5cb2938aad1eef353cf6b661555a4ced44e
Signed-off-by: Fengwei Yin <fengwei.yin@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
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>
Revert "don't hide _nres, necessary for nslookup in busybox."

This reverts commit 0aa56a2ed38e470259b0fcbfc7ba4387149b81db.

Fixed in busybox : http://review.cyanogenmod.com/10762

should be reverted to keep aosp compatibility

Change-Id: I173f0a5cffd8f39ea70bee30a3490e04bbfabf19
videodev2: added V4L2_CID_CACHEABLE

Change-Id: Ia8b7b71034a7328deac9923ef2467e69dc5e4cb2
sreadahead: adding readahead system call into bionic libc

Add bionic libc to support readahead system call.
This is needed to enable sreadahead to work.

Change-Id: I3856e1a3833db82e6cf42fd34af7631bd40cc723
Author: Winson Yung <winson.w.yung@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Basic KSM Support
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 USE_MALLOC_ALIGNMENT in the BoardConfig.mk:
USE_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>
include <machine/cpu-features.h> in byteorder.h

Without including cpu-features.h, __ARM_ARCH__ is undefined.

Change-Id: Ie1e005a4263dfa55364f03d95449dc52516c5987
Add mlockall syscall
Bionic: x86: Fix libm macro definitions

http://code.google.com/p/android/issues/detail?id=19276

GCC would remove inline asm due to lack of knowledge
of FPU register changes.

Change-Id: I9f9e8623fa6580843b7cd8178439ace8c2db2d51
Signed-off-by: Mark D Horn <mark.d.horn@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Author: Jingwei Zhang <jingwei.zhang@intel.com>
Add MADV_MERGEABLE/MADV_UNMERGEABLE constants to
allow indicating memory blocks can be merged via KSM
bionic: Add msm_rotator.h

Add the msm_rotator header file to match the rotator driver header file
used on the msm7x30 target.

Change-Id: I208219e79c9ec5878c6078cb4cfb8b242a2f6a67
Signed-off-by: Evan McClain <aeroevan@gmail.com>
Rename msm_audio_7X30 -> msm_audio_7x30.

Change-Id: Ife311904bcabe5df51a7c2040e927e0d1bc4b620
Signed-off-by: Evan McClain <aeroevan@gmail.com>
linker: After lookup of symbol failed in all DT_NEEDED libs,
	use all loaded libs. This makes it possible to load some
	old libs, which do not directly link needed symbols, but indirectly.

Change-Id: Ida87fd7f2f76142de040cd0295815d8c6c4e068b
for froyo ... testing
Revert "linker: After lookup of symbol failed in all DT_NEEDED libs,"

This reverts commit 3ee4521993ebeac2bc3f7b257538139c8dc7f9f7.
Adding a timeout to tcp dns lookup connects.

TCP isn't supported on some dns servers, which makes the old code
hang forever.

NOT adding a stopship to remove debugging stuff - it was too painful
(14s timeout on failed tcp dns lookups) so we decided not to bother people.

bug:5766949
Change-Id: I381c20c3e11b8e994438d4f7c58ef643cd36554e
+ testing
Merge branch 'froyo' of https://github.com/voku/android_bionic into froyo

Conflicts:
	libc/arch-arm/syscalls/readahead.S