Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CHERI extension #627

Open
ivmai opened this issue Mar 20, 2024 · 8 comments
Open

Support CHERI extension #627

ivmai opened this issue Mar 20, 2024 · 8 comments

Comments

@ivmai
Copy link
Owner

ivmai commented Mar 20, 2024

The purpose of this is not only support the protected mode but also better test bdwgc.

The patches in https://github.com/capablevms/bdwgc (master) should be useful.

Related issue: #461

ivmai added a commit that referenced this issue Mar 23, 2024
(refactoring)

Issue #627 (bdwgc).

* tests/huge.c (GC_WORD_MAX): Rename to SIZE_MAX; change its type from
GC_word to size_t.
* tests/huge.c (SIZE_MAX): Undefine it (before definition).
* tests/huge.c (GC_SWORD_MAX): Rename to U_SSIZE_MAX; change type from
GC_signed_word to size_t (unsigned).
* tests/huge.c (main): Rename GC_WORD_MAX to SIZE_MAX; rename
GC_SWORD_MAX to U_SSIZE_MAX.
ivmai added a commit that referenced this issue Mar 23, 2024
(refactoring)

Issue #627 (bdwgc).

Also, change sizeof(word) to sizeof(ptr_t) where PTR_ALIGN_DOWN/UP
macros are used.

* allchblk.c (find_nonbl_hblk): Change type of search_end local
variable from word to ptr_t.
* allchblk.c (find_nonbl_hblk): Use PTR_ALIGN_DOWN().
* dyn_load.c [HAVE_DL_ITERATE_PHDR && PT_GNU_RELRO && CPP_WORDSZ==64]
(GC_register_dynlib_callback): Likewise.
* dyn_load.c [ANY_MSWIN && !THREADS] (GC_cond_add_roots): Likewise.
* include/private/gc_priv.h (HBLKPTR, HBLK_PAGE_ALIGNED): Likewise.
* mark.c (GC_push_all, GC_custom_push_range, GC_push_all_eager,
GC_push_all_stack): Likewise.
* mark.c [!GC_DISABLE_INCREMENTAL] (GC_push_selected): Likewise.
* mark_rts.c (GC_add_roots_inner, GC_remove_roots_inner,
GC_exclude_static_roots): Likewise.
* misc.c [!ALWAYS_SMALL_CLEAR_STACK && !STACK_NOT_SCANNED]
(GC_clear_stack): Likewise.
* misc.c (GC_base): Likewise.
* os_dep.c [OPENBSD] (GC_skip_hole_openbsd): Likewise.
* os_dep.c [ANY_MSWIN && !CYGWIN32] (GC_get_stack_base): Likewise.
* os_dep.c [NEED_FIND_LIMIT || USE_PROC_FOR_LIBRARIES && THREADS]
(GC_find_limit_with_bound): Likewise.
* os_dep.c [HPUX_STACK_BOTTOM] (GC_get_register_stack_base): Likewise.
* os_dep.c [!ECOS && !NOSYS && !SYMBIAN && !EMSCRIPTEN && !AMIGA
&& !EMBOX && !HAIKU && !OS2 && !ANY_MSWIN && !GC_OPENBSD_THREADS
&& (!GC_SOLARIS_THREADS || _STRICT_STDC) && !STACKBOTTOM && HEURISTIC1
&& STACK_GROWS_UP] (GC_get_main_stack_base): Likewise.
* os_dep.c [MSWIN32] (GC_least_described_address): Likewise.
* dyn_load.c [HAVE_DL_ITERATE_PHDR && PT_GNU_RELRO && CPP_WORDSZ==64]
(GC_register_dynlib_callback): Change sizeof(word) to sizeof(ptr_t).
* mark.c (GC_push_all_eager, GC_push_all_stack): Likewise.
* mark_rts.c (GC_add_roots_inner, GC_remove_roots_inner,
GC_exclude_static_roots): Likewise.
* os_dep.c [!ANY_MSWIN && (SVR4 || AIX || DGUX) && !PCR]
(GC_SysVGetDataStart): Likewise.
* os_dep.c [DATASTART_USES_BSDGETDATASTART] (GC_FreeBSDGetDataStart):
Likewise.
* dyn_load.c [(SOLARISDL || LINUX) && !USE_PROC_FOR_LIBRARIES]
(GC_register_dynamic_libraries): Remove redundant parentheses.
* dyn_load.c [HAVE_DL_ITERATE_PHDR && PT_GNU_RELRO]
(GC_register_dynlib_callback): Use PTR_ALIGN_UP() instead of
PTRT_ROUNDUP_BY_MASK().
* include/private/gcconfig.h [M68K && LINUX && !__ELF__ || I386
&& (SEQUENT || HAIKU || SCO || LINUX && !__ELF__ || DJGPP) || MIPS
&& EWS4800 && _MIPS_SZPTR!=64 || M88K && CX_UX] (DATASTART): Likewise.
* include/private/gcconfig.h [MIPS && EWS4800 && _MIPS_SZPTR!=64]
(DATASTART2): Likewise.
* mark.c (GC_push_all, GC_custom_push_range, GC_push_all_eager,
GC_push_all_stack): Likewise.
* mark.c [!GC_DISABLE_INCREMENTAL] (GC_push_selected): Likewise.
* mark_rts.c (GC_add_roots_inner, GC_remove_roots_inner,
GC_exclude_static_roots): Likewise.
* os_dep.c [!ECOS && !NOSYS && !SYMBIAN && !EMSCRIPTEN && !AMIGA
&& !EMBOX && !HAIKU && !OS2 && !ANY_MSWIN && !GC_OPENBSD_THREADS
&& (!GC_SOLARIS_THREADS || _STRICT_STDC) && !STACKBOTTOM && HEURISTIC1
&& !STACK_GROWS_UP] (GC_get_main_stack_base): Likewise.
* os_dep.c [!ANY_MSWIN && (SVR4 || AIX || DGUX) && !PCR]
(GC_SysVGetDataStart): Likewise.
* os_dep.c [DATASTART_USES_BSDGETDATASTART] (GC_FreeBSDGetDataStart):
Likewise.
* os_dep.c [MMAP_SUPPORTED && !MSWIN_XBOX1] (GC_unix_mmap_get_mem):
Likewise.
* os_dep.c [!MSWIN_XBOX1 && !MSWINCE && USE_WINALLOC && MSWIN32
&& !MSWINRT_FLAVOR] (GC_win32_get_mem): Likewise.
* os_dep.c [USE_MUNMAP] (GC_unmap_start): Likewise.
* os_dep.c [MPROTECT_VDB && DONT_PROTECT_PTRFREE] (GC_protect_heap):
Likewise.
* os_dep.c [PROC_VDB] (GC_proc_read_dirty): Likewise.
* os_dep.c [MPROTECT_VDB] (GC_remove_protection): Likewise.
* dyn_load.c [ANY_MSWIN] (GC_cond_add_roots): Change type of base and
limit arguments from char* to ptr_t.
* dyn_load.c [ANY_MSWIN && !THREADS] (GC_cond_add_roots): Change type
of stack_top local variable from char* to ptr_t.
* dyn_load.c [ANY_MSWIN] (GC_register_dynamic_libraries): Change type
of p local variable from PVOID to ptr_t; change type of base, limit,
new_limit local variables from char* to ptr_t.
* dyn_load.c [ANY_MSWIN && MSWINCE] (GC_register_dynamic_libraries):
Use PTR_ALIGN_UP().
* include/private/gcconfig.h (PTR_ALIGN_DOWN): New macro.
* include/private/gcconfig.h (PTRT_ROUNDUP_BY_MASK): Define
PTR_ALIGN_UP() macro instead.
* mark.c (GC_push_all_eager, GC_push_all_stack): Change type of lim
local variable from word* to ptr_t.
* misc.c (GC_base): Declare limit and sz local variables at the
beginning of the function.
* os_dep.c [OPENBSD] (GC_skip_hole_openbsd): Change type of pgsz local
variable from word to size_t.
ivmai added a commit that referenced this issue Mar 23, 2024
(refactoring)

Issue #627 (bdwgc).

* tests/gctest.c (small_cons_uncollectable): Use GC_HIDE_POINTER().
* tests/gctest.c (UNCOLLECTABLE_CDR): Use GC_REVEAL_POINTER().
ivmai added a commit that referenced this issue Apr 15, 2024
(refactoring)

Issue #627 (bdwgc).

* include/private/gc_priv.h (COOLER_THAN): Remove.
* include/private/gc_priv.h (HOTTER_THAN): Change macro to have two
arguments; add comment.
* include/private/gc_priv.h (MAKE_HOTTER): Rename x,y arguments to p,d.
* include/private/gc_priv.h [!THREADS] (GC_is_static_root): Change type
of argument from void* to ptr_t.
* mark_rts.c [!THREADS] (GC_is_static_root): Likewise.
* ptr_chck.c [!THREADS] (GC_on_stack): Likewise.
* mark_rts.c [THREADS] (GC_push_all_stack_sections): Update condition
according to MAKE_HOTTER defintion change.
* mark_rts.c [!THREADS] (GC_push_all_stack_part_eager_sections):
Likewise.
* misc.c [!ALWAYS_SMALL_CLEAR_STACK && !STACK_NOT_SCANNED
&& !ASM_CLEAR_CODE && !THREADS] (GC_clear_stack_inner): Likewise.
* misc.c [!THREADS] (GC_init, GC_call_with_gc_active): Likewise.
* os_dep.c [!ECOS && !NOSYS && !SYMBIAN && EMSCRIPTEN && !AMIGA
&& !EMBOX && !HAIKU && !OS2 && !ANY_MSWIN && !GC_OPENBSD_THREADS
&& (!GC_SOLARIS_THREADS || _STRICT_STDC) && !CPPCHECK]
(GC_get_main_stack_base): Likewise.
* os_dep.c [GC_DARWIN_THREADS && !NO_PTHREAD_GET_STACKADDR_NP
|| GC_SOLARIS_THREADS && !_STRICT_STDC || !GET_MAIN_STACKBASE_SPECIAL]
(GC_get_stack_base): Likewise.
* os_dep.c [NEED_CALLINFO && SAVE_CALL_CHAIN && !(NARGS==0
&& NFRAMES%2==0 && GC_HAVE_BUILTIN_BACKTRACE) && (I386 || SPARC)]
(GC_save_callers): Likewise.
* pthread_support.c (GC_call_with_gc_active): Likewise.
* ptr_chck.c [!THREADS] (GC_on_stack): Likewise.
* win32_threads.c [!WOW64_THREAD_CONTEXT_WORKAROUND]
(GC_push_stack_for): Likewise.
ivmai added a commit that referenced this issue Apr 15, 2024
…tr_t

(refactoring)

Issue #627 (bdwgc).

* backgraph.c (add_back_edges): Rename current local variable to q.
* mark.c (GC_mark_from): Likewise.
* typd_mlc.c (GC_typed_mark_proc): Likewise.
* backgraph.c (add_back_edges): Change type of q local variable from
word to ptr_t.
* finalize.c (GC_ignore_self_finalize_mark_proc): Likewise.
* mark.c (GC_mark_from): Likewise.
* mark.c [WRAP_MARK_SOME && PARALLEL_MARK] (GC_push_conditional_eager):
Likewise.
* typd_mlc.c (GC_typed_mark_proc): Likewise.
* include/private/gc_pmark.h (GC_mark_and_push_stack): Do not case p
argument to ptr_t.
* include/private/gc_pmark.h (GC_PUSH_ONE_STACK, GC_PUSH_ONE_HEAP):
Cast p argument to word.
* include/private/gc_pmark.h [NEED_FIXUP_POINTER] (GC_PUSH_ONE_STACK):
Change type of pp local variable from word to ptr_t.
* include/private/gc_priv.h [E2K && __ptr64__] (LOAD_TAGGED_VALUE):
Change type of val local variable from word to ptr_t.
* include/private/gc_priv.h [!E2K] (LOAD_TAGGED_VALUE): Cast p argument
to ptr_t* instead of word*.
* include/private/gcconfig.h [!FIXUP_POINTER && (DYNAMIC_POINTER_MASK
|| POINTER_MASK)] (FIXUP_POINTER): Expect p argument is of ptr_t type
(instead of word); add comment.
* mark.c [!SMALL_CONFIG && !USE_PTR_HWTAG] (GC_mark_from): Change type
of deferred local variable from word to ptr_t.
* mark.c [AMIGA || MACOS || GC_DARWIN_THREADS] (GC_push_one): Cast p
argument to ptr_t.
* mark.c [GC_WIN32_THREADS] (GC_push_many_regs): Cast regs[i] to ptr_t.
* mark.c [!SMALL_CONFIG && !USE_MARK_BYTES && !MARK_BIT_PER_OBJ]
(PUSH_GRANULE): Change type of qcontents from word to ptr_t.
* mark.c [USE_PUSH_MARKED_ACCELERATORS] (GC_push_marked1): Change type
of p, plim, q from word* to ptr_t*; cast h to ptr_t instead of word;
adjust code indentation (and reformat comment).
* mark.c [USE_PUSH_MARKED_ACCELERATORS && !UNALIGNED_PTRS]
(GC_push_marked2): Likewise.
* mark.c [USE_PUSH_MARKED_ACCELERATORS && !UNALIGNED_PTRS
&& GC_GRANULE_WORDS<4] (GC_push_marked4): Likewise.
ivmai added a commit that referenced this issue Apr 15, 2024
(refactoring)

