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