From 72a2ada7f32d4485a7b39f4e22f1aa43ca045584 Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Mon, 26 Feb 2018 07:53:37 +0300 Subject: [PATCH] Change Darwin-specific code to comply with C++11 standard 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). --- darwin_stop_world.c | 10 +++++----- os_dep.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/darwin_stop_world.c b/darwin_stop_world.c index 3a8441e72..fd04fcd28 100644 --- a/darwin_stop_world.c +++ b/darwin_stop_world.c @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/os_dep.c b/os_dep.c index cdda0be29..13fe6d126 100644 --- a/os_dep.c +++ b/os_dep.c @@ -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 @@ -3919,7 +3924,12 @@ GC_INNER void GC_remove_protection(struct hblk *h, word nblocks, #include #include -/* 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 *); @@ -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 @@ -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)