Issue #627 (bdwgc).

Also, for gcc (and clang), do not cast pointers to words in relative
comparisons.

* allchblk.c (GC_dump_regions, find_nonbl_hblk, drop_hblk_in_chunks):
Use ADDR_LT() and ADDR_GE().
* alloc.c (GC_add_to_heap, GC_print_heap_sects,
GC_scratch_recycle_inner, GC_expand_hp_inner): Likewise.
* backgraph.c (ensure_struct, add_back_edges): Likewise.
* blacklst.c (GC_number_stack_black_listed): Likewise.
* checksums.c (GC_checksum, GC_check_dirty): Likewise.
* darwin_stop_world.c (GC_stack_range_for, GC_push_all_stacks):
Likewise.
* dbg_mlc.c (GC_get_back_ptr_info, GC_print_smashed_obj,
GC_check_heap_block): Likewise.
* dyn_load.c [USE_PROC_FOR_LIBRARIES] (sort_heap_sects): Likewise.
* dyn_load.c (GC_register_map_entries, GC_register_dynlib_callback,
GC_register_dynamic_libraries_dl_iterate_phdr): Likewise.
* dyn_load.c [ANY_MSWIN] (GC_cond_add_roots): Likewise.
* finalize.c (GC_ignore_self_finalize_mark_proc): Likewise.
* headers.c (GC_scratch_alloc, GC_install_counts, GC_remove_counts):
Likewise.
* include/private/gc_pmark.h (GC_PUSH_ONE_STACK, GC_PUSH_ONE_HEAP,
GC_mark_stack_empty): Likewise.
* include/private/gc_priv.h (HOTTER_THAN): Likewise.
* malloc.c (GC_malloc_kind_aligned_global): Likewise.
* mark.c (GC_mark_some_inner, GC_mark_from, GC_steal_mark_stack,
GC_return_mark_stack, GC_do_local_mark, GC_mark_local, GC_push_all,
GC_custom_push_range, GC_custom_push_proc, GC_push_proc,
GC_push_all_eager, GC_push_all_stack, GC_push_marked2, GC_push_marked4,
GC_push_marked, GC_push_unconditionally, GC_block_was_dirty): Likewise.
* mark_rts.c (GC_add_roots_inner, GC_add_roots_inner,
GC_remove_roots, GC_remove_roots_inner, GC_next_exclusion,
GC_exclude_static_roots_inner, GC_push_conditional_with_exclusions,
GC_push_current_stack): Likewise.
* misc.c (GC_base): Likewise.
* new_hblk.c (GC_build_fl_clear2, GC_build_fl_clear4, GC_build_fl2,
GC_build_fl4, GC_build_fl): Likewise.
* os_dep.c (GC_text_mapping, GC_init_linux_data_start, tiny_sbrk,
GC_skip_hole_openbsd, GC_find_limit_with_bound,
GC_least_described_address, GC_register_root_section,
GC_FreeBSDGetDataStart, GC_register_data_segments, GC_unmap_start,
GC_gww_read_dirty, GC_protect_heap, GC_proc_read_dirty,
soft_set_grungy_pages, GC_remove_protection, GC_print_callers):
Likewise.
* pthread_stop_world.c (GC_push_all_stacks): Likewise.
* pthread_support.c [USE_PROC_FOR_LIBRARIES]
(GC_segment_is_thread_stack): Likewise.
* pthread_support.c [(HAVE_PTHREAD_ATTR_GET_NP
|| HAVE_PTHREAD_GETATTR_NP) && IA64] (GC_greatest_stack_base_below):
Likewise.
* ptr_chck.c (GC_same_obj, GC_is_valid_displacement): Likewise.
* typd_mlc.c (GC_typed_mark_proc): Likewise.
* win32_threads.c (GC_push_stack_for): Likewise.
* alloc.c (GC_add_to_heap): Rename p argument to h; update comment;
change type of endp, hs_start, hs_end local variables from word to
ptr_t.
* alloc.c [GC_ASSERTIONS] (GC_add_to_heap): Use ADDR_INSIDE().
* dyn_load.c (GC_register_dynlib_callback): Likewise.
* malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER] (malloc,
free): Likewise.
* mark.c (GC_mark_from): Likewise.
* mark_rts.c (GC_is_static_root, GC_remove_roots_inner): Likewise.
* os_dep.c (GC_enclosing_writable_mapping, GC_page_was_dirty,
GC_remove_protection): Likewise.
* pthread_support.c [USE_PROC_FOR_LIBRARIES && STACK_GROWS_UP]
(GC_segment_is_thread_stack): Likewise.
* ptr_chck.c (GC_same_obj): Likewise.
* win32_threads.c (GC_push_stack_for): Likewise.
* blacklst.c (GC_unpromote_black_lists, GC_add_to_black_list_stack,
GC_is_black_listed, GC_number_stack_black_listed): Remove unneeded cast
of PHT_HASH() argument.
* checksums.c (GC_checksum): Change while() loop to for() one.
* checksums.c (GC_check_dirty): Remove goto label.
* ptr_chck.c (GC_same_obj, GC_is_valid_displacement): Likewise.
* dbg_mlc.c (GC_check_heap_block): Change type of p, plim local
variables from char* to ptr_t.
* dyn_load.c [ANY_MSWIN] (GC_cond_add_roots): Change type of curr_base,
next_stack_lo, next_stack_hi local variables from char* to ptr_t.
* include/gc/gc.h (GC_ADDR_LT): New public macro.
* include/gc/gc.h [__GNUC__] (GC_ADDR_LT): Do not cast arguments to
GC_word.
* include/gc/gc.h [__CYGWIN32__ || __CYGWIN__] (GC_DATASTART,
GC_DATAEND): Use GC_ADDR_LT().
* include/gc/gc_mark.h (GC_MARK_AND_PUSH): Likewise.
* tests/gctest.c [!VERY_SMALL_CONFIG] (cons): Likewise.
* include/private/gc_priv.h (ADDR_LT, ADDR_GE, ADDR_INSIDE): New macro.
* include/private/gc_priv.h (_GC_arrays._least_real_heap_addr,
_GC_arrays._greatest_real_heap_addr): Change type from word to ptr_t.
* include/private/gc_priv.h (endGC_arrays): Use beginGC_arrays.
* include/private/gc_priv.h (GC_exclude_static_roots_inner): Use ptr_t
instead of char* type for arguments.
* include/private/gc_priv.h [GC_WIN32_THREADS] (GC_get_next_stack):
Likewise.
* win32_threads.c (GC_get_next_stack): Likewise.
* include/private/gc_priv.h [GC_WIN32_THREADS] (GC_get_next_stack):
Move comment from win32_threads.c.
* mark.c [ENABLE_TRACE] (GC_mark_from): Declare base local variable to
avoid computing GC_base() twice.
* mark_rts.c (GC_exclude_static_roots_inner): Change type of arguments
from void* to ptr_t.
* mark_rts.c (GC_push_conditional_with_exclusions): Change code to
avoid assignment inside a conditional expression.
* os_dep.c [ECOS] (ecos_gc_brk): Change type from char* to ptr_t.
* os_dep.c [MSWIN32] (GC_least_described_address): Change type of
limit, q local variables from LPVOID to ptr_t.
* os_dep.c [MSWIN32] (GC_register_root_section): Change type of p,
base, limit local variables from LPVOID and char* to ptr_t.
* os_dep.c [GWW_VDB] (GC_gww_read_dirty): Change type of h_end local
variable from struct hblk* to ptr_t.
* os_dep.c [!GC_DISABLE_INCREMENTAL] (GC_remove_protection): Likewise.
* os_dep.c [MPROTECT_VDB] (GC_protect_heap): Change type of limit local
variable from struct hblk* to ptr_t.
* os_dep.c [SOFT_VDB] (soft_set_grungy_pages): Change type of vaddr,
limit_buf, next_vaddr local variables from word to ptr_t.
* pthread_support.c (ADDR_INSIDE_OBJ): New macro.
* pthread_support.c [GC_ASSERTIONS && THREAD_LOCAL_ALLOC]
(GC_is_thread_tsd_valid): Use ADDR_INSIDE_OBJ().
* pthread_support.c [USE_PROC_FOR_LIBRARIES]
(GC_segment_is_thread_stack): Replace crtn local variable to stack_end.
* pthread_support.c [(HAVE_PTHREAD_ATTR_GET_NP
|| HAVE_PTHREAD_GETATTR_NP) && IA64] (GC_greatest_stack_base_below):
Likewise.
* win32_threads.c (GC_get_next_stack): Change type of current_min local
variable from char* to ptr_t.
ivmai added a commit that referenced this issue Apr 15, 2024
…ze_t

Issue #627 (bdwgc).

* include/gc/gc.h [GC_THREADS] (GC_register_altstack): Change type of
normstack_size and altstack_size arguments from GC_word to size_t.
* pthread_support.c [!GC_WIN32_THREADS] (GC_register_altstack):
Likewise.
* include/private/pthread_support.h [!GC_WIN32_THREADS]
(GC_StackContext_Rep): Reorder normstack and altstack_size fields.
* include/private/pthread_support.h [!GC_WIN32_THREADS]
(GC_StackContext_Rep.altstack_size, GC_StackContext_Rep.normstack):
Change type from word to size_t.
ivmai added a commit that referenced this issue Apr 15, 2024
…pages

(fix of commit e37ab2a)

Issue #627 (bdwgc).

* os_dep.c [SOFT_VDB] (soft_set_grungy_pages): Cast h to ptr_t when
passed to ADDR_LT().
ivmai added a commit that referenced this issue Apr 16, 2024
(fix of commit e37ab2a)

Issue #627 (bdwgc).

* allchblk.c (drop_hblk_in_chunks): Declare limit local variable as
a const pointer.
* mark.c [ENABLE_TRACE] (GC_mark_from): Declare base local variable as
a const pointer.
ivmai added a commit that referenced this issue Apr 16, 2024
(fix of commit e37ab2a)

Issue #627 (bdwgc).

* checksums.c (GC_check_dirty): Move h, start local variables to inner
block statement.
* ptr_chck.c (GC_same_obj): Move h local variable to inner block
statement.
ivmai added a commit that referenced this issue Apr 16, 2024
(fix of commit e37ab2a)

Issue #627 (bdwgc).

* include/gc/gc.h [__CYGWIN32__ || __CYGWIN__] (GC_DATASTART,
GC_DATAEND): Cast GC_ADDR_LT() arguments to char*.
ivmai added a commit that referenced this issue Apr 24, 2024
(refactoring)

Issue #627 (bdwgc).

* tests/gctest.c (live_indicators): Change type from GC_word[] to
void*[]; do not define if GC_NO_FINALIZATION.
* tests/gctest.c (MAX_FINALIZED_PER_THREAD, MAX_FINALIZED): Do not
define if GC_NO_FINALIZATION.
* tests/gctest.c [MACOS] (mktree): Do not set if GC_NO_FINALIZATION.
* tests/gctest.c [!GC_NO_FINALIZATION] (mktree): Remove redundant casts
to void** of &live_indicators[my_index].
ivmai added a commit that referenced this issue Apr 24, 2024
(fix of commit e37ab2a)

Issue #627 (bdwgc).

