Commit graph

127 commits

Author SHA1 Message Date
Jack Ren
e480fc83b2 bionic: fix pthread_{create, exit}/signal race condition
(1) in pthread_create:
    If the one signal is received before esp is subtracted by 16 and
    __thread_entry( ) is called, the stack will be cleared by kernel
    when it tries to contruct the signal stack frame. That will cause
    that __thread_entry will get a wrong tls pointer from the stack
    which leads to the segment fault when trying to access tls content.

(2) in pthread_exit
    After pthread_exit called system call unmap(), its stack will be
    freed.  If one signal is received at that time, there is no stack
    available for it.

Fixed by subtracting the child's esp by 16 before the clone system
call and by blocking signal handling before pthread_exit is started.

Author: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-11-29 17:09:51 -08:00
Jack Ren
31e72bc328 bionic: fix __get_tls( ) crash issue
When running the stress test of pthread create/destroy, a crash may
oocur in __get_tls(). That is caused by the race condition with __set_tls( ):

Author: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-11-29 17:09:15 -08:00
David 'Digit' Turner
0fec6b9d88 libc: provide atomic operations will full barriers for NDK apps.
__atomic_cmpxchg and other related atomic operations did not
provide memory barriers, which can be a problem for non-platform
code that links against them when it runs on multi-core devices.

This patch does two things to fix this:

- It modifies the existing implementation of the functions
  that are exported by the C library to always provide
  full memory barriers. We need to keep them exported by
  the C library to prevent breaking existing application
  machine code.

- It also modifies <sys/atomics.h> to only export
  always-inlined versions of the functions, to ensure that
  any application code compiled against the new header will
  not rely on the platform version of the functions.

  This ensure that said machine code will run properly on
  all multi-core devices.

This is based on the GCC built-in sync primitives.

The end result should be only slightly slower than the
previous implementation.

Note that the platform code does not use these functions
at all. A previous patch completely removed their usage in
the pthread and libstdc++ code.

+ rename arch-arm/bionic/atomics_arm.S to futex_arm.S
+ rename arch-x86/bionic/atomics_x86.S to futex_x86.S
+ remove arch-x86/include/sys/atomics.h which already
  provided inlined functions to the x86 platform.

Change-Id: I752a594475090cf37fa926bb38209c2175dda539
2011-11-16 17:37:15 +01:00
David Turner
f5aa1382ec Merge "x86 libc: Fix the range to check the error" 2011-08-05 08:08:57 -07:00
Bruce Beare
3964084282 Enable functional DSO object destruction
Unfortunately, legacy .so files for ARM don't have a correct crtbegin file.
Consequently, we have to grandfather the old __dso_handle behaviour.
Add some ifdefs for ARM to allow it to use the old code until we can work
out a transition.

Change-Id: I6a28f368267d792c94e1d985d8344023bc632f6f
Author: H.J. Lu <hongjiu.lu@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-06-20 14:44:44 -07:00
Jun Nakajima
5288fee835 x86 libc: Fix the range to check the error
The spec says "A value in the range between -4095 to -1 indicates an error" (not -129).
This was pointed out in the comment in 22039.

Change-Id: I11b7c45015a9e4ccf09aed5364a889437eab6ab8
Signed-off-by: Jun Nakajima <jun.nakajima@intel.com>
2011-06-17 14:37:50 -07:00
Bruce Beare
e0b4844a20 x86: Enable -fstack-protector
Change-Id: Ib69514c3afcb4c1f5e5f3f8cd91acfd145a0866c
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-05-24 13:32:14 -07:00
Mark D Horn
dc3bc87b43 Update X86 Bionic CRT files for unwind/exceptions
Several updates to Bionic crt*.o files to implement Linux/x86
stack unwind/exception handling.
Mark __dso_handle as hidden.
Note: Requires complete rebuild due to CRT changes. Google will
need to regenerate and check-in all the prebuilt x86 CRT object
files and libraries which link to them.

Change-Id: I191ce1afb0dee7bbc28dcd9694e5919226dbd070
Signed-off-by: Bruce J Beare <bruce.j.beare@intel.com>
Signed-off-by: Mark D Horn <mark.d.horn@intel.com>
Author: Lu, Hongjiu <hongjiu.lu@intel.com>
2011-05-24 13:31:50 -07:00
Kan-Ru Chen
8488efaa09 x86 libc: fix the wrong return value of syscall
According to Intel ABI spec, there is no need to save %eax, %ecx, %edx
on the stack. Worse, popping %eax will wipe out the return value.

Change-Id: Ida536c3b98174b8deef88f8f3b9352eaaeb7c0c0
2011-03-29 13:16:42 +08:00
Bruce Beare
48e1feaa9d Updated gcc 4.4.3 IA toolchain doesn't require the .ctors list
Change-Id: Ia840a19a45257128eccdcf25d105f500f2d90741
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-02-16 17:50:23 -08:00
Bruce Beare
f4680b57ed Remove an extra register move.
Change-Id: I63c217b73203b44b1a2e74950b58f2ec12989cab
Author: H.J. Lu <hjl.tools@gmail.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-02-03 12:21:04 -08:00
Bruce Beare
0f2001b147 Replace __atomic_XXX with GCC __sync_XXX intrinsics.
Change-Id: I14f275392fcd70cc15e307470e0a099777c7c09e
Author: H.J. Lu <hjl.tools@gmail.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-02-03 12:21:03 -08:00
Chih-Wei Huang
18635d9c17 android-x86: add sigsetjmp.S
It adds two functions sigsetjmp and siglongjmp
that fix compiling errors in bluetooth and mksh.

