3 #if defined(HAVE_SGEN_GC) && defined(HOST_WIN32)
5 #include "io-layer/io-layer.h"
7 #include "metadata/sgen-gc.h"
8 #include "metadata/gc-internal.h"
11 sgen_resume_thread (SgenThreadInfo *info)
13 DWORD id = mono_thread_info_get_tid (info);
14 HANDLE handle = OpenThread (THREAD_ALL_ACCESS, FALSE, id);
19 result = ResumeThread (handle);
20 g_assert (result != (DWORD)-1);
24 return result != (DWORD)-1;
28 sgen_suspend_thread (SgenThreadInfo *info)
30 DWORD id = mono_thread_info_get_tid (info);
31 HANDLE handle = OpenThread (THREAD_ALL_ACCESS, FALSE, id);
35 g_assert (id != GetCurrentThreadId ());
39 result = SuspendThread (handle);
40 if (result == (DWORD)-1) {
41 fprintf (stderr, "could not suspend thread %x (handle %p): %d\n", id, handle, GetLastError ()); fflush (stderr);
46 context.ContextFlags = CONTEXT_INTEGER | CONTEXT_CONTROL;
48 if (!GetThreadContext (handle, &context)) {
49 g_assert_not_reached ();
50 ResumeThread (handle);
55 g_assert (context.ContextFlags & CONTEXT_INTEGER);
56 g_assert (context.ContextFlags & CONTEXT_CONTROL);
60 info->stopped_ip = (gpointer)context.Eip;
61 info->stack_start = (char*)context.Esp - REDZONE_SIZE;
64 memset (&info->ctx, 0, sizeof (MonoContext));
65 info->ctx.edi = context.Edi;
66 info->ctx.esi = context.Esi;
67 info->ctx.ebx = context.Ebx;
68 info->ctx.edx = context.Edx;
69 info->ctx.ecx = context.Ecx;
70 info->ctx.eax = context.Eax;
71 info->ctx.ebp = context.Ebp;
72 info->ctx.esp = context.Esp;
74 info->regs [0] = context.Edi;
75 info->regs [1] = context.Esi;
76 info->regs [2] = context.Ebx;
77 info->regs [3] = context.Edx;
78 info->regs [4] = context.Ecx;
79 info->regs [5] = context.Eax;
80 info->regs [6] = context.Ebp;
81 info->regs [7] = context.Esp;
85 if (mono_gc_get_gc_callbacks ()->thread_suspend_func)
86 mono_gc_get_gc_callbacks ()->thread_suspend_func (info->runtime_data, NULL, NULL);
92 sgen_wait_for_suspend_ack (int count)
94 /* Win32 suspend/resume is synchronous, so we don't need to wait for anything */
98 sgen_thread_handshake (BOOL suspend)
100 SgenThreadInfo *info;
101 SgenThreadInfo *current = mono_thread_info_current ();
104 FOREACH_THREAD_SAFE (info) {
107 if (info->gc_disabled)
110 if (!sgen_suspend_thread (info))
113 if (!sgen_resume_thread (info))
117 } END_FOREACH_THREAD_SAFE
127 mono_gc_get_suspend_signal (void)