* reclaim.c (GC_clear_block, GC_start_reclaim): Use ADDR_LT().
* win32_threads.c (GC_push_stack_for): Likewise.
* reclaim.c (GC_reclaim_clear, GC_reclaim_uninit, GC_reclaim_check,
GC_do_enumerate_reachable_objects): Use ADDR_GE().
* reclaim.c [ENABLE_DISCLAIM] (GC_disclaim_and_reclaim): Likewise.
* reclaim.c [VALGRIND_TRACKING] (GC_reclaim_block): Likewise.
* tests/gctest.c [!VERY_SMALL_CONFIG] (cons): Replace ptr_t to char*
casts for GC_ADDR_LT() arguments.
ivmai added a commit that referenced this issue Apr 24, 2024
(refactoring)

Issue #627 (bdwgc).

* allchblk.c (GC_split_block): Reformat comment; rename h argument to
hbp; rename n argument to last_hbp; rename nhdr argument to last_hdr.
* allchblk.c (GC_split_block): Change (word)p-(word)q to
(word)((ptr_t)p-(ptr_t)q).
* dbg_mlc.c (GC_debug_free, GC_debug_free_inner, GC_debug_realloc):
Likewise.
* mark.c (GC_set_mark_bit, GC_clear_mark_bit, GC_is_marked): Likewise.
* mark.c (GC_push_all, GC_custom_push_range): Likewise.
* ptr_chck.c (GC_is_visible): Likewise.
* allchblk.c (GC_allochblk_nth): Rename n argument to index.
* allchblk.c (ALIGN_PAD_SZ, GC_allochblk_nth): Use ADDR() instead of
a direct cast to word.
* alloc.c (GC_set_fl_marks, GC_add_to_heap, GC_scratch_recycle_inner,
GC_expand_hp_inner): Likewise.
* backgraph.c (ensure_struct, add_edge, reset_back_edge,
backwards_height, update_max_height): Likewise.
* checksums.c [MPROTECT_VDB] (GC_record_fault): Likewise.
* checksums.c (GC_was_faulted): Likewise.
* dbg_mlc.c (CROSSES_HBLK, GC_debug_print_heap_obj_proc): Likewise.
* dyn_load.c [E2K && __ptr64__] (GC_register_map_entries): Likewise.
* dyn_load.c (GC_register_dynamic_libraries_dl_iterate_phdr,
GC_register_dynamic_libraries): Likewise.
* finalize.c (HASH3, GC_push_finalizer_structures,
GC_register_disappearing_link_inner,
GC_general_register_disappearing_link,
GC_unregister_disappearing_link): Likewise.
* finalize.c [!GC_TOGGLE_REFS_NOT_NEEDED] (GC_process_togglerefs,
GC_mark_togglerefs, GC_clear_togglerefs, GC_toggleref_add): Likewise.
* finalize.c [!GC_LONG_REFS_NOT_NEEDED] (GC_register_long_link,
GC_unregister_long_link): Likewise.
* finalize.c [!GC_MOVE_DISAPPEARING_LINK_NOT_NEEDED && GC_ASSERTIONS]
(GC_move_disappearing_link_inner): Likewise.
* finalize.c [!GC_MOVE_DISAPPEARING_LINK_NOT_NEEDED]
(GC_move_disappearing_link): Likewise.
* finalize.c [!GC_MOVE_DISAPPEARING_LINK_NOT_NEEDED
&& !GC_LONG_REFS_NOT_NEEDED] (GC_move_long_link): Likewise.
* fnlz_mlc.c [ENABLE_DISCLAIM] (GC_finalized_malloc): Likewise.
* headers.c (GC_header_cache_miss, GC_scratch_alloc, GC_install_header,
GC_next_block, GC_prev_block): Likewise.
* include/private/gc_hdrs.h (HCE, HCE_VALID_FOR, HDR_FROM_BI,
IS_FORWARDING_ADDR_OR_NIL): Likewise.
* include/private/gc_hdrs.h [!HASH_TL] (BI): Likewise.
* include/private/gc_hdrs.h [HASH_TL] (GET_BI): Likewise.
* include/private/gc_priv.h (MAKE_COOLER, PHT_HASH): Likewise.
* include/private/specific.h (HASH, quick_thread_id): Likewise.
* malloc.c (GC_alloc_large, GC_malloc_kind_aligned_global): Likewise.
* mark.c (GC_mark_from): Likewise.
* mark_rts.c (rt_hash, GC_remove_roots_inner,
GC_exclude_static_roots_inner): Likewise.
* misc.c [ENABLE_TRACE] (GC_init): Likewise.
* os_dep.c (GC_skip_hole_openbsd, GC_find_limit_with_bound,
GC_linux_main_stack_base, GC_SysVGetDataStart,
GC_register_data_segments, GC_unix_sbrk_get_mem, PAGE_ALIGNED,
GC_proc_read_dirty, soft_set_grungy_pages, GC_mprotect_thread,
GC_print_callers): Likewise.
* pthread_support.c (GC_record_stack_base, GC_thr_init,
GC_set_stackbottom): Likewise.
* ptr_chck.c (GC_same_obj, GC_is_visible): Likewise.
* reclaim.c [USE_MARK_BYTES] (GC_clear_block): Likewise.
* specific.c (GC_key_create_inner): Likewise.
* thread_local_alloc.c (return_single_freelist, return_freelists,
GC_init_thread_local, GC_mark_thread_local_fls_for): Likewise.
* typd_mlc.c (GC_add_ext_descriptor): Likewise.
* win32_threads.c [WOW64_THREAD_CONTEXT_WORKAROUND]
(GC_push_stack_for): Likewise.
* win32_threads.c (GC_thr_init): Likewise.
* alloc.c [SET_REAL_HEAP_BOUNDS] (GC_add_to_heap): Use ADDR() instead
of ADDR_LT() and ADDR_GE() where one argument is of word type.
* alloc.c (GC_expand_hp_inner): Likewise.
* backgraph.c (add_back_edges): Likewise.
* dbg_mlc.c [ALIGNMENT==1] (GC_get_back_ptr_info): Likewise.
* dyn_load.c [IRIX5 || USE_PROC_FOR_LIBRARIES && !LINUX]
(GC_register_dynamic_libraries): Likewise.
* headers.c (GC_scratch_alloc): Likewise.
* malloc.c (GC_malloc_kind_aligned_global): Likewise.
* mark.c (GC_mark_from, GC_steal_mark_stack): Likewise.
* dbg_mlc.c (GC_debug_realloc): Change type of base local variable from
void* to ptr_t.
* dyn_load.c [IRIX5 || USE_PROC_FOR_LIBRARIES && !LINUX]
(GC_register_dynamic_libraries): Change type of heap_start, heap_end
local variables from word to ptr_t; use ADDR() instead of ADDR_INSIDE()
where some arguments of word type.
* headers.c (get_index): Remove redundant cast of argument to word.
* include/private/gc_pmark.h [ENABLE_TRACE] (TRACE, TRACE_TARGET):
Use GC_trace_ptr instead of GC_trace_addr.
* include/private/gc_priv.h (ADDR): New macro.
* include/private/gc_priv.h (GC_scratch_end_ptr): Rename to
GC_scratch_end_addr; update comment.
* include/private/gc_priv.h (_GC_arrays._last_heap_addr,
_GC_arrays._scratch_end_addr): Change type from ptr_t to word.
* include/private/gc_priv.h [GC_ASSERTIONS || MAKE_BACK_GRAPH
|| INCLUDE_LINUX_THREAD_DESCR || KEEP_BACK_PTRS && ALIGNMENT==1]
(_GC_arrays._least_real_heap_addr,
_GC_arrays._greatest_real_heap_addr): Likewise.
* include/private/gc_priv.h [ENABLE_TRACE] (GC_trace_addr): Rename to
GC_trace_ptr.
* include/private/specific.h (CACHE_HASH): Rename to TS_CACHE_HASH.
* include/private/specific.h (HASH): Rename to TS_HASH.
* include/private/specific.h (quick_thread_id): Rename to
ts_quick_thread_id.
* mark.c (GC_mark_from): Use GC_trace_ptr instead of GC_trace_addr.
* mark_rts.c (GC_approx_sp): Change type of sp from volatile word to
volatile ptr_t.
* misc.c [ENABLE_TRACE] (GC_init): Rename addr local variable to p.
* pthread_support.c [PARALLEL_MARK] (GC_mark_thread): Define id_n local
variable (of word type); use it instead of (word)id.
* specific.c (GC_setspecific, GC_remove_specific_after_fork,
GC_slow_getspecific): Use TS_HASH() instead of HASH().
* thread_local_alloc.c (return_single_freelist): Replace while loop
to do-while one.
ivmai added a commit that referenced this issue Apr 24, 2024
(refactoring)

Issue #627 (bdwgc).

* allchblk.c [VALGRIND_TRACKING] (GC_free_profiler_hook): Replace
GC_noop1((word)p) to NOOP1_PTR(p).
* alloc.c [!GC_DISABLE_INCREMENTAL && !NO_CLOCK && CPPCHECK]
(GC_timeout_stop_func): Likewise.
* alloc.c [GWW_VDB] (GC_add_to_heap): Likewise.
* alloc.c [CPPCHECK] (GC_allocobj): Likewise.
* backgraph.c [CPPCHECK] (push_in_progress, ensure_struct, add_edge,
backwards_height, update_max_height): Likewise.
* darwin_stop_world.c [!POWERPC && !ARM32 && !AARCH64 && CPPCHECK]
(GC_FindTopOfStack): Likewise.
* dyn_load.c [LINUX && !USE_PROC_FOR_LIBRARIES && CPPCHECK
&& HOST_ANDROID && !GC_DONT_DEFINE_LINK_MAP && !(__ANDROID_API__>=21)]
(GC_register_dynamic_libraries): Likewise.
* dyn_load.c [DARWIN && LINT2] (GC_init_dyld): Likewise.
* include/private/gc_priv.h [E2K && CPPCHECK] (PS_ALLOCA_BUF):
Likewise.
* mach_dep.c [!HAVE_PUSH_REGS && !EMSCRIPTEN && UNIX_LIKE
&& !NO_GETCONTEXT && GETCONTEXT_FPU_EXCMASK_BUG && X86_64 && CPPCHECK]
(GC_with_callee_saves_pushed): Likewise.
* mark.c [CPPCHECK] (GC_signal_mark_stack_overflow,
GC_steal_mark_stack): Likewise.
* misc.c [CPPCHECK] (GC_default_warn_proc, GC_call_with_gc_active):
Likewise.
* misc.c [!THREAD && CPPCHECK] (GC_do_blocking_inner): Likewise.
* os_dep.c [NEED_PROC_MAPS && LINT2] (GC_get_maps): Likewise.
* os_dep.c [(NEED_FIND_LIMIT || UNIX_LIKE || WRAP_MARK_SOME)
&& CPPCHECK && ADDRESS_SANITIZER] (GC_set_and_save_fault_handler):
Likewise.
* os_dep.c [CPPCHECK] (GC_get_register_stack_base,
GC_linux_main_stack_base): Likewise.
* os_dep.c [!ANY_MSWIN && (SVR4 || AIX || DGUX) && !PCR
&& !AO_HAVE_fetch_and_add && CPPCHECK] (GC_SysVGetDataStart): Likewise.
* os_dep.c [USE_MUNMAP && (CPPCHECK || LINT2)] (block_unmap_inner,
GC_remap): Likewise.
* os_dep.c [MPROTECT_VDB && !DARWIN && CPPCHECK && ADDRESS_SANITIZER]
(GC_dirty_init): Likewise.
* pthread_support.c [CPPCHECK] (GC_call_with_gc_active): Likewise.
* specific.c [LINT2] (GC_remove_specific_after_fork): Likewise.
* tests/gctest.c [CPPCHECK] (reverse_test_inner, test_long_mult,
warn_proc): Likewise.
* tests/gctest.c [!NO_TYPED_TEST] (typed_test): Likewise.
* tests/gctest.c (run_one_test): Likewise.
* win32_threads.c [CPPCHECK] (copy_ptr_regs, GC_win32_start_inner):
Likewise.
* include/private/gc_priv.h (NOOP1_PTR): New macro.
ivmai added a commit that referenced this issue Jun 12, 2024
(replacement of commit 0ca8be5)

Issue #627 (bdwgc).

GC_noop1_ptr() replaces NOOP1_PTR() and GC_noop1() where used for
pointers.

* allchblk.c [VALGRIND_TRACKING] (GC_free_profiler_hook): Replace
NOOP1_PTR() usage to GC_noop1_ptr() call.
* alloc.c [!GC_DISABLE_INCREMENTAL && !NO_CLOCK && CPPCHECK]
(GC_timeout_stop_func): Likewise.
* alloc.c [GWW_VDB] (GC_add_to_heap): Likewise.
* alloc.c [CPPCHECK] (GC_allocobj): Likewise.
* backgraph.c [CPPCHECK] (push_in_progress, ensure_struct, add_edge,
backwards_height, update_max_height): Likewise.
* darwin_stop_world.c [!POWERPC && !ARM32 && !AARCH64 && CPPCHECK]
(GC_FindTopOfStack): Likewise.
* dyn_load.c [LINUX && !USE_PROC_FOR_LIBRARIES && CPPCHECK
&& HOST_ANDROID && !GC_DONT_DEFINE_LINK_MAP && !(__ANDROID_API__>=21)]
(GC_register_dynamic_libraries): Likewise.
* dyn_load.c [DARWIN && LINT2] (GC_init_dyld): Likewise.
* include/private/gc_priv.h [E2K && CPPCHECK] (PS_ALLOCA_BUF):
Likewise.
* mach_dep.c [!HAVE_PUSH_REGS && !EMSCRIPTEN && UNIX_LIKE
&& !NO_GETCONTEXT && GETCONTEXT_FPU_EXCMASK_BUG && X86_64 && CPPCHECK]
(GC_with_callee_saves_pushed): Likewise.
* mark.c [CPPCHECK] (GC_signal_mark_stack_overflow,
GC_steal_mark_stack): Likewise.
* misc.c [CPPCHECK] (GC_default_warn_proc, GC_call_with_gc_active):
Likewise.
* misc.c [!THREAD && CPPCHECK] (GC_do_blocking_inner): Likewise.
* os_dep.c [NEED_PROC_MAPS && LINT2] (GC_get_maps): Likewise.
* os_dep.c [(NEED_FIND_LIMIT || UNIX_LIKE || WRAP_MARK_SOME)
&& CPPCHECK && ADDRESS_SANITIZER] (GC_set_and_save_fault_handler):
Likewise.
* os_dep.c [CPPCHECK] (GC_get_register_stack_base,
GC_linux_main_stack_base): Likewise.
* os_dep.c [!ANY_MSWIN && (SVR4 || AIX || DGUX) && !PCR
&& !AO_HAVE_fetch_and_add && CPPCHECK] (GC_SysVGetDataStart): Likewise.
* os_dep.c [USE_MUNMAP && (CPPCHECK || LINT2)] (block_unmap_inner,
GC_remap): Likewise.
* os_dep.c [MPROTECT_VDB && !DARWIN && CPPCHECK && ADDRESS_SANITIZER]
(GC_dirty_init): Likewise.
* pthread_support.c [CPPCHECK] (GC_call_with_gc_active): Likewise.
* specific.c [LINT2] (GC_remove_specific_after_fork): Likewise.
* tests/gctest.c [CPPCHECK] (reverse_test_inner, test_long_mult,
warn_proc): Likewise.
* tests/gctest.c [!NO_TYPED_TEST] (typed_test): Likewise.
* tests/gctest.c (run_one_test): Likewise.
* win32_threads.c [CPPCHECK] (copy_ptr_regs, GC_win32_start_inner):
Likewise.
* cord/tests/cordtest.c [CPPCHECK] (test_fn, id_cord_fn): Replace
GC_noop1() call to GC_noop1_ptr() one.
* finalize.c [GC_ASSERTIONS] (GC_register_disappearing_link_inner,
GC_move_disappearing_link_inner): Likewise.
* include/gc/gc.h [(!__GNUC__ || __INTEL_COMPILER) && !LINT2]
(GC_reachable_here): Likewise.
* tests/disclaim.c [CPPCHECK] (misc_sizes_dct, pair_dct): Likewise.
* tests/staticroots_lib.c [CPPCHECK] (libsrl_getpelem): Likewise.
* tests/threadkey.c [CPPCHECK] (on_thread_exit_inner): Likewise.
* tests/weakmap.c [CPPCHECK] (set_mark_bit): Likewise.
* dyn_load.c [DARWIN && CPPCHECK] (GC_init_dyld): Call
GC_noop1_ptr(dl_handle).
* finalize.c (GC_unreachable_finalize_mark_proc): Mention GC_noop1_ptr
instead of GC_noop1 in comment.
* include/gc/gc.h [(!__GNUC__ || __INTEL_COMPILER) && LINT2]
(GC_reachable_here): Refine comment.
* include/gc/gc.h (GC_noop1): Improve comment.
* include/gc/gc.h (GC_noop1_ptr): New API function declaration.
* include/private/gc_priv.h (NOOP1_PTR): Remove macro.
* mark.c (GC_noop1_ptr): Implement.
ivmai added a commit that referenced this issue Jun 12, 2024
(refactoring)

Issue #627 (bdwgc).

* backgraph.c (add_edge): Use ADDR() for COVERT_DATAFLOW() argument.
* dyn_load.c [SOLARISDL && !USE_PROC_FOR_LIBRARIES
|| HAVE_DL_ITERATE_PHDR] (GC_FirstDLOpenedLinkMap): Likewise.
* dyn_load.c [!USE_PROC_FOR_LIBRARIES && HAVE_DL_ITERATE_PHDR]
(GC_register_main_static_data): Likewise.
* mach_dep.c (GC_with_callee_saves_pushed): Likewise.
* misc.c [!ALWAYS_SMALL_CLEAR_STACK && !STACK_NOT_SCANNED
&& !ASM_CLEAR_CODE && !CPPCHECK] (GC_clear_stack_inner): Likewise.
* misc.c (GC_call_with_stack_base): Likewise.
* misc.c [!THREADS] (GC_call_with_gc_active): Likewise.
* os_dep.c [SEARCH_FOR_DATA_START] (GC_init_linux_data_start):
Likewise.
* os_dep.c [NEED_CALLINFO && LINUX && !SMALL_CONFIG]
(GC_print_callers): Likewise.
* pthread_support.c (GC_call_with_gc_active): Likewise.
* include/private/gc_priv.h (TRUSTED_STRING): Use COVERT_DATAFLOW_P(p)
instead of COVERT_DATAFLOW(p); remove cast to char*.
* misc.c [!THREADS] (GC_call_with_gc_active): Likewise.
* pthread_support.c [GC_PTHREADS && !SN_TARGET_ORBIS
&& !SN_TARGET_PSP2] (GC_pthread_join, GC_pthread_detach): Likewise.
* include/private/gcconfig.h (COVERT_DATAFLOW): Move definition down
(to be somewhere after CPP_WORDSZ definition).
* include/private/gcconfig.h (COVERT_DATAFLOW_P): Define macro.
ivmai added a commit that referenced this issue Jun 12, 2024
Issue #627 (bdwgc).

* cord/cordprnt.c (CORD_vsprintf): Compare len (instead of res) to buf;
cast len and buf values to GC_uintptr_t instead of casting res to word
and then to char*.
* cord/cordxtra.c (CORD_nul_func, CORD_chars, refill_cache,
CORD_lf_func): Cast between pointer and char thru GC_uintptr_t instead
of word.
* include/private/dbg_mlc.h (MARKED_FOR_FINALIZATION,
MARKED_FROM_REGISTER, NOT_MARKED): Likewise.
* cord/tests/cordtest.c (test_fn, test_cord_x1, test_cord_x2):
Likewise.
* dbg_mlc.c (GC_has_other_debug_info, GC_store_debug_info_inner,
GC_check_annotated_obj): Cast body, sz to GC_uintptr_t (instead of
word); cast base/ohdr to GC_uintptr_t* instead of word*.
* dbg_mlc.c (GC_print_backtrace): Remove out label; adjust indentation.
* dbg_mlc.c (GET_OH_LINENUM): Add missing parentheses.
* include/gc/gc.h (GC_PRE_INCR3, GC_POST_INCR3): Likewise.
* dbg_mlc.c [!SHORT_DBG_HDRS] (GC_print_smashed_obj): Rename
clobbered_addr argument to clobbered; reformat comment.
* dbg_mlc.c (GC_FREED_MEM_MARKER): Move definition to dbg_mlc.h.
* dbg_mlc.c (GC_debug_free): Cast sz and GC_size(base) to GC_uintptr_t;
cast p to GC_uintptr_t* instead of word*.
* dbg_mlc.c (GC_check_leaked): Cast base to GC_uintptr_t* instead of
word*.
* include/private/dbg_mlc.h [(KEEP_BACK_PTRS || MAKE_BACK_GRAPH)
&& !(PARALLEL_MARK || KEEP_BACK_PTRS)] (GC_HAS_DEBUG_INFO): Likewise.
* dbg_mlc.c (GC_debug_invoke_finalizer): Change "fns" to "function" in
comment.
* dbg_mlc.c (store_old, GC_debug_register_finalizer,
GC_debug_register_finalizer_no_order,
GC_debug_register_finalizer_unreachable,
GC_debug_register_finalizer_ignore_self): Store NULL (instead of 0)
to *ocd.
* gc.man (.TH): Update date.
* gc.man (GC_set_warn_proc): Change arg type from GC_word to
GC_uintptr_t.
* include/gc/gc.h (GC_warn_proc, GC_ignore_warn_proc): Likewise.
* misc.c (GC_default_warn_proc, GC_ignore_warn_proc): Likewise.
* tests/cpp.cc (warn_proc): Likewise.
* gcj_mlc.c (GC_gcj_fake_mark_proc, GC_init_gcj_malloc): Rename
FUNCPTR_IS_WORD to FUNCPTR_IS_DATAPTR.
* include/private/gc_priv.h (FUNCPTR_IS_WORD): Likewise.
* misc.c [!CPPCHECK] (GC_init): Likewise.
* pthread_support.c [GC_PTHREADS && !SN_TARGET_ORBIS && !SN_TARGET_PSP2
&& DEBUG_THREADS] (GC_start_rtn_prepare_thread): Likewise.
* include/gc/gc.h (GC_uintptr_t): Define unconditionally; move
definition to the beginning of the file.
* include/gc/gc.h (GC_general_register_disappearing_link,
GC_malloc_many): Refine comment.
* include/private/gc_priv.h (GC_PUSH_ALL_SYM): Likewise.
* include/gc/gc.h (GC_hidden_pointer): Change type from GC_word to
GC_uintptr_t.
* include/private/gc_priv.h (GC_funcptr_uint): Likewise.
* include/private/dbg_mlc.h (GC_FREED_MEM_MARKER, START_FLAG,
END_FLAG): Cast to GC_uintptr_t instead of word.
* include/private/dbg_mlc.h [ALIGNMENT==1] (HIDE_BACK_PTR): Likewise.
* include/private/dbg_mlc.h (oh): Remove oh_dummy field; make
oh_back_ptr and oh_bg_ptr field either present both or not; refine
comment.
* include/private/dbg_mlc.h [!SHORT_DBG_HDRS] (oh.oh_sz, oh.oh_sf):
Change type from word to GC_uintptr_t.
* include/private/gc_priv.h (GC_ASSERT): Move definition upper (to be
right after include gc_locks.h).
* include/private/gc_priv.h (WARN): Cast arg to GC_uintptr_t instead
of word.
* include/private/gc_priv.h (WARN_PRIdPTR): Change comment to TODO
item.
* mallocx.c [_FORTIFY_SOURCE && __GNUC__ && !__clang__] (GC_realloc):
Change type of cleared_p local variable from word to GC_uintptr_t;
reformat comment.
* mallocx.c [!_FORTIFY_SOURCE || !__GNUC__ || __clang__] (GC_realloc):
Define cleared_p as a macro (and undefine it at the end of function).
* misc.c [!CPPCHECK] (GC_init): Change ptr_t to ptrdiff_t in comparison
to sizeof word.
* misc.c [!CPPCHECK && FUNCPTR_IS_DATAPTR] (GC_init): Change word to
ptr_t in comparison to sizeof GC_funcptr_uint.
* misc.c [!CPPCHECK] (GC_init): Add assertion that size of GC_uintptr_t
matches size of ptr_t.
* pthread_support.c [E2K] (GC_record_stack_base, GC_set_stackbottom):
Cast sb->reg_base to GC_uintptr_t instead of ADDR() usage.
* pthread_support.c [E2K] (GC_get_my_stackbottom): Cast crtn->ps_ofs to
GC_uintptr_t instead of word; add comment.
* tests/cpp.cc (Disguise): Change type or result from
GC_word to GC_uintptr_t.
* tests/cpp.cc (Undisguise): Rename i argument to v and change its type
from GC_word to GC_uintptr_t.
* tests/cpp.cc (main): Change type of as, bs local variables from
GC_word[] to GC_uintptr_t[].
* tests/cpp.cc (INT_TO_SEXPR, SEXPR_TO_INT): Rename argument; cast thru
GC_uintptr_t instead of GC_word.
* tests/cpp.cc [TEST_WITH_SYSTEM_MALLOC] (reverse): Cast
TEST_WITH_SYSTEM_MALLOC() result to GC_word.
* tests/cpp.cc (reverse_test_inner, finalizer, mktree): Cast between
pointer and int thru GC_uintptr_t instead GC_word.
* thread_local_alloc.c (return_freelists, GC_init_thread_local):
Likewise.
* tests/cpp.cc (warn_proc): Rename argument from p to arg; remove cast
of arg to unsigned long.
ivmai added a commit that referenced this issue Jun 12, 2024
Issue #627 (bdwgc).

