From 5d6a5f6b0de0ff946eb96f1a190e241e2ded1102 Mon Sep 17 00:00:00 2001 From: Andi McClure Date: Fri, 15 Jan 2016 14:18:56 -0500 Subject: [PATCH] Fix build on platforms where native thread IDs are not pointer sized Certain of our debug prints assume thread ids can be cast directly to a pointer. This does not work on platforms where thread IDs are ints. --- mono/metadata/sgen-os-posix.c | 6 ++--- mono/metadata/sgen-os-win32.c | 2 +- mono/metadata/sgen-stw.c | 2 +- mono/mini/debugger-agent.c | 58 +++++++++++++++++++++---------------------- mono/sgen/sgen-gc.c | 2 +- mono/utils/hazard-pointer.c | 2 +- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/mono/metadata/sgen-os-posix.c b/mono/metadata/sgen-os-posix.c index 2a8b7ad10f4..29ce34f917c 100644 --- a/mono/metadata/sgen-os-posix.c +++ b/mono/metadata/sgen-os-posix.c @@ -107,7 +107,7 @@ suspend_thread (SgenThreadInfo *info, void *context) if (mono_gc_get_gc_callbacks ()->thread_suspend_func) mono_gc_get_gc_callbacks ()->thread_suspend_func (info->client_info.runtime_data, context, NULL); - SGEN_LOG (4, "Posting suspend_ack_semaphore for suspend from %p %p", info, (gpointer)mono_native_thread_id_get ()); + SGEN_LOG (4, "Posting suspend_ack_semaphore for suspend from %p %p", info, (gpointer) (gsize) mono_native_thread_id_get ()); /* Block the restart signal. @@ -129,7 +129,7 @@ suspend_thread (SgenThreadInfo *info, void *context) /* Unblock the restart signal. */ pthread_sigmask (SIG_UNBLOCK, &suspend_ack_signal_mask, NULL); - SGEN_LOG (4, "Posting suspend_ack_semaphore for resume from %p %p\n", info, (gpointer)mono_native_thread_id_get ()); + SGEN_LOG (4, "Posting suspend_ack_semaphore for resume from %p %p\n", info, (gpointer) (gsize) mono_native_thread_id_get ()); /* notify the waiting thread */ SGEN_SEMAPHORE_POST (suspend_ack_semaphore_ptr); } @@ -163,7 +163,7 @@ MONO_SIG_HANDLER_FUNC (static, restart_handler) info = mono_thread_info_current (); info->client_info.signal = restart_signal_num; - SGEN_LOG (4, "Restart handler in %p %p", info, (gpointer)mono_native_thread_id_get ()); + SGEN_LOG (4, "Restart handler in %p %p", info, (gpointer) (gsize) mono_native_thread_id_get ()); errno = old_errno; } diff --git a/mono/metadata/sgen-os-win32.c b/mono/metadata/sgen-os-win32.c index 8a2ae113da9..f9f699b7601 100644 --- a/mono/metadata/sgen-os-win32.c +++ b/mono/metadata/sgen-os-win32.c @@ -1,6 +1,6 @@ #include "config.h" -#if defined(HAVE_SGEN_GC) && defined(HOST_WIN32) +#if defined(HAVE_SGEN_GC) && !defined(USE_COOP_GC) && defined(HOST_WIN32) #include "io-layer/io-layer.h" diff --git a/mono/metadata/sgen-stw.c b/mono/metadata/sgen-stw.c index 651dbb59de1..b2cb17c3b91 100644 --- a/mono/metadata/sgen-stw.c +++ b/mono/metadata/sgen-stw.c @@ -224,7 +224,7 @@ sgen_client_stop_world (int generation) update_current_thread_stack (&generation); sgen_global_stop_count++; - SGEN_LOG (3, "stopping world n %d from %p %p", sgen_global_stop_count, mono_thread_info_current (), (gpointer)mono_native_thread_id_get ()); + SGEN_LOG (3, "stopping world n %d from %p %p", sgen_global_stop_count, mono_thread_info_current (), (gpointer) (gsize) mono_native_thread_id_get ()); TV_GETTIME (stop_world_time); if (mono_thread_info_unified_management_enabled ()) { diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index a8e6b3920eb..c2a4b7c4f6d 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -2387,7 +2387,7 @@ buffer_add_typeid (Buffer *buf, MonoDomain *domain, MonoClass *klass) if (is_debugger_thread ()) DEBUG_PRINTF (2, "[dbg] send class [%s]\n", s); else - DEBUG_PRINTF (2, "[%p] send class [%s]\n", (gpointer)mono_native_thread_id_get (), s); + DEBUG_PRINTF (2, "[%p] send class [%s]\n", (gpointer) (gsize) mono_native_thread_id_get (), s); g_free (s); } } @@ -2665,7 +2665,7 @@ notify_thread (gpointer key, gpointer value, gpointer user_data) if (mono_native_thread_id_equals (mono_native_thread_id_get (), tid) || tls->terminated) return; - DEBUG_PRINTF (1, "[%p] Interrupting %p...\n", (gpointer)mono_native_thread_id_get (), (gpointer)tid); + DEBUG_PRINTF (1, "[%p] Interrupting %p...\n", (gpointer) (gsize) mono_native_thread_id_get (), (gpointer)tid); /* This is _not_ equivalent to ves_icall_System_Threading_Thread_Abort () */ InterruptData interrupt_data = { 0 }; @@ -2673,7 +2673,7 @@ notify_thread (gpointer key, gpointer value, gpointer user_data) mono_thread_info_safe_suspend_and_run ((MonoNativeThreadId)(gpointer)(gsize)thread->tid, FALSE, debugger_interrupt_critical, &interrupt_data); if (!interrupt_data.valid_info) { - DEBUG_PRINTF (1, "[%p] mono_thread_info_suspend_sync () failed for %p...\n", (gpointer)mono_native_thread_id_get (), (gpointer)tid); + DEBUG_PRINTF (1, "[%p] mono_thread_info_suspend_sync () failed for %p...\n", (gpointer) (gsize) mono_native_thread_id_get (), (gpointer)tid); /* * Attached thread which died without detaching. */ @@ -2704,7 +2704,7 @@ process_suspend (DebuggerTlsData *tls, MonoContext *ctx) if (suspend_count - tls->resume_count > 0) tls->suspending = TRUE; - DEBUG_PRINTF (1, "[%p] Received single step event for suspending.\n", (gpointer)mono_native_thread_id_get ()); + DEBUG_PRINTF (1, "[%p] Received single step event for suspending.\n", (gpointer) (gsize) mono_native_thread_id_get ()); if (suspend_count - tls->resume_count == 0) { /* @@ -2712,7 +2712,7 @@ process_suspend (DebuggerTlsData *tls, MonoContext *ctx) * suspending is still active. * FIXME: This slows down single threaded invokes. */ - DEBUG_PRINTF (1, "[%p] Ignored during single threaded invoke.\n", (gpointer)mono_native_thread_id_get ()); + DEBUG_PRINTF (1, "[%p] Ignored during single threaded invoke.\n", (gpointer) (gsize) mono_native_thread_id_get ()); return; } @@ -2743,7 +2743,7 @@ suspend_vm (void) suspend_count ++; - DEBUG_PRINTF (1, "[%p] Suspending vm...\n", (gpointer)mono_native_thread_id_get ()); + DEBUG_PRINTF (1, "[%p] Suspending vm...\n", (gpointer) (gsize) mono_native_thread_id_get ()); if (suspend_count == 1) { // FIXME: Is it safe to call this inside the lock ? @@ -2782,7 +2782,7 @@ resume_vm (void) g_assert (suspend_count > 0); suspend_count --; - DEBUG_PRINTF (1, "[%p] Resuming vm, suspend count=%d...\n", (gpointer)mono_native_thread_id_get (), suspend_count); + DEBUG_PRINTF (1, "[%p] Resuming vm, suspend count=%d...\n", (gpointer) (gsize) mono_native_thread_id_get (), suspend_count); if (suspend_count == 0) { // FIXME: Is it safe to call this inside the lock ? @@ -2906,7 +2906,7 @@ suspend_current (void) mono_coop_sem_post (&suspend_sem); } - DEBUG_PRINTF (1, "[%p] Suspended.\n", (gpointer)mono_native_thread_id_get ()); + DEBUG_PRINTF (1, "[%p] Suspended.\n", (gpointer) (gsize) mono_native_thread_id_get ()); while (suspend_count - tls->resume_count > 0) { err = mono_coop_cond_wait (&suspend_cond, &suspend_mutex); @@ -2920,7 +2920,7 @@ suspend_current (void) mono_coop_mutex_unlock (&suspend_mutex); - DEBUG_PRINTF (1, "[%p] Resumed.\n", (gpointer)mono_native_thread_id_get ()); + DEBUG_PRINTF (1, "[%p] Resumed.\n", (gpointer) (gsize) mono_native_thread_id_get ()); if (tls->pending_invoke) { /* Save the original context */ @@ -3736,7 +3736,7 @@ process_event (EventKind event, gpointer arg, gint32 il_offset, MonoContext *ctx vm_start_event_sent = TRUE; } - DEBUG_PRINTF (1, "[%p] Sent %d events %s(%d), suspend=%d.\n", (gpointer)mono_native_thread_id_get (), nevents, event_to_string (event), ecount, suspend_policy); + DEBUG_PRINTF (1, "[%p] Sent %d events %s(%d), suspend=%d.\n", (gpointer) (gsize) mono_native_thread_id_get (), nevents, event_to_string (event), ecount, suspend_policy); switch (suspend_policy) { case SUSPEND_POLICY_NONE: @@ -4512,7 +4512,7 @@ ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, DebuggerTlsData *t /* * These seq points are inserted by the JIT after calls, step over needs to skip them. */ - DEBUG_PRINTF (1, "[%p] Seq point at nonempty stack %x while stepping over, continuing single stepping.\n", (gpointer)mono_native_thread_id_get (), sp->il_offset); + DEBUG_PRINTF (1, "[%p] Seq point at nonempty stack %x while stepping over, continuing single stepping.\n", (gpointer) (gsize) mono_native_thread_id_get (), sp->il_offset); return FALSE; } @@ -4522,7 +4522,7 @@ ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, DebuggerTlsData *t compute_frame_info (tls->thread, tls); if (req->nframes && tls->frame_count && tls->frame_count > req->nframes) { /* Hit the breakpoint in a recursive call */ - DEBUG_PRINTF (1, "[%p] Breakpoint at lower frame while stepping over, continuing single stepping.\n", (gpointer)mono_native_thread_id_get ()); + DEBUG_PRINTF (1, "[%p] Breakpoint at lower frame while stepping over, continuing single stepping.\n", (gpointer) (gsize) mono_native_thread_id_get ()); return FALSE; } } @@ -4533,7 +4533,7 @@ ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, DebuggerTlsData *t mono_thread_state_init_from_monoctx (&tls->context, ctx); compute_frame_info (tls->thread, tls); if (ss_req->start_method == method && req->nframes && tls->frame_count == req->nframes) {//Check also frame count(could be recursion) - DEBUG_PRINTF (1, "[%p] Seq point at nonempty stack %x while stepping in, continuing single stepping.\n", (gpointer)mono_native_thread_id_get (), sp->il_offset); + DEBUG_PRINTF (1, "[%p] Seq point at nonempty stack %x while stepping in, continuing single stepping.\n", (gpointer) (gsize) mono_native_thread_id_get (), sp->il_offset); return FALSE; } } @@ -4549,11 +4549,11 @@ ss_update (SingleStepReq *req, MonoJitInfo *ji, SeqPoint *sp, DebuggerTlsData *t loc = mono_debug_method_lookup_location (minfo, sp->il_offset); if (!loc) { - DEBUG_PRINTF (1, "[%p] No line number info for il offset %x, continuing single stepping.\n", (gpointer)mono_native_thread_id_get (), sp->il_offset); + DEBUG_PRINTF (1, "[%p] No line number info for il offset %x, continuing single stepping.\n", (gpointer) (gsize) mono_native_thread_id_get (), sp->il_offset); ss_req->last_method = method; hit = FALSE; } else if (loc && method == ss_req->last_method && loc->row == ss_req->last_line) { - DEBUG_PRINTF (1, "[%p] Same source line (%d), continuing single stepping.\n", (gpointer)mono_native_thread_id_get (), loc->row); + DEBUG_PRINTF (1, "[%p] Same source line (%d), continuing single stepping.\n", (gpointer) (gsize) mono_native_thread_id_get (), loc->row); hit = FALSE; } @@ -4626,7 +4626,7 @@ process_breakpoint_inner (DebuggerTlsData *tls, gboolean from_signal) g_assert (found_sp); - DEBUG_PRINTF (1, "[%p] Breakpoint hit, method=%s, ip=%p, [il=0x%x,native=0x%x].\n", (gpointer)mono_native_thread_id_get (), method->name, ip, sp.il_offset, native_offset); + DEBUG_PRINTF (1, "[%p] Breakpoint hit, method=%s, ip=%p, [il=0x%x,native=0x%x].\n", (gpointer) (gsize) mono_native_thread_id_get (), method->name, ip, sp.il_offset, native_offset); bp = NULL; for (i = 0; i < breakpoints->len; ++i) { @@ -4733,7 +4733,7 @@ resume_from_signal_handler (void *sigctx, void *func) // FIXME: This might not work on an altstack ? tls = (DebuggerTlsData *)mono_native_tls_get_value (debugger_tls_id); if (!tls) - fprintf (stderr, "Thread %p is not attached to the JIT.\n", (gpointer)mono_native_thread_id_get ()); + fprintf (stderr, "Thread %p is not attached to the JIT.\n", (gpointer) (gsize) mono_native_thread_id_get ()); g_assert (tls); // FIXME: MonoContext usually doesn't include the fp registers, so these are @@ -4857,7 +4857,7 @@ process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal) if (log_level > 0) { ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, &domain); - DEBUG_PRINTF (1, "[%p] Single step event (depth=%s) at %s (%p)[0x%x], sp %p, last sp %p\n", (gpointer)mono_native_thread_id_get (), ss_depth_to_string (ss_req->depth), mono_method_full_name (jinfo_get_method (ji), TRUE), MONO_CONTEXT_GET_IP (ctx), (int)((guint8*)MONO_CONTEXT_GET_IP (ctx) - (guint8*)ji->code_start), MONO_CONTEXT_GET_SP (ctx), ss_req->last_sp); + DEBUG_PRINTF (1, "[%p] Single step event (depth=%s) at %s (%p)[0x%x], sp %p, last sp %p\n", (gpointer) (gsize) mono_native_thread_id_get (), ss_depth_to_string (ss_req->depth), mono_method_full_name (jinfo_get_method (ji), TRUE), MONO_CONTEXT_GET_IP (ctx), (int)((guint8*)MONO_CONTEXT_GET_IP (ctx) - (guint8*)ji->code_start), MONO_CONTEXT_GET_SP (ctx), ss_req->last_sp); } ji = mini_jit_info_table_find (mono_domain_get (), (char*)ip, &domain); @@ -5877,7 +5877,7 @@ decode_vtype (MonoType *t, MonoDomain *domain, guint8 *addr, guint8 *buf, guint8 if (t && klass != mono_class_from_mono_type (t)) { char *name = mono_type_full_name (t); char *name2 = mono_type_full_name (&klass->byval_arg); - DEBUG_PRINTF (1, "[%p] Expected value of type %s, got %s.\n", (gpointer)mono_native_thread_id_get (), name, name2); + DEBUG_PRINTF (1, "[%p] Expected value of type %s, got %s.\n", (gpointer) (gsize) mono_native_thread_id_get (), name, name2); g_free (name); g_free (name2); return ERR_INVALID_ARGUMENT; @@ -5913,7 +5913,7 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr, !(t->type == MONO_TYPE_GENERICINST && type == MONO_TYPE_VALUETYPE) && !(t->type == MONO_TYPE_VALUETYPE && type == MONO_TYPE_OBJECT)) { char *name = mono_type_full_name (t); - DEBUG_PRINTF (1, "[%p] Expected value of type %s, got 0x%0x.\n", (gpointer)mono_native_thread_id_get (), name, type); + DEBUG_PRINTF (1, "[%p] Expected value of type %s, got 0x%0x.\n", (gpointer) (gsize) mono_native_thread_id_get (), name, type); g_free (name); return ERR_INVALID_ARGUMENT; } @@ -6057,7 +6057,7 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr, g_free (vtype_buf); } else { char *name = mono_type_full_name (t); - DEBUG_PRINTF (1, "[%p] Expected value of type %s, got 0x%0x.\n", (gpointer)mono_native_thread_id_get (), name, type); + DEBUG_PRINTF (1, "[%p] Expected value of type %s, got 0x%0x.\n", (gpointer) (gsize) mono_native_thread_id_get (), name, type); g_free (name); return ERR_INVALID_ARGUMENT; } @@ -6471,7 +6471,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8 * Invoke this method directly, currently only Environment.Exit () is supported. */ this_arg = NULL; - DEBUG_PRINTF (1, "[%p] Invoking method '%s' on receiver '%s'.\n", (gpointer)mono_native_thread_id_get (), mono_method_full_name (invoke->method, TRUE), this_arg ? this_arg->vtable->klass->name : ""); + DEBUG_PRINTF (1, "[%p] Invoking method '%s' on receiver '%s'.\n", (gpointer) (gsize) mono_native_thread_id_get (), mono_method_full_name (invoke->method, TRUE), this_arg ? this_arg->vtable->klass->name : ""); mono_runtime_invoke (invoke->method, NULL, invoke->args, &exc); g_assert_not_reached (); } @@ -6489,7 +6489,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8 /* Should be null */ int type = decode_byte (p, &p, end); if (type != VALUE_TYPE_ID_NULL) { - DEBUG_PRINTF (1, "[%p] Error: Static vtype method invoked with this argument.\n", (gpointer)mono_native_thread_id_get ()); + DEBUG_PRINTF (1, "[%p] Error: Static vtype method invoked with this argument.\n", (gpointer) (gsize) mono_native_thread_id_get ()); return ERR_INVALID_ARGUMENT; } memset (this_buf, 0, mono_class_instance_size (m->klass)); @@ -6519,7 +6519,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8 if (MONO_CLASS_IS_INTERFACE (m->klass)) { if (!this_arg) { - DEBUG_PRINTF (1, "[%p] Error: Interface method invoked without this argument.\n", (gpointer)mono_native_thread_id_get ()); + DEBUG_PRINTF (1, "[%p] Error: Interface method invoked without this argument.\n", (gpointer) (gsize) mono_native_thread_id_get ()); return ERR_INVALID_ARGUMENT; } m = mono_object_get_virtual_method (this_arg, m); @@ -6530,7 +6530,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8 } } else if ((m->flags & METHOD_ATTRIBUTE_VIRTUAL) && !m->klass->valuetype && invoke->flags & INVOKE_FLAG_VIRTUAL) { if (!this_arg) { - DEBUG_PRINTF (1, "[%p] Error: invoke with INVOKE_FLAG_VIRTUAL flag set without this argument.\n", (gpointer)mono_native_thread_id_get ()); + DEBUG_PRINTF (1, "[%p] Error: invoke with INVOKE_FLAG_VIRTUAL flag set without this argument.\n", (gpointer) (gsize) mono_native_thread_id_get ()); return ERR_INVALID_ARGUMENT; } m = mono_object_get_virtual_method (this_arg, m); @@ -6540,7 +6540,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8 } } - DEBUG_PRINTF (1, "[%p] Invoking method '%s' on receiver '%s'.\n", (gpointer)mono_native_thread_id_get (), mono_method_full_name (m, TRUE), this_arg ? this_arg->vtable->klass->name : ""); + DEBUG_PRINTF (1, "[%p] Invoking method '%s' on receiver '%s'.\n", (gpointer) (gsize) mono_native_thread_id_get (), mono_method_full_name (m, TRUE), this_arg ? this_arg->vtable->klass->name : ""); if (this_arg && this_arg->vtable->domain != domain) NOT_IMPLEMENTED; @@ -6622,7 +6622,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8 else res = mono_runtime_invoke (m, this_arg, args, &exc); mono_stopwatch_stop (&watch); - DEBUG_PRINTF (1, "[%p] Invoke result: %p, exc: %s, time: %ld ms.\n", (gpointer)mono_native_thread_id_get (), res, exc ? exc->vtable->klass->name : NULL, (long)mono_stopwatch_elapsed_ms (&watch)); + DEBUG_PRINTF (1, "[%p] Invoke result: %p, exc: %s, time: %ld ms.\n", (gpointer) (gsize) mono_native_thread_id_get (), res, exc ? exc->vtable->klass->name : NULL, (long)mono_stopwatch_elapsed_ms (&watch)); if (exc) { buffer_add_byte (buf, 0); buffer_add_value (buf, &mono_defaults.object_class->byval_arg, &exc, domain); @@ -6770,7 +6770,7 @@ invoke_method (void) tls->resume_count -= invoke->suspend_count; } - DEBUG_PRINTF (1, "[%p] Invoke finished (%d), resume_count = %d.\n", (gpointer)mono_native_thread_id_get (), err, tls->resume_count); + DEBUG_PRINTF (1, "[%p] Invoke finished (%d), resume_count = %d.\n", (gpointer) (gsize) mono_native_thread_id_get (), err, tls->resume_count); /* * Take the loader lock to avoid race conditions with CMD_VM_ABORT_INVOKE: @@ -9590,7 +9590,7 @@ debugger_thread (void *arg) gboolean no_reply; gboolean attach_failed = FALSE; - DEBUG_PRINTF (1, "[dbg] Agent thread started, pid=%p\n", (gpointer)mono_native_thread_id_get ()); + DEBUG_PRINTF (1, "[dbg] Agent thread started, pid=%p\n", (gpointer) (gsize) mono_native_thread_id_get ()); debugger_thread_id = mono_native_thread_id_get (); diff --git a/mono/sgen/sgen-gc.c b/mono/sgen/sgen-gc.c index b73c1d88ff1..0af554a01ff 100644 --- a/mono/sgen/sgen-gc.c +++ b/mono/sgen/sgen-gc.c @@ -3193,7 +3193,7 @@ sgen_stop_world (int generation) SGEN_ASSERT (0, !world_is_stopped, "Why are we stopping a stopped world?"); - binary_protocol_world_stopping (generation, sgen_timestamp (), (gpointer)mono_native_thread_id_get ()); + binary_protocol_world_stopping (generation, sgen_timestamp (), (gpointer) (gsize) mono_native_thread_id_get ()); sgen_client_stop_world (generation); diff --git a/mono/utils/hazard-pointer.c b/mono/utils/hazard-pointer.c index 606387c073e..89dfe54512f 100644 --- a/mono/utils/hazard-pointer.c +++ b/mono/utils/hazard-pointer.c @@ -177,7 +177,7 @@ mono_hazard_pointer_get (void) if (small_id < 0) { static MonoThreadHazardPointers emerg_hazard_table; - g_warning ("Thread %p may have been prematurely finalized", (gpointer)mono_native_thread_id_get ()); + g_warning ("Thread %p may have been prematurely finalized", (gpointer) (gsize) mono_native_thread_id_get ()); return &emerg_hazard_table; } -- 2.11.4.GIT