Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 1 | /* |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 2 | * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include "linux/file.h" |
Alexey Dobriyan | 4e950f6 | 2007-07-30 02:36:13 +0400 | [diff] [blame] | 7 | #include "linux/fs.h" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 8 | #include "linux/mm.h" |
| 9 | #include "linux/sched.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include "linux/utsname.h" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 11 | #include "asm/current.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "asm/mman.h" |
| 13 | #include "asm/uaccess.h" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 14 | #include "asm/unistd.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | long sys_fork(void) |
| 17 | { |
| 18 | long ret; |
| 19 | |
| 20 | current->thread.forking = 1; |
Jeff Dike | e0877f0 | 2005-06-25 14:55:21 -0700 | [diff] [blame] | 21 | ret = do_fork(SIGCHLD, UPT_SP(¤t->thread.regs.regs), |
| 22 | ¤t->thread.regs, 0, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | current->thread.forking = 0; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 24 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | long sys_vfork(void) |
| 28 | { |
| 29 | long ret; |
| 30 | |
| 31 | current->thread.forking = 1; |
Jeff Dike | e0877f0 | 2005-06-25 14:55:21 -0700 | [diff] [blame] | 32 | ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, |
| 33 | UPT_SP(¤t->thread.regs.regs), |
| 34 | ¤t->thread.regs, 0, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | current->thread.forking = 0; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 36 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /* common code for old and new mmaps */ |
| 40 | long sys_mmap2(unsigned long addr, unsigned long len, |
| 41 | unsigned long prot, unsigned long flags, |
| 42 | unsigned long fd, unsigned long pgoff) |
| 43 | { |
| 44 | long error = -EBADF; |
| 45 | struct file * file = NULL; |
| 46 | |
| 47 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
| 48 | if (!(flags & MAP_ANONYMOUS)) { |
| 49 | file = fget(fd); |
| 50 | if (!file) |
| 51 | goto out; |
| 52 | } |
| 53 | |
| 54 | down_write(¤t->mm->mmap_sem); |
| 55 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); |
| 56 | up_write(¤t->mm->mmap_sem); |
| 57 | |
| 58 | if (file) |
| 59 | fput(file); |
| 60 | out: |
| 61 | return error; |
| 62 | } |
| 63 | |
| 64 | long old_mmap(unsigned long addr, unsigned long len, |
| 65 | unsigned long prot, unsigned long flags, |
| 66 | unsigned long fd, unsigned long offset) |
| 67 | { |
| 68 | long err = -EINVAL; |
| 69 | if (offset & ~PAGE_MASK) |
| 70 | goto out; |
| 71 | |
| 72 | err = sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT); |
| 73 | out: |
| 74 | return err; |
| 75 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 77 | long sys_uname(struct old_utsname __user * name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | long err; |
| 80 | if (!name) |
| 81 | return -EFAULT; |
| 82 | down_read(&uts_sem); |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 83 | err = copy_to_user(name, utsname(), sizeof (*name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | up_read(&uts_sem); |
| 85 | return err?-EFAULT:0; |
| 86 | } |
| 87 | |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 88 | long sys_olduname(struct oldold_utsname __user * name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
| 90 | long error; |
| 91 | |
| 92 | if (!name) |
| 93 | return -EFAULT; |
| 94 | if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname))) |
| 95 | return -EFAULT; |
Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 96 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 97 | down_read(&uts_sem); |
Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 98 | |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 99 | error = __copy_to_user(&name->sysname, &utsname()->sysname, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | __OLD_UTS_LEN); |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 101 | error |= __put_user(0, name->sysname + __OLD_UTS_LEN); |
| 102 | error |= __copy_to_user(&name->nodename, &utsname()->nodename, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | __OLD_UTS_LEN); |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 104 | error |= __put_user(0, name->nodename + __OLD_UTS_LEN); |
| 105 | error |= __copy_to_user(&name->release, &utsname()->release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | __OLD_UTS_LEN); |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 107 | error |= __put_user(0, name->release + __OLD_UTS_LEN); |
| 108 | error |= __copy_to_user(&name->version, &utsname()->version, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | __OLD_UTS_LEN); |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 110 | error |= __put_user(0, name->version + __OLD_UTS_LEN); |
| 111 | error |= __copy_to_user(&name->machine, &utsname()->machine, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | __OLD_UTS_LEN); |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 113 | error |= __put_user(0, name->machine + __OLD_UTS_LEN); |
Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | up_read(&uts_sem); |
Jeff Dike | 1d3468a | 2006-07-10 04:45:13 -0700 | [diff] [blame] | 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | error = error ? -EFAULT : 0; |
| 118 | |
| 119 | return error; |
| 120 | } |
| 121 | |
Arnd Bergmann | 3db03b4 | 2006-10-02 02:18:31 -0700 | [diff] [blame] | 122 | int kernel_execve(const char *filename, char *const argv[], char *const envp[]) |
| 123 | { |
| 124 | mm_segment_t fs; |
| 125 | int ret; |
| 126 | |
| 127 | fs = get_fs(); |
| 128 | set_fs(KERNEL_DS); |
| 129 | ret = um_execve(filename, argv, envp); |
| 130 | set_fs(fs); |
| 131 | |
| 132 | return ret; |
| 133 | } |