Skip to content

Commit 3d21a3a

Browse files
committed
[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 <[email protected]>. Test: Build, copied into the NDK, passed openmp test on ICS. Bug: android/ndk#9 llvm-svn: 367070
1 parent 8f15d40 commit 3d21a3a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

openmp/runtime/src/z_Linux_util.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,13 @@ void __kmp_create_worker(int gtid, kmp_info_t *th, size_t stack_size) {
802802
and also gives the user the stack space they requested for all threads */
803803
stack_size += gtid * __kmp_stkoffset * 2;
804804

805+
#if defined(__ANDROID__) && __ANDROID_API__ < 19
806+
// Round the stack size to a multiple of the page size. Older versions of
807+
// Android (until KitKat) would fail pthread_attr_setstacksize with EINVAL
808+
// if the stack size was not a multiple of the page size.
809+
stack_size = (stack_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
810+
#endif
811+
805812
KA_TRACE(10, ("__kmp_create_worker: T#%d, default stacksize = %lu bytes, "
806813
"__kmp_stksize = %lu bytes, final stacksize = %lu bytes\n",
807814
gtid, KMP_DEFAULT_STKSIZE, __kmp_stksize, stack_size));

0 commit comments

Comments
 (0)