Skip to content

Commit

Permalink
Define COVERT_DATAFLOW_P() internal macro
Browse files Browse the repository at this point in the history
(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.
  • Loading branch information
ivmai committed Jun 6, 2024
1 parent f9b4b19 commit 636a478
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion backgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static void add_edge(ptr_t p, ptr_t q)

if ((ADDR(pred) & FLAG_MANY) != 0) {
n_edges = e -> n_edges;
} else if ((ADDR(COVERT_DATAFLOW(pred)) & 1) == 0) {
} else if ((COVERT_DATAFLOW(ADDR(pred)) & 1) == 0) {
/* A misinterpreted freelist link. */
n_edges = 1;
local = -1;
Expand Down
6 changes: 3 additions & 3 deletions dyn_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ STATIC GC_has_static_roots_func GC_has_static_roots = 0;
dynStructureAddr = &_DYNAMIC;
# endif

if (0 == COVERT_DATAFLOW(dynStructureAddr)) {
if (0 == COVERT_DATAFLOW(ADDR(dynStructureAddr))) {
/* _DYNAMIC symbol not resolved. */
return NULL;
}
Expand Down Expand Up @@ -563,7 +563,7 @@ GC_INNER GC_bool GC_register_main_static_data(void)
/* zero (otherwise a compiler might issue a warning). */
return FALSE;
# else
return 0 == COVERT_DATAFLOW(dl_iterate_phdr);
return 0 == COVERT_DATAFLOW(ADDR(dl_iterate_phdr));
# endif
}

Expand Down Expand Up @@ -694,7 +694,7 @@ GC_FirstDLOpenedLinkMap(void)
{
static struct link_map *cachedResult = 0;

if (0 == COVERT_DATAFLOW(_DYNAMIC)) {
if (0 == COVERT_DATAFLOW(ADDR(_DYNAMIC))) {
/* _DYNAMIC symbol not resolved. */
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ GC_EXTERN GC_warn_proc GC_current_warn_proc;
/* A tagging macro (for a code static analyzer) to indicate that the */
/* string obtained from an untrusted source (e.g., argv[], getenv) is */
/* safe to use in a vulnerable operation (e.g., open, exec). */
#define TRUSTED_STRING(s) (char*)COVERT_DATAFLOW(s)
#define TRUSTED_STRING(s) COVERT_DATAFLOW_P(s)

/* Get environment entry */
#ifdef GC_READ_ENV_FILE
Expand Down
26 changes: 14 additions & 12 deletions include/private/gcconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,6 @@ EXTERN_C_BEGIN
# define GC_CLANG_PREREQ_FULL(major, minor, patchlevel) 0
#endif

#ifdef LINT2
/* A macro (based on a tricky expression) to prevent false warnings */
/* like "Array compared to 0", "Comparison of identical expressions", */
/* "Untrusted loop bound" output by some static code analysis tools. */
/* The argument should not be a literal value. The result is */
/* converted to word type. (Actually, GC_word is used instead of */
/* word type as the latter might be undefined at the place of use.) */
# define COVERT_DATAFLOW(w) (~(GC_word)(w)^(~(GC_word)0))
#else
# define COVERT_DATAFLOW(w) ((GC_word)(w))
#endif

/* Machine dependent parameters. Some tuning parameters can be found */
/* near the top of gc_priv.h. */

Expand Down Expand Up @@ -3407,6 +3395,20 @@ EXTERN_C_BEGIN
# define FIXUP_POINTER(p) (void)(p)
#endif

#ifdef LINT2
/* A macro (based on a tricky expression) to prevent false warnings */
/* like "Array compared to 0", "Comparison of identical expressions", */
/* "Untrusted loop bound" output by some static code analysis tools. */
/* The argument should not be a literal value. The result is */
/* converted to word type. (Actually, GC_word is used instead of */
/* word type as the latter might be undefined at the place of use.) */
# define COVERT_DATAFLOW(w) (~(GC_word)(w)^(~(GC_word)0))
#else
# define COVERT_DATAFLOW(w) ((GC_word)(w))
#endif

# define COVERT_DATAFLOW_P(p) ((ptr_t)COVERT_DATAFLOW(p))

#if defined(REDIRECT_MALLOC) && defined(THREADS) && !defined(LINUX) \
&& !defined(REDIRECT_MALLOC_IN_HEADER)
/* May work on other platforms (e.g. Darwin) provided the client */
Expand Down
2 changes: 1 addition & 1 deletion mach_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ GC_INNER void GC_with_callee_saves_pushed(GC_with_callee_saves_func fn,
/* Strongly discourage the compiler from treating the above */
/* as a tail-call, since that would pop the register */
/* contents before we get a chance to look at them. */
GC_noop1(COVERT_DATAFLOW(&dummy));
GC_noop1(COVERT_DATAFLOW(ADDR(&dummy)));
# undef volatile_arg
}

Expand Down
8 changes: 4 additions & 4 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ STATIC void GC_init_size_map(void)
# if defined(CPPCHECK)
GC_noop1(dummy[0]);
# else
GC_noop1(COVERT_DATAFLOW(dummy));
GC_noop1(COVERT_DATAFLOW(ADDR(dummy)));
# endif
return arg;
}
Expand Down Expand Up @@ -2302,7 +2302,7 @@ GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func fn, void *arg)
result = (*(GC_stack_base_func volatile *)&fn)(&base, arg);
/* Strongly discourage the compiler from treating the above */
/* as a tail call. */
GC_noop1(COVERT_DATAFLOW(&base));
GC_noop1(COVERT_DATAFLOW(ADDR(&base)));
return result;
}

Expand All @@ -2326,13 +2326,13 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn, void *client_data)
/* GC_get_main_stack_base() is unimplemented or broken for */
/* the platform). */
if (HOTTER_THAN(GC_stackbottom, (ptr_t)(&stacksect)))
GC_stackbottom = (ptr_t)COVERT_DATAFLOW(&stacksect);
GC_stackbottom = COVERT_DATAFLOW_P(&stacksect);

if (GC_blocked_sp == NULL) {
/* We are not inside GC_do_blocking() - do nothing more. */
client_data = (*(GC_fn_type volatile *)&fn)(client_data);
/* Prevent treating the above as a tail call. */
GC_noop1(COVERT_DATAFLOW(&stacksect));
GC_noop1(COVERT_DATAFLOW(ADDR(&stacksect)));
return client_data; /* result */
}

Expand Down
6 changes: 3 additions & 3 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,12 @@ GC_INNER const char * GC_get_maps(void)
/* code is put into a shared library (directly or indirectly) */
/* which is linked with -Bsymbolic-functions option. Thus, */
/* the following is not used by default. */
if (COVERT_DATAFLOW(__data_start) != 0) {
if (COVERT_DATAFLOW(ADDR(__data_start)) != 0) {
GC_data_start = (ptr_t)(__data_start);
} else {
GC_data_start = (ptr_t)(data_start);
}
if (COVERT_DATAFLOW(GC_data_start) != 0) {
if (COVERT_DATAFLOW(ADDR(GC_data_start)) != 0) {
if (ADDR_LT(data_end, GC_data_start))
ABORT_ARG2("Wrong __data_start/_end pair",
": %p .. %p", (void *)GC_data_start, (void *)data_end);
Expand Down Expand Up @@ -5526,7 +5526,7 @@ GC_API int GC_CALL GC_get_pages_executable(void)
if (strncmp(result_buf, "main",
nl != NULL
? (size_t)(ADDR(nl) /* a cppcheck workaround */
- COVERT_DATAFLOW(result_buf))
- COVERT_DATAFLOW(ADDR(result_buf)))
: result_len) == 0) {
stop = TRUE;
}
Expand Down
6 changes: 3 additions & 3 deletions pthread_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn, void *client_data)
/* Cast fn to a volatile type to prevent its call inlining. */
client_data = (*(GC_fn_type volatile *)&fn)(client_data);
/* Prevent treating the above as a tail call. */
GC_noop1(COVERT_DATAFLOW(&stacksect));
GC_noop1(COVERT_DATAFLOW(ADDR(&stacksect)));
return client_data; /* result */
}

Expand Down Expand Up @@ -2372,7 +2372,7 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)

/* After the join, thread id may have been recycled. */
READER_LOCK();
t = (GC_thread)COVERT_DATAFLOW(GC_lookup_by_pthread(thread));
t = (GC_thread)COVERT_DATAFLOW_P(GC_lookup_by_pthread(thread));
/* This is guaranteed to be the intended one, since the thread id */
/* cannot have been recycled by pthreads. */
READER_UNLOCK();
Expand Down Expand Up @@ -2418,7 +2418,7 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)

INIT_REAL_SYMS();
READER_LOCK();
t = (GC_thread)COVERT_DATAFLOW(GC_lookup_by_pthread(thread));
t = (GC_thread)COVERT_DATAFLOW_P(GC_lookup_by_pthread(thread));
READER_UNLOCK();
result = REAL_FUNC(pthread_detach)(thread);
if (EXPECT(0 == result, TRUE)) {
Expand Down

0 comments on commit 636a478

Please sign in to comment.