625 Commits

Author SHA1 Message Date
Niklas Therning 3307974624 Allow thread local allocations from within pthread TLS destructors. This patch
prevents the GC_thread_key from being cleared on thread exit until after the
thread has been unregistered by GC_unregister_my_thread_inner().
2015-01-06 23:32:43 +01:00
Niklas Therning a583a080fd Initial support for iOS ARM64 (Aarch64) 2014-12-12 15:58:45 +01:00
Niklas Therning 53309c00eb Merge remote-tracking branch 'upstream/master'
Conflicts:
	darwin_stop_world.c
2014-12-11 11:37:30 +01:00
Ivan Maidanski 946796d0d5 Avoid explicit use of machine-specific x_THREAD_STATE macros (Darwin)
(code refactoring)

* include/private/gc_priv.h (GC_MACH_THREAD_STATE,
GC_MACH_THREAD_STATE_COUNT): Remove explicit definition to
PPC_THREAD_STATE[_COUNT], ARM_THREAD_STATE[_COUNT] (as the correct
values are defined via MACHINE_THREAD_STATE[_COUNT] macro).
2014-11-04 17:55:18 +03:00
Ivan Maidanski cdf0265336 Fix mistyped ARM_THREAD_STATE macro (Darwin/arm)
* include/private/gc_priv.h (GC_MACH_THREAD_STATE,
GC_MACH_THREAD_STATE_COUNT): Define to ARM_THREAD_STATE[_COUNT],
respectively, instead of mistyped ARM_MACHINE_THREAD_STATE[_COUNT]
(if DARWIN and ARM32).
2014-11-04 17:01:39 +03:00
Niklas Therning d42e7cc944 Renamed GC_apply_to_each_object() to GC_rvm_apply_to_each_object() and
GC_apply_to_each_live_object() to GC_rvm_apply_to_each_live_object() to avoid
conflict with the GC_apply_to_each_object() function in backgraph.c.
2014-10-26 17:44:42 +01:00
Niklas Therning 0699344a94 Merge branch 'thread_get_state_stack_corruption_on_ios7_64bit_and_ios8' 2014-10-26 16:31:04 +01:00
Ivan Maidanski 479b187e62 Fix missing msvc_dbg.h in dist_noinst_HEADERS (Automake)
* include/include.am (dist_noinst_HEADERS): Add msvc_dbg.h entry.
2014-10-21 10:31:11 +04:00
Yusuke Suzuki b725923951 Fix __alloc_size__ availability detection (Clang)
Since __clang_major__/__clang_minor__ etc. are vendor dependent values,
we cannot implement the feature detection based on it.
For example, Apple clang versioning is different from the FreeBSD clang.
(At this time, Apple clang version is "6.0 (clang-600.0.51)" and
__clang_major__ is 6.)
Instead of this, we can use the clang feature detection macro,
__has_attribute.

* include/gc_config_macros.h (GC_ATTR_ALLOC_SIZE): Replace predefined
__clang_major/minor__ testing with __has_attribute() one (in case of
clang).
2014-10-17 00:15:12 +04:00
Ivan Maidanski 734827bf66 Fix missing error handling of pthreads_mutex_init and cond_wait
* include/private/darwin_semaphore.h (sem_init): Destroy sem->mutex if
sem->cond initialization failed.
* include/private/darwin_semaphore.h (sem_post): Ignore
pthread_mutex_unlock result in case of pthread_cond_signal.
* include/private/darwin_semaphore.h (sem_wait): Unlock mutex and
return error (-1) if pthread_cond_wait failed.
* include/private/darwin_semaphore.h (sem_init): If pshared then
return -1 (with the appropriate errno code set) instead of ABORT.
* include/private/darwin_semaphore.h (sem_init, sem_post, sem_wait):
Treat non-zero value returned by pthread functions as error (instead
of only negative values).
* include/private/darwin_semaphore.h (sem_init, sem_post, sem_wait):
Reformat code.
* misc.c (GC_init): Abort (with the appropriate message) if
pthread_mutex[attr]_init failed (SN_TARGET_PS3 case only).
* specific.c (GC_key_create_inner): If pthread_mutex_init failed then
return its error code.
2014-09-27 20:03:20 +04:00
Ivan Maidanski 8fc1f3b61b Workaround 'unknown attribute __alloc_size__' warning for Clang 3.5 (trunk)
* include/gc_config_macros.h (GC_ATTR_ALLOC_SIZE): Define to empty if
clang 3.5.0 (workaround "unknown attribute '__alloc_size__' ignored"
warning in clang3.5 (trunk)).
2014-09-24 22:47:59 +04:00
Jan Alexander Steffens (heftig) 6927ee91a4 Also enable the TSX workaround for i386 (Linux)
* include/private/gcconfig.h (GLIBC_2_19_TSX_BUG): Define for
LINUX/I386 (if __GLIBC__).
2014-09-23 23:48:49 +04:00
Ivan Maidanski d0615e61c9 Fix setup_mark_lock missing prototype
(and do not call it if no parallel marker)

* include/private/pthread_support.h (GC_setup_mark_lock): Remove
prototype.
* misc.c (GC_init): Remove GC_setup_mark_lock call (move it to
GC_thr_init).
* pthread_support.c (setup_mark_lock): Rename from GC_setup_mark_lock;
add prototype (only if PARALLEL_MARK).
* pthread_support.c (GC_thr_init): Call setup_mark_lock() unless
available_markers_m1 is 0.
2014-09-23 23:20:08 +04:00
Niklas Therning 87a8c152ad Revert "Modified darwin_stop_world.c to use an arm_unified_thread_state_t struct to"
This reverts commit b45b5347a6.
2014-09-18 20:55:51 +02:00
Niklas Therning b45b5347a6 Modified darwin_stop_world.c to use an arm_unified_thread_state_t struct to
store a thread's state when compiling against the iOS 7/8 SDK. Without this
patch GC_stack_range_for() crashes when running a 32-bit app on iOS 64-bit.
The old code passed an arm_thread_state_t and ARM_THREAD_STATE to
thread_get_state(). ARM_THREAD_STATE is the same as ARM_UNIFIED_THREAD_STATE
on iOS 7/8 and thread_get_state() actually expects an
arm_unified_thread_state_t. On iOS 32-bit it looks like thread_get_state()
only touches the first bytes corresponding to the size of arm_thread_state_t
so no crash there. On iOS 64-bit however it seems thread_get_state() writes to
the full arm_unified_thread_state_t which meant it would overflow the stack
allocated struct passed to it and mess up other values on the stack leading to
a crash later on.
2014-09-17 18:09:55 +02:00
Niklas Therning dc388634fa Regenerated configure script. 2014-09-17 16:47:10 +02:00
Niklas Therning 2332fa0b83 Merge remote-tracking branch 'upstream/master'
Conflicts:
	.gitignore
2014-09-17 16:37:08 +02:00
Ivan Maidanski 3d342554dc Fix and code refactoring of lock elision workaround (Linux/x64)
* configure.ac (HAVE_LIBC_VERSION_H, HAVE_GNU_GET_LIBC_VERSION): Remove
(revert change in previous commit).
* include/private/gcconfig.h (GLIBC_2_19_TSX_BUG): New macro defined
for Linux/x86_64 (if Glibc used) to workaround a bug in Glibc lock
elision implementation.
* pthread_support.c: Move include of gnu/libc-version.h to gcconfig.h
(used to check whether lock elision workaround needed).
* misc.c (GC_init): Reformat code.
* pthread_support.c (mark_mutex): Initialize (to
PTHREAD_MUTEX_INITIALIZER) even lock elision workaround is needed
(revert change in previous commit).
* pthread_support.c (parse_version): New static function (defined only
if GLIBC_2_19_TSX_BUG).
* pthread_support.c (GC_setup_mark_lock): Use parse_version to check
target Glibc version properly; do not reinitialize mutex unless
workaround needed; call ABORT (with the appropriate message) in case
of a failure in pthread_mutexattr_init/settype, pthread_mutex_init.
2014-09-11 03:18:59 +04:00
Paul Bone f2b1938c21 Workaround Linux NTPL lock elision bug.
glibc 2.19 on Linux x86-64 platforms includes support for lock elision,
by using Intel's TSX support when it is available.  Without modifying an
application this converts suitable critical sections that use mutex into
transactional memory critical sections.  See http://lwn.net/Articles/534758/
If a problem occurs that means that transactional memory can't be used, such
as a system call or buffer overflow, the pthreads implementation will catch
this error and retry the critical section using a normal mutex.

I noticed that since upgrading glibc that programs using Boehm GC crash, one
of these crashes was an assertion that the owner field of a mutex was
invalid.  The assertion was generated by the pthreads implementation.
I believe that there is a bug in glibc that when a mutex cannot be used
safely for transactions that some series of events causes it's owner field
to be set incorrectly (or cleared when it shouldn't be).

I've found that I can work around this problem by having Boehm GC use an
error checking mutex, which I believe doesn't use lock elision and in my
testing doesn't crash.

XXX: This work-around mostly works except for linking the feature detection
in configure.ac to the conditional compilation in pthread_support.c as there
isn't an obvious way to make it work for automake and Makefile.direct.
Could I have some help updating the build system please?

include/private/pthread_support.h:
pthread_support.c:
    Define GC_setup_mark_lock()  This procedure creates the lock specifying a
    pthread_mutexattr_t structure.  This is used to disable lock elision on
    Linux with glibc 2.19 or greater.

configure.ac:
    If we're using Linux then check for the gnu extensions required to
    identify the version of glibc at runtime.

misc.c:
    Call GC_setup_mark_lock() when initialising the collector.
2014-09-11 03:18:28 +04:00
Manuel A. Fernandez Montecelo 5eed8647ea Fix getcontext usage on OpenRISC/or1k
* include/private/gcconfig.h (NO_GETCONTEXT): Do not use getcontext(2)
on OpenRISC 1000 (or1k) as it is not implemented yet.
2014-08-23 13:19:43 +04:00
Peter Wang 94b85eea2e Support winpthreads
Winpthreads is a different pthread implementation for MinGW-w64.
This patch redefines GC_WIN32_PTHREADS to mean either pthreads-win32
or winpthreads.

* configure.ac (GC_WIN32_PTHREADS): Improve description to cover
"winpthreads" library.
* doc/README.macros (GC_WIN32_PTHREADS): Likewise.
* doc/README.win32: Likewise.
* include/gc_config_macros.h (GC_WIN32_THREADS): Mention "winpthreads"
library in comment.
* win32_threads.c (GC_pthread_join): Likewise.
* include/private/gc_locks.h (NUMERIC_THREAD_ID, THREAD_EQUAL,
NUMERIC_THREAD_ID_UNIQUE): Define to support winpthreads properly (if
GC_WIN32_PTHREADS).
* win32_threads.c (GC_PTHREAD_PTRVAL): Likewise.
2014-08-23 12:48:37 +04:00
Niklas Therning 771fc48733 Added GC_apply_to_each_object() function. 2014-08-14 22:31:01 +02:00
Ivan Maidanski b41c6771a3 Fix pthreads-win32 name in comments and documentation
* configure.ac (GC_WIN32_PTHREADS): Fix pthreads-win32 name.
* doc/README.macros (GC_WIN32_PTHREADS): Likewise.
* doc/README.win32: Likewise.
* include/gc.h (GC_WIN32_THREADS): Likewise.
* include/gc_config_macros.h (GC_WIN32_PTHREADS): Likewise.
* include/private/gc_locks.h (NUMERIC_THREAD_ID): Likewise.
* win32_threads.c (GC_pthread_join): Likewise.
* doc/README.win32: Add information how to build for Win32 with
pthreads-win32 using configure.
* include/private/gc_locks.h (NUMERIC_THREAD_ID): Adjust comment
(capitalize 1st word of a sentence, add dot at sentence end).
* win32_threads.c (GC_pthread_join): Join adjacent GC_WIN32_PTHREADS
checks; refine comment about pthreads-win32 id.
2014-08-10 13:06:36 +04:00
Manuel A. Fernandez Montecelo 1bdcd768b0 Add support for OpenRISC/or1k
* include/private/gcconfig.h (OR1K, mach_type_known, CPP_WORDSZ,
MACH_TYPE, OS_TYPE, DYNAMIC_LOADING, _end, DATAEND, __data_start,
DATASTART, ALIGNMENT, HBLKSIZE, LINUX_STACKBOTTOM): Define for __or1k__.
2014-08-02 13:12:08 +04:00
Ivan Maidanski 4eaea0afad Code refactoring of Emscripten platform support (single-threaded)
* alloc.c (min_bytes_allocd): Test STACK_NOT_SCANNED macro instead
of __EMSCRIPTEN__ (stack size to scan is zero if STACK_NOT_SCANNED).
* include/private/gcconfig.h (ALIGNMENT): Remove duplicate definition
for _EMSCRIPTEN__.
* include/private/gcconfig.h (STACK_NOT_SCANNED): New macro defined
for __EMSCRIPTEN__ target (in addition to  OS_TYPE, CPP_WORDSZ,
ALIGNMENT, DATASTART, DATAEND).
* mach_dep.c (GC_push_regs): Test STACK_NOT_SCANNED macro instead
of __EMSCRIPTEN__ (push nothing if STACK_NOT_SCANNED).
* mark_rts.c (GC_push_roots): Test STACK_NOT_SCANNED macro instead
of __EMSCRIPTEN__ (do not call GC_push_regs_and_stack if
STACK_NOT_SCANNED); mark cold_gc_frame argument as potentially unused.
* misc.c (GC_clear_stack): Test STACK_NOT_SCANNED macro instead
of __EMSCRIPTEN__ (do not clear stack if STACK_NOT_SCANNED).
* misc.c (GC_clear_stack): Reformat code.
2014-07-13 12:29:48 +04:00