public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: torvalds@transmeta.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] add a stub by which a module can bind to the AFS syscall
Date: Wed, 30 Apr 2003 14:44:54 +0100	[thread overview]
Message-ID: <25734.1051710294@warthog.warthog> (raw)


Hi Linus,

This patch makes it possible for a module to bind safely to the AFS syscall,
without having to modify the syscall table directly.

David

diff -uNr -x'*.o' -x'.*' -xTAGS linux-2.5.67/include/linux/syscallstub.h linux-2.5.67-afs/include/linux/syscallstub.h
--- linux-2.5.67/include/linux/syscallstub.h	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.5.67-afs/include/linux/syscallstub.h	2003-04-07 13:17:38.000000000 +0100
@@ -0,0 +1,28 @@
+/* syscallstub.h: system call stub management
+ *
+ * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _LINUX_SYSCALLSTUB_H
+#define _LINUX_SYSCALLSTUB_H
+
+#include <linux/module.h>
+
+/*
+ * AFS system call stub management
+ */
+typedef int (*afs_syscall_handler_t)(long cmd, va_list va);
+
+extern int register_afs_syscall_handler(afs_syscall_handler_t handler, struct module *owner);
+extern void unregister_afs_syscall_handler(afs_syscall_handler_t handler, struct module *owner);
+
+extern asmlinkage int sys_afs(long cmd, ...);
+
+
+#endif /* _LINUX_SYSCALLSTUB_H */
diff -uNr -x'*.o' -x'.*' -xTAGS linux-2.5.67/kernel/Makefile linux-2.5.67-afs/kernel/Makefile
--- linux-2.5.67/kernel/Makefile	2003-03-05 03:29:02.000000000 +0000
+++ linux-2.5.67-afs/kernel/Makefile	2003-04-07 13:16:52.000000000 +0100
@@ -6,7 +6,8 @@
 	    exit.o itimer.o time.o softirq.o resource.o \
 	    sysctl.o capability.o ptrace.o timer.o user.o \
 	    signal.o sys.o kmod.o workqueue.o futex.o pid.o \
-	    rcupdate.o intermodule.o extable.o params.o posix-timers.o
+	    rcupdate.o intermodule.o extable.o params.o posix-timers.o \
+	    syscallstub.o
 
 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
 obj-$(CONFIG_SMP) += cpu.o
diff -uNr -x'*.o' -x'.*' -xTAGS linux-2.5.67/kernel/syscallstub.c linux-2.5.67-afs/kernel/syscallstub.c
--- linux-2.5.67/kernel/syscallstub.c	1970-01-01 01:00:00.000000000 +0100
+++ linux-2.5.67-afs/kernel/syscallstub.c	2003-04-30 14:35:11.000000000 +0100
@@ -0,0 +1,88 @@
+/* syscallstub.c: module providable syscall stub management
+ *
+ * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+#include <linux/syscallstub.h>
+#include <linux/spinlock.h>
+#include <linux/errno.h>
+
+/*
+ * AFS system call stub management
+ */
+static afs_syscall_handler_t	afs_syscall_handler;
+static struct module		*afs_syscall_owner;
+static rwlock_t			afs_syscall_handler_lock = RW_LOCK_UNLOCKED;
+
+int register_afs_syscall_handler(afs_syscall_handler_t handler, struct module *owner)
+{
+	int ret;
+
+	if (!handler || !owner)
+		return -EINVAL;
+
+	ret = -EEXIST;
+	write_lock(&afs_syscall_handler_lock);
+
+	if (!afs_syscall_handler) {
+		afs_syscall_handler	= handler;
+		afs_syscall_owner	= owner;
+		ret = 0;
+	}
+
+	write_unlock(&afs_syscall_handler_lock);
+
+	return ret;
+}
+
+EXPORT_SYMBOL(register_afs_syscall_handler);
+
+void unregister_afs_syscall_handler(afs_syscall_handler_t handler, struct module *owner)
+{
+	write_lock(&afs_syscall_handler_lock);
+
+	if (afs_syscall_handler==handler && afs_syscall_owner==owner) {
+		afs_syscall_handler	= NULL;
+		afs_syscall_owner	= NULL;
+	}
+	else {
+		printk("module %s tried to free AFS syscall which it did not own\n",
+		       owner->name);
+	}
+
+	write_unlock(&afs_syscall_handler_lock);
+}
+
+EXPORT_SYMBOL(unregister_afs_syscall_handler);
+
+asmlinkage int sys_afs(long cmd, ...)
+{
+	afs_syscall_handler_t handler;
+	struct module *owner;
+	va_list va;
+	int ret;
+
+	ret = -ENOSYS;
+	read_lock(&afs_syscall_handler_lock);
+	handler = afs_syscall_handler;
+	owner = afs_syscall_owner;
+	if (handler && try_module_get(owner))
+			ret = 0;
+	read_unlock(&afs_syscall_handler_lock);
+
+	if (ret<0)
+		return ret;
+
+	va_start(va,cmd);
+	ret = handler(cmd,va);
+	va_end(va);
+
+	module_put(owner);
+	return ret;
+}
+
diff -uNr -x'*.o' -x'.*' -xTAGS linux-2.5.67/arch/i386/kernel/entry.S linux-2.5.67-afs/arch/i386/kernel/entry.S
--- linux-2.5.67/arch/i386/kernel/entry.S	2003-03-28 11:37:52.000000000 +0000
+++ linux-2.5.67-afs/arch/i386/kernel/entry.S	2003-04-30 14:38:32.000000000 +0100
@@ -721,7 +721,7 @@
 	.long sys_bdflush
 	.long sys_sysfs		/* 135 */
 	.long sys_personality
-	.long sys_ni_syscall	/* reserved for afs_syscall */
+	.long sys_afs
 	.long sys_setfsuid16
 	.long sys_setfsgid16
 	.long sys_llseek	/* 140 */

             reply	other threads:[~2003-04-30 13:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-30 13:44 David Howells [this message]
2003-04-30 14:02 ` [PATCH] add a stub by which a module can bind to the AFS syscall Christoph Hellwig
2003-04-30 14:46   ` Jeff Garzik
2003-04-30 14:55     ` Christoph Hellwig
2003-04-30 14:57   ` chas williams
2003-04-30 15:02     ` Christoph Hellwig
2003-04-30 15:13       ` chas williams
2003-04-30 15:27         ` Christoph Hellwig
2003-04-30 15:33           ` chas williams
2003-04-30 15:38             ` Christoph Hellwig
2003-04-30 15:50             ` Arjan van de Ven
2003-04-30 15:42           ` Anton Blanchard
2003-04-30 15:56         ` viro
2003-05-08 14:01           ` David Howells
2003-04-30 15:30       ` David Howells
2003-04-30 15:37         ` Christoph Hellwig
2003-04-30 18:07         ` Jan Harkes
2003-04-30 18:19           ` Trond Myklebust

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=25734.1051710294@warthog.warthog \
    --to=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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