diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2022-02-08 22:42:00 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2022-02-08 22:42:00 +0100 |
commit | 2fc8b4c4bac576427b0054a13cc78e395b93d6c4 (patch) | |
tree | ac772e718f70e0ace0def75d4d1ebe4b007b09a6 /sysdep/unix/alloc.c | |
parent | ef614f29843ab2bdfb0ff5ed5da0a989eeaa33a6 (diff) |
Alloc: Use posix_memalign() instead of aligned_alloc()
For compatibility with older systems use posix_memalign(). We can
switch to aligned_alloc() when we commit to C11 for multithreading.
Diffstat (limited to 'sysdep/unix/alloc.c')
-rw-r--r-- | sysdep/unix/alloc.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/sysdep/unix/alloc.c b/sysdep/unix/alloc.c index 5dd70c99..0e944d57 100644 --- a/sysdep/unix/alloc.c +++ b/sysdep/unix/alloc.c @@ -72,16 +72,17 @@ alloc_page(void) { void *ret = mmap(NULL, get_page_size(), PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (ret == MAP_FAILED) - bug("mmap(%lu) failed: %m", page_size); + bug("mmap(%lu) failed: %m", (long unsigned int) page_size); return ret; } else #endif { - void *ret = aligned_alloc(page_size, page_size); - if (!ret) - bug("aligned_alloc(%lu) failed", page_size); - return ret; + void *ptr = NULL; + int err = posix_memalign(&ptr, page_size, page_size); + if (err || !ptr) + bug("posix_memalign(%lu) failed", (long unsigned int) page_size); + return ptr; } } |