From: lateralusX Date: Tue, 4 Oct 2016 13:36:00 +0000 (+0200) Subject: Build libmono under none desktop Windows API family. X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=72a43d3355e712e782747971e1478134af4a5775 Build libmono under none desktop Windows API family. Initial work to build libmono under none desktop Windows API families. --- diff --git a/mono/mini/Makefile.am.in b/mono/mini/Makefile.am.in index 62e771c78b9..488b3cd0c4e 100755 --- a/mono/mini/Makefile.am.in +++ b/mono/mini/Makefile.am.in @@ -373,6 +373,7 @@ darwin_sources = \ windows_sources = \ mini-windows.c \ + mini-windows.h \ mini-windows-dllmain.c posix_sources = \ diff --git a/mono/mini/aot-compiler.c b/mono/mini/aot-compiler.c index 4a502964121..e0e23e29270 100644 --- a/mono/mini/aot-compiler.c +++ b/mono/mini/aot-compiler.c @@ -8895,13 +8895,13 @@ emit_extra_methods (MonoAotCompile *acfg) 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); diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 9bfbb44647b..bc78ececf09 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -71,6 +71,7 @@ #include #include #include +#include #include "debugger-agent.h" #include "mini.h" #include "seq-points.h" @@ -932,7 +933,7 @@ mono_debugger_agent_parse_options (char *options) /* 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)); } } diff --git a/mono/mini/driver.c b/mono/mini/driver.c index 6e06724a9f0..09a436818ab 100644 --- a/mono/mini/driver.c +++ b/mono/mini/driver.c @@ -2113,7 +2113,7 @@ mono_main (int argc, char* argv[]) 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 (); diff --git a/mono/mini/exceptions-amd64.c b/mono/mini/exceptions-amd64.c index 919682acca6..dbef0887519 100644 --- a/mono/mini/exceptions-amd64.c +++ b/mono/mini/exceptions-amd64.c @@ -152,6 +152,7 @@ void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler) #endif /* TARGET_WIN32 */ +#ifndef DISABLE_JIT /* * mono_arch_get_restore_context: * @@ -285,6 +286,7 @@ mono_arch_get_call_filter (MonoTrampInfo **info, gboolean aot) return start; } +#endif /* !DISABLE_JIT */ /* * The first few arguments are dummy, to force the other arguments to be passed on @@ -350,6 +352,7 @@ mono_amd64_resume_unwind (guint64 dummy1, guint64 dummy2, guint64 dummy3, guint6 mono_resume_unwind (&ctx); } +#ifndef DISABLE_JIT /* * get_throw_trampoline: * @@ -496,6 +499,7 @@ mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot) { return get_throw_trampoline (info, FALSE, TRUE, FALSE, FALSE, "throw_corlib_exception", aot); } +#endif /* !DISABLE_JIT */ /* * mono_arch_unwind_frame: @@ -833,6 +837,7 @@ mono_amd64_get_original_ip (void) return lmf->rip; } +#ifndef DISABLE_JIT GSList* mono_amd64_get_exception_trampolines (gboolean aot) { @@ -851,6 +856,7 @@ mono_amd64_get_exception_trampolines (gboolean aot) return tramps; } +#endif /* !DISABLE_JIT */ void mono_arch_exceptions_init (void) @@ -878,7 +884,7 @@ 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 @@ -1118,9 +1124,9 @@ mono_arch_unwindinfo_install_unwind_info (gpointer* monoui, gpointer code, guint 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) { @@ -1172,7 +1178,7 @@ mono_tasklets_arch_restore (void) saved = start; return (MonoContinuationRestore)saved; } -#endif +#endif /* MONO_SUPPORT_TASKLETS && !defined(DISABLE_JIT) */ /* * mono_arch_setup_resume_sighandler_ctx: @@ -1190,3 +1196,56 @@ mono_arch_setup_resume_sighandler_ctx (MonoContext *ctx, gpointer func) 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) */ diff --git a/mono/mini/mini-windows-uwp.c b/mono/mini/mini-windows-uwp.c new file mode 100644 index 00000000000..c2367aae9c2 --- /dev/null +++ b/mono/mini/mini-windows-uwp.c @@ -0,0 +1,43 @@ +/* + * 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 +#include + +#if G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT) +#include + +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) */ + diff --git a/mono/mini/mini-windows.c b/mono/mini/mini-windows.c index e7764e91beb..2aa3a7b75d1 100644 --- a/mono/mini/mini-windows.c +++ b/mono/mini/mini-windows.c @@ -44,6 +44,7 @@ #include #include "mini.h" +#include "mini-windows.h" #include #include #include "trace.h" @@ -51,7 +52,7 @@ #include "jit-icalls.h" -#ifdef _WIN32 +#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) #include #endif @@ -91,16 +92,17 @@ MONO_SIG_HANDLER_SIGNATURE (mono_chain_signal) 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 @@ -109,57 +111,75 @@ win32_time_proc (UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) } } -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; @@ -172,10 +192,29 @@ mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo 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); @@ -203,4 +242,3 @@ mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoThreadInfo return TRUE; } - diff --git a/mono/mini/mini-windows.h b/mono/mini/mini-windows.h new file mode 100644 index 00000000000..337b1abb02c --- /dev/null +++ b/mono/mini/mini-windows.h @@ -0,0 +1,15 @@ +#ifndef __MONO_MINI_WINDOWS_H__ +#define __MONO_MINI_WINDOWS_H__ + +#include +#include + +#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__ */ diff --git a/mono/mini/tramp-amd64.c b/mono/mini/tramp-amd64.c index cf769a9e530..7d7cc41aa61 100644 --- a/mono/mini/tramp-amd64.c +++ b/mono/mini/tramp-amd64.c @@ -33,6 +33,7 @@ #define IS_REX(inst) (((inst) >= 0x40) && ((inst) <= 0x4f)) +#ifndef DISABLE_JIT /* * mono_arch_get_unbox_trampoline: * @m: method pointer @@ -110,6 +111,7 @@ mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericCo return start; } +#endif /* !DISABLE_JIT */ #ifdef _WIN64 // Workaround lack of Valgrind support for 64-bit Windows @@ -171,6 +173,7 @@ mono_arch_patch_callsite (guint8 *method_start, guint8 *orig_code, guint8 *addr) } } +#ifndef DISABLE_JIT guint8* mono_arch_create_llvm_native_thunk (MonoDomain *domain, guint8 *addr) { @@ -190,6 +193,7 @@ 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) @@ -208,6 +212,7 @@ mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *a InterlockedExchangePointer (plt_jump_table_entry, addr); } +#ifndef DISABLE_JIT static void stack_unaligned (MonoTrampolineType tramp_type) { @@ -756,6 +761,7 @@ mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg) x86_push_imm (code, (guint64)func_arg); amd64_call_reg (code, AMD64_R11); } +#endif /* !DISABLE_JIT */ gpointer mono_amd64_handler_block_trampoline_helper (void) @@ -764,6 +770,7 @@ 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) { @@ -832,6 +839,7 @@ mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot) return buf; } +#endif /* !DISABLE_JIT */ /* * mono_arch_get_call_target: @@ -862,6 +870,7 @@ mono_arch_get_plt_info_offset (guint8 *plt_entry, mgreg_t *regs, guint8 *code) return *(guint32*)(plt_entry + 6); } +#ifndef DISABLE_JIT /* * mono_arch_create_sdb_trampoline: * @@ -960,3 +969,69 @@ mono_arch_create_sdb_trampoline (gboolean single_step, MonoTrampInfo **info, gbo 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 */ diff --git a/msvc/libmono-static.vcxproj b/msvc/libmono-static.vcxproj index 5d638f1b8fb..775c7b8e5e3 100644 --- a/msvc/libmono-static.vcxproj +++ b/msvc/libmono-static.vcxproj @@ -60,6 +60,7 @@ true true + true true diff --git a/msvc/libmono-static.vcxproj.filters b/msvc/libmono-static.vcxproj.filters index 35641c0e6af..e0a3ad1227f 100644 --- a/msvc/libmono-static.vcxproj.filters +++ b/msvc/libmono-static.vcxproj.filters @@ -231,6 +231,9 @@ Header Files + + Header Files +