Skip to content

Commit

Permalink
Change Darwin-specific code to comply with C++11 standard
Browse files Browse the repository at this point in the history
Issue #206 (bdwgc).

* darwin_stop_world.c (GC_stack_range_for): Cast pointer which is
assinged to lo local variable to ptr_t (instead of void*).
* os_dep.c [GC_DARWIN_THREADS && MPROTECT_VDB]: Include
darwin_stop_world.h (so that GC_mprotect_stop and GC_mprotect_resume
to be declared and later defined as extern "C").
* os_dep.c [MPROTECT_VDB && DARWIN] (exc_server, exception_raise,
exception_raise_state): Wrap into extern "C" block; refine comment.
* os_dep.c [MPROTECT_VDB && DARWIN] (catch_exception_raise_state,
catch_exception_raise_state_identity): Declare as extern "C" (before
the definition).
* os_dep.c [MPROTECT_VDB && DARWIN && THREADS] (GC_mprotect_state):
Initialize to GC_MP_NORMAL (instead of integer 0).
  • Loading branch information
jaykrell authored and ivmai committed Feb 26, 2018
1 parent c3f6e72 commit 72a2ada
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
10 changes: 5 additions & 5 deletions darwin_stop_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p,
ABORT("thread_get_state failed");

# if defined(I386)
lo = (void *)state.THREAD_FLD(esp);
lo = (ptr_t)state.THREAD_FLD(esp);
# ifndef DARWIN_DONT_PARSE_STACK
*phi = GC_FindTopOfStack(state.THREAD_FLD(esp));
# endif
Expand All @@ -221,7 +221,7 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p,
GC_push_one(state.THREAD_FLD(ebp));

# elif defined(X86_64)
lo = (void *)state.THREAD_FLD(rsp);
lo = (ptr_t)state.THREAD_FLD(rsp);
# ifndef DARWIN_DONT_PARSE_STACK
*phi = GC_FindTopOfStack(state.THREAD_FLD(rsp));
# endif
Expand All @@ -243,7 +243,7 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p,
GC_push_one(state.THREAD_FLD(r15));

# elif defined(POWERPC)
lo = (void *)(state.THREAD_FLD(r1) - PPC_RED_ZONE_SIZE);
lo = (ptr_t)(state.THREAD_FLD(r1) - PPC_RED_ZONE_SIZE);
# ifndef DARWIN_DONT_PARSE_STACK
*phi = GC_FindTopOfStack(state.THREAD_FLD(r1));
# endif
Expand Down Expand Up @@ -280,7 +280,7 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p,
GC_push_one(state.THREAD_FLD(r31));

# elif defined(ARM32)
lo = (void *)state.THREAD_FLD(sp);
lo = (ptr_t)state.THREAD_FLD(sp);
# ifndef DARWIN_DONT_PARSE_STACK
*phi = GC_FindTopOfStack(state.THREAD_FLD(r[7])); /* fp */
# endif
Expand All @@ -296,7 +296,7 @@ STATIC ptr_t GC_stack_range_for(ptr_t *phi, thread_act_t thread, GC_thread p,
GC_push_one(state.THREAD_FLD(lr));

# elif defined(AARCH64)
lo = (void *)state.THREAD_FLD(sp);
lo = (ptr_t)state.THREAD_FLD(sp);
# ifndef DARWIN_DONT_PARSE_STACK
*phi = GC_FindTopOfStack(state.THREAD_FLD(fp));
# endif
Expand Down
35 changes: 32 additions & 3 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
# include "mm/PCR_MM.h"
#endif

#if defined(GC_DARWIN_THREADS) && defined(MPROTECT_VDB)
/* Declare GC_mprotect_stop and GC_mprotect_resume as extern "C". */
# include "private/darwin_stop_world.h"
#endif

#if !defined(NO_EXECUTE_PERMISSION)
STATIC GC_bool GC_pages_executable = TRUE;
#else
Expand Down Expand Up @@ -3919,7 +3924,12 @@ GC_INNER void GC_remove_protection(struct hblk *h, word nblocks,
#include <mach/task.h>
#include <pthread.h>

/* These are not defined in any header, although they are documented */
#ifdef __cplusplus
extern "C" {
#endif

/* Some of the following prototypes are missing in any header, although */
/* they are documented. Some are in mach/exc.h file. */
extern boolean_t
exc_server(mach_msg_header_t *, mach_msg_header_t *);

Expand All @@ -3944,7 +3954,26 @@ exception_raise_state_identity(mach_port_t, mach_port_t, mach_port_t,
GC_API_OSCALL kern_return_t
catch_exception_raise(mach_port_t exception_port, mach_port_t thread,
mach_port_t task, exception_type_t exception,
exception_data_t code, mach_msg_type_number_t code_count);
exception_data_t code,
mach_msg_type_number_t code_count);

GC_API_OSCALL kern_return_t
catch_exception_raise_state(mach_port_name_t exception_port,
int exception, exception_data_t code,
mach_msg_type_number_t codeCnt, int flavor,
thread_state_t old_state, int old_stateCnt,
thread_state_t new_state, int new_stateCnt);

GC_API_OSCALL kern_return_t
catch_exception_raise_state_identity(mach_port_name_t exception_port,
mach_port_t thread, mach_port_t task, int exception,
exception_data_t code, mach_msg_type_number_t codeCnt,
int flavor, thread_state_t old_state, int old_stateCnt,
thread_state_t new_state, int new_stateCnt);

#ifdef __cplusplus
} /* extern "C" */
#endif

/* These should never be called, but just in case... */
GC_API_OSCALL kern_return_t
Expand Down Expand Up @@ -4019,7 +4048,7 @@ typedef enum {
/* This value is only used on the reply port. */
# define ID_ACK 3

STATIC GC_mprotect_state_t GC_mprotect_state = 0;
STATIC GC_mprotect_state_t GC_mprotect_state = GC_MP_NORMAL;

/* The following should ONLY be called when the world is stopped. */
STATIC void GC_mprotect_thread_notify(mach_msg_id_t id)
Expand Down

0 comments on commit 72a2ada

Please sign in to comment.