Skip to content

Commit 74d2477

Browse files
Merge pull request #856 from Unity-Technologies/fix-uwp-and-xbox-one-build-for-debugger
Fix Mono so libil2cpp with debugger compiles on UWP and Xbox One
2 parents 991e78a + 3aa9801 commit 74d2477

22 files changed

+162
-39
lines changed

mono/eglib/glib.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,11 @@ gboolean g_file_test (const gchar *filename, GFileTest test);
889889
#define g_open open
890890
#define g_rename rename
891891
#define g_stat stat
892+
#ifdef G_OS_WIN32
893+
#define g_unlink _unlink
894+
#else
892895
#define g_unlink unlink
896+
#endif
893897
#define g_fopen fopen
894898
#define g_lstat lstat
895899
#define g_rmdir rmdir

mono/eglib/gpath.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ g_find_program_in_path (const gchar *program)
252252
x = NULL;
253253
probe_path = g_build_path (G_DIR_SEPARATOR_S, l, program, NULL);
254254
#if !defined(NO_HAVE_ACCESS)
255-
if (access (probe_path, X_OK) == 0){ /* FIXME: on windows this is just a read permissions test */
255+
#ifdef G_OS_WIN32
256+
if (_access (probe_path, X_OK) == 0){ /* FIXME: on windows this is just a read permissions test */
257+
#else
258+
if (access(probe_path, X_OK) == 0) {
259+
#endif
256260
g_free (curdir);
257261
g_free (p);
258262
return probe_path;
@@ -268,7 +272,7 @@ g_find_program_in_path (const gchar *program)
268272
program_exe = g_strjoin(NULL,program,suffix_list[listx],NULL);
269273
probe_path = g_build_path (G_DIR_SEPARATOR_S, l, program_exe, NULL);
270274
#if !defined(NO_HAVE_ACCESS)
271-
if (access (probe_path, X_OK) == 0){ /* FIXME: on windows this is just a read permissions test */
275+
if (_access (probe_path, X_OK) == 0){ /* FIXME: on windows this is just a read permissions test */
272276
g_free (curdir);
273277
g_free (p);
274278
g_free (program_exe);

mono/eglib/gunicode-win32-uwp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ g_get_charset (G_CONST_RETURN char **charset)
1919
{
2020
if (my_charset == NULL) {
2121
static char buf [14];
22-
CPINFOEXA cp_info;
22+
CPINFOEXW cp_info;
2323

24-
GetCPInfoExA (CP_ACP, 0, &cp_info);
24+
GetCPInfoExW (CP_ACP, 0, &cp_info);
2525
sprintf (buf, "CP%u", cp_info.CodePage);
2626
my_charset = buf;
2727
is_utf8 = FALSE;

mono/eglib/gunicode-win32.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <config.h>
88
#include <glib.h>
99

10-
#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
10+
#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT | HAVE_XBOXONE_WINAPI_SUPPORT)
1111
#define CODESET 1
1212
#include <windows.h>
1313

@@ -30,7 +30,7 @@ g_get_charset (G_CONST_RETURN char **charset)
3030
return is_utf8;
3131
}
3232

33-
#else /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
33+
#else /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT | HAVE_XBOXONE_WINAPI_SUPPORT) */
3434

3535
#ifdef _MSC_VER
3636
// Quiet Visual Studio linker warning, LNK4221, in cases when this source file intentional ends up empty.

mono/metadata/threads.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,13 @@ ves_icall_System_Threading_WaitHandle_Wait_internal (gpointer *handles, gint32 n
19861986
return map_native_wait_result_to_managed (ret, numhandles);
19871987
}
19881988

1989+
/*
1990+
* UWP doesn't support SignalObjectAndWait until SDK version 15063. Our minspec currently is 10240.
1991+
* Since we don't care about running Mono runtime for now, let's just disable this icall and reevaluate
1992+
* in some months when we have to get libmono with IL2CPP up & running
1993+
*/
1994+
#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
1995+
19891996
gint32
19901997
ves_icall_System_Threading_WaitHandle_SignalAndWait_Internal (gpointer toSignal, gpointer toWait, gint32 ms, MonoError *error)
19911998
{
@@ -2013,6 +2020,8 @@ ves_icall_System_Threading_WaitHandle_SignalAndWait_Internal (gpointer toSignal,
20132020
return map_native_wait_result_to_managed (ret, 1);
20142021
}
20152022

2023+
#endif
2024+
20162025
gint32 ves_icall_System_Threading_Interlocked_Increment_Int (gint32 *location)
20172026
{
20182027
return mono_atomic_inc_i32 (location);

mono/mini/debugger-agent.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,6 @@ typedef struct ReplyPacket {
636636
Buffer *data;
637637
} ReplyPacket;
638638

639-
#define DEBUG(level,s) do { if (G_UNLIKELY ((level) <= log_level)) { s; fflush (log_file); } } while (0)
640-
641639
#ifdef HOST_ANDROID
642640
#define DEBUG_PRINTF(level, ...) do { if (G_UNLIKELY ((level) <= log_level)) { g_print (__VA_ARGS__); } } while (0)
643641
#else
@@ -1465,7 +1463,11 @@ socket_transport_connect (const char *address)
14651463
break; /* Success */
14661464

14671465
MONO_ENTER_GC_SAFE;
1466+
#ifdef HOST_WIN32
1467+
closesocket (sfd);
1468+
#else
14681469
close (sfd);
1470+
#endif
14691471
MONO_EXIT_GC_SAFE;
14701472
}
14711473

mono/mini/il2cpp-compat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
#define mono_method_get_class il2cpp_method_get_class
240240
#define mono_class_get_image il2cpp_class_get_image
241241
#define mono_class_get_interfaces il2cpp_class_get_interfaces
242+
#undef MONO_CLASS_IS_INTERFACE
242243
#define MONO_CLASS_IS_INTERFACE il2cpp_class_is_interface
243244
#define mono_image_get_assembly il2cpp_image_get_assembly
244245
#define mono_image_get_name il2cpp_image_get_name
@@ -252,10 +253,13 @@
252253
#define mono_method_get_token il2cpp_method_get_token
253254
#define mono_method_is_generic il2cpp_method_is_generic
254255
#define mono_method_is_inflated il2cpp_method_is_inflated
256+
#undef mono_field_is_deleted
255257
#define mono_field_is_deleted il2cpp_field_is_deleted
256258
#define mono_domain_get_assemblies_iter il2cpp_domain_get_assemblies_iter
257259

260+
#undef mono_domain_assemblies_lock
258261
#define mono_domain_assemblies_lock
262+
#undef mono_domain_assemblies_unlock
259263
#define mono_domain_assemblies_unlock
260264

261265
#define mono_get_string_class il2cpp_mono_get_string_class

mono/utils/atomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static inline void
167167
mono_atomic_store_i8 (volatile gint8 *dst, gint8 val)
168168
{
169169
#if (_MSC_VER >= 1600)
170-
InterlockedExchange8 ((CHAR volatile *)dst, (CHAR)val);
170+
_InterlockedExchange8 ((CHAR volatile *)dst, (CHAR)val);
171171
#else
172172
*dst = val;
173173
mono_memory_barrier ();

mono/utils/dlmalloc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,9 @@ DEFAULT_MMAP_THRESHOLD default: 256K
461461
#endif /* _WIN32 */
462462
#endif /* WIN32 */
463463
#ifdef WIN32
464+
#ifndef WIN32_LEAN_AND_MEAN
464465
#define WIN32_LEAN_AND_MEAN
466+
#endif
465467
#include <windows.h>
466468
#define HAVE_MMAP 1
467469
#define HAVE_MORECORE 0

mono/utils/mono-context.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,24 @@ mono_monoctx_to_sigctx (MonoContext *mctx, void *ctx)
395395
#include <mono/arch/arm/arm-codegen.h>
396396
#include <mono/arch/arm/arm-vfp-codegen.h>
397397

398+
#ifdef HOST_WIN32
399+
#include <windows.h>
400+
#endif
401+
398402
void
399403
mono_sigctx_to_monoctx (void *sigctx, MonoContext *mctx)
400404
{
401405
#ifdef MONO_CROSS_COMPILE
402406
g_assert_not_reached ();
407+
#elif defined(HOST_WIN32)
408+
CONTEXT *context = (CONTEXT*)sigctx;
409+
410+
mctx->pc = context->Pc;
411+
mctx->cpsr = context->Cpsr;
412+
memcpy (&mctx->regs, &context->R0, sizeof (DWORD) * 16);
413+
414+
/* Why are we only copying 16 registers?! There are 32! */
415+
memcpy (&mctx->fregs, &context->D, sizeof (double) * 16);
403416
#else
404417
arm_ucontext *my_uc = sigctx;
405418

@@ -418,6 +431,15 @@ mono_monoctx_to_sigctx (MonoContext *mctx, void *ctx)
418431
{
419432
#ifdef MONO_CROSS_COMPILE
420433
g_assert_not_reached ();
434+
#elif defined(HOST_WIN32)
435+
CONTEXT *context = (CONTEXT*)ctx;
436+
437+
context->Pc = mctx->pc;
438+
context->Cpsr = mctx->cpsr;
439+
memcpy (&context->R0, &mctx->regs, sizeof (DWORD) * 16);
440+
441+
/* Why are we only copying 16 registers?! There are 32! */
442+
memcpy (&context->D, &mctx->fregs, sizeof (double) * 16);
421443
#else
422444
arm_ucontext *my_uc = ctx;
423445

0 commit comments

Comments
 (0)