aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/kmp_stub.cpp
diff options
context:
space:
mode:
authorJonathan Peyton <jonathan.l.peyton@intel.com>2017-11-29 22:29:38 +0000
committerJonathan Peyton <jonathan.l.peyton@intel.com>2017-11-29 22:29:38 +0000
commitb77eb553e284f1cadaac13c2ad20e7af58da3ec0 (patch)
treef6c42abf6f2e04f552dcccb1158f8982d0c4a999 /runtime/src/kmp_stub.cpp
parente9075904db4b4854416c181e5e3ffa19277f09a0 (diff)
Fix aligned memory allocation in the stub library
kmp_aligned_malloc() always returned NULL on Windows (stub library only) that may cause Fortran application crash. With this change all memory allocation functions were fixed to use aligned{m,re,rec}alloc() to allocate/reallocate memory. To deallocate that memory _aligned_free() is used in kmp_free(). Patch by Olga Malysheva Differential Revision: https://reviews.llvm.org/D40296 git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@319375 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'runtime/src/kmp_stub.cpp')
-rw-r--r--runtime/src/kmp_stub.cpp43
1 files changed, 34 insertions, 9 deletions
diff --git a/runtime/src/kmp_stub.cpp b/runtime/src/kmp_stub.cpp
index c704e61..d487a3d 100644
--- a/runtime/src/kmp_stub.cpp
+++ b/runtime/src/kmp_stub.cpp
@@ -139,34 +139,59 @@ void kmp_set_disp_num_buffers(omp_int_t arg) { i; }
/* KMP memory management functions. */
void *kmp_malloc(size_t size) {
i;
- return malloc(size);
+ void *res;
+#if KMP_OS_WINDOWS
+ // If succesfull returns a pointer to the memory block, otherwise returns
+ // NULL.
+ // Sets errno to ENOMEM or EINVAL if memory allocation failed or parameter
+ // validation failed.
+ res = _aligned_malloc(size, 1);
+#else
+ res = malloc(size);
+#endif
+ return res;
}
void *kmp_aligned_malloc(size_t sz, size_t a) {
i;
+ int err;
+ void *res;
#if KMP_OS_WINDOWS
- errno = ENOSYS; // not supported
- return NULL; // no standard aligned allocator on Windows (pre - C11)
+ res = _aligned_malloc(sz, a);
#else
- void *res;
- int err;
if (err = posix_memalign(&res, a, sz)) {
errno = err; // can be EINVAL or ENOMEM
- return NULL;
+ res = NULL;
}
- return res;
#endif
+ return res;
}
void *kmp_calloc(size_t nelem, size_t elsize) {
i;
- return calloc(nelem, elsize);
+ void *res;
+#if KMP_OS_WINDOWS
+ res = _aligned_recalloc(NULL, nelem, elsize, 1);
+#else
+ res = calloc(nelem, elsize);
+#endif
+ return res;
}
void *kmp_realloc(void *ptr, size_t size) {
i;
- return realloc(ptr, size);
+ void *res;
+#if KMP_OS_WINDOWS
+ res = _aligned_realloc(ptr, size, 1);
+#else
+ res = realloc(ptr, size);
+#endif
+ return res;
}
void kmp_free(void *ptr) {
i;
+#if KMP_OS_WINDOWS
+ _aligned_free(ptr);
+#else
free(ptr);
+#endif
}
static int __kmps_blocktime = INT_MAX;