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>
libm: fix invalid result of function remquo/remquof

Currently we will get the wrong result as follows:
remquof(0x7bb33336, 0x63000000) = -671088640, 0x00000000
remquo(0xbff0000000000003, 0x3ff0000000000003) = 1, 0x8000000000000000
remquo(0x9120000000000001, 0x0000000000000005) = -1288490188, 0x0000000000000004
while the correct one should be:
remquof(0x7bb33336, 0x63000000) = 1476395008, 0x00000000
remquo(0xbff0000000000003, 0x3ff0000000000003) = -1, 0x8000000000000000
remquo(0x9120000000000001, 0x0000000000000005) = -1288490189, 0x0000000000000001

Fixed in this patch.

original id of the change: I540b348cd10a539f3b39b1753945c893c4c7ec46
Signed-off-by: Jingwei Zhang <jingwei.zhang@intel.com>
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>

picked from
https://android-review.googlesource.com/#/c/33341/

fix whitespaces
Prevent deadlock when using fork

When forking of a new process in bionic, it is critical that it
does not allocate any memory according to the comment in
java_lang_ProcessManager.c:
"Note: We cannot malloc() or free() after this point!
A no-longer-running thread may be holding on to the heap lock, and
an attempt to malloc() or free() would result in deadlock."
However, as fork is using standard lib calls when tracing it a bit,
they might allocate memory, and thus causing the deadlock.
This is a rewrite so that the function cpuacct_add, that fork calls,
will use system calls instead of standard lib calls.

Signed-off-by: christian bejram <christian.bejram@stericsson.com>

original identificator of the change is Iff22ea6b424ce9f9bf0ac8e9c76593f689e0cc86

picked from
https://android-review.googlesource.com/#/c/21627/
Redesign dlopen() locks to be recursive per thread
picked from
https://github.com/android/platform_bionic/commit/f9c5afb1f9d8e615ab98774a10bbf117962db66d
bm: cherry-pick one patch from freebsd to fix logb() denormals issue

picked from
https://github.com/android/platform_bionic/commit/9c9b0fc7e1dff39baa8cdf2536be9776aa4af766