[PATCH libaio 8/8] Add time64 public functions on 32-bit architectures

Guillem Jover <[email protected]>
Newsgroups gmane.linux.kernel.aio.general
Message-ID <[email protected]>
From: Guillem Jover <[email protected]>

This adds new time64 functions for io_getevents() and io_pgetevents()
that will get redirected when building with _TIME_BITS=64.

Ideally we should generate the .map file and not include these symbols
on 64-bit architectures, but this will do for now.

Signed-off-by: Guillem Jover <[email protected]>
---
 src/Makefile                                    |  3 ++-
 src/compat-0_1.c                                |  7 +++++++
 src/io_getevents.c                              |  7 +++++++
 src/{io_getevents.c => io_getevents_time64.c}   | 15 +++++++--------
 src/io_pgetevents.c                             |  7 +++++++
 src/{io_pgetevents.c => io_pgetevents_time64.c} | 12 ++++++------
 src/io_queue_wait.c                             |  7 +++++++
 src/libaio.h                                    | 17 +++++++++++++++++
 src/libaio.map                                  |  6 ++++++
 9 files changed, 66 insertions(+), 15 deletions(-)
 copy src/{io_getevents.c => io_getevents_time64.c} (78%)
 copy src/{io_pgetevents.c => io_pgetevents_time64.c} (82%)

diff --git a/src/Makefile b/src/Makefile
index 7e56172..2d23377 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -4,7 +4,7 @@ libdir=$(prefix)/lib
 
 CFLAGS ?= -g -fomit-frame-pointer -O2
 CFLAGS += -Wall -I. -fPIC
-SO_CFLAGS=-shared $(CFLAGS)
+SO_CFLAGS=-shared -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 $(CFLAGS)
 L_CFLAGS=$(CFLAGS)
 LINK_FLAGS=
 LINK_FLAGS+=$(LDFLAGS)
@@ -30,6 +30,7 @@ libaio_srcs += io_queue_wait.c io_queue_run.c
 libaio_srcs += aio_pgetevents.c aio_getevents.c
 libaio_srcs += io_getevents.c io_submit.c io_cancel.c
 libaio_srcs += io_setup.c io_destroy.c io_pgetevents.c
+libaio_srcs += io_pgetevents_time64.c io_getevents_time64.c
 
 # old symbols
 libaio_srcs += compat-0_1.c
diff --git a/src/compat-0_1.c b/src/compat-0_1.c
index 25b789a..61df3b3 100644
--- a/src/compat-0_1.c
+++ b/src/compat-0_1.c
@@ -19,6 +19,13 @@
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  */
+
+/*
+ * On 32-bit systems these were using 32-bit struct timespec, keep these
+ * backward compatibility functions that way.
+ */
+#undef _TIME_BITS
+
 #include <stdlib.h>
 #include <asm/errno.h>
 
diff --git a/src/io_getevents.c b/src/io_getevents.c
index c06e803..0b2d448 100644
--- a/src/io_getevents.c
+++ b/src/io_getevents.c
@@ -17,6 +17,13 @@
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  */
+
+/*
+ * On 32-bit systems these were using 32-bit struct timespec, keep this
+ * backward compatibility function that way.
+ */
+#undef _TIME_BITS
+
 #include <libaio.h>
 #include <errno.h>
 #include <stdlib.h>
diff --git a/src/io_getevents.c b/src/io_getevents_time64.c
similarity index 78%
copy from src/io_getevents.c
copy to src/io_getevents_time64.c
index c06e803..bff6dcf 100644
--- a/src/io_getevents.c
+++ b/src/io_getevents_time64.c
@@ -1,4 +1,4 @@
-/* io_getevents.c
+/* io_getevents_time64.c
    libaio Linux async I/O interface
    Copyright 2002 Red Hat, Inc.
    Copyright 2024 Guillem Jover <[email protected]>
@@ -24,14 +24,13 @@
 #include "syscall.h"
 #include "aio_time.h"
 
-int io_getevents_0_4(io_context_t ctx, long min_nr, long nr,
+#if __BITS_PER_LONG == 32
+int io_getevents_time64(io_context_t ctx, long min_nr, long nr,
 		struct io_event * events, struct timespec * timeout)
 {
-	struct __kernel_timespec ts;
+	struct __kernel_timespec kts;
 
-	if (timeout)
-		aio_get_timespec(&ts, timeout);
-	return aio_getevents(ctx, min_nr, nr, events, timeout ? &ts : NULL);
+	aio_get_timespec(&kts, timeout);
+	return aio_getevents(ctx, min_nr, nr, events, &kts);
 }
-
-DEFSYMVER(io_getevents_0_4, io_getevents, 0.4);
+#endif
diff --git a/src/io_pgetevents.c b/src/io_pgetevents.c
index d960a05..50b8d1c 100644
--- a/src/io_pgetevents.c
+++ b/src/io_pgetevents.c
@@ -17,6 +17,13 @@
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  */
+
+/*
+ * On 32-bit systems these were using 32-bit struct timespec, keep this
+ * backward compatibility function that way.
+ */
+#undef _TIME_BITS
+
 #include <libaio.h>
 #include <errno.h>
 #include <stdlib.h>
