patches/mono-02-sgen.diff
author jurikm
Sun, 12 Feb 2012 14:04:10 +0000
changeset 8245 383896da4129
parent 3798 9e63fe04e9f8
permissions -rw-r--r--
SFEsauerbraten.spec: add IPS package name

--- a/configure.in	Mon Sep 19 02:59:42 2011
+++ b/configure.in	Mon Sep 19 03:00:51 2011
@@ -2198,6 +2198,7 @@
 			# foo.c:6: warning: visibility attribute not supported in this configuration; ignored
 			# ld: fatal: relocation error: R_386_GOTOFF: file /var/tmp//ccxYR96k.o: symbol astruct: relocation must bind locally
 			have_visibility_hidden=no
+			sgen_supported=true
 			;;
 		  cygwin*)
 			have_visibility_hidden=no		  
@@ -2269,6 +2270,7 @@
 		if test x"$AR" = xfalse; then
 			AC_MSG_ERROR([The required utility 'ar' is not found in your PATH. Usually it can be found in /usr/ccs/bin.])
 		fi
+		sgen_supported=true
 		;;
        alpha*-*-linux* | alpha*-*-osf*)
 		TARGET=ALPHA;
--- a/mono/metadata/sgen-archdep.h	Mon Sep 19 03:01:52 2011
+++ b/mono/metadata/sgen-archdep.h	Mon Sep 19 03:04:32 2011
@@ -213,6 +213,78 @@
 	((a)[15] = (gpointer) (UCONTEXT_GREGS((ctx))) [15]);		\
 	} while (0)
 
+#elif defined(__sparc__)
+
+#define REDZONE_SIZE   0
+
+/* Don't bother with %g0 (%r0), it's always hard-coded to zero */
+#define ARCH_NUM_REGS 15       
+#ifdef __sparcv9
+#define ARCH_STORE_REGS(ptr)   \
+       __asm__ __volatile__(   \
+               "st %%g1,[%0]\n\t"      \
+               "st %%g2,[%0+0x08]\n\t" \
+               "st %%g3,[%0+0x10]\n\t" \
+               "st %%g4,[%0+0x18]\n\t" \
+               "st %%g5,[%0+0x20]\n\t" \
+               "st %%g6,[%0+0x28]\n\t" \
+               "st %%g7,[%0+0x30]\n\t" \
+               "st %%o0,[%0+0x38]\n\t" \
+               "st %%o1,[%0+0x40]\n\t" \
+               "st %%o2,[%0+0x48]\n\t" \
+               "st %%o3,[%0+0x50]\n\t" \
+               "st %%o4,[%0+0x58]\n\t" \
+               "st %%o5,[%0+0x60]\n\t" \
+               "st %%o6,[%0+0x68]\n\t" \
+               "st %%o7,[%0+0x70]\n\t" \
+               :                       \
+               : "r" (ptr)             \
+               : "memory"                      \
+       )
+#else
+#define ARCH_STORE_REGS(ptr)   \
+       __asm__ __volatile__(   \
+               "st %%g1,[%0]\n\t"      \
+               "st %%g2,[%0+0x04]\n\t" \
+               "st %%g3,[%0+0x08]\n\t" \
+               "st %%g4,[%0+0x0c]\n\t" \
+               "st %%g5,[%0+0x10]\n\t" \
+               "st %%g6,[%0+0x14]\n\t" \
+               "st %%g7,[%0+0x18]\n\t" \
+               "st %%o0,[%0+0x1c]\n\t" \
+               "st %%o1,[%0+0x20]\n\t" \
+               "st %%o2,[%0+0x24]\n\t" \
+               "st %%o3,[%0+0x28]\n\t" \
+               "st %%o4,[%0+0x2c]\n\t" \
+               "st %%o5,[%0+0x30]\n\t" \
+               "st %%o6,[%0+0x34]\n\t" \
+               "st %%o7,[%0+0x38]\n\t" \
+               :                       \
+               : "r" (ptr)             \
+               : "memory"                      \
+       )
 #endif
 
+#define ARCH_SIGCTX_SP(ctx)    (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_SP])
+#define ARCH_SIGCTX_IP(ctx)    (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_PC])
+#define ARCH_COPY_SIGCTX_REGS(a,ctx) do {      \
+       (a)[0] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G1]);        \
+       (a)[1] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G2]);        \
+       (a)[2] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G3]);        \
+       (a)[3] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G4]);        \
+       (a)[4] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G5]);        \
+       (a)[5] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G6]);        \
+       (a)[6] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_G7]);        \
+       (a)[7] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O0]);        \
+       (a)[8] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O1]);        \
+       (a)[9] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O2]);        \
+       (a)[10] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O3]);       \
+       (a)[11] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O4]);       \
+       (a)[12] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O5]);       \
+       (a)[13] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O6]);       \
+       (a)[14] = (gpointer) (((ucontext_t *)(ctx))->uc_mcontext.gregs [REG_O7]);       \
+       } while (0)
+
+#endif
+
 #endif /* __MONO_SGENARCHDEP_H__ */
--- a/mono/utils/mono-sigcontext.h	Mon Sep 19 03:05:28 2011
+++ b/mono/utils/mono-sigcontext.h	Mon Sep 19 03:06:21 2011
@@ -67,6 +67,16 @@
 	#define UCONTEXT_REG_ESI(ctx) (((ucontext_t*)(ctx))->sc_esi)
 	#define UCONTEXT_REG_EDI(ctx) (((ucontext_t*)(ctx))->sc_edi)
 	#define UCONTEXT_REG_EIP(ctx) (((ucontext_t*)(ctx))->sc_eip)
