summaryrefslogtreecommitdiff
path: root/lang/mono2/patches/patch-dg
blob: 45dac7fc904a4e720ad34e60ebbb8868948086d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$NetBSD: patch-dg,v 1.1 2013/06/17 12:43:28 wiz Exp $

Avoid calling pthread_setspecific via SET_CURRENT_OBJECT(NULL)
after the key has been removed. This can result in hangs or
assertions.

--- mono/metadata/threads.c.orig	2012-01-30 18:01:23.000000000 +0000
+++ mono/metadata/threads.c
@@ -1,3 +1,4 @@
+
 /*
  * threads.c: Thread support internal calls
  *
@@ -77,6 +78,8 @@ extern int tkill (pid_t tid, int signal)
 #   endif
 #endif
 
+static int tls_key_initialised;
+
 struct StartInfo 
 {
 	guint32 (*func)(void *);
@@ -814,7 +817,8 @@ static guint32 WINAPI start_wrapper_inte
 	 * Boehm GC - the io-layer keeps a GC-visible hash of pointers
 	 * to TLS data.)
 	 */
-	SET_CURRENT_OBJECT (NULL);
+	if (tls_key_initialised)
+		SET_CURRENT_OBJECT (NULL);
 	mono_domain_unset ();
 
 	return(0);
@@ -1016,8 +1020,16 @@ mono_thread_get_stack_bounds (guint8 **s
 #    if !defined(__OpenBSD__)
 	pthread_attr_getstack (&attr, (void**)staddr, stsize);
 #    endif
+	/*
+	 * he@NetBSD.org: For some reason, this test fails on NetBSD/powerpc,
+	 * so just avoid it.
+	 * kefren@: as a hint if somebody want to take a closer look: this
+	 * triggers also when building in a i386 chroot on amd64
+	 */
+#   if !(defined(__NetBSD__) && defined(__powerpc__))
 	if (*staddr)
 		g_assert ((current > *staddr) && (current < *staddr + *stsize));
+#   endif
 #  endif
 
 	pthread_attr_destroy (&attr);
@@ -2651,6 +2663,7 @@ void mono_thread_init (MonoThreadStartCB
 	mono_init_static_data_info (&context_static_info);
 
 	mono_native_tls_alloc (&current_object_key, NULL);
+	tls_key_initialised = 1;
 	THREAD_DEBUG (g_message ("%s: Allocated current_object_key %d", __func__, current_object_key));
 
 	mono_thread_start_cb = start_cb;
@@ -2701,6 +2714,7 @@ void mono_thread_cleanup (void)
 	delayed_free_table = NULL;
 
 	mono_native_tls_free (current_object_key);
+	tls_key_initialised = 0;
 }
 
 void