Skip to content

Instantly share code, notes, and snippets.

@ndethore
Created March 27, 2014 19:21
Show Gist options
  • Save ndethore/9815924 to your computer and use it in GitHub Desktop.
Save ndethore/9815924 to your computer and use it in GitHub Desktop.
Patch file for adding a dumb syscall into the 3.2.0 Linux Kernel
diff -ruN /usr/src/linux-source-3.2.0/linux-source-3.2.0/arch/x86/include/asm/unistd_32.h /tmp/linux-source-3.2.0/arch/x86/include/asm/unistd_32.h
--- /usr/src/linux-source-3.2.0/linux-source-3.2.0/arch/x86/include/asm/unistd_32.h 2012-01-04 15:55:44.000000000 -0800
+++ /tmp/linux-source-3.2.0/arch/x86/include/asm/unistd_32.h 2014-03-27 12:11:39.267530664 -0700
@@ -354,10 +354,11 @@
#define __NR_setns 346
#define __NR_process_vm_readv 347
#define __NR_process_vm_writev 348
+#define __NR_foo 349
#ifdef __KERNEL__
-#define NR_syscalls 349
+#define NR_syscalls 350
#define __ARCH_WANT_IPC_PARSE_VERSION
#define __ARCH_WANT_OLD_READDIR
diff -ruN /usr/src/linux-source-3.2.0/linux-source-3.2.0/arch/x86/include/asm/unistd_64.h /tmp/linux-source-3.2.0/arch/x86/include/asm/unistd_64.h
--- /usr/src/linux-source-3.2.0/linux-source-3.2.0/arch/x86/include/asm/unistd_64.h 2012-01-04 15:55:44.000000000 -0800
+++ /tmp/linux-source-3.2.0/arch/x86/include/asm/unistd_64.h 2014-03-27 12:12:40.465775648 -0700
@@ -686,6 +686,8 @@
__SYSCALL(__NR_process_vm_readv, sys_process_vm_readv)
#define __NR_process_vm_writev 311
__SYSCALL(__NR_process_vm_writev, sys_process_vm_writev)
+#define __NR_foo 312
+__SYSCALL(__NR_foo, sys_foo)
#ifndef __NO_STUBS
#define __ARCH_WANT_OLD_READDIR
diff -ruN /usr/src/linux-source-3.2.0/linux-source-3.2.0/arch/x86/kernel/syscall_table_32.S /tmp/linux-source-3.2.0/arch/x86/kernel/syscall_table_32.S
--- /usr/src/linux-source-3.2.0/linux-source-3.2.0/arch/x86/kernel/syscall_table_32.S 2012-01-04 15:55:44.000000000 -0800
+++ /tmp/linux-source-3.2.0/arch/x86/kernel/syscall_table_32.S 2014-03-27 12:13:23.048571388 -0700
@@ -348,3 +348,4 @@
.long sys_setns
.long sys_process_vm_readv
.long sys_process_vm_writev
+ .long sys_foo
diff -ruN /usr/src/linux-source-3.2.0/linux-source-3.2.0/foo/foo.c /tmp/linux-source-3.2.0/foo/foo.c
--- /usr/src/linux-source-3.2.0/linux-source-3.2.0/foo/foo.c 1969-12-31 16:00:00.000000000 -0800
+++ /tmp/linux-source-3.2.0/foo/foo.c 2014-03-27 12:05:25.422238627 -0700
@@ -0,0 +1,8 @@
+#include <linux/kernel.h>
+#include <asm/linkage.h>
+
+asmlinkage long sys_foo(void)
+{
+ printk(KERN_INFO "Hello sys_foo !\n");
+ return 0;
+}
diff -ruN /usr/src/linux-source-3.2.0/linux-source-3.2.0/foo/Makefile /tmp/linux-source-3.2.0/foo/Makefile
--- /usr/src/linux-source-3.2.0/linux-source-3.2.0/foo/Makefile 1969-12-31 16:00:00.000000000 -0800
+++ /tmp/linux-source-3.2.0/foo/Makefile 2014-03-27 12:05:25.422238627 -0700
@@ -0,0 +1 @@
+obj-m += foo.o
diff -ruN /usr/src/linux-source-3.2.0/linux-source-3.2.0/include/linux/syscalls.h /tmp/linux-source-3.2.0/include/linux/syscalls.h
--- /usr/src/linux-source-3.2.0/linux-source-3.2.0/include/linux/syscalls.h 2012-01-04 15:55:44.000000000 -0800
+++ /tmp/linux-source-3.2.0/include/linux/syscalls.h 2014-03-27 12:09:42.502884836 -0700
@@ -856,5 +856,6 @@
const struct iovec __user *rvec,
unsigned long riovcnt,
unsigned long flags);
+asmlinkage long sys_foo(void);
#endif
diff -ruN /usr/src/linux-source-3.2.0/linux-source-3.2.0/Makefile /tmp/linux-source-3.2.0/Makefile
--- /usr/src/linux-source-3.2.0/linux-source-3.2.0/Makefile 2014-02-18 19:55:00.000000000 -0800
+++ /tmp/linux-source-3.2.0/Makefile 2014-03-27 12:02:12.291799664 -0700
@@ -717,7 +717,7 @@
ifeq ($(KBUILD_EXTMOD),)
-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ foo/
vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
$(core-y) $(core-m) $(drivers-y) $(drivers-m) \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment