Initial work to build libmono under none desktop Windows API families.
windows_sources = \
mini-windows.c \
+ mini-windows.h \
mini-windows-dllmain.c
posix_sources = \
static void
generate_aotid (guint8* aotid)
{
- gpointer *rand_handle;
+ gpointer rand_handle;
MonoError error;
mono_rand_open ();
rand_handle = mono_rand_init (NULL, 0);
- mono_rand_try_get_bytes (rand_handle, aotid, 16, &error);
+ mono_rand_try_get_bytes (&rand_handle, aotid, 16, &error);
mono_error_assert_ok (&error);
mono_rand_close (rand_handle);
#include <mono/utils/mono-time.h>
#include <mono/utils/mono-threads.h>
#include <mono/utils/networking.h>
+#include <mono/utils/mono-proclib.h>
#include "debugger-agent.h"
#include "mini.h"
#include "seq-points.h"
/* Waiting for deferred attachment */
agent_config.defer = TRUE;
if (agent_config.address == NULL) {
- agent_config.address = g_strdup_printf ("0.0.0.0:%u", 56000 + (getpid () % 1000));
+ agent_config.address = g_strdup_printf ("0.0.0.0:%u", 56000 + (mono_process_current_pid () % 1000));
}
}
exit (1);
}
-#ifdef HOST_WIN32
+#if defined(HOST_WIN32) && G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
/* Detach console when executing IMAGE_SUBSYSTEM_WINDOWS_GUI on win32 */
if (!enable_debugging && !mono_compile_aot && ((MonoCLIImageInfo*)(mono_assembly_get_image (assembly)->image_info))->cli_header.nt.pe_subsys_required == IMAGE_SUBSYSTEM_WINDOWS_GUI)
FreeConsole ();
#endif /* TARGET_WIN32 */
+#ifndef DISABLE_JIT
/*
* mono_arch_get_restore_context:
*
return start;
}
+#endif /* !DISABLE_JIT */
/*
* The first few arguments are dummy, to force the other arguments to be passed on
mono_resume_unwind (&ctx);
}
+#ifndef DISABLE_JIT
/*
* get_throw_trampoline:
*
{
return get_throw_trampoline (info, FALSE, TRUE, FALSE, FALSE, "throw_corlib_exception", aot);
}
+#endif /* !DISABLE_JIT */
/*
* mono_arch_unwind_frame:
return lmf->rip;
}
+#ifndef DISABLE_JIT
GSList*
mono_amd64_get_exception_trampolines (gboolean aot)
{
return tramps;
}
+#endif /* !DISABLE_JIT */
void
mono_arch_exceptions_init (void)
}
}
-#ifdef TARGET_WIN32
+#if defined(TARGET_WIN32) && !defined(DISABLE_JIT)
/*
* The mono_arch_unwindinfo* methods are used to build and add
RtlInstallFunctionTableCallback (((DWORD64)code) | 0x3, (DWORD64)code, code_size, MONO_GET_RUNTIME_FUNCTION_CALLBACK, code, NULL);
}
-#endif
+#endif /* defined(TARGET_WIN32) !defined(DISABLE_JIT) */
-#if MONO_SUPPORT_TASKLETS
+#if MONO_SUPPORT_TASKLETS && !defined(DISABLE_JIT)
MonoContinuationRestore
mono_tasklets_arch_restore (void)
{
saved = start;
return (MonoContinuationRestore)saved;
}
-#endif
+#endif /* MONO_SUPPORT_TASKLETS && !defined(DISABLE_JIT) */
/*
* mono_arch_setup_resume_sighandler_ctx:
MONO_CONTEXT_SET_SP (ctx, (guint64)MONO_CONTEXT_GET_SP (ctx) - 8);
MONO_CONTEXT_SET_IP (ctx, func);
}
+
+#ifdef DISABLE_JIT
+gpointer
+mono_arch_get_restore_context (MonoTrampInfo **info, gboolean aot)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+gpointer
+mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+gpointer
+mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+gpointer
+mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+gpointer
+mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+GSList*
+mono_amd64_get_exception_trampolines (gboolean aot)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+#endif /* DISABLE_JIT */
+
+#if !MONO_SUPPORT_TASKLETS || defined(DISABLE_JIT)
+MonoContinuationRestore
+mono_tasklets_arch_restore (void)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+#endif /* !MONO_SUPPORT_TASKLETS || defined(DISABLE_JIT) */
--- /dev/null
+/*
+ * mini-windows-uwp.c: UWP profiler stat support for Mono.
+ *
+ * Copyright 2016 Microsoft
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
+ */
+#include <config.h>
+#include <glib.h>
+
+#if G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT)
+#include <Windows.h>
+
+void
+mono_runtime_setup_stat_profiler (void)
+{
+ g_unsupported_api ("OpenThread, GetThreadContext");
+ SetLastError (ERROR_NOT_SUPPORTED);
+ return;
+}
+
+void
+mono_runtime_shutdown_stat_profiler (void)
+{
+ g_unsupported_api ("OpenThread, GetThreadContext");
+ SetLastError (ERROR_NOT_SUPPORTED);
+ return;
+}
+
+static gboolean
+mono_setup_thread_context(DWORD thread_id, MonoContext *mono_context)
+{
+ memset (mono_context, 0, sizeof (MonoContext));
+ return FALSE;
+}
+
+#else /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */
+
+#ifdef _MSC_VER
+// Quiet Visual Studio linker warning, LNK4221, in cases when this source file intentional ends up empty.
+void __mono_win32_mini_windows_uwp_quiet_lnk4221(void) {}
+#endif
+#endif /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */
+
#include <mono/utils/dtrace.h>
#include "mini.h"
+#include "mini-windows.h"
#include <string.h>
#include <ctype.h>
#include "trace.h"
#include "jit-icalls.h"
-#ifdef _WIN32
+#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
#include <mmsystem.h>
#endif
return TRUE;
}
-static HANDLE win32_main_thread;
-static MMRESULT win32_timer;
+#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
+static MMRESULT g_timer_event = 0;
+static HANDLE g_timer_main_thread = INVALID_HANDLE_VALUE;
-static void CALLBACK
-win32_time_proc (UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
+static VOID
+thread_timer_expired (HANDLE thread)
{
CONTEXT context;
context.ContextFlags = CONTEXT_CONTROL;
- if (GetThreadContext (win32_main_thread, &context)) {
+ if (GetThreadContext (thread, &context)) {
#ifdef _WIN64
mono_profiler_stat_hit ((guchar *) context.Rip, &context);
#else
}
}
-void
-mono_runtime_setup_stat_profiler (void)
+static VOID CALLBACK
+timer_event_proc (UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
{
- static int inited = 0;
- TIMECAPS timecaps;
+ thread_timer_expired ((HANDLE)dwUser);
+}
- if (inited)
- return;
+static VOID
+stop_profiler_timer_event (void)
+{
+ if (g_timer_event != 0) {
+
+ timeKillEvent (g_timer_event);
+ g_timer_event = 0;
+ }
+
+ if (g_timer_main_thread != INVALID_HANDLE_VALUE) {
+
+ CloseHandle (g_timer_main_thread);
+ g_timer_main_thread = INVALID_HANDLE_VALUE;
+ }
+}
+
+static VOID
+start_profiler_timer_event (void)
+{
+ g_return_if_fail (g_timer_main_thread == INVALID_HANDLE_VALUE && g_timer_event == 0);
+
+ TIMECAPS timecaps;
- inited = 1;
if (timeGetDevCaps (&timecaps, sizeof (timecaps)) != TIMERR_NOERROR)
return;
- if ((win32_main_thread = OpenThread (READ_CONTROL | THREAD_GET_CONTEXT, FALSE, GetCurrentThreadId ())) == NULL)
+ g_timer_main_thread = OpenThread (READ_CONTROL | THREAD_GET_CONTEXT, FALSE, GetCurrentThreadId ());
+ if (g_timer_main_thread == NULL)
return;
if (timeBeginPeriod (1) != TIMERR_NOERROR)
return;
- if ((win32_timer = timeSetEvent (1, 0, (LPTIMECALLBACK)win32_time_proc, (DWORD_PTR)NULL, TIME_PERIODIC)) == 0) {
+ g_timer_event = timeSetEvent (1, 0, (LPTIMECALLBACK)timer_event_proc, (DWORD_PTR)g_timer_main_thread, TIME_PERIODIC | TIME_KILL_SYNCHRONOUS);
+ if (g_timer_event == 0) {
timeEndPeriod (1);
return;
}
}
+void
+mono_runtime_setup_stat_profiler (void)
+{
+ start_profiler_timer_event ();
+ return;
+}
+
void
mono_runtime_shutdown_stat_profiler (void)
{
+ stop_profiler_timer_event ();
+ return;
}
gboolean
-mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo *info)
+mono_setup_thread_context(DWORD thread_id, MonoContext *mono_context)
{
- DWORD id = mono_thread_info_get_tid (info);
HANDLE handle;
CONTEXT context;
- DWORD result;
- MonoContext *ctx;
- MonoJitTlsData *jit_tls;
- void *domain;
- MonoLMF *lmf = NULL;
- gpointer *addr;
-
- tctx->valid = FALSE;
- tctx->unwind_data [MONO_UNWIND_DATA_DOMAIN] = NULL;
- tctx->unwind_data [MONO_UNWIND_DATA_LMF] = NULL;
- tctx->unwind_data [MONO_UNWIND_DATA_JIT_TLS] = NULL;
- g_assert (id != GetCurrentThreadId ());
+ g_assert (thread_id != GetCurrentThreadId ());
- handle = OpenThread (THREAD_ALL_ACCESS, FALSE, id);
+ handle = OpenThread (THREAD_ALL_ACCESS, FALSE, thread_id);
g_assert (handle);
context.ContextFlags = CONTEXT_INTEGER | CONTEXT_CONTROL;
g_assert (context.ContextFlags & CONTEXT_INTEGER);
g_assert (context.ContextFlags & CONTEXT_CONTROL);
- ctx = &tctx->ctx;
+ memset (mono_context, 0, sizeof (MonoContext));
+ mono_sigctx_to_monoctx (&context, mono_context);
- memset (ctx, 0, sizeof (MonoContext));
- mono_sigctx_to_monoctx (&context, ctx);
+ CloseHandle (handle);
+ return TRUE;
+}
+#endif /* G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) */
+
+gboolean
+mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo *info)
+{
+ DWORD id = mono_thread_info_get_tid (info);
+ MonoJitTlsData *jit_tls;
+ void *domain;
+ MonoLMF *lmf = NULL;
+ gpointer *addr;
+
+ tctx->valid = FALSE;
+ tctx->unwind_data [MONO_UNWIND_DATA_DOMAIN] = NULL;
+ tctx->unwind_data [MONO_UNWIND_DATA_LMF] = NULL;
+ tctx->unwind_data [MONO_UNWIND_DATA_JIT_TLS] = NULL;
+
+ mono_setup_thread_context(id, &tctx->ctx);
/* mono_set_jit_tls () sets this */
jit_tls = mono_thread_info_tls_get (info, TLS_KEY_JIT_TLS);
return TRUE;
}
-
--- /dev/null
+#ifndef __MONO_MINI_WINDOWS_H__
+#define __MONO_MINI_WINDOWS_H__
+
+#include <config.h>
+#include <glib.h>
+
+#ifdef HOST_WIN32
+#include "Windows.h"
+#include "mini.h"
+#include "mono/utils/mono-context.h"
+
+gboolean
+mono_setup_thread_context(DWORD thread_id, MonoContext *mono_context);
+#endif /* HOST_WIN32 */
+#endif /* __MONO_MINI_WINDOWS_H__ */
#define IS_REX(inst) (((inst) >= 0x40) && ((inst) <= 0x4f))
+#ifndef DISABLE_JIT
/*
* mono_arch_get_unbox_trampoline:
* @m: method pointer
return start;
}
+#endif /* !DISABLE_JIT */
#ifdef _WIN64
// Workaround lack of Valgrind support for 64-bit Windows
}
}
+#ifndef DISABLE_JIT
guint8*
mono_arch_create_llvm_native_thunk (MonoDomain *domain, guint8 *addr)
{
mono_profiler_code_buffer_new (thunk_start, thunk_code - thunk_start, MONO_PROFILER_CODE_BUFFER_HELPER, NULL);
return addr;
}
+#endif /* !DISABLE_JIT */
void
mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
InterlockedExchangePointer (plt_jump_table_entry, addr);
}
+#ifndef DISABLE_JIT
static void
stack_unaligned (MonoTrampolineType tramp_type)
{
x86_push_imm (code, (guint64)func_arg);
amd64_call_reg (code, AMD64_R11);
}
+#endif /* !DISABLE_JIT */
gpointer
mono_amd64_handler_block_trampoline_helper (void)
return jit_tls->handler_block_return_address;
}
+#ifndef DISABLE_JIT
gpointer
mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot)
{
return buf;
}
+#endif /* !DISABLE_JIT */
/*
* mono_arch_get_call_target:
return *(guint32*)(plt_entry + 6);
}
+#ifndef DISABLE_JIT
/*
* mono_arch_create_sdb_trampoline:
*
return buf;
}
+#endif /* !DISABLE_JIT */
+
+#ifdef DISABLE_JIT
+gpointer
+mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+gpointer
+mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+gpointer
+mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+guchar*
+mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+gpointer
+mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+gpointer
+mono_arch_create_general_rgctx_lazy_fetch_trampoline (MonoTrampInfo **info, gboolean aot)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+gpointer
+mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+void
+mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg)
+{
+ g_assert_not_reached ();
+ return;
+}
+
+guint8*
+mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gboolean aot)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+#endif /* DISABLE_JIT */
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>\r
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>\r
</ClInclude>\r
+ <ClInclude Include="..\mono\mini\mini-windows.h" />\r
<ClInclude Include="..\mono\mini\mini-x86.h">\r
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>\r
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>\r
<ClInclude Include="..\mono\mini\mini-amd64-gsharedvt.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
+ <ClInclude Include="..\mono\mini\mini-windows.h">\r
+ <Filter>Header Files</Filter>\r
+ </ClInclude>\r
</ItemGroup>\r
<ItemGroup>\r
<Filter Include="Header Files">\r