Line 0
Link Here
|
|
|
1 |
--- ./mono/metadata/threads.c.orig 2013-01-08 13:41:07.000000000 -0500 |
2 |
+++ ./mono/metadata/threads.c 2013-02-09 12:28:05.000000000 -0500 |
3 |
@@ -785,7 +785,16 @@ |
4 |
void |
5 |
mono_thread_get_stack_bounds (guint8 **staddr, size_t *stsize) |
6 |
{ |
7 |
-#if defined(HAVE_PTHREAD_GET_STACKSIZE_NP) && defined(HAVE_PTHREAD_GET_STACKADDR_NP) |
8 |
+#if defined(HOST_WIN32) |
9 |
+ /* FIXME: If this function won't (or shouldn't) ever be called when running on |
10 |
+ Windows, use the error preprocessor declaration here instead of this |
11 |
+ default code (to _ensure_ we don't call this function on Windows). */ |
12 |
+ *staddr = NULL; |
13 |
+ *stsize = (size_t)-1; |
14 |
+ return; |
15 |
+ |
16 |
+#elif defined(HAVE_PTHREAD_GET_STACKSIZE_NP) && defined(HAVE_PTHREAD_GET_STACKADDR_NP) |
17 |
+ /* Mac OS X */ |
18 |
*staddr = (guint8*)pthread_get_stackaddr_np (pthread_self ()); |
19 |
*stsize = pthread_get_stacksize_np (pthread_self ()); |
20 |
|
21 |
@@ -793,52 +802,54 @@ |
22 |
*staddr -= *stsize; |
23 |
*staddr = (guint8*)((gssize)*staddr & ~(mono_pagesize () - 1)); |
24 |
return; |
25 |
- /* FIXME: simplify the mess below */ |
26 |
-#elif !defined(HOST_WIN32) |
27 |
+ |
28 |
+#elif (defined(HAVE_PTHREAD_GETATTR_NP) || defined(HAVE_PTHREAD_ATTR_GET_NP)) && defined(HAVE_PTHREAD_ATTR_GETSTACK) |
29 |
+ /* Linux, BSD */ |
30 |
+ |
31 |
pthread_attr_t attr; |
32 |
guint8 *current = (guint8*)&attr; |
33 |
|
34 |
- pthread_attr_init (&attr); |
35 |
-# ifdef HAVE_PTHREAD_GETATTR_NP |
36 |
- pthread_getattr_np (pthread_self(), &attr); |
37 |
-# else |
38 |
-# ifdef HAVE_PTHREAD_ATTR_GET_NP |
39 |
- pthread_attr_get_np (pthread_self(), &attr); |
40 |
-# elif defined(sun) |
41 |
- *staddr = NULL; |
42 |
- pthread_attr_getstacksize (&attr, &stsize); |
43 |
-# elif defined(__OpenBSD__) |
44 |
- stack_t ss; |
45 |
- int rslt; |
46 |
- |
47 |
- rslt = pthread_stackseg_np(pthread_self(), &ss); |
48 |
- g_assert (rslt == 0); |
49 |
+ #if defined(HAVE_PTHREAD_GETATTR_NP) |
50 |
+ /* Linux */ |
51 |
+ pthread_getattr_np (pthread_self (), &attr); |
52 |
|
53 |
- *staddr = (guint8*)((size_t)ss.ss_sp - ss.ss_size); |
54 |
- *stsize = ss.ss_size; |
55 |
-# else |
56 |
- *staddr = NULL; |
57 |
- *stsize = 0; |
58 |
- return; |
59 |
-# endif |
60 |
-# endif |
61 |
+ #elif defined(HAVE_PTHREAD_ATTR_GET_NP) |
62 |
+ /* BSD */ |
63 |
+ pthread_attr_init (&attr); |
64 |
+ pthread_attr_get_np (pthread_self (), &attr); |
65 |
+ |
66 |
+ #else |
67 |
+ #error Cannot determine which API is needed to retrieve pthread attributes. |
68 |
+ #endif |
69 |
|
70 |
-# if !defined(sun) |
71 |
-# if !defined(__OpenBSD__) |
72 |
pthread_attr_getstack (&attr, (void**)staddr, stsize); |
73 |
-# endif |
74 |
+ pthread_attr_destroy (&attr); |
75 |
+ |
76 |
if (*staddr) |
77 |
g_assert ((current > *staddr) && (current < *staddr + *stsize)); |
78 |
-# endif |
79 |
|
80 |
+ /* When running under emacs, sometimes staddr is not aligned to a page size */ |
81 |
+ *staddr = (guint8*)((gssize)*staddr & ~(mono_pagesize () - 1)); |
82 |
+ |
83 |
+#elif defined(sun) |
84 |
+ /* What OS / architecture is this for? */ |
85 |
+ pthread_attr_t attr; |
86 |
+ pthread_attr_init (&attr); |
87 |
+ pthread_attr_getstacksize (&attr, &stsize); |
88 |
pthread_attr_destroy (&attr); |
89 |
-#else |
90 |
*staddr = NULL; |
91 |
- *stsize = (size_t)-1; |
92 |
-#endif |
93 |
|
94 |
/* When running under emacs, sometimes staddr is not aligned to a page size */ |
95 |
*staddr = (guint8*)((gssize)*staddr & ~(mono_pagesize () - 1)); |
96 |
+ return; |
97 |
+ |
98 |
+#else |
99 |
+ /* FIXME: It'd be better to use the 'error' preprocessor macro here so we know |
100 |
+ at compile-time if the target platform isn't supported. */ |
101 |
+ *staddr = NULL; |
102 |
+ *stsize = 0; |
103 |
+ return; |
104 |
+#endif |
105 |
} |
106 |
|
107 |
MonoThread * |