1From 5b5e2985f355c8e99c196d9ce5d02c15bebadfbc Mon Sep 17 00:00:00 2001 2From: Alistair Francis <alistair.francis@wdc.com> 3Date: Thu, 29 Aug 2019 13:56:21 -0700 4Subject: [PATCH] Add support for io_pgetevents_time64 syscall 5 632-bit architectures that are y2038 safe don't include syscalls that use 732-bit time_t. Instead these architectures have suffixed syscalls that 8always use a 64-bit time_t. In the case of the io_getevents syscall the 9syscall has been replaced with the io_pgetevents_time64 syscall instead. 10 11This patch changes the io_getevents() function to use the correct 12syscall based on the avaliable syscalls and the time_t size. We will 13only use the new 64-bit time_t syscall if the architecture is using a 1464-bit time_t. This is to avoid having to deal with 32/64-bit 15conversions and relying on a 64-bit timespec struct on 32-bit time_t 16platforms. As of Linux 5.3 there are no 32-bit time_t architectures 17without __NR_io_getevents. In the future if a 32-bit time_t architecture 18wants to use the 64-bit syscalls we can handle the conversion. 19 20This fixes build failures on 32-bit RISC-V. 21 22Signed-off-by: Alistair Francis <alistair.francis@wdc.com> 23 24Reviewed-by: Richard Levitte <levitte@openssl.org> 25Reviewed-by: Paul Dale <paul.dale@oracle.com> 26(Merged from https://github.com/openssl/openssl/pull/9819) 27--- 28 engines/e_afalg.c | 16 ++++++++++++++++ 29 1 file changed, 16 insertions(+) 30 31diff --git a/engines/e_afalg.c b/engines/e_afalg.c 32index dacbe358cb..99516cb1bb 100644 33--- a/engines/e_afalg.c 34+++ b/engines/e_afalg.c 35@@ -125,7 +125,23 @@ static ossl_inline int io_getevents(aio_context_t ctx, long min, long max, 36 struct io_event *events, 37 struct timespec *timeout) 38 { 39+#if defined(__NR_io_getevents) 40 return syscall(__NR_io_getevents, ctx, min, max, events, timeout); 41+#elif defined(__NR_io_pgetevents_time64) 42+ /* Let's only support the 64 suffix syscalls for 64-bit time_t. 43+ * This simplifies the code for us as we don't need to use a 64-bit 44+ * version of timespec with a 32-bit time_t and handle converting 45+ * between 64-bit and 32-bit times and check for overflows. 46+ */ 47+ if (sizeof(timeout->tv_sec) == 8) 48+ return syscall(__NR_io_pgetevents_time64, ctx, min, max, events, timeout, NULL); 49+ else { 50+ errno = ENOSYS; 51+ return -1; 52+ } 53+#else 54+# error "We require either the io_getevents syscall or __NR_io_pgetevents_time64." 55+#endif 56 } 57 58 static void afalg_waitfd_cleanup(ASYNC_WAIT_CTX *ctx, const void *key, 59-- 602.25.1 61 62