Copy directly from sigsetjmp.S of OpenBSD.

Change-Id: I4696f82ee6f85d1c93cbdd3c9e40f4917d50f3a6
2010-12-26 09:22:13 -08:00
Bruce Beare
16984423bc Fix missing NL
Change-Id: Ic210fe9f740b9a8235a66d479ad4eddc869998bb
Signed-off-by: Bruce Beare <brucex.j.beare@intel.com>
2010-07-08 11:12:36 -07:00
David 'Digit' Turner
3b43f87d29 Allow dlclose() to properly call static C++ destructors.
With this patch _and_ an upcoming build/ patch, the destruction
of static C++ objects contained in shared libraries will happen
properly when dlclose() is called.

Note that this change introduces crtbegin_so.S and crtend_so.S which
are currently ignored by the build system.

+ move definition of __dso_handle to the right place
(before that, all shared libraries used the __dso_handle
global variable from the C library).

Note that we keep a 'weak' __dso_handle in aeabi.c to avoid
breaking the build until the next patch to build/core/combo/
appears. We will be able to remove that later.

+ move bionic/aeabi.c to arch-arm/bionic/ (its proper location)

NOTE: The NDK will need to be modified to enable this feature in
         the shared libraries that are generated through it.

Change-Id: I99cd801375bbaef0581175893d1aa0943211b9bc
2010-07-01 23:09:28 -07:00
The Android Open Source Project
377d4c979d merge from open-source master
Change-Id: I70266ee8c520b216773f267e46c8273d2334c31d
2010-03-22 15:55:09 -07:00
David 'Digit' Turner
88f06cd84a Use private futexes for pthread_mutex_t.
This does not change the implementation of conditional variables
since we're waiting for other system components to properly use
pthread_condattr_init/setpshared before that.

Also remove an obsolete x86 source file.

Change-Id: Ia3e3fbac35b87a534fb04d4381c3c66b975bc8f7
2010-03-18 17:13:41 -07:00
Fabrice Di Meglio
8641833b62 Revert "bionic: pthread: use private futexes by default for mutexes and condvars"
This reverts commit ba9c6f0989.
2010-03-11 14:47:47 -08:00
David 'Digit' Turner
ba9c6f0989 bionic: pthread: use private futexes by default for mutexes and condvars
Private futexes are a recent kernel addition: faster futexes that cannot be
shared between processes. This patch uses them by default, unless the PROCESS_SHARED
attribute flag is used when creating a mutex and/or conditional variable.

Also introduces pthread_condattr_init/destroy/setpshared/getpshared.

Change-Id: I3a0e2116f467072b046524cb5babc00e41057a53
2010-03-11 11:48:38 -08:00
Bruce Beare
3c543e1da9 x86 syscall system call implementation 2010-03-04 10:29:38 -08:00
David 'Digit' Turner
97cf7f3394 Implement clone() C library function properly.
Only provide an implementation for ARM at the moment, since
it requires specific assembly fragments (the standard syscall
stubs cannot be used because the child returns in a different
stack).
2010-01-25 11:18:30 -08:00
David 'Digit' Turner
3a654b1e04 Revert "Fix the C library initialization to avoid calling static C++ constructors twice."
This reverts commit 03eabfe65e.
2009-06-03 19:32:37 +02:00
David 'Digit' Turner
03eabfe65e Fix the C library initialization to avoid calling static C++ constructors twice.
The problem was due to the fact that, in the case of dynamic executables,
the dynamic linker calls the DT_PREINIT_ARRAY, DT_INIT and DT_INIT_ARRAY
constructors when loading shared libraries and dynamic executables,
*before* calling the executable's entry point (i.e. arch-$ARCH/bionic/crtbegin_dynamic.c)
which in turns call __libc_init() in libc.so, as defined by bionic/libc_init_dynamic.c

The latter did call these constructors array again, mistakenly.

The patch also updates the documentation of many related functions.

Also adds a new section to linker/README.TXT explaining restrictions on
C library usage.

The patch has been tested on a Dream for stability issues with
proprietary blobs:

- H264 decoding works
- Camera + Video recording works
- GPS works
- Sensors work

The tests in system/extra/tests/bionic/libc/common/test_static_cpp_mutex.cpp has been
run and shows the static C++ constructor being called only once.
2009-06-02 23:27:44 +02:00
The Android Open Source Project
1dc9e472e1 auto import from //depot/cupcake/@135843 2009-03-03 19:28:35 -08:00
The Android Open Source Project
1767f908af auto import from //depot/cupcake/@135843 2009-03-03 18:28:13 -08:00
The Android Open Source Project
4e468ed2eb Code drop from //branches/cupcake/...@124589 2008-12-17 18:03:48 -08:00
The Android Open Source Project
a27d2baa0c Initial Contribution 2008-10-21 07:00:00 -07:00