public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Spatzier <tspat@de.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: linux-archs@vger.kernel.org
Subject: [PATCH] compat syscalls for sys_io_...
Date: Wed, 5 Nov 2003 19:08:10 +0100	[thread overview]
Message-ID: <20031105180810.GA2691@de.ibm.com> (raw)

I've implemented compat wrapper functions for the sys_io... set of
system calls for 32 bit emulation on s390. I think, these
wrapper functions will also be needed by architectures other than s390
(I found implementations for ppc64 and x86_64; compat_io_setup is
heavily based on the ppc64 implementation);
therefore I think they should be put into fs/compat.c.
Please verify/comment on the patch below. AFAICS they should do across
archs.

Regards,
Thomas.


diff -urN linux-2.6.0-test9/fs/compat.c linux-2.6.0-test9-compat-aio/fs/compat.c
--- linux-2.6.0-test9/fs/compat.c	2003-09-29 13:30:29.000000000 +0200
+++ linux-2.6.0-test9-compat-aio/fs/compat.c	2003-11-05 18:57:43.000000000 +0100
@@ -554,3 +554,88 @@
 	return compat_sys_fcntl64(fd, cmd, arg);
 }
 
+/* posix aio functions: sys_io_... */
+extern asmlinkage long
+sys_io_setup(unsigned, aio_context_t *ctx);
+
+asmlinkage long
+sys32_io_setup(unsigned nr_events, compat_aio_context_t *ctx)
+{
+	aio_context_t kctx;
+	mm_segment_t old_fs;
+	long ret;
+
+	// ctx points to 4 byte area (u32) in userspace !
+	ret = get_user(kctx, ctx);
+	if (ret)
+		goto out;
+	old_fs = get_fs();
+	set_fs(KERNEL_DS);
+	ret = sys_io_setup(nr_events, &kctx);
+	set_fs(old_fs);
+	if (!ret)
+		ret = put_user(kctx, ctx);
+out:
+	return ret;
+}
+
+extern asmlinkage long
+sys_io_getevents(aio_context_t,long,long,struct io_event *,struct timespec *);
+
+asmlinkage long
+sys32_io_getevents(compat_aio_context_t ctx_id, long min_nr, long nr,
+		struct io_event *events,
+		struct compat_timespec *timeout)
+{
+	struct timespec ktimeout;
+	struct timespec *usr_timeout;
+	long ret;
+
+	ret = -EFAULT;
+	if ( get_compat_timespec(&ktimeout, timeout) )
+		goto out;
+	usr_timeout = compat_alloc_user_space(sizeof(*usr_timeout));
+	if ( copy_to_user(usr_timeout, &ktimeout, sizeof(ktimeout)) )
+		goto out;
+	ret = sys_io_getevents(ctx_id, min_nr, nr, events, usr_timeout);
+out:
+	return ret;
+}
+
+extern asmlinkage long
+sys_io_submit(aio_context_t, long, struct iocb __user **);
+
+static inline long
+get_64bit_user_ptr_array(long nr, u32 *ptr32, u64 *ptr64)
+{
+	u32 uptr;
+	long ret;
+
+	ret = -EFAULT;
+	int i;
+	for (i = 0; i < nr; ++i) {
+		if ( get_user(uptr, ptr32 + i) )
+			goto out;
+		if ( put_user((u64)compat_ptr(uptr), ptr64 + i) )
+			goto out;
+	}
+	ret = 0;
+out:
+	return ret;
+}
+
+asmlinkage long
+sys32_io_submit(compat_aio_context_t ctx_id, long nr, u32 *iocb)
+{
+	struct iocb **iocb64; //array of 64bit pointers in user space
+	long ret;
+
+	//alloc 64 bit pointer array in user space
+	iocb64 = compat_alloc_user_space(nr*sizeof(*iocb64));
+	ret = get_64bit_user_ptr_array(nr, (u32 *)iocb, (u64 *)iocb64);
+	if (ret)
+		goto out;
+	ret = sys_io_submit(ctx_id, nr, iocb64);
+out:
+	return ret;
+}
diff -urN linux-2.6.0-test9/include/linux/compat.h linux-2.6.0-test9-compat-aio/include/linux/compat.h
--- linux-2.6.0-test9/include/linux/compat.h	2003-10-09 19:19:51.000000000 +0200
+++ linux-2.6.0-test9-compat-aio/include/linux/compat.h	2003-11-04 15:46:54.000000000 +0100
@@ -97,5 +97,7 @@
 	char		d_name[256];
 };
 
+typedef unsigned int compat_aio_context_t;
+
 #endif /* CONFIG_COMPAT */
 #endif /* _LINUX_COMPAT_H */

                 reply	other threads:[~2003-11-05 18:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031105180810.GA2691@de.ibm.com \
    --to=tspat@de.ibm.com \
    --cc=linux-archs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox