|
| 1 | +From 65fbeec557a2a495b0aaf3c8d1bc1f6d0cc73d5d Mon Sep 17 00:00:00 2001 |
| 2 | +From: Finagolfin < [email protected]> |
| 3 | +Date: Thu, 1 Feb 2024 19:05:58 +0530 |
| 4 | +Subject: [PATCH] Keep posix_memalign() around for older Android APIs |
| 5 | + |
| 6 | +--- |
| 7 | + src/io.c | 5 +++++ |
| 8 | + tests/dispatch_io.c | 4 ++++ |
| 9 | + tests/dispatch_read2.c | 4 ++++ |
| 10 | + 3 files changed, 13 insertions(+) |
| 11 | + |
| 12 | +diff --git a/src/io.c b/src/io.c |
| 13 | +index 70c6721be..f317c1857 100644 |
| 14 | +--- a/src/io.c |
| 15 | ++++ b/src/io.c |
| 16 | +@@ -2373,6 +2373,11 @@ _dispatch_operation_perform(dispatch_operation_t op) |
| 17 | + bQueried = true; |
| 18 | + } |
| 19 | + op->buf = _aligned_malloc(op->buf_siz, siInfo.dwPageSize); |
| 20 | ++#elif defined(__ANDROID_API__) && __ANDROID_API__ < 28 |
| 21 | ++ err = posix_memalign(&op->buf, (size_t)PAGE_SIZE, op->buf_siz); |
| 22 | ++ if (err != 0) { |
| 23 | ++ goto error; |
| 24 | ++ } |
| 25 | + #else |
| 26 | + op->buf = aligned_alloc((size_t)PAGE_SIZE, op->buf_siz) |
| 27 | + #endif |
| 28 | +diff --git a/tests/dispatch_io.c b/tests/dispatch_io.c |
| 29 | +index a5a1cea67..1988cea69 100644 |
| 30 | +--- a/tests/dispatch_io.c |
| 31 | ++++ b/tests/dispatch_io.c |
| 32 | +@@ -398,7 +398,11 @@ test_async_read(char *path, size_t size, int option, dispatch_queue_t queue, |
| 33 | + buffer = _aligned_malloc(size, si.dwPageSize); |
| 34 | + #else |
| 35 | + size_t pagesize = (size_t)sysconf(_SC_PAGESIZE); |
| 36 | ++#if defined(__ANDROID_API__) && __ANDROID_API__ < 28 |
| 37 | ++ posix_memalign((void **)&buffer, pagesize, size); |
| 38 | ++#else |
| 39 | + buffer = aligned_alloc(pagesize, size); |
| 40 | ++#endif |
| 41 | + #endif |
| 42 | + ssize_t r = dispatch_test_fd_read(fd, buffer, size); |
| 43 | + if (r == -1) { |
| 44 | +diff --git a/tests/dispatch_read2.c b/tests/dispatch_read2.c |
| 45 | +index 401fb4f62..36e5575b2 100644 |
| 46 | +--- a/tests/dispatch_read2.c |
| 47 | ++++ b/tests/dispatch_read2.c |
| 48 | +@@ -91,7 +91,11 @@ dispatch_read2(dispatch_fd_t fd, |
| 49 | + buffer = _aligned_malloc(bufsiz, pagesize); |
| 50 | + #else |
| 51 | + size_t pagesize = (size_t)sysconf(_SC_PAGESIZE); |
| 52 | ++#if defined(__ANDROID_API__) && __ANDROID_API__ < 28 |
| 53 | ++ posix_memalign((void **)&buffer, pagesize, bufsiz); |
| 54 | ++#else |
| 55 | + buffer = aligned_alloc(pagesize, bufsiz); |
| 56 | ++#endif |
| 57 | + #endif |
| 58 | + ssize_t actual = dispatch_test_fd_read(fd, buffer, bufsiz); |
| 59 | + if (actual == -1) { |
0 commit comments