diff --git a/src/io_pgetevents.c b/src/io_pgetevents_time64.c
similarity index 82%
copy from src/io_pgetevents.c
copy to src/io_pgetevents_time64.c
index d960a05..e0810bb 100644
--- a/src/io_pgetevents.c
+++ b/src/io_pgetevents_time64.c
@@ -24,14 +24,14 @@
 #include <signal.h>
 #include "aio_time.h"
 
-int io_pgetevents(io_context_t ctx, long min_nr, long nr,
+#if __BITS_PER_LONG == 32
+int io_pgetevents_time64(io_context_t ctx, long min_nr, long nr,
 		struct io_event *events, struct timespec *timeout,
 		sigset_t *sigmask)
 {
-	struct __kernel_timespec ts;
+	struct __kernel_timespec kts;
 
-	if (timeout)
-		aio_get_timespec(&ts, timeout);
-	return aio_pgetevents(ctx, min_nr, nr, events, timeout ? &ts : NULL,
-			sigmask);
+	aio_get_timespec(&kts, timeout);
+	return aio_pgetevents(ctx, min_nr, nr, events, &kts, sigmask);
 }
+#endif
diff --git a/src/io_queue_wait.c b/src/io_queue_wait.c
index b4bb236..fe89291 100644
--- a/src/io_queue_wait.c
+++ b/src/io_queue_wait.c
@@ -17,6 +17,13 @@
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  */
+
+/*
+ * On 32-bit systems these were using 32-bit struct timespec, keep this
+ * backward compatibility function that way.
+ */
+#undef _TIME_BITS
+
 #define NO_SYSCALL_ERRNO
 #include <sys/types.h>
 #include <libaio.h>
diff --git a/src/libaio.h b/src/libaio.h
index f247c96..504144c 100644
--- a/src/libaio.h
+++ b/src/libaio.h
@@ -27,6 +27,7 @@
 extern "C" {
 #endif
 
+#include <linux/types.h>
 #include <sys/types.h>
 #include <string.h>
 #include <signal.h>
@@ -50,6 +51,10 @@ typedef enum io_iocb_cmd {
 	IO_CMD_PWRITEV = 8,
 } io_iocb_cmd_t;
 
+#define LIBAIO_ASMNAME(cname) LIBAIO_ASMNAME_PREFIX(__USER_LABEL_PREFIX__, cname)
+#define LIBAIO_ASMNAME_PREFIX(prefix, cname) LIBAIO_STRING(prefix) cname
+#define LIBAIO_REDIRECT(name, proto, alias) name proto __asm__(LIBAIO_ASMNAME(#alias))
+
 /* little endian, 32 bits */
 #if defined(__i386__) || (defined(__arm__) && !defined(__ARMEB__)) || \
     defined(__sh__) || defined(__bfin__) || defined(__MIPSEL__) || \
@@ -165,11 +170,23 @@ extern int io_destroy(io_context_t ctx);
 extern int io_submit(io_context_t ctx, long nr, struct iocb *ios[]);
 extern int io_cancel(io_context_t ctx, struct iocb *iocb,
 		struct io_event *evt);
+#if __BITS_PER_LONG == 32 && defined(__TIME_BITS) && __TIME_BITS == 64
+extern int LIBAIO_REDIRECT(io_getevents, (io_context_t ctx,
+		long min_nr, long nr,
+		struct io_event *events, struct timespec *timeout),
+		io_getevents_time64);
+extern int LIBAIO_REDIRECT(io_pgetevents, (io_context_t ctx,
+		long min_nr, long nr,
+		struct io_event *events, struct timespec *timeout,
+		sigset_t *sigmask),
+		io_pgetevents_time64);
+#else
 extern int io_getevents(io_context_t ctx, long min_nr, long nr,
 		struct io_event *events, struct timespec *timeout);
 extern int io_pgetevents(io_context_t ctx, long min_nr, long nr,
 		struct io_event *events, struct timespec *timeout,
 		sigset_t *sigmask);
+#endif
 
 
 static inline void io_set_callback(struct iocb *iocb, io_callback_t cb)
diff --git a/src/libaio.map b/src/libaio.map
index ec9d13b..74b2c08 100644
--- a/src/libaio.map
+++ b/src/libaio.map
@@ -25,3 +25,9 @@ LIBAIO_0.5 {
 	global:
 		io_pgetevents;
 } LIBAIO_0.4;
+
+LIBAIO_0.6 {
+	global:
+		io_getevents_time64;
+		io_pgetevents_time64;
+} LIBAIO_0.5;
-- 
2.45.1


--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to [email protected].  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.