aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYi Kong <yikong@google.com>2019-07-25 22:29:55 +0000
committerYi Kong <yikong@google.com>2019-07-25 22:29:55 +0000
commit34b2830c8305adcd0710076127e8a817ba4ba4db (patch)
treeb52997bd1c3636049ce1439450fd067111814003
parentca7d371ddfa08d131688282b20a2f678a4339b9f (diff)
[openmp] Workaround bug in old Android pthread_attr_setstacksize
Round the stack size to a multiple of the page size. Older versions of Android (until KitKat) would fail pthread_attr_setstacksize with EINVAL if the stack size was not a multiple of the page size. Patch by Dan Albert <danalbert@google.com>. Test: Build, copied into the NDK, passed openmp test on ICS. Bug: https://github.com/android-ndk/ndk/issues/9 git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@367070 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--runtime/src/z_Linux_util.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/runtime/src/z_Linux_util.cpp b/runtime/src/z_Linux_util.cpp
index a35e1d3..5f572ab 100644
--- a/runtime/src/z_Linux_util.cpp
+++ b/runtime/src/z_Linux_util.cpp
@@ -802,6 +802,13 @@ void __kmp_create_worker(int gtid, kmp_info_t *th, size_t stack_size) {
and also gives the user the stack space they requested for all threads */
stack_size += gtid * __kmp_stkoffset * 2;
+#if defined(__ANDROID__) && __ANDROID_API__ < 19
+ // Round the stack size to a multiple of the page size. Older versions of
+ // Android (until KitKat) would fail pthread_attr_setstacksize with EINVAL
+ // if the stack size was not a multiple of the page size.
+ stack_size = (stack_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
+#endif
+
KA_TRACE(10, ("__kmp_create_worker: T#%d, default stacksize = %lu bytes, "
"__kmp_stksize = %lu bytes, final stacksize = %lu bytes\n",
gtid, KMP_DEFAULT_STKSIZE, __kmp_stksize, stack_size));