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