+void
+mono_threads_core_resume_created (MonoThreadInfo *info, MonoNativeThreadId tid)
+{
+ HANDLE handle;
+
+ handle = OpenThread (THREAD_ALL_ACCESS, TRUE, tid);
+ g_assert (handle);
+ ResumeThread (handle);
+ CloseHandle (handle);
+}
+
+#if HAVE_DECL___READFSDWORD==0
+static MONO_ALWAYS_INLINE unsigned long long
+__readfsdword (unsigned long offset)
+{
+ unsigned long value;
+ // __asm__("movl %%fs:%a[offset], %k[value]" : [value] "=q" (value) : [offset] "irm" (offset));
+ __asm__ volatile ("movl %%fs:%1,%0"
+ : "=r" (value) ,"=m" ((*(volatile long *) offset)));
+ return value;
+}
+#endif
+
+void
+mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize)
+{
+ MEMORY_BASIC_INFORMATION meminfo;
+#ifdef _WIN64
+ /* win7 apis */
+ NT_TIB* tib = (NT_TIB*)NtCurrentTeb();
+ guint8 *stackTop = (guint8*)tib->StackBase;
+ guint8 *stackBottom = (guint8*)tib->StackLimit;
+#else
+ /* http://en.wikipedia.org/wiki/Win32_Thread_Information_Block */
+ void* tib = (void*)__readfsdword(0x18);
+ guint8 *stackTop = (guint8*)*(int*)((char*)tib + 4);
+ guint8 *stackBottom = (guint8*)*(int*)((char*)tib + 8);
+#endif
+ /*
+ Windows stacks are expanded on demand, one page at time. The TIB reports
+ only the currently allocated amount.
+ VirtualQuery will return the actual limit for the bottom, which is what we want.
+ */
+ if (VirtualQuery (&meminfo, &meminfo, sizeof (meminfo)) == sizeof (meminfo))
+ stackBottom = MIN (stackBottom, (guint8*)meminfo.AllocationBase);
+
+ *staddr = stackBottom;
+ *stsize = stackTop - stackBottom;
+
+}
+
+gboolean
+mono_threads_core_yield (void)
+{
+ return SwitchToThread ();
+}
+
+void
+mono_threads_core_exit (int exit_code)
+{
+ ExitThread (exit_code);
+}
+
+void
+mono_threads_core_unregister (MonoThreadInfo *info)
+{
+}
+
+HANDLE
+mono_threads_core_open_handle (void)
+{
+ HANDLE thread_handle;
+
+ thread_handle = GetCurrentThread ();
+ g_assert (thread_handle);
+
+ /*
+ * The handle returned by GetCurrentThread () is a pseudo handle, so it can't be used to
+ * refer to the thread from other threads for things like aborting.
+ */
+ DuplicateHandle (GetCurrentProcess (), thread_handle, GetCurrentProcess (), &thread_handle,
+ THREAD_ALL_ACCESS, TRUE, 0);
+
+ return thread_handle;
+}
+
+int
+mono_threads_get_max_stack_size (void)
+{
+ //FIXME
+ return INT_MAX;
+}
+
+HANDLE
+mono_threads_core_open_thread_handle (HANDLE handle, MonoNativeThreadId tid)
+{
+ return OpenThread (THREAD_ALL_ACCESS, TRUE, tid);
+}
+
+#if defined(_MSC_VER)
+const DWORD MS_VC_EXCEPTION=0x406D1388;
+#pragma pack(push,8)
+typedef struct tagTHREADNAME_INFO
+{
+ DWORD dwType; // Must be 0x1000.
+ LPCSTR szName; // Pointer to name (in user addr space).
+ DWORD dwThreadID; // Thread ID (-1=caller thread).
+ DWORD dwFlags; // Reserved for future use, must be zero.
+} THREADNAME_INFO;
+#pragma pack(pop)
+#endif
+
+void
+mono_threads_core_set_name (MonoNativeThreadId tid, const char *name)
+{
+#if defined(_MSC_VER)
+ /* http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx */
+ THREADNAME_INFO info;
+ info.dwType = 0x1000;
+ info.szName = name;
+ info.dwThreadID = tid;
+ info.dwFlags = 0;
+
+ __try {
+ RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
+ }
+ __except(EXCEPTION_EXECUTE_HANDLER) {
+ }
+#endif
+}
+