* dbg_mlc.c (GC_debug_ptr_store_and_dirty): Use
GC_CAST_AWAY_CONST_PVOID() instead of explicit cast to word and then
to void*.
* include/gc/gc.h (GC_GENERAL_REGISTER_DISAPPEARING_LINK_SAFE,
GC_REGISTER_LONG_LINK_SAFE): Likewise.
* include/private/gc_priv.h (GC_base_C): Likewise.
* specific.c (GC_key_create_inner): Likewise.
* include/gc/gc.h (include/gc/gc.h): New public macro.
ivmai added a commit that referenced this issue Jun 12, 2024
(refactoring)

Issue #627 (bdwgc).

* alloc.c (GC_clear_a_few_frames): Use CAST_AWAY_VOLATILE_PVOID()
instead of a direct no-volatile cast.
* mach_dep.c (GC_with_callee_saves_pushed): Likewise.
* misc.c (GC_clear_stack, GC_clear_stack_inner): Likewise.
* os_dep.c [!ANY_MSWIN && (SVR4 || AIX || DGUX)] (GC_SysVGetDataStart):
Likewise.
* os_dep.c [!GC_DISABLE_INCREMENTAL] (GC_read_dirty): Likewise.
* specific.c (GC_setspecific): Likewise.
* win32_threads.c (GC_start_world): Likewise.
* gcj_mlc.c [FUNCPTR_IS_DATAPTR] (GC_init_gcj_malloc): Use
CAST_THRU_UINTPTR().
* include/private/gc_priv.h (NONNULL_ARG_NOT_NULL): Likewise.
* mark.c (GC_push_marked): Likewise.
* os_dep.c [GWW_VDB && MSWINRT_FLAVOR && FUNCPTR_IS_DATAPTR]
(detect_GetWriteWatch): Likewise.
* pthread_support.c [GC_PTHREADS && !SN_TARGET_ORBIS
&& !SN_TARGET_PSP2 && DEBUG_THREADS && FUNCPTR_IS_DATAPTR]
(GC_start_rtn_prepare_thread): Likewise.
* tests/gctest.c (reverse_test_inner): Likewise.
* win32_threads.c [((!HAVE_PTHREAD_SETNAME_NP_WITH_TID && !MSWINCE
&& PARALLEL_MARK) || WOW64_THREAD_CONTEXT_WORKAROUND) && MSWINRT_FLAVOR
&& FUNCPTR_IS_DATAPTR] (GC_thr_init): Likewise.
* include/private/gc_priv.h (CAST_THRU_UINTPTR,
CAST_AWAY_VOLATILE_PVOID): New macro.
* pthread_support.c [GC_USE_DLOPEN_WRAP] (TYPED_DLSYM): Likewise.
* pthread_support.c [GC_USE_DLOPEN_WRAP] (GC_init_real_syms): Use
TYPED_DLSYM().
ivmai added a commit that referenced this issue Jun 12, 2024
…calls

(fix of commit f9b4b19)

Issue #627 (bdwgc).

* include/gc/gc.h (GC_noop1_ptr): Change argument type from
volatile void* to const volatile void*.
* mark.c (GC_noop1_ptr): Likewise.
ivmai added a commit that referenced this issue Jun 12, 2024
(fix of commit f68db21)

Issue #627 (bdwgc).

* dbg_mlc.c [KEEP_BACK_PTRS] (GC_print_backtrace): Move source, offset,
base local variables to the inner scope.
ivmai added a commit that referenced this issue Jun 14, 2024
(fix of commit f68db21)

Issue #627 (bdwgc).

* include/gc/gc.h [!_UINTPTR_T && !_UINTPTR_T_DEFINED] (GC_uintptr_t):
Define as GC_word regardless of UINTPTR_MAX presence.
ivmai added a commit that referenced this issue Jun 14, 2024
…_ptr"

Issue #627 (bdwgc).

This reverts commit f985d63.

Reason: GC_noop1_ptr() should not tell the compiler that the argument
is a const pointer.
ivmai added a commit that referenced this issue Jun 14, 2024
(fix of commit f9b4b19)

Issue #627 (bdwgc).

* include/gc/gc.h [(!__GNUC__ || __INTEL_COMPILER) && !LINT2]
(GC_reachable_here): Use GC_CAST_AWAY_CONST_PVOID() for the argument.
ivmai added a commit that referenced this issue Jun 14, 2024
(fix of commit 0ca8be5)

Issue #627 (bdwgc).

* os_dep.c [(NEED_FIND_LIMIT || UNIX_LIKE || WRAP_MARK_SOME)
&& CPPCHECK && ADDRESS_SANITIZER] (GC_set_and_save_fault_handler):
Use GC_noop1((word)(GC_funcptr_uint)&fn) instead of GC_noop1_ptr(&fn).
* os_dep.c [MPROTECT_VDB && !DARWIN && CPPCHECK && ADDRESS_SANITIZER]
(GC_dirty_init): Likewise.
ivmai added a commit that referenced this issue Jun 14, 2024
Issue #627 (bdwgc).

GC_return_addr_t is a type to hold a function return address (pointer).
Never used for calling a function.

* dbg_mlc.c [GC_ADD_CALLER && HAVE_DLADDR
&& GC_HAVE_RETURN_ADDR_PARENT] (GC_caller_func_offset): Define if macro
unless FUNCPTR_IS_DATAPTR.
* dbg_mlc.c [GC_ADD_CALLER && HAVE_DLADDR && FUNCPTR_IS_DATAPTR
&& GC_HAVE_RETURN_ADDR_PARENT] (GC_caller_func_offset): Rename ad to
ra an change its type from word to GC_return_addr_t; replace char*
casts to ptr_t ones.
* include/gc/gc.h [(GC_CAN_SAVE_CALL_STACKS || GC_ADD_CALLER)
&& !GC_RETURN_ADDR_T_DEFINED] (GC_return_addr_t): New type.
* include/gc/gc.h [(GC_CAN_SAVE_CALL_STACKS || GC_ADD_CALLER)
&& !GC_RETURN_ADDR_T_DEFINED] (GC_RETURN_ADDR_T_DEFINED): Define macro.
* include/gc/gc.h [GC_ADD_CALLER] (GC_EXTRA_PARAMS): Change type of ra
from GC_word to GC_return_addr_t.
* include/gc/gc_config_macros.h (GC_RETURN_ADDR): Cast to
GC_return_addr_t.
* include/private/gc_priv.h [NEED_CALLINFO] (callinfo.ci_pc): Change
type from word to GC_return_addr_t.
* os_dep.c [SAVE_CALL_CHAIN] (GC_save_callers_no_unlock,
GC_save_callers): Cast value stored to ci_pc field to GC_return_addr_t
instead of word.
* os_dep.c [SAVE_CALL_CHAIN] (GC_save_callers): Do not cast
fp->fr_arg[i] to signed_word.
* os_dep.c [NEED_CALLINFO && GC_HAVE_BUILTIN_BACKTRACE
&& !GC_BACKTRACE_SYMBOLS_BROKEN] (GC_print_callers): Do not call
backtrace_symbols() and free() unless FUNCPTR_IS_DATAPTR.
ivmai added a commit that referenced this issue Jun 15, 2024
(fix of commit f9b4b19)

Issue #627 (bdwgc).

* dyn_load.c [DARWIN && !NO_DYLD_BIND_FULLY_IMAGE && !USE_DYLD_TO_BIND]
(GC_init_dyld): Remove const qualifier from pointer type of dl_handle
local variable.
ivmai added a commit that referenced this issue Jun 15, 2024
(fix of commit b2552e0)

Issue #627 (bdwgc).

* include/gc/gc.h [(GC_CAN_SAVE_CALL_STACKS || GC_ADD_CALLER)
&& !GC_RETURN_ADDR_T_DEFINED && __GNUC__] (GC_return_addr_t): Define
as void* instead of a functional type; add comment.
ivmai added a commit that referenced this issue Jul 25, 2024
(fix of commit 1fcf50d)

Issue #627 (bdwgc).

* tests/atomicops.c [AO_HAVE_compare_and_swap_release] (main): Define
cptr local variable; call GC_cptr_compare_and_swap() and check its
result.
ivmai added a commit that referenced this issue Jul 29, 2024
(fix of commits 1fcf50d, 60634d0)

Issue #627 (bdwgc).

The error happens if the source is compiled with -D AO_USE_PTHREAD_DEFS.

tests/atomicops.c [(GC_BUILTIN_ATOMIC || GC_THREADS)
&& AO_HAVE_compare_and_swap_release] (main): Do no define cptr variable
and do not call GC_cptr_compare_and_swap() unless AO_REQUIRE_CAS.
ivmai added a commit that referenced this issue Jul 29, 2024
(fix of commits f68db21, 03560ac)

Issue #627 (bdwgc).

MSYS2 might provide __uintptr_t instead of uintptr_t.

* include/gc/gc.h [__MSYS__] (GC_uintptr_t): Define type as GC_word
even if _UINTPTR_T_DEFINED or _UINTPTR_T macro is defined; add comment.
ivmai added a commit that referenced this issue Jul 29, 2024
(refactoring)

Issue #627 (bdwgc).

* tests/gctest.c (run_one_test): Do not cast &fail_count to GC_word.
* tests/gctest.c (run_one_test): Set y to fail_proc1 only if
FUNCPTR_IS_DATAPTR and not PCR; use CAST_THRU_UINTPTR() instead of
cast of fail_count to GC_word.
* tests/gctest.c [GC_PTHREADS] (main): Do not cast &atomic_count to
GC_word.
ivmai added a commit that referenced this issue Jul 29, 2024
Issue #627 (bdwgc).

* include/gc/gc_typed.h (GC_CALLOC_TYPED_DESCR_PTRS): New macro.
* include/gc/gc_typed.h (GC_CALLOC_TYPED_DESCR_WORDS): Add comment
(that the value is the number of both "normal" and "pointer-sized"
words).
* include/gc/gc_typed.h [!GC_BUILD] (GC_calloc_typed_descr_s.opaque_p):
New field.
* include/gc/gc_typed.h [!GC_BUILD] (GC_calloc_typed_descr_s.opaque):
Change elements count from GC_CALLOC_TYPED_DESCR_WORDS to
GC_CALLOC_TYPED_DESCR_WORDS-GC_CALLOC_TYPED_DESCR_PTRS.
* typd_mlc.c (GC_calloc_typed_descr_s): Move complex_d field upper to
be the first field.
* typd_mlc.c (GC_calloc_prepare_explicitly_typed): Update static assert
about size of GC_calloc_typed_descr_s to use both
GC_CALLOC_TYPED_DESCR_WORDS and GC_CALLOC_TYPED_DESCR_PTRS.
ivmai added a commit that referenced this issue Jul 29, 2024
…llers

(fix of commit b2552e0)

Issue #627 (bdwgc).

* os_dep.c [NEED_CALLINFO && SAVE_CALL_CHAIN && NARGS == 0
&& NFRAMES%2==0 && GC_HAVE_BUILTIN_BACKTRACE && REDIRECT_MALLOC
&& THREADS && DBG_HDRS_ALL] (GC_save_callers_no_unlock): Use
CAST_THRU_UINTPTR() to set info[0].ci_pc.
* os_dep.c [NEED_CALLINFO && SAVE_CALL_CHAIN && NARGS == 0
&& NFRAMES%2==0 && GC_HAVE_BUILTIN_BACKTRACE && REDIRECT_MALLOC]
(GC_save_callers): Likewise.
ivmai added a commit that referenced this issue Aug 3, 2024
(refactoring)