+#elif defined(PLATFORM_SOLARIS)
+       #define UCONTEXT_REG_EAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EAX])
+       #define UCONTEXT_REG_EBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EBX])
+       #define UCONTEXT_REG_ECX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [ECX])
+       #define UCONTEXT_REG_EDX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EDX])
+       #define UCONTEXT_REG_EBP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EBP])
+       #define UCONTEXT_REG_ESP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [ESP])
+       #define UCONTEXT_REG_ESI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [ESI])
+       #define UCONTEXT_REG_EDI(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EDI])
+       #define UCONTEXT_REG_EIP(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [EIP])
 #else
 	#define UCONTEXT_REG_EAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_EAX])
 	#define UCONTEXT_REG_EBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.gregs [REG_EBX])
--- a/configure	Mon Sep 19 03:06:47 2011
+++ b/configure	Mon Sep 19 03:07:30 2011
@@ -22898,6 +22898,7 @@
 			# foo.c:6: warning: visibility attribute not supported in this configuration; ignored
 			# ld: fatal: relocation error: R_386_GOTOFF: file /var/tmp//ccxYR96k.o: symbol astruct: relocation must bind locally
 			have_visibility_hidden=no
+			sgen_supported=true
 			;;
 		  cygwin*)
 			have_visibility_hidden=no
@@ -23017,6 +23018,7 @@
 		if test x"$AR" = xfalse; then
 			as_fn_error $? "The required utility 'ar' is not found in your PATH. Usually it can be found in /usr/ccs/bin." "$LINENO" 5
 		fi
+		sgen_supported=true
 		;;
        alpha*-*-linux* | alpha*-*-osf*)
 		TARGET=ALPHA;
--- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/X11Keyboard.cs	Mon Sep 19 03:11:00 2011
+++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/X11Keyboard.cs	Mon Sep 19 03:19:04 2011
@@ -208,6 +208,8 @@
 				XSetICFocus (xic);
 		}
 
+		private bool have_Xutf8ResetIC = true;
+
 		public void FocusOut (IntPtr window)
 		{
 			if (xim == IntPtr.Zero)
@@ -216,7 +218,13 @@
 			this.client_window = IntPtr.Zero;
 			IntPtr xic = GetXic (window);
 			if (xic != IntPtr.Zero) {
-				Xutf8ResetIC (xic);
+				if (have_Xutf8ResetIC) {
+					try {
+						Xutf8ResetIC (xic);
+					} catch (EntryPointNotFoundException) {
+						have_Xutf8ResetIC = false;
+					}
+				}
 				XUnsetICFocus (xic);
 			}
 		}
@@ -1173,6 +1181,8 @@
 			}
 		}
 
+		private bool have_Xutf8LookupString = true;
+
 		private int LookupString (ref XEvent xevent, int len, out XKeySym keysym, out IntPtr status)
 		{
 			IntPtr keysym_res;
@@ -1180,9 +1190,27 @@
 
 			status = IntPtr.Zero;
 			IntPtr xic = GetXic (client_window);
-			if (xic != IntPtr.Zero) {
+			if (xic != IntPtr.Zero && have_Xutf8LookupString) {
 				do {
-					res = Xutf8LookupString (xic, ref xevent, lookup_byte_buffer, 100, out keysym_res,  out status);
+					try {
+						res = Xutf8LookupString (xic, ref xevent, lookup_byte_buffer, 100, out keysym_res,  out status);
+					} catch (EntryPointNotFoundException) {
+						have_Xutf8LookupString = false;
+
+						/* Duplicate of the non-xic clause */
+						do {
+							res = XLookupString (ref xevent, lookup_byte_buffer, 100, out keysym_res, out status);
+							if ((int) status != -1) // XLookupBufferOverflow
+								break;
+							lookup_byte_buffer = new byte [lookup_byte_buffer.Length << 1];
+						} while (true);
+						lookup_buffer.Length = 0;
+						string s2 = Encoding.ASCII.GetString (lookup_byte_buffer, 0, res);
+						lookup_buffer.Append (s2);
+						keysym = (XKeySym) keysym_res.ToInt32 ();
+						return res;
+					}
+					
 					if ((int) status != -1) // XLookupBufferOverflow
 						break;
 					lookup_byte_buffer = new byte [lookup_byte_buffer.Length << 1];
--- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs	Mon Sep 19 03:19:48 2011
+++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs	Mon Sep 19 03:23:16 2011
@@ -499,6 +499,12 @@
 
 				wake = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
 				wake.Connect(listen.LocalEndPoint);
+				
+				// Make this non-blocking, so it doesn't
+				// deadlock if too many wakes are sent
+				// before the wake_receive end is polled
+				wake.Blocking = false;
+				
 				wake_receive = listen.Accept();
 
 				#if __MonoCS__
@@ -1230,7 +1236,13 @@
 		}
 
 		void WakeupMain () {
-			wake.Send (new byte [] { 0xFF });
+			try {
+				wake.Send (new byte [] { 0xFF });
+			} catch (SocketException ex) {
+				if (ex.SocketErrorCode != SocketError.WouldBlock) {
+					throw;
+				}
+			}
 		}
 
 		XEventQueue ThreadQueue(Thread thread) {