From 87d33e720c063c517a985dc227148c6357075a71 Mon Sep 17 00:00:00 2001 From: Yan Drugalya Date: Sun, 15 Feb 2026 20:54:10 +0100 Subject: [PATCH 1/4] Build oop on mac --- mono/metadata/Makefile.am | 1 + mono/metadata/oop.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mono/metadata/Makefile.am b/mono/metadata/Makefile.am index 28f26b280b34..33c65e4f8f15 100644 --- a/mono/metadata/Makefile.am +++ b/mono/metadata/Makefile.am @@ -244,6 +244,7 @@ endif common_sources = \ $(platform_sources) \ $(unity_sources) \ + oop.c \ appdomain.c \ assembly-load-context.c \ domain.c \ diff --git a/mono/metadata/oop.c b/mono/metadata/oop.c index bcf1c1f3ce7a..0fe21ee9318e 100644 --- a/mono/metadata/oop.c +++ b/mono/metadata/oop.c @@ -15,6 +15,19 @@ #include #include #include +#include + +/* min/max macros for non-Windows platforms */ +#ifndef _WIN32 +#ifndef min +#define min(a, b) ((a) < (b) ? (a) : (b)) +#endif +#ifndef max +#define max(a, b) ((a) > (b) ? (a) : (b)) +#endif +/* Use snprintf instead of sprintf_s on non-Windows */ +#define sprintf_s(buf, size, ...) snprintf(buf, size, __VA_ARGS__) +#endif #include #include @@ -476,7 +489,8 @@ mono_unity_oop_get_stack_frame_details( frameDetails->methodToken = read_dword(OFFSET_MEMBER(MonoMethod, method, token)); - // IL offset +#ifdef _WIN32 + // IL offset (g_hash_table_lookup_oop is only available on Windows) DebugDomainInfo* debug_info = read_pointer(OFFSET_MEMBER(MonoDomain, domain, debug_info)); if (debug_info != NULL) { @@ -511,6 +525,7 @@ mono_unity_oop_get_stack_frame_details( } } } +#endif return TRUE; } From 74c17a7c628591c26602c6e9d9bc2255edc13d8a Mon Sep 17 00:00:00 2001 From: Yan Drugalya Date: Tue, 24 Feb 2026 20:25:51 +0100 Subject: [PATCH 2/4] try to make other OOP functions cross-platoform --- mono/eglib/ghashtable.c | 4 ---- mono/eglib/glib.h | 4 ---- mono/metadata/oop.c | 4 +--- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/mono/eglib/ghashtable.c b/mono/eglib/ghashtable.c index 5f49702b467f..25cc0455806a 100644 --- a/mono/eglib/ghashtable.c +++ b/mono/eglib/ghashtable.c @@ -348,8 +348,6 @@ g_hash_table_lookup_extended (GHashTable *hash, gconstpointer key, gpointer *ori } return FALSE; } -#ifdef G_OS_WIN32 - #define OFFSET_MEMBER(type, base, member) ((gpointer)((gchar*)(base) + offsetof(type, member))) gpointer @@ -377,8 +375,6 @@ g_hash_table_lookup_oop(GHashTable* hash, gconstpointer key, GReadPointerFunc re return NULL; } -#endif - void g_hash_table_foreach (GHashTable *hash, GHFunc func, gpointer user_data) { diff --git a/mono/eglib/glib.h b/mono/eglib/glib.h index 5f4739ce2cf7..aeafbc5fcaf5 100644 --- a/mono/eglib/glib.h +++ b/mono/eglib/glib.h @@ -493,11 +493,9 @@ typedef void (*GDestroyNotify) (gpointer data); typedef guint (*GHashFunc) (gconstpointer key); typedef gboolean (*GEqualFunc) (gconstpointer a, gconstpointer b); typedef void (*GFreeFunc) (gpointer data); -#ifdef G_OS_WIN32 /* oop support*/ typedef gpointer (*GReadPointerFunc)(gconstpointer address); typedef guint32 (*GReadUInt32Func) (gconstpointer address); -#endif /* * Lists @@ -635,9 +633,7 @@ gboolean g_hash_table_contains (GHashTable *hash, gconstpointer key); G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least. gpointer g_hash_table_lookup (GHashTable *hash, gconstpointer key); gboolean g_hash_table_lookup_extended (GHashTable *hash, gconstpointer key, gpointer *orig_key, gpointer *value); -#ifdef G_OS_WIN32 gpointer g_hash_table_lookup_oop (GHashTable* hash, gconstpointer key, GReadPointerFunc read_pointer, GReadUInt32Func read_uint32); -#endif G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least. void g_hash_table_foreach (GHashTable *hash, GHFunc func, gpointer user_data); gpointer g_hash_table_find (GHashTable *hash, GHRFunc predicate, gpointer user_data); diff --git a/mono/metadata/oop.c b/mono/metadata/oop.c index 0fe21ee9318e..b21025ceebb5 100644 --- a/mono/metadata/oop.c +++ b/mono/metadata/oop.c @@ -489,8 +489,7 @@ mono_unity_oop_get_stack_frame_details( frameDetails->methodToken = read_dword(OFFSET_MEMBER(MonoMethod, method, token)); -#ifdef _WIN32 - // IL offset (g_hash_table_lookup_oop is only available on Windows) + // IL offset DebugDomainInfo* debug_info = read_pointer(OFFSET_MEMBER(MonoDomain, domain, debug_info)); if (debug_info != NULL) { @@ -525,7 +524,6 @@ mono_unity_oop_get_stack_frame_details( } } } -#endif return TRUE; } From f2cb77ce77f17e31b271154ac8a0c13504e6ba59 Mon Sep 17 00:00:00 2001 From: Yan Drugalya Date: Thu, 5 Mar 2026 13:38:23 +0100 Subject: [PATCH 3/4] Rollback some unnecessary changes --- mono/eglib/ghashtable.c | 4 ++++ mono/eglib/glib.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/mono/eglib/ghashtable.c b/mono/eglib/ghashtable.c index 25cc0455806a..5f49702b467f 100644 --- a/mono/eglib/ghashtable.c +++ b/mono/eglib/ghashtable.c @@ -348,6 +348,8 @@ g_hash_table_lookup_extended (GHashTable *hash, gconstpointer key, gpointer *ori } return FALSE; } +#ifdef G_OS_WIN32 + #define OFFSET_MEMBER(type, base, member) ((gpointer)((gchar*)(base) + offsetof(type, member))) gpointer @@ -375,6 +377,8 @@ g_hash_table_lookup_oop(GHashTable* hash, gconstpointer key, GReadPointerFunc re return NULL; } +#endif + void g_hash_table_foreach (GHashTable *hash, GHFunc func, gpointer user_data) { diff --git a/mono/eglib/glib.h b/mono/eglib/glib.h index aeafbc5fcaf5..5f4739ce2cf7 100644 --- a/mono/eglib/glib.h +++ b/mono/eglib/glib.h @@ -493,9 +493,11 @@ typedef void (*GDestroyNotify) (gpointer data); typedef guint (*GHashFunc) (gconstpointer key); typedef gboolean (*GEqualFunc) (gconstpointer a, gconstpointer b); typedef void (*GFreeFunc) (gpointer data); +#ifdef G_OS_WIN32 /* oop support*/ typedef gpointer (*GReadPointerFunc)(gconstpointer address); typedef guint32 (*GReadUInt32Func) (gconstpointer address); +#endif /* * Lists @@ -633,7 +635,9 @@ gboolean g_hash_table_contains (GHashTable *hash, gconstpointer key); G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least. gpointer g_hash_table_lookup (GHashTable *hash, gconstpointer key); gboolean g_hash_table_lookup_extended (GHashTable *hash, gconstpointer key, gpointer *orig_key, gpointer *value); +#ifdef G_OS_WIN32 gpointer g_hash_table_lookup_oop (GHashTable* hash, gconstpointer key, GReadPointerFunc read_pointer, GReadUInt32Func read_uint32); +#endif G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least. void g_hash_table_foreach (GHashTable *hash, GHFunc func, gpointer user_data); gpointer g_hash_table_find (GHashTable *hash, GHRFunc predicate, gpointer user_data); From 22724acc692e4a7cb6880e41889d6407a2464bf8 Mon Sep 17 00:00:00 2001 From: Yan Drugalya Date: Thu, 5 Mar 2026 13:42:36 +0100 Subject: [PATCH 4/4] Minimize amount of changes --- mono/metadata/oop.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/mono/metadata/oop.c b/mono/metadata/oop.c index b21025ceebb5..5354ecf96314 100644 --- a/mono/metadata/oop.c +++ b/mono/metadata/oop.c @@ -15,19 +15,6 @@ #include #include #include -#include - -/* min/max macros for non-Windows platforms */ -#ifndef _WIN32 -#ifndef min -#define min(a, b) ((a) < (b) ? (a) : (b)) -#endif -#ifndef max -#define max(a, b) ((a) > (b) ? (a) : (b)) -#endif -/* Use snprintf instead of sprintf_s on non-Windows */ -#define sprintf_s(buf, size, ...) snprintf(buf, size, __VA_ARGS__) -#endif #include #include @@ -123,7 +110,7 @@ gsize read_nt_string(char* buffer, gsize max_size, const void* address) } // Ensure there's a null-terminator - buffer[min(read, max_size-1)] = '\0'; + buffer[MIN(read, max_size-1)] = '\0'; return read; } @@ -438,7 +425,7 @@ mono_unity_oop_get_stack_frame_details( const MonoMethod* method = read_pointer(OFFSET_MEMBER(MonoJitInfo, ji, d.method)); const MonoClass* klass = read_pointer(OFFSET_MEMBER(MonoMethod, method, klass)); const MonoImage* image = read_pointer(OFFSET_MEMBER(MonoClass, klass, image)); - size_t classNameLen = max(frameDetails->classNameLen, 256); + size_t classNameLen = MAX(frameDetails->classNameLen, 256); char* className = (char*)malloc(classNameLen); char* nsName = (char*)malloc(classNameLen); @@ -459,14 +446,14 @@ mono_unity_oop_get_stack_frame_details( read_pointer(OFFSET_MEMBER(MonoClass, klass, name))); if (*nsName) { - frameDetails->classNameLen = sprintf_s( + frameDetails->classNameLen = g_snprintf( frameDetails->className, frameDetails->classNameLen, "%s.%s", nsName, className); } else { - frameDetails->classNameLen = sprintf_s( + frameDetails->classNameLen = g_snprintf( frameDetails->className, frameDetails->classNameLen, "%s",