[PATCH -mm 1/9] unshare system call : system call handler function

[PATCH -mm 1/9] unshare system call : system call handler function

Post by JANAK DESA » Wed, 14 Dec 2005 22:50:29


[PATCH -mm 1/9] unshare system call: System call handler function sys_unshare

Signed-off-by: Janak Desai


fork.c | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 235 insertions(+)


diff -Naurp 2.6.15-rc5-mm2/kernel/fork.c 2.6.15-rc5-mm2+patch/kernel/fork.c
--- 2.6.15-rc5-mm2/kernel/fork.c 2005-12-12 03:05:59.000000000 +0000
+++ 2.6.15-rc5-mm2+patch/kernel/fork.c 2005-12-12 19:31:48.000000000 +0000
@@ -1330,3 +1330,238 @@ void __init proc_caches_init(void)
sizeof(struct mm_struct), 0,
SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
}
+
+
+/*
+ * Check constraints on flags passed to the unshare system call and
+ * force unsharing of additional process context as appropriate.
+ */
+static inline void check_unshare_flags(unsigned long *flags_ptr)
+{
+ /*
+ * If unsharing a thread from a thread group, must also
+ * unshare vm.
+ */
+ if (*flags_ptr & CLONE_THREAD)
+ *flags_ptr |= CLONE_VM;
+
+ /*
+ * If unsharing vm, must also unshare signal handlers.
+ */
+ if (*flags_ptr & CLONE_VM)
+ *flags_ptr |= CLONE_SIGHAND;
+
+ /*
+ * If unsharing signal handlers and the task was created
+ * using CLONE_THREAD, then must unshare the thread
+ */
+ if ((*flags_ptr & CLONE_SIGHAND) &&
+ (atomic_read(¤t->signal->count) > 1))
+ *flags_ptr |= CLONE_THREAD;
+
+ /*
+ * If unsharing namespace, must also unshare filesystem information.
+ */
+ if (*flags_ptr & CLONE_NEWNS)
+ *flags_ptr |= CLONE_FS;
+}
+
+/*
+ * Unsharing of tasks created with CLONE_THREAD is not supported yet
+ */
+static int unshare_thread(unsigned long unshare_flags)
+{
+ if (unshare_flags & CLONE_THREAD)
+ return -EINVAL;
+
+ return 0;
+}
+
+/*
+ * Unsharing of fs info for tasks created with CLONE_FS is not supported yet
+ */
+static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
+{
+ struct fs_struct *fs = current->fs;
+
+ if ((unshare_flags & CLONE_FS) &&
+ (fs && atomic_read(&fs->count) > 1))
+ return -EINVAL;
+
+ return 0;
+}
+
+/*
+ * Unsharing of namespace for tasks created without CLONE_NEWNS is not
+ * supported yet
+ */
+static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp)
+{
+ struct namespace *ns = current->namespace;
+
+ if ((unshare_flags & CLONE_NEWNS) &&
+ (ns && atomic_read(&ns->count) > 1))
+ return -EINVAL;
+
+ return 0;
+}
+
+/*
+ * Unsharing of sighand for tasks created with CLONE_SIGHAND is not
+ * supported yet
+ */
+static int unshare_sighand(unsigned long unshare_flags, struct sighand_struct **new_sighp)
+{
+ struct sighand_struct *sigh = current->sighand;
+
+ if ((unshare_flags & CLONE_SIGHAND) &&
+ (sigh && atomic_read(&sigh->count) > 1))
+ return -EINVAL;
+ else
+ return 0;
+}
+
+/*
+ * Unsharing of vm for tasks created with CLONE_VM is not supported yet
+ */
+static int unshare_vm(unsigned long unshare_flags, struct mm_struct **new_mmp)
+{
+ struct mm_struct *mm = current->mm;
+
+ if ((unshare_flags & CLONE_VM) &&
+ (mm && atomic_read(&mm->mm_users) > 1))
+ return -EINVAL;
+
+ return 0;
+
+}
+
+/*
+ * Unsharing of files for tasks created with CLONE_FILES is not supported yet
+ */
+static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp)
+
 
 
 

1. [PATCH -mm 10/10] unshare system call -v5 : system call registration for x86_64

2. [PATCH -mm 3/9] unshare system call : system call registration for powerpc


[PATCH -mm 3/9] unshare system call: System call registration for
powerpc

Signed-off-by: Janak Desai


arch/powerpc/kernel/systbl.S | 1 +
include/asm-powerpc/unistd.h | 3 ++-
2 files changed, 3 insertions(+), 1 deletion(-)


diff -Naurp 2.6.15-rc5-mm2/arch/powerpc/kernel/systbl.S
2.6.15-rc5-mm2+powerpc/arch/powerpc/kernel/systbl.S
--- 2.6.15-rc5-mm2/arch/powerpc/kernel/systbl.S 2005-12-12
03:05:39.000000000 +0000
+++ 2.6.15-rc5-mm2+powerpc/arch/powerpc/kernel/systbl.S 2005-12-12
20:15:54.000000000 +0000
@@ -322,3 +322,4 @@ SYSCALL(inotify_rm_watch)
SYSCALL(spu_run)
SYSCALL(spu_create)
SYSCALL(migrate_pages)
+SYSCALL(unshare)
diff -Naurp 2.6.15-rc5-mm2/include/asm-powerpc/unistd.h
2.6.15-rc5-mm2+powerpc/include/asm-powerpc/unistd.h
--- 2.6.15-rc5-mm2/include/asm-powerpc/unistd.h 2005-12-12
03:05:58.000000000 +0000
+++ 2.6.15-rc5-mm2+powerpc/include/asm-powerpc/unistd.h 2005-12-12
20:18:03.000000000 +0000
@@ -299,8 +299,9 @@
#define __NR_spu_run 278
#define __NR_spu_create 279
#define __NR_migrate_pages 280
+#define __NR_unshare 281

-#define __NR_syscalls 281
+#define __NR_syscalls 282

#ifdef __KERNEL__
#define __NR__exit __NR_exit


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to XXXX@XXXXX.COM
More majordomo info at http://www.yqcomputer.com/
Please read the FAQ at http://www.yqcomputer.com/

3. [PATCH -mm 3/9] unshare system call: system call registration for powerpc

4. [PATCH -mm 5/9] unshare system call: system call registration for x86_64

5. [PATCH -mm 2/9] unshare system call : system call registration for i386

6. [PATCH -mm 9/10] unshare system call -v5 : system call registration for ppc

7. [PATCH -mm 3/10] unshare system call -v5 : unshare filesystem info

8. [PATCH -mm 5/10] unshare system call -v5 : unshare vm

9. [PATCH -mm 4/10] unshare system call -v5 : unshare namespace

10. [PATCH -mm 6/10] unshare system call -v5 : unshare files

11. [PATCH -mm 0/9] unshare system call : updated patch series

12. [PATCH -mm 6/9] unshare system call: allow unsharing of filesystem

13. [PATCH -mm 6/9] unshare system call : allow unsharing of fs

14. [PATCH -mm 8/9] unshare system call : allow unsharing of vm

15. [PATCH -mm 6/9] unshare system call : allow unsharing of fs structure