mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Phillip Lougher <phillip@lougher.demon.co.uk>,
	Arnd Bergmann <arnd@arndb.de>, Al Viro <viro@zeniv.linux.org.uk>,
	linux-kernel@vger.kernel.org
Subject: [RFC v2 PATCH 1/3] init: add sys-wrapper.h
Date: Mon, 30 Aug 2010 02:28:46 +0900	[thread overview]
Message-ID: <1283102928-3051-2-git-send-email-namhyung@gmail.com> (raw)
In-Reply-To: <1283102928-3051-1-git-send-email-namhyung@gmail.com>

sys-wrapper.h contains wrapper functions for various syscalls used in init
code. This wrappers handle proper address space conversion so that it can
remove a lot of warnings from sparse.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
---
 init/sys-wrapper.h |  246 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 246 insertions(+), 0 deletions(-)
 create mode 100644 init/sys-wrapper.h

diff --git a/init/sys-wrapper.h b/init/sys-wrapper.h
new file mode 100644
index 0000000..e4227f9
--- /dev/null
+++ b/init/sys-wrapper.h
@@ -0,0 +1,246 @@
+/*
+ * init/sys-wrapper.h
+ *
+ * Copyright (C) 2010  Namhyung Kim <namhyung@gmail.com>
+ *
+ * wrappers for various syscalls for use in the init code
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include <linux/fs.h>
+#include <linux/types.h>
+#include <linux/fcntl.h>
+#include <linux/dirent.h>
+#include <linux/syscalls.h>
+
+
+/* These macro are called just before/after actual syscalls. */
+#define KSYS_PREPARE				\
+	mm_segment_t old_fs = get_fs();		\
+	set_fs(KERNEL_DS);
+
+#define KSYS_RESTORE				\
+	set_fs(old_fs);
+
+
+static inline int kern_sys_link(const char *oldname, const char *newname)
+{
+       int ret;
+       KSYS_PREPARE;
+
+       ret = sys_link((const char __user __force *) oldname,
+		      (const char __user __force *) newname);
+       KSYS_RESTORE;
+       return ret;
+}
+
+static inline int kern_sys_unlink(const char *pathname)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_unlink((const char __user __force *) pathname);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_newlstat(const char *filename,
+				    struct stat *statbuf)
+{
+       int ret;
+       KSYS_PREPARE;
+
+       ret = sys_newlstat((const char __user __force *) filename,
+                          (struct stat __user __force *) statbuf);
+       KSYS_RESTORE;
+       return ret;
+}
+
+static inline int kern_sys_mkdir(const char *pathname, int mode)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_mkdir((const char __user __force *) pathname, mode);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_rmdir(const char *pathname)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_rmdir((const char __user __force *) pathname);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_mknod(const char *filename, int mode, unsigned dev)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_mknod((const char __user __force *) filename, mode, dev);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_chown(const char *filename, uid_t user, gid_t group)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_chown((const char __user __force *) filename, user, group);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_chmod(const char *filename, mode_t mode)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_chmod((const char __user __force *) filename, mode);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_open(const char *filename, int flags, int mode)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_open((const char __user __force *) filename, flags, mode);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_fchown(unsigned int fd, uid_t user, gid_t group)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_fchown(fd, user, group);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_fchmod(unsigned int fd, mode_t mode)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_fchmod(fd, mode);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_ftruncate(unsigned int fd, unsigned long length)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_ftruncate(fd, length);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_read(unsigned int fd, char *buf, size_t count)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_read(fd, (char __user __force *) buf, count);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_write(unsigned int fd, const char *buf,
+				 size_t count)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_write(fd, (const char __user __force *) buf, count);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_close(unsigned int fd)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_close(fd);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_symlink(const char *oldname, const char *newname)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_symlink((const char __user __force *) oldname,
+			  (const char __user __force *) newname);
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_lchown(const char *filename, uid_t user,
+				  gid_t group)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_lchown((const char __user __force *) filename, user, group);
+
+	KSYS_RESTORE;
+	return ret;
+}
+
+static inline int kern_sys_getdents64(unsigned int fd,
+				      struct linux_dirent64 *dirent,
+				      unsigned int count)
+{
+	int ret;
+	KSYS_PREPARE;
+
+	ret = sys_getdents64(fd,
+			     (struct linux_dirent64 __user __force *) dirent,
+			     count);
+	KSYS_RESTORE;
+	return ret;
+}
+
+
+#undef KSYS_PREPARE
+#undef KSYS_RESTORE
-- 
1.7.2.2


  reply	other threads:[~2010-08-29 17:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-29 17:28 [RFC v2 PATCH 0/3] initramfs: cleanups Namhyung Kim
2010-08-29 17:28 ` Namhyung Kim [this message]
2010-08-30 12:11   ` [RFC v2 PATCH 1/3] init: add sys-wrapper.h Arnd Bergmann
2010-08-30 14:17     ` Namhyung Kim
2010-08-29 17:28 ` [RFC v2 PATCH 2/3] initramfs: use kern_sys_* wrappers instead of syscall Namhyung Kim
2010-08-29 17:28 ` [RFC v2 PATCH 3/3] init: introduce CONFIG_USE_INIT_SYSCALL_AS_KERNEL_ROUTINE Namhyung Kim
2010-08-30 12:02 ` [RFC v2 PATCH 0/3] initramfs: cleanups Arnd Bergmann
2010-08-30 14:05   ` Namhyung Kim

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=1283102928-3051-2-git-send-email-namhyung@gmail.com \
    --to=namhyung@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillip@lougher.demon.co.uk \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®