Ivan Maidanski [Sat, 30 Apr 2016 22:07:53 +0000 (01:07 +0300)]
Fix GC_new_kind in case of client-defined PREDEFINED_KINDS
There are 2 types of kinds - "pre-allocated" ones (with the number less
than PREDEFINED_KINDS) which have pre-allocated free lists and object
allocation for these kinds is dealt by GC_malloc_kind typically,
and "custom" kinds which require the client to supply the free list
(e.g., allocated by GC_new_free_list[_inner]) and arrange own object
allocation procedure.
By design, GC_new_kind[_inner] creates new "custom" kind.
* mark.c (GC_N_KINDS_INITIAL_VALUE): Simplify and comment out (for now).
* mark.c (GC_n_kinds): Initialize to PREDEFINED_KINDS (instead of
GC_N_KINDS_INITIAL_VALUE); add TODO item.
Ivan Maidanski [Tue, 5 Apr 2016 19:08:55 +0000 (22:08 +0300)]
Fix GC_REALLOC to call GC_FREE if new size is zero and pointer is non-NULL
* dbg_mlc.c (GC_debug_realloc): Call GC_debug_free (and return NULL)
if lb is zero and p is non-NULL.
* extra/AmigaOS.c (GC_amiga_realloc): Do not retry and do not call
WARN if new_size_in_bytes is zero.
* include/gc.h (GC_realloc): Refine comment (better document the cases
of NULL and/or zero arguments).
* mallocx.c (GC_realloc): Call GC_free (skip it if IGNORE_FREE) and
return NULL if lb is zero and p is non-NULL.
Ivan Maidanski [Fri, 18 Mar 2016 18:06:53 +0000 (21:06 +0300)]
Fix 'GC_generic_malloc_inner_ignore_off_page not used' compiler warning
(for GC_NO_FINALIZATION case)
* include/private/gc_priv.h (GC_generic_malloc_inner_ignore_off_page):
Do not declare unless DBG_HDRS_ALL or GC_GCJ_SUPPORT, or
!GC_NO_FINALIZATION.
* malloc.c (GC_generic_malloc_inner_ignore_off_page): Do not define
unless DBG_HDRS_ALL or GC_GCJ_SUPPORT, or !GC_NO_FINALIZATION.
Ivan Maidanski [Fri, 4 Mar 2016 22:11:05 +0000 (01:11 +0300)]
start_mark_threads refactoring regarding GC_markers_m1 update (Win32)
(Sync semantics around GC_markers_m1 with that of pthread_support.c.)
(fix commit 95947bd)
* win32_threads.c (GC_start_mark_threads_inner): Update GC_markers_m1
value to i just after loop creating the threads.
Hiroshi Yokota [Sat, 6 Feb 2016 01:25:48 +0000 (10:25 +0900)]
Fix user-defined signals drop by marker threads
When one user thread sets its own signal handler in multi-threaded
code, GC marker thread sometimes steal and drop user signal calls.
Because GC marker thread doesn't knows the user thread's signal
handler, and uses the default signal handler that ignores any signal
call. This becomes to drop the signal call.
This patch inhibits to accept signals by GC marker threads except
GC system signals, and don't drop user signal calls.
This patch comes from Gauche.
* include/private/gcconfig.h (NO_MARKER_SPECIAL_SIGMASK): New macro.
* pthread_support.c (GC_start_mark_threads_inner): Unless
NO_MARKER_SPECIAL_SIGMASK, call pthread_sigmask to block all signals
(except for the ones used for GC suspend/resume if any) before
starting marker threads and restore signals mask afterwards.
* win32_threads.c (GC_start_mark_threads_inner): Likewise.
Ivan Maidanski [Wed, 2 Mar 2016 07:20:28 +0000 (10:20 +0300)]
Fix 'CORD_iter5 unused result' code defect in cordxtra
* cord/cordxtra.c (CORD_fill_buf): Return CORD_iter5() result (instead
of void); update description comment.
* cord/cordxtra.c (CORD_to_char_star): Do not execute CORD_fill_buf()
if cord is empty (CORD_fill_buf returns 0 in case of empty cord);
check CORD_fill_buf result (abort in case of unexpected result).
Ivan Maidanski [Mon, 29 Feb 2016 21:07:07 +0000 (00:07 +0300)]
Fix unchecked pthread_join() result in threadkey_test
* tests/threadkey_test.c: Include stdio.h (unconditionally), stdlib.h
for fprintf() and exit().
* tests/threadkey_test.c (main): Abort in case of GC_pthread_join
failure.
Niklas Therning [Wed, 17 Feb 2016 13:16:01 +0000 (14:16 +0100)]
Skip GC_DS_PER_OBJECT objects with negative descriptor in GC_mark_from
Added a check in GC_mark_from() for GC_DS_PER_OBJECT objects with
negative descriptors to prevent mistaking the free list pointers in
free objects for being type descriptor pointers. If the specified
descriptor offset was larger than the object size this could lead to
arbitrary data from allocated objects being misinterpreted as
descriptors and the process crashing.
* mark.c (GC_mark_from): In case of GC_DS_PER_OBJECT, skip objects
those descriptor is outside object.
Ivan Maidanski [Wed, 17 Feb 2016 07:54:31 +0000 (10:54 +0300)]
Fix 'statement unreachable' compiler warning in GC_mark_from
* mark.c (GC_mark_from): Initialize 'limit' local variable
unconditionally; add static assertion on GC_DS_TAGS (to check that it
corresponds to number of switch cases); remove switch default (as it
cannot happen).
Ivan Maidanski [Wed, 17 Feb 2016 07:23:55 +0000 (10:23 +0300)]
Fix 'signed-to-bigger-unsigned value assignment' warning in GC_setpagesize
* include/private/gcconfig.h (GETPAGESIZE): Cast getpagesize() and
sysconf() result to unsigned int.
* tools/setjmp_t.c (main): Change type of "ps" local variable from
long to unsigned int.
Ivan Maidanski [Tue, 16 Feb 2016 20:34:43 +0000 (23:34 +0300)]
Fix 'signed-to-bigger-unsigned value assignment' warning for hb_map
* include/private/gc_priv.h (hblkhdr): Change type of hb_map from
short to unsigned short.
* include/private/gc_priv.h (_GC_arrays): Change type of _obj_map from
short to unsigned short.
* obj_map.c (GC_add_map_entry): Change type of new_map local variable
from short to unsigned short.
Ivan Maidanski [Mon, 15 Feb 2016 21:18:54 +0000 (00:18 +0300)]
Fix potential left shift overflows in finalize.c (64-bit targets)
* finalize.c (HASH2, GC_grow_table): Cast 1 to word before shift to
avoid overflow.
* finalize.c (GC_dump_finalization_links, GC_dump_finalization,
ITERATE_DL_HASHTBL_BEGIN, GC_finalize): Cast 1 to size_t before
shift to avoid overflow.
Ivan Maidanski [Fri, 12 Feb 2016 18:12:40 +0000 (21:12 +0300)]
Fix missing numeric casts in cord
* cord/cordprnt.c (CORD_vsprintf): Explicitly cast "prec" to unsigned
(to avoid assignment of a signed value to a variable of a bigger
unsigned integer type).
* cord/cordxtra.c (CORD_nul_func, CORD_chars): Cast between pointer
and char via GC_word (instead of long); explicitly cast char to
unsigned char (to avoid a signed value cast to a bigger unsigned one).
* cord/tests/de.c (replace_line): Explicitly cast COLS to unsigned
(when compared to "len" local variable).
Ivan Maidanski [Fri, 12 Feb 2016 16:49:31 +0000 (19:49 +0300)]
cord/de: Change main() declaration style from K-R to ANSI C
* cord/tests/de.c (main): Replace the K&R-style function definition
with the ANSI C one.
* cord/tests/de.c (main): Replace goto with a block.
* cord/tests/de.c (main): Replace exit(0) with return.
Ivan Maidanski [Fri, 12 Feb 2016 08:46:06 +0000 (11:46 +0300)]
Fix de_win WndProc prototype parameters for 64-bit (Win64)
* cord/tests/de_win.h (WndProc): Change UINT type (for wParam) to
WPARAM; change LONG type to LPARAM.
* cord/tests/de_win.h (AboutBox): Remove unused declaration.
Ivan Maidanski [Thu, 11 Feb 2016 21:22:44 +0000 (00:22 +0300)]
Fix null-pointer dereferences in case of out-of-memory in cord
* cord/cordprnt.c: Include <stdlib.h> (for abort() declaration).
* cord/cordprnt.c (OUT_OF_MEMORY): New macro.
* cord/tests/de.c (OUT_OF_MEMORY): Likewise.
* cord/cordprnt.c (CORD_vsprintf): Execute OUT_OF_MEMORY if
GC_MALLOC_ATOMIC returns NULL.
* cord/cordxtra.c (CORD_ec_flush_buf): Likewise.
* cord/tests/de.c (replace_line, main): Likewise.
* tests/cordtest.c (test_extras): Declare "u" local variable; do ABORT
if CORD_substr returns NULL (to avoid null pointer dereference in
strcmp).
* cord/tests/de_win.c (plain_chars, control_chars): Return NULL if
GC_MALLOC_ATOMIC returns NULL.
* cord/tests/de_win.c (WndProc): Execute de_error() (with the
appropriate message) if plain_chars() or control_chars() returned
NULL (and do not call the corresponding TextOutA in such a case).
Ivan Maidanski [Tue, 9 Feb 2016 20:35:33 +0000 (23:35 +0300)]
Fix null pointer dereference on out-of-memory in tests
* tests/disclaim_bench.c (main): Check GC_MALLOC result for NULL
(abort in case of out-of-memory) before dereference.
* tests/test.c (run_one_test): Likewise.
* tests/disclaim_test.c (pair_new): Move is_pair call (in my_assert)
down to be after GC_finalized_malloc result check for NULL.
Ivan Maidanski [Tue, 9 Feb 2016 06:51:22 +0000 (09:51 +0300)]
Workaround 'identical expr on both sides of bitwise op' warning
* gcj_mlc.c (GC_init_gcj_malloc): Comment out "0 |" (in the expression
of "0 | GC_DS_LENGTH").
* mark.c (GC_obj_kinds, GC_push_marked, GC_push_unconditionally):
Likewise.
Yuki Okumura [Tue, 2 Feb 2016 13:49:11 +0000 (22:49 +0900)]
Fix Cygwin64 build
On x86_64, Cygwin symbols do not have leading underscore anymore,
so an additional underscore is needed on linker-generated symbols
access from C.
* include/gc.h (GC_DATASTART, GC_DATAEND): Prefix _data_start__,
_bss_start__, _data_end__ and _bss_end__ with an extra underscore if
__x86_64__ (only if __CYGWIN__); reformat code.
Alessandro Bruni [Wed, 27 Jan 2016 21:03:49 +0000 (00:03 +0300)]
GC_malloc[_atomic] global and thread-local generalization with kind
* include/gc_inline.h (GC_malloc_kind, GC_malloc_kind_global): New
public function declaration.
* include/gc_inline.h (GC_MALLOC_WORDS_KIND): New public macro.
* include/gc_inline.h (GC_MALLOC_WORDS, GC_MALLOC_ATOMIC_WORDS): Use
GC_MALLOC_WORDS_KIND.
* include/gc_inline.h (GC_CONS): Use GC_malloc_kind (instead of
GC_malloc); reformat code.
* include/private/gc_priv.h (MAXOBJKINDS): Allow user-defined values.
* include/private/gc_priv.h (GC_core_malloc, GC_core_malloc_atomic):
Remove prototype.
* malloc.c: Include gc_inline.h (to get GC_malloc_kind prototype).
* mallocx.c: Likewise.
* malloc.c (GC_generic_malloc_inner,
GC_generic_malloc_inner_ignore_off_page, GC_generic_malloc): Add
assertion on "k" (kind) argument (should be less than MAXOBJKINDS).
* mallocx.c (GC_generic_malloc_ignore_off_page,
GC_generic_malloc_many): Likewise.
* malloc.c (GC_generic_malloc_uncollectable): Add assertion on "k"
argument (should be less than PREDEFINED_KINDS).
* malloc.c (GC_core_malloc_atomic, GC_core_malloc): Replace with
GC_malloc_kind_global.
* malloc.c (GC_malloc_atomic, GC_malloc): Define as a wrapper around
GC_malloc_kind_global.
* malloc.c (GC_malloc_kind): Redirect to GC_malloc_kind_global if
not defined in gc_inline.h (as a macro) or in thread_local_alloc.c.
* mallocx.c (GC_generic_or_special_malloc): Call GC_malloc_kind
instead of GC_malloc_kind and GC_malloc.
* thread_local_alloc.c (GC_malloc, GC_malloc_atomic): Replace with
GC_malloc_kind; remove tiny_fl local variable; call
GC_malloc_kind_global instead of GC_core_malloc and
GC_core_malloc_atomic.
* thread_local_alloc.c (GC_destroy_thread_local): Adjust static assert
to guard against global _freelists overrun.
Ivan Maidanski [Fri, 15 Jan 2016 09:48:06 +0000 (12:48 +0300)]
GC_malloc_[atomic_]uncollectable generalization
* include/gc_mark.h (GC_generic_malloc_uncollectable): New public
function declaration.
* malloc.c (GC_generic_malloc_uncollectable): New function
(imlementation mostly copied from GC_malloc_uncollectable).
* malloc.c (GC_malloc_uncollectable, GC_malloc_atomic_uncollectable,
calloc): Use GC_malloc_atomic_uncollectable.
* mallocx.c (GC_generic_or_special_malloc): Likewise.
* mallocx.c (GC_malloc_atomic_uncollectable): Move to malloc.c.
Alessandro Bruni [Tue, 12 Jan 2016 08:09:00 +0000 (11:09 +0300)]
Refactoring of thread-local *_freelists
(use single array to keep free lists except for GCJ and "finalized" kinds)
* include/private/thread_local_alloc.h (THREAD_FREELISTS_KINDS): New
macro.
* include/private/thread_local_alloc.h (thread_local_freelists):
Replace ptrfree_freelists and normal_freelists fields with
_freelists[]; define ptrfree_freelists and normal_freelists as macros
(they are used by some external clients, e.g., Mono).
* thread_local_alloc.c (GC_init_thread_local): Rename "i" local
variable to "j"; refine comment about zero-sized GCJ object; remove
loop unrolling (for zero index).
* thread_local_alloc.c (GC_init_thread_local, GC_destroy_thread_local,
GC_mark_thread_local_fls_for, GC_check_tls_for): Define "i" local
variable; replace ptrfree_freelists and normal_freelists with
_freelists[i].
Ivan Maidanski [Mon, 28 Dec 2015 17:24:33 +0000 (20:24 +0300)]
Fix undefined PTRFREE/NORMAL in gc_inline.h
Allow to use gc_inline.h public header without include gc_priv.h.
* include/gc_inline.h (GC_I_PTRFREE, GC_I_NORMAL): New macro.
* include/gc_inline.h (GC_FAST_MALLOC_GRANS, GC_MALLOC_WORDS,
GC_MALLOC_ATOMIC_WORDS, GC_CONS): Use GC_I_PTRFREE and GC_I_NORMAL
instead of PTRFREE and NORMAL (private macros), respectively.
Ivan Maidanski [Mon, 28 Dec 2015 15:34:57 +0000 (18:34 +0300)]
Allow GC_FAST_MALLOC_GRANS() multiple use in a function
Avoid goto statement in gc_inline.h public header (to fix
'duplicate label' compiler error in GC_FAST_MALLOC_GRANS if the macro
is used multiple times in a function).
* include/gc_inline.h (GC_FAST_MALLOC_GRANS): Replace goto with break
Ivan Maidanski [Mon, 28 Dec 2015 14:49:54 +0000 (17:49 +0300)]
Workaround 'comparison is always false' GCC warning in GC_FAST_MALLOC_GRANS
* include/gc_inline.h (GC_FAST_MALLOC_GRANS): Refactoring of condition
expression for entry containing counter or is NULL to avoid
"comparison of unsigned expression < 0 is always false" warning
reported by GCC.
Ivan Maidanski [Wed, 2 Dec 2015 21:08:02 +0000 (00:08 +0300)]
Remove references to missing linux_threads.c from documentation
* README.md (copyright): Change linux_threads.c to pthread_stop_world.c
and pthread_support.c files.
* doc/README.DGUX386: Remove reference to linux-threads.c file.
* doc/README.environment (GC_RETRY_SIGNALS, GC_NO_RETRY_SIGNALS):
Likewise.
* doc/gcdescr.html: Likewise.
* doc/README.DGUX386: Update information how to pass DEBUG_THREADS to
make.
* doc/gcdescr.html: Update threads support information for Irix and
Solaris.
* include/private/gc_locks.h: Remove reference to linux-threads.c in
a comment.
* pthread_support.c: Likewise.
Ivan Maidanski [Thu, 19 Nov 2015 22:22:39 +0000 (01:22 +0300)]
Remove 'sig' argument of GC_suspend_handler_inner
(Code refactoring)
* pthread_stop_world.c (GC_suspend_handler_inner): Rename "sig_arg"
argument to "dummy"; mark it as GC_ATTR_UNUSED.
* pthread_stop_world.c (GC_suspend_handler): Pass NULL instead of sig
to GC_suspend_handler_inner.
* pthread_stop_world.c (GC_suspend_handler): Move sig check from
GC_suspend_handler_inner.
Ivan Maidanski [Thu, 29 Oct 2015 21:08:44 +0000 (00:08 +0300)]
Do no declare kernel_id field of GC_Thread_Rep for 64-bit Android
* include/private/pthread_support.h (GC_Thread_Rep): Do not declare
kernel_id field unless USE_TKILL_ON_ANDROID (instead of
PLATFORM_ANDROID).
* pthread_support.c (GC_new_thread, GC_remove_all_threads_but_me): Do
not set kernel_id field unless USE_TKILL_ON_ANDROID.
Ivan Maidanski [Mon, 26 Oct 2015 05:25:54 +0000 (08:25 +0300)]
Check DATASTART is less than DATAEND even assertions off
* dyn_load.c (GC_register_dynamic_libraries_dl_iterate_phdr):
Abort with the appropriate message if DATASTART is NULL or greater than
DATAEND (same for DATASTART2 and DATAEND2).
* os_dep.c (GC_init_linux_data_start, GC_register_data_segments):
Likewise.
* os_dep.c (GC_init_linux_data_start, GC_register_data_segments):
Remove assertion about DATASTART and DATAEND.
* os_dep.c (GC_init_linux_data_start): Code refactoring.
Ivan Maidanski [Fri, 23 Oct 2015 09:24:21 +0000 (12:24 +0300)]
Workaround invalid '_end' symbol on Android clang 3.5+
* include/gc.h (GC_INIT_CONF_ROOTS): Handle Android clang (3.5-3.6)
case when "_end" symbol has incorrect address but "__end__" is defined
(by bfd linker only); declare "__end__" symbol as weak.
* include/private/gcconfig.h (DATAEND): Redefine for Android/clang;
define __end__ as weak symbol.
* os_dep.c (_end): Remove declaration (declared in gcconfig.h).
* os_dep.c (GC_init_linux_data_start): Define new local variable
(data_end); set it to DATAEND; use it instead of _end.
Ivan Maidanski [Wed, 21 Oct 2015 23:50:00 +0000 (02:50 +0300)]
Fix lock assert violation in GC_gcollect_inner if GC_ALWAYS_MULTITHREADED
* alloc.c (GC_expand_hp): Do not hold the allocation lock when calling
GC_init.
* malloc.c (GC_alloc_large, GC_generic_malloc_inner): Likewise.
* mallocx.c (GC_generic_malloc_many): Likewise.
* misc.c (GC_enable_incremental): Likewise.
* misc.c (GC_init): Surround GC_gcollect_inner call with LOCK/UNLOCK
(only if GC_ASSERTIONS and GC_ALWAYS_MULTITHREADED otherwise
redundant).
Ivan Maidanski [Tue, 20 Oct 2015 21:48:56 +0000 (00:48 +0300)]
Fix lock assertion violation in GC_new_thread if GC_ALWAYS_MULTITHREADED
* include/private/gc_priv.h (GC_start_mark_threads_inner): Define macro
(or declare function depending on CAN_HANDLE_FORK).
* misc.c (GC_init): Surround GC_thr_init call with LOCK/UNLOCK (only
if GC_ASSERTIONS and GC_ALWAYS_MULTITHREADED otherwise redundant);
call GC_start_mark_threads_inner (if PARALLEL_MARK).
* pthread_support.c (GC_mark_thread): Update comment.
* win32_threads.c (GC_mark_thread): Likewise.
* pthread_support.c (start_mark_threads): Remove macro (moved to
gc_priv.h); rename function to GC_start_mark_threads_inner; replace
"static" to GC_INNER; check assertion on GC_fl_builder_count only if
the markers should actually be started; move the check for disabled
parallel markers (available_markers_m1) from GC_thr_init (make it
unconditional).
* win32_threads.c (start_mark_threads): Likewise.
* win32_threads.c (GC_start_mark_threads_inner): Add assertion about
the lock status.
* pthread_support.c (GC_thr_init): Remove comment about expected lock
status; add assertion about holding the lock (duplicating that in
GC_new_thread); remove start_mark_threads call (moved to GC_init).
* win32_threads.c (GC_thr_init): Likewise.
Elijah Taylor [Thu, 31 Jan 2013 20:04:20 +0000 (12:04 -0800)]
NaCl runtime fixes
(Apply commit b328e88 from 'mono_libgc' branch.)
* fix compile/runtime issues caused by upstream changes
* add NaCl glibc support
* various changes to support running tests in NaCl glibc
from 'make check'