Skip to content

Commit

Permalink
Provide correct GC_uintptr_t, CPP_PTRSZ, GC_GRANULE_PTRS for CHERI
Browse files Browse the repository at this point in the history
(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]>
  • Loading branch information
Dejice Jacob and ivmai committed Oct 19, 2024
1 parent 420b0a8 commit e1fb227
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
8 changes: 5 additions & 3 deletions include/gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ typedef GC_SIGNEDWORD GC_signed_word;
#undef GC_SIGNEDWORD
#undef GC_UNSIGNEDWORD

#if (defined(_UINTPTR_T) || defined(_UINTPTR_T_DEFINED)) && !defined(__MSYS__)
/* Note: MSYS2 might provide __uintptr_t instead of uintptr_t. */
#if (defined(_UINTPTR_T) || defined(_UINTPTR_T_DECLARED) \
|| defined(_UINTPTR_T_DEFINED)) \
&& !defined(__MSYS__)
/* Note: MSYS2 might provide __uintptr_t but not uintptr_t. */
typedef uintptr_t GC_uintptr_t;
#else
typedef GC_word GC_uintptr_t;
Expand Down Expand Up @@ -1476,7 +1478,7 @@ GC_API int GC_CALL GC_invoke_finalizers(void);
#if defined(__GNUC__) && !defined(__INTEL_COMPILER) \
&& !(defined(__APPLE__) && defined(__arm__) && defined(__TINYC__))
/* TCC (as of v0.9.28rc) does not support asm on macOS/arm. */
# if defined(__TINYC__)
# if defined(__CHERI_PURE_CAPABILITY__) || defined(__TINYC__)
# define GC_reachable_here(ptr) \
__asm__ __volatile__(" " : : "g"(ptr) : "memory")
# elif defined(__e2k__)
Expand Down
10 changes: 5 additions & 5 deletions include/gc/gc_config_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@
# define __GC
# if !defined(_WIN32_WCE) || defined(__GNUC__)
# include <stddef.h>
# if defined(__MINGW32__) && !defined(_WIN32_WCE)
# if defined(__MINGW32__) && !defined(_WIN32_WCE) \
|| defined(__CHERI_PURE_CAPABILITY__)
# include <stdint.h>
/* We mention uintptr_t. */
/* Perhaps this should be included in pure msft environments */
/* as well? */
/* We mention uintptr_t. Perhaps this should be included in pure */
/* msft environments as well. */
# endif
# else /* _WIN32_WCE */
# else
/* Yet more kludges for WinCE. */
# include <stdlib.h> /* size_t is defined here */
# ifndef _PTRDIFF_T_DEFINED
Expand Down
6 changes: 5 additions & 1 deletion include/gc/gc_tiny_fl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
#ifdef GC_GRANULE_BYTES
# define GC_GRANULE_PTRS (GC_GRANULE_BYTES / GC_SIZEOF_PTR)
#else
# define GC_GRANULE_PTRS 2 /* in pointers */
# if defined(__CHERI_PURE_CAPABILITY__)
# define GC_GRANULE_PTRS 1
# else
# define GC_GRANULE_PTRS 2 /* in pointers */
# endif
# define GC_GRANULE_BYTES (GC_GRANULE_PTRS * GC_SIZEOF_PTR)
#endif /* !GC_GRANULE_BYTES */

Expand Down
11 changes: 10 additions & 1 deletion include/private/gcconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2488,6 +2488,11 @@ extern char __global_base, __heap_base;
# define USE_MMAP_ANON
#endif

#if defined(__CHERI_PURE_CAPABILITY__) && defined(USE_MMAP)
/* TODO: currently turned off to avoid downgrading permissions on CHERI */
# undef USE_MUNMAP
#endif

#if defined(REDIRECT_MALLOC) && defined(THREADS) \
&& (defined(LINUX) || defined(NACL))
/* TODO: Unclear if NaCl really needs this. */
Expand Down Expand Up @@ -2674,7 +2679,11 @@ EXTERN_C_BEGIN
#endif

#ifndef CPP_PTRSZ
# define CPP_PTRSZ CPP_WORDSZ
# if defined(__CHERI_PURE_CAPABILITY__)
# define CPP_PTRSZ (__SIZEOF_POINTER__ * 8)
# else
# define CPP_PTRSZ CPP_WORDSZ
# endif
#endif

#ifndef CPPCHECK
Expand Down

0 comments on commit e1fb227

Please sign in to comment.