Issue #627 (bdwgc).

This is to reduce code duplication between GC_next_block, GC_prev_block
and GC_apply_to_all_blocks.

* headers.c (HBLK_ADDR): New macro.
* headers.c (GC_apply_to_all_blocks): Move j local variable to the
nested block; rename index_p local variable to bi; use ADDR() for hhdr.
* headers.c (GC_apply_to_all_blocks, ):
Use HBLK_ADDR().
* headers.c (GC_next_block): Change while() outermost loop to for().
ivmai added a commit that referenced this issue Aug 3, 2024
(a cherry-pick of commits ab69d29, d8ecfa3, c81f06e, 8c8c740, 403baec,
71cc392 partly from capablevms/bdwgc)

Issue #627 (bdwgc).

Original capability should be used to reclaim memory (and during
explicit object free) rather than a computed integer value for the
capability systems.

* allchblk.c (GC_get_first_part): Set rest_hdr->hb_block value (i.e.,
add hblk pointer within header during re-allocation of GC'd memory).
* dbg_mlc.c [!SHORT_DBG_HDRS] (GC_check_heap_block): Add assertion that
p is equal to hhdr->hb_block.
* headers.c (GC_apply_to_all_blocks): Pass hhdr->hb_block (instead of
HBLK_ADDR(bi,j)) to fn().
* headers.c (GC_apply_to_all_blocks, GC_next_block): Add assertion that
HBLK_ADDR(bi,j) is equal to ADDR(hhdr->hb_block).
* headers.c (GC_next_block): Return hhdr->hb_block instead of
HBLK_ADDR(bi,j).
* headers.c (GC_prev_block): Add TODO item to return hhdr->hb_block
and add the corresponding assertion (as in GC_next_block).
* malloc.c (free_internal): Pass hhdr->hb_block (instead of HBLKPTR(p))
to GC_freehblk(); add assertion that ADDR(HBLKPTR(p)) is equal to
ADDR(hhdr->hb_block).
* reclaim.c (GC_reclaim_small_nonempty_block, GC_reclaim_block): Add
assertion that hbp is equal to hhdr->hb_block.

Co-authored-by: Ivan Maidanski <[email protected]>
@ivmai
Copy link
Owner Author

ivmai commented Aug 3, 2024

Current status: I've done a lot of refactoring to simplify porting to CHERI, and backported some changes from https://github.com/capablevms/bdwgc/ (see c29365b). Still many CHERI-specific changes to be backported.

@ivmai
Copy link
Owner Author

ivmai commented Aug 3, 2024

And below is the list of code places worth attention during enabling of CHERI in master:

  • headers.c: GC_prev_block: resolve TODO (in a similar way as for GC_next_block but some other changes are needed to avoid assertion violation)
  • include/gc/gc.h: GC_ADDR_LT: compare addr part only?
  • include/gc/gc.h: GC_HIDE_POINTER, GC_HIDE_NZ_POINTER (and the reveal ops)
  • include/gc/gc_tiny_fl.h: GC_TINY_FREELISTS (is the current value OK?)
  • include/private/dbg_mlc.h: GC_FREED_MEM_MARKER, START_FLAG, END_FLAG
  • include/private/gcconfig.h: PTR_ALIGN_DOWN, PTR_ALIGN_UP: use cheri_align_down/up, include cheriintrin.h
  • include/private/gcconfig.h: FIXUP_POINTER
  • include/private/gc_priv.h: CPTR_CLEAR_FLAGS, CPTR_SET_FLAGS
  • tests/gctest.c: check_heap_stats: increase max_heap_sz if CPP_PTRSZ > 64
  • pointers comparison for equality: e.g. in get_block_ending_at, GC_add_to_fl (should we compare addr part only?)

@ivmai
Copy link
Owner Author

ivmai commented Aug 3, 2024

A number of changes are not ported yet (as of commit 7f1503d), here's a diff:

diff --git a/.buildbot.sh b/.buildbot.sh
new file mode 100755
index 00000000..7d432e28
--- /dev/null
+++ b/.buildbot.sh
+    BUILD_OPTS="-DCMAKE_BUILD_TYPE=Debug \
+                -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
+                -Denable_gcj_support=OFF \
+                -Denable_threads=OFF \
+                -Denable_dynamic_loading=${DYNAMIC_LIBTEST}"
diff --git a/allchblk.c b/allchblk.c
index a5a356f5..56b0c036 100644
--- a/allchblk.c
+++ b/allchblk.c
@@ -540,6 +540,11 @@ GC_INNER void GC_merge_unmapped(void)
         /* Coalesce with successor, if possible */
           if (0 != nexthdr && HBLK_IS_FREE(nexthdr)
               && (signed_word) (size + (nextsize = nexthdr->hb_sz)) > 0
+#           if defined(__CHERI_PURE_CAPABILITY__)
+              /* CVMFIXME : coalesce with super-capability */
+              && (cheri_base_get(h) <= cheri_address_get(next))
+              && (cheri_base_get(h) + cheri_length_get(h)) >= (cheri_address_get(next) + nextsize)
+#           endif
                  /* no pot. overflow */) {
             /* Note that we usually try to avoid adjacent free blocks   */
             /* that are either both mapped or both unmapped.  But that  */
@@ -978,6 +984,14 @@ GC_INNER void GC_freehblk(struct hblk *hbp)
     /* Coalesce with successor, if possible */
       if(0 != nexthdr && HBLK_IS_FREE(nexthdr) && IS_MAPPED(nexthdr)
          && (signed_word)(hhdr -> hb_sz + nexthdr -> hb_sz) > 0
+#     if defined(__CHERI_PURE_CAPABILITY__)
+         /* CVMFIXME : coalesce with super-capability */
+         /* Bounds of capability should span entire coalesced memory */
+         /* Bounds being larger than blk-size is OK; bounded by the imprecision */
+         /* of original capability obtained from system memory */
+         && (cheri_base_get(hbp) <= cheri_address_get(next))
+         && (cheri_base_get(hbp) + cheri_length_get(hbp)) >= (cheri_address_get(next) + nexthdr->hb_sz)
+#     endif
          /* no overflow */) {
         GC_remove_from_fl(nexthdr);
         hhdr -> hb_sz += nexthdr -> hb_sz;
@@ -987,7 +1001,12 @@ GC_INNER void GC_freehblk(struct hblk *hbp)
       if (prev /* != NULL */) { /* CPPCHECK */
         prevhdr = HDR(prev);
         if (IS_MAPPED(prevhdr)
-            && (signed_word)(hhdr -> hb_sz + prevhdr -> hb_sz) > 0) {
+            && (signed_word)(hhdr -> hb_sz + prevhdr -> hb_sz) > 0
+#       if defined(__CHERI_PURE_CAPABILITY__)
+            /* CVMFIXME : coalesce with super-capability */
+            && (cheri_base_get(hbp) <= cheri_address_get(prev))
+#       endif
+            /* no overflow */ ) {
           GC_remove_from_fl(prevhdr);
           prevhdr -> hb_sz += hhdr -> hb_sz;
 #         ifdef USE_MUNMAP
diff --git a/dyn_load.c b/dyn_load.c
index 2289b68c..a833d94d 100644
--- a/dyn_load.c
+++ b/dyn_load.c
@@ -499,8 +502,17 @@ STATIC int GC_register_dynlib_callback(struct dl_phdr_info * info,
       GC_has_static_roots_func callback = GC_has_static_roots;
       if ((p->p_flags & PF_W) == 0) continue;
 
+#     if !defined(__CHERI_PURE_CAPABILITY__)
         start = (ptr_t)p->p_vaddr + info->dlpi_addr;
         end = start + p->p_memsz;
+#     else
+        start = cheri_align_up(info->dlpi_addr + (vaddr_t)p->p_vaddr, sizeof(ptr_t));
+        end = cheri_align_down(start + p->p_memsz, sizeof(ptr_t));
+        if (!SPANNING_CAPABILITY( info->dlpi_addr, start, end)) continue;
+
+	start = cheri_bounds_set( start, (size_t)(end - start));
+#     endif /* __CHERI_PURE_CAPABILITY__  */
+
       if (callback != 0 && !callback(info->dlpi_name, start, p->p_memsz))
         continue;
 #     ifdef PT_GNU_RELRO
diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h
index c93710be..18d7a321 100644
--- a/include/private/gc_priv.h
+++ b/include/private/gc_priv.h
@@ -2103,6 +2132,26 @@ GC_INNER void GC_with_callee_saves_pushed(void (*fn)(ptr_t, void *),
           LOAD_TAGGED_VALUE(v, tag, p); \
           if (tag != 0) continue; \
         }
+#elif defined(__CHERI_PURE_CAPABILITY__)
+  /* Load value, check tag and permissions of the target memory.   */
+# define LOAD_WORD_OR_CONTINUE(v, p) \
+        { \
+            v = *(void **)(p);                                               \
+            if (!cheri_tag_get(v)) continue;                                 \
+            size_t in_bounds = (v >= (word)cheri_base_get(v))                \
+                                && (v < (word)cheri_base_get(v)              \
+                                        + (word)cheri_length_get(v));        \
+            size_t has_rwx = cheri_perms_get(v) & (CHERI_PERM_LOAD           \
+                                                   | CHERI_PERM_STORE        \
+                                                   | CHERI_PERM_EXECUTE);    \
+            if (!in_bounds || !has_rwx) continue;                            \
+        }
+
+# define SPANNING_CAPABILITY(cap, start, end) \
+      (cheri_tag_get((cap)) \
+        && cheri_base_get((cap)) <= (start)    \
+        && (cheri_base_get((cap)) + cheri_length_get((cap))) >= (end) \
+        && (cheri_perms_get((cap)) & (CHERI_PERM_LOAD|CHERI_PERM_LOAD_CAP)) != 0)
 #else
 # define LOAD_WORD_OR_CONTINUE(v, p) (void)(v = *(word *)(p))
 #endif /* !E2K */
diff --git a/mark.c b/mark.c
index ae8f314f..69133827 100644
--- a/mark.c
+++ b/mark.c
@@ -548,7 +548,12 @@ GC_INNER mse * GC_mark_from(mse *mark_stack_top, mse *mark_stack,
 {
   signed_word credit = HBLKSIZE;  /* Remaining credit for marking work. */
   ptr_t current_p;      /* Pointer to current candidate ptr.            */
+# if defined(__CHERI_PURE_CAPABILITY__)
+  void **current;       /* Candidate pointer.                           */
+  word has_rwx;         /* permissions on capability                    */
+# else
   word current;         /* Candidate pointer.                           */
+# endif
   ptr_t limit = 0;      /* (Incl) limit of current candidate range.     */
   word descr;
   ptr_t greatest_ha = (ptr_t)GC_greatest_plausible_heap_addr;
@@ -728,16 +733,17 @@ GC_INNER mse * GC_mark_from(mse *mark_stack_top, mse *mark_stack,
 #     define PREF_DIST 4
 
 #     if !defined(SMALL_CONFIG) && !defined(USE_PTR_HWTAG)
+#       if !defined(__CHERI_PURE_CAPABILITY__)
           word deferred;
   
@@ -763,6 +769,50 @@ GC_INNER mse * GC_mark_from(mse *mark_stack_top, mse *mark_stack,
             }
             if ((word)current_p > (word)limit) goto next_object;
           }
+#       else   /* !defined(__CHERI_PURE_CAPABILITY__) */  // it is better to avoid code duplication
+          void **deferred;
+  
+          /* Check each pointer for validity before dereferencing         */
+          /* to prevent capability exceptions.                            */
+          /* Utilise the pointer meta-data to speed-up the loop.          */
+          /* If the loop is below the pointer bounds, skip the rest of    */
+          /* marking for that chunk.                                      */
+          /* If the *limit* capability restricts us to reading fewer than */
+          /* sizeof(ptr_t),                                               */
+          /*  a. there can't possibly be a pointer at limit's pointer     */
+          /*  b. reading at that location will raise a capability         */
+          /*     exception                                                */
+          if (cheri_address_get(limit) + sizeof(ptr_t) - 1
+                >= (cheri_base_get(limit) + cheri_length_get(limit))) {
+            /* Decrement limit so that it's within current_p's bounds */
+            limit = cheri_address_set( current_p, ((cheri_base_get(limit)
+                                      + cheri_length_get(limit) - sizeof(ptr_t))
+                                      & ~(sizeof(ptr_t)-1)));
+            if ((word)current_p > (word)limit) goto next_object;
+          }
+          for(;;) {
+            GC_ASSERT((word)limit >= (word)current_p);
+            if (cheri_address_get(limit) < cheri_base_get(limit)) goto next_object;
+
+            has_rwx = cheri_perms_get(limit) & (CHERI_PERM_LOAD
+                                                | CHERI_PERM_STORE
+                                                | CHERI_PERM_EXECUTE);
+            if ((cheri_tag_get(limit) == 0) || !has_rwx) {
+              limit -= ALIGNMENT;
+            } else {
+              deferred = *(void **)limit;
+              FIXUP_POINTER(deferred);
+              limit -= ALIGNMENT;
+              has_rwx = cheri_perms_get(deferred) & (CHERI_PERM_LOAD
+                                                     | CHERI_PERM_STORE
+                                                     | CHERI_PERM_EXECUTE);
+              if (((cheri_tag_get(deferred) != 0) && has_rwx)
+                    && (deferred >= (word)least_ha && deferred < (word)greatest_ha))
+                break;
+            }
+            if ((word)current_p > (word)limit) goto next_object;
+          }
+#       endif   // defined(__CHERI_PURE_CAPABILITY__)
 #     endif
 
       for (; (word)current_p <= (word)limit; current_p += ALIGNMENT) {
@@ -1502,7 +1557,13 @@ GC_API void GC_CALL GC_print_trace(word gc_no)
 GC_ATTR_NO_SANITIZE_ADDR GC_ATTR_NO_SANITIZE_MEMORY GC_ATTR_NO_SANITIZE_THREAD
 GC_API void GC_CALL GC_push_all_eager(void *bottom, void *top)
 {
+# if defined(__CHERI_PURE_CAPABILITY__)
+    REGISTER void ** current_p; // it is better to use ptr_t instead of void**
+# else
     REGISTER ptr_t current_p;
+# endif
     REGISTER word *lim;
     REGISTER ptr_t greatest_ha = (ptr_t)GC_greatest_plausible_heap_addr;
     REGISTER ptr_t least_ha = (ptr_t)GC_least_plausible_heap_addr;
@@ -1512,6 +1573,18 @@ GC_API void GC_CALL GC_push_all_eager(void *bottom, void *top)
     if (top == 0) return;
 
     /* Check all pointers in range and push if they appear to be valid. */
+# if defined(__CHERI_PURE_CAPABILITY__)
+    lim = t - 1;
+    if ((intptr_t)lim >= (cheri_base_get(b) + cheri_length_get(b)))
+      lim = cheri_base_get(b) + cheri_length_get(b) - sizeof(ptr_t);
+
+    for (current_p = b; (word)current_p <= (word)lim; current_p++) {
+      REGISTER void *q = *current_p;
+
+      LOAD_WORD_OR_CONTINUE(q, current_p);
+      GC_PUSH_ONE_STACK(q, current_p);
+    }
+# else
     lim = (word *)(((word)top) & ~(ALIGNMENT-1)) - 1;
     for (current_p = (ptr_t)(((word)bottom + ALIGNMENT-1) & ~(ALIGNMENT-1));
          (word)current_p <= (word)lim; current_p += ALIGNMENT) {
@@ -1520,6 +1593,7 @@ GC_API void GC_CALL GC_push_all_eager(void *bottom, void *top)
       LOAD_WORD_OR_CONTINUE(q, current_p);
       GC_PUSH_ONE_STACK(q, current_p);
     }
+# endif
 #   undef GC_greatest_plausible_heap_addr
 #   undef GC_least_plausible_heap_addr
 }
diff --git a/os_dep.c b/os_dep.c
index 16e0ffd8..86ba0f93 100644
--- a/os_dep.c
+++ b/os_dep.c
@@ -90,6 +90,10 @@
 # include "mm/PCR_MM.h"
 #endif
 
+#if defined(__CHERI_PURE_CAPABILITY__)
+# include <link.h>
+#endif
+
 #if !defined(NO_EXECUTE_PERMISSION)
   STATIC GC_bool GC_pages_executable = TRUE;
 #else
@@ -1035,8 +1043,15 @@ GC_INNER size_t GC_page_size = 0;
 
     void * GC_find_limit(void * p, int up)
     {
+#     if defined(__CHERI_PURE_CAPABILITY__)
+        vaddr_t bound = up ? cheri_base_get(p) + cheri_length_get(p)
+                             : cheri_address_set(p, cheri_base_get(p));
+        return GC_find_limit_with_bound((ptr_t)p, (GC_bool)up,
+                                        cheri_address_set(p, bound));
+#     else
         return GC_find_limit_with_bound((ptr_t)p, (GC_bool)up,
                                         up ? (ptr_t)GC_WORD_MAX : 0);
+#     endif
     }
 # endif /* NEED_FIND_LIMIT || USE_PROC_FOR_LIBRARIES */
 
@@ -2035,6 +2050,7 @@ void GC_register_data_segments(void)
 /* For now we don't assume that there is always an empty page after     */
 /* etext.  But in some cases there actually seems to be slightly more.  */
 /* This also deals with holes between read-only data and writable data. */
+# if !defined(__CHERI_PURE_CAPABILITY__)
     GC_INNER ptr_t GC_FreeBSDGetDataStart(size_t max_page_size,
                                           ptr_t etext_addr)
     {
@@ -2056,8 +2072,88 @@ void GC_register_data_segments(void)
           /* As above, we go to plan B    */
           result = (ptr_t)GC_find_limit(DATAEND, FALSE);
       }
     return result;
     }
+# else  /* !defined(__CHERI_PURE_CAPABILITY__) */
+    /* The CheriBSD LLVM compiler declares `etext`, `edata` and `end` as */
+    /* typeless variables. If bdwgc is statically linked with the main   */
+    /* executable, these capabilities are compiled with read-only        */
+    /* permissions and bounds that span the .data and .bss sections.     */
+    /*                                                                   */
+    /* If bdwgc is compiled as a shared library, these symbols are       */
+    /* compiled with zero bounds and cannot be dereferenced. Instead,    */
+    /* read-only capability returned by the loader is utilised           */
+    struct scan_bounds {
+        vaddr_t start;
+        vaddr_t end;
+        ptr_t  ld_cap;
+    };
+
+    STATIC int GC_ld_cap_search(struct dl_phdr_info *info, size_t size, void *data)
+    {
+      struct scan_bounds *region = (struct scan_bounds *)data;
+      ptr_t load_addr = info->dlpi_addr;
+
+      if (!region || !SPANNING_CAPABILITY(load_addr,
+             region->start, region->end)) {
+        return 0;
+      }
+
+      region->ld_cap = cheri_bounds_set(
+                                    cheri_address_set(load_addr, region->start),
+                                    (size_t)(region->end - region->start));
+      return 1;
+
+    }
+
+    GC_INNER ptr_t GC_derive_cap_from_ldr(ptr_t range_start, ptr_t range_end)
+    {
+      vaddr_t scan_start = cheri_address_get(range_start);
+      vaddr_t scan_end = cheri_address_get(range_end);
+      /* If symbols already span required range, return it. */
+      if (SPANNING_CAPABILITY(range_start, scan_start, scan_end)) {
+        return range_start;
+      } else if (SPANNING_CAPABILITY(range_end, scan_start, scan_end)) {
+        return range_end;
+      }
+
+      /* Fall-back option : derive .data + .bss end pointer from */
+      /* read-only capability provided by loader */
+      struct scan_bounds region = { .start = scan_start,
+                                    .end = scan_end,
+                                    .ld_cap = NULL };
+      if (!dl_iterate_phdr(GC_ld_cap_search, (void *)&region)) {
+        ABORT("Cannot find static roots for capability system");
+      }
+      return region.ld_cap;
+    }
+
+    GC_INNER ptr_t GC_FreeBSDGetDataStart(size_t max_page_size,
+                                          ptr_t etext_addr)
+    {
+      volatile ptr_t cap_next_page = NULL;
+      ptr_t text_end = cheri_align_up(etext_addr, sizeof(ptr_t));
+      text_end = GC_derive_cap_from_ldr(text_end, DATAEND);
+      /* etext rounded to word boundary       */
+      volatile vaddr_t next_page = cheri_align_up(text_end, max_page_size);
+      volatile ptr_t result = text_end;
+      GC_setup_temporary_fault_handler();
+      if (SETJMP(GC_jmp_buf) == 0) {
+          /* Try reading at the address.                          */
+          /* This should happen before there is another thread.   */
+          for (; next_page < (word)DATAEND; next_page += (word)max_page_size) {
+              cap_next_page = cheri_address_set(text_end, next_page);
+              GC_noop1((word)(*cap_next_page));
+          }
+          GC_reset_fault_handler();
+      } else {
+          GC_reset_fault_handler();
+          /* As above, we go to plan B    */
+          result = (ptr_t)GC_find_limit(cheri_address_set(text_end,DATAEND), FALSE);
+      }
+      return(result);
     }
+# endif  /* !defined(__CHERI_PURE_CAPABILITY__) */
 #endif /* DATASTART_USES_BSDGETDATASTART */
 

ivmai added a commit that referenced this issue Oct 9, 2024
(fix of commit 176d640)

Issue #627 (bdwgc).

* tools/setjmp_t.c (nested_sp, main): Use ADDR().
ivmai added a commit that referenced this issue Oct 19, 2024
…CHERI

(fix of commit 433e2dd)

Issue #627 (bdwgc).

* include/gc/gc_typed.h [!GC_BUILD] (GC_calloc_typed_descr_s): First
define it as a macro (referring to GC_calloc_typed_descr_opaque_s).
* include/gc/gc_typed.h (GC_calloc_typed_descr_s): Undefine (after
definition of struct GC_calloc_typed_descr_s.
* typd_mlc.c (GC_calloc_prepare_explicitly_typed): Compare sizeof
GC_calloc_typed_descr_s to that of GC_calloc_typed_descr_opaque_s in
static assert (instead of computing the struct size using
GC_CALLOC_TYPED_DESCR_PTRS and GC_CALLOC_TYPED_DESCR_WORDS).
ivmai added a commit that referenced this issue Oct 19, 2024
(a cherry-pick of commits 8120c8b, 4f431ac partly from capablevms/bdwgc)

Issue #627 (bdwgc).

Changes specific to CHERI capability systems are conditionally compiled
using the macro __CHERI_PURE_CAPABILITY__.

* include/gc/gc.h [_UINTPTR_T_DECLARED && !__MSYS__] (GC_uintptr_t):
Define to uintptr_t.
* include/gc/gc.h [__GNUC__ && !__INTEL_COMPILER
&& __CHERI_PURE_CAPABILITY__] (GC_reachable_here): Use "g" constraint
instead of "X".
* include/gc/gc_config_macros.h [__GNUC__
&& __CHERI_PURE_CAPABILITY__]: Include stdint.h; reformat comment.
* include/gc/gc_tiny_fl.h [!GC_GRANULE_BYTES
&& __CHERI_PURE_CAPABILITY__] (GC_GRANULE_PTRS): Define to 1 (instead
of 2).
* include/private/gcconfig.h [__CHERI_PURE_CAPABILITY__ && USE_MMAP]
(USE_MUNMAP): Undefine; add TODO item.
* include/private/gcconfig.h [!CPP_PTRSZ && __CHERI_PURE_CAPABILITY__]
(CPP_PTRSZ): Define to __SIZEOF_POINTER__*8 instead of CPP_WORDSZ.

Co-authored-by: Ivan Maidanski <[email protected]>
@ivmai
Copy link
Owner Author

ivmai commented Oct 19, 2024

As of commit e1fb227, bdwgc could be built using:

./configure --disable-dynamic-loading --enable-cplusplus --enable-gc-assertions --enable-werror
make check CFLAGS_EXTRA="-Wno-cheri-capability-misuse -Wno-capability-to-integer-cast"

All tests fail currently, because of missing some patches from https://github.com/capablevms/bdwgc

@ivmai
Copy link
Owner Author

ivmai commented Oct 19, 2024

Note: some suppressed warnings could be eliminated by modifying GC_CAST_AWAY_CONST_PVOID() and CAST_THRU_UINTPTR() - remove intermediate GC_uintptr_t if __CHERI_PURE_CAPABILITY__.

ivmai added a commit that referenced this issue Oct 30, 2024
(fix of commits 42c770a, 176d640)

Issue #627 (bdwgc).

* darwin_stop_world.c (StackFrame): Remove reserved, savedRTOC fields
(these are unused trailing ones).
* darwin_stop_world.c (GC_FindTopOfStack): Use MAKE_CPTR() for
stack_start and frame->savedSP; compare frame to NULL instead of
stack_start to zero.
* darwin_stop_world.c [CPPCHECK] (GC_FindTopOfStack): Call
GC_noop1(frame->savedCR) (to make a dummy use of the field).
* dyn_load.c (GC_FirstDLOpenedLinkMap): Use MAKE_CPTR() for
dp->d_un.d_ptr.
* dyn_load.c (GC_register_dynamic_libraries): Replace char* to ptr_t;
use ADDR() for e.
* dyn_load.c (GC_register_dynamic_libraries,
GC_register_dynlib_callback): Use MAKE_CPTR() for p->p_vaddr.
* dyn_load.c [AIX] (GC_register_dynamic_libraries): Replace while()
loop with a for(;;) one; cast ldi->ldinfo_dataorg to ptr_t instead of
use of MAKE_CPTR().
* dyn_load.c [DARWIN] (dyld_section_add_del): Change type of start,
end local variables from unsigned long to ptr_t; use MAKE_CPTR() for
slide+sec->addr.
* headers.c (GC_prev_block): Use MAKE_CPTR() for HBLK_ADDR(bi,j).
* include/private/gc_priv.h (HBLKDISPL): Use ADDR().
* os_dep.c [NEED_CALLINFO && SAVE_CALL_CHAIN && (NARGS!=0
|| NFRAMES%2!=0 || !GC_HAVE_BUILTIN_BACKTRACE) && (I386 || SPARC)]
(GC_save_callers): Cast frame->FR_SAVFP to ptr_t instead of long; use
MAKE_CPTR() for fp->fr_arg[i].
* os_dep.c [NEED_CALLINFO] (GC_print_callers): Use ADDR() for
info[i].ci_pc.
* pthread_support.c [GC_PTHREADS_PARAMARK && GC_ASSERTIONS
&& GC_WIN32_THREADS && !USE_PTHREAD_LOCKS] (NUMERIC_THREAD_ID): Use
ADDR() for GC_PTHREAD_PTRVAL(id); refine comment.
ivmai added a commit that referenced this issue Oct 30, 2024
(refactoring)

Issue #627 (bdwgc).

Convert an unsigned value to a void pointer.  Typically used to print
a numeric value using "%p" format specifier.  The pointer is not
supposed to be dereferenced.

* headers.c (GC_install_counts): Use NUMERIC_TO_VPTR().
* include/private/dbg_mlc.h [KEEP_BACK_PTRS || PRINT_BLACK_LIST]
(MARKED_FOR_FINALIZATION, MARKED_FROM_REGISTER, NOT_MARKED): Likewise.
* misc.c [E2K] (GC_call_with_stack_base): Likewise.
* pthread_stop_world.c [NACL] (GC_suspend_all): Likewise.
* pthread_support.c [PARALLEL_MARK
&& HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG] (set_marker_thread_name):
Likewise.
* pthread_support.c [GC_PTHREADS_PARAMARK]
(GC_start_mark_threads_inner): Likewise.
* pthread_support.c [E2K] (GC_get_my_stackbottom): Likewise.
* reclaim.c (GC_start_reclaim): Likewise.
* tests/gctest.c (INT_TO_SEXPR, reverse_test_inner, typed_test):
Likewise.
* thread_local_alloc.c (return_freelists, GC_init_thread_local):
Likewise.
* win32_threads.c [PARALLEL_MARK && !GC_PTHREADS_PARAMARK]
(GC_start_mark_threads_inner): Likewise.
* win32_threads.c (GC_win32_start_inner): Likewise.
* win32_threads.c [GC_WINMAIN_REDIRECT]
(GC_waitForSingleObjectInfinite): Likewise.
* include/private/dbg_mlc.h [CPP_WORDSZ!=32] (GC_FREED_MEM_MARKER,
START_FLAG, END_FLAG): Add outermost parentheses.
* include/private/gc_priv.h (NUMERIC_TO_VPTR): New macro.
* pthread_support.c [E2K] (GC_record_stack_base, GC_set_stackbottom):
Remove redundant parentheses.
* win32_threads.c [CPPCHECK] (GC_use_threads_discovery): Add extra
parentheses.
ivmai added a commit that referenced this issue Oct 30, 2024
(refactoring)

Issue #627 (bdwgc).

* include/private/gcconfig.h [GC_PRIVATE_H && !OS2 && (NEXT || DOS4GW
|| NONSTOP || SOLARIS && !USE_MMAP || RTEMS || EMBOX || KOS
|| __CC_ARM)] (GET_MEM): Cast calloc() result to ptr_t instead of
size_t.
ivmai added a commit that referenced this issue Oct 30, 2024
Issue #627 (bdwgc).

* include/gc/gc.h [__GNUC__ && __CHERI_PURE_CAPABILITY__] (GC_ADDR_LT):
Cast pointers to GC_word before comparison.
ivmai added a commit that referenced this issue Oct 30, 2024
(fix of commit 1fcf50d)

Issue #627 (bdwgc).

* include/private/gc_atomic_ops.h [!GC_BUILTIN_ATOMIC]: Check
__CHERI_PURE_CAPABILITY__ instead of CPP_PTRSZ>CPP_WORDSZ (because the
later ones might not be defined when the header is included from a
test).
ivmai added a commit that referenced this issue Oct 30, 2024
Issue #627 (bdwgc).

Cast between numeric and pointer through GC_uintptr_t instead of word.

* cord/tests/de_win.c [CPPCHECK] (WinMain): Cast a pointer to word
through GC_uintptr_t.
* include/gc/gc.h [!__GNUC__ || __CHERI_PURE_CAPABILITY__]
(GC_ADDR_LT): Likewise.
* include/gc/gc_cpp.h (gc_cleanup::cleanup): Likewise.
* include/gc/gc_inline.h (GC_FAST_MALLOC_GRANS): Likewise.
* include/private/gc_priv.h (ADDR): Likewise.
* pthread_support.c [PARALLEL_MARK] (GC_mark_thread): Likewise.
* tests/subthreadcreate.c (entry): Likewise.
* gcj_mlc.c [FUNCPTR_IS_DATAPTR && CPPCHECK] (GC_gcj_fake_mark_proc):
Cast to word through GC_funcptr_uint.
* os_dep.c [MPROTECT_VDB && DARWIN && CPPCHECK] (GC_dirty_init):
Likewise.
* include/gc/gc.h [include/gc/gc.h [] (GC_HIDE_NZ_POINTER): Cast p to
intptr_t instead of GC_signed_word.
* include/private/gc_hdrs.h (FORWARDED_ADDR): Cast to size_t through
GC_uintptr_t.
* include/private/gc_locks.h [GC_PTHREADS && !GC_WIN32_PTHREADS]
(NUMERIC_THREAD_ID): Cast to unsigned long through GC_uintptr_t.
* include/private/gc_priv.h (NUMERIC_TO_VPTR, MAKE_CPTR): Cast to
pointer through GC_uintptr_t.
* include/private/gcconfig.h [I386 && DGUX] (MAP_FAILED): Likewise.
* pthread_stop_world.c (GC_suspend_all, GC_restart_all): Likewise.
* tests/staticroots.c (root_nz): Likewise.
* tests/staticroots_lib.c (root_nz): Likewise.
* tests/subthreadcreate.c (main): Likewise.
* include/private/gc_priv.h (CPTR_CLEAR_FLAGS, CPTR_SET_FLAGS): Cast
pointer to GC_uintptr_t instead of word.
* include/private/gcconfig.h (PTR_ALIGN_DOWN, PTR_ALIGN_UP): Likewise.
* tests/cpp.cc (D::CleanUp): Likewise.
* tests/cpp.cc [CPPCHECK] (WinMain): Likewise.
* tests/cpp.cc [!CPPCHECK] (main): Likewise.
* tests/weakmap.c (IS_FLAG_SET): Likewise.
* pthread_support.c [DEBUG_THREADS && !GC_WIN32_PTHREADS]
(GC_new_thread, GC_delete_thread, GC_unregister_my_thread_inner,
GC_thread_exit_proc): Cast to pointer through GC_uintptr_t instead of
signed_word.
* tests/gctest.c (SEXPR_TO_INT): Cast pointer to int through
GC_uintptr_t instead of GC_word.
* tests/initfromthread.c [!GC_PTHREADS] (thread): Cast to DWORD through
GC_uintptr_t instead of GC_word.
* tests/threadleak.c [!GC_PTHREADS] (test): Likewise.
* win32_threads.c (GC_win32_start): Likewise.
* win32_threads.c [GC_WINMAIN_REDIRECT] (WinMain): Likewise.
* tests/threadkey.c (on_thread_exit): Cast unused result to void.
@ivmai
Copy link
Owner Author

ivmai commented Oct 30, 2024

As of commit 5d619ee, bdwgc could be built using:

./autogen.sh
./configure --enable-cplusplus --enable-gc-assertions --enable-werror
make check

Or, using make -f Makefile.direct check or using cmake.
All tests fail currently (as noted above).

1 similar comment
@ivmai
Copy link
Owner Author

ivmai commented Oct 31, 2024

As of commit 5d619ee, bdwgc could be built using:

./autogen.sh
./configure --enable-cplusplus --enable-gc-assertions --enable-werror
make check

Or, using make -f Makefile.direct check or using cmake.
All tests fail currently (as noted above).

ivmai added a commit that referenced this issue Nov 1, 2024
(refactoring)

Issue #627 (bdwgc).

* include/private/gcconfig.h (DATASTART, DATAEND): Remove extra
parentheses.
* include/private/gcconfig.h (DATASTART, HEAP_START, STACKBOTTOM): Use
`MAKE_CPTR()`.
* include/private/gcconfig.h [OPENBSD && __ELF__] (DATAEND): Remove
unneeded "&" operation.
* include/private/gcconfig.h [POWERPC && AIX] (STACKBOTTOM, DATASTART,
DATAEND): Do not cast pointer through ulong.
* include/private/gcconfig.h [POWERPC && AIX] (errno): Do not declare
if `__64BIT__` is defined.
* include/private/gcconfig.h [I386 && SCO || MIPS && EWS4800]
(DATASTART): Use `ADDR()`.
* include/private/gcconfig.h [I386 && DJGPP]: Remove commented out
`STACKBOTTOM` definition.
* include/private/gcconfig.h [ALPHA && OSF1] (STACKBOTTOM): Use
`PTR_ALIGN_UP()`.
* include/private/gcconfig.h [ALPHA && OSF1] (HEURISTIC2_LIMIT): Use
`PTR_ALIGN_DOWN()`.
ivmai added a commit that referenced this issue Nov 1, 2024
Issue #627 (bdwgc).

* include/private/gc_priv.h (HBLKPTR, HBLK_PAGE_ALIGNED): Cast `objptr`
to `ptr_t`.
* include/private/gcconfig.h [GC_CLANG_PREREQ(11,0)] (PTR_ALIGN_DOWN):
Define using `__builtin_align_down()`; refine comment.
* include/private/gcconfig.h [GC_CLANG_PREREQ(11,0)] (PTR_ALIGN_UP):
Define using `__builtin_align_up()`.
* include/private/gcconfig.h [(M68K || I386) && LINUX && !__ELF__
|| I386 && (SEQUENT || HAIKU || SCO || DJGPP) || MIPS && EWS4800
|| M88K && CX_UX] (DATASTART): Cast first argument of `PTR_ALIGN_UP()`
to `ptr_t`.
ivmai added a commit that referenced this issue Nov 1, 2024
(fix of commit 6040089)

Issue #627 (bdwgc).

* include/private/gc_priv.h (CAST_THRU_UINTPTR): Refine comment.
@ivmai
Copy link
Owner Author

ivmai commented Nov 5, 2024

GCJ support is not working because it expects granule to be at least twice bigger than pointer currently. Should be fixed by #652.
For now, please pass -Denable_gcj_support=OFF to cmake (or --disable-gcj-support to configure).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant