aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/kernel/syscall.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/kernel/syscall.c')
-rw-r--r--arch/um/kernel/syscall.c174
1 files changed, 152 insertions, 22 deletions
diff --git a/arch/um/kernel/syscall.c b/arch/um/kernel/syscall.c
index 1731d90e6850..48cf88dd02d4 100644
--- a/arch/um/kernel/syscall.c
+++ b/arch/um/kernel/syscall.c
@@ -1,36 +1,166 @@
1/* 1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 2 * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL 3 * Licensed under the GPL
4 */ 4 */
5 5
6#include "linux/sched.h"
7#include "linux/file.h"
8#include "linux/smp_lock.h"
9#include "linux/mm.h"
10#include "linux/utsname.h"
11#include "linux/msg.h"
12#include "linux/shm.h"
13#include "linux/sys.h"
14#include "linux/syscalls.h"
15#include "linux/unistd.h"
16#include "linux/slab.h"
17#include "linux/utime.h"
18#include "asm/mman.h"
19#include "asm/uaccess.h"
6#include "kern_util.h" 20#include "kern_util.h"
7#include "syscall.h" 21#include "user_util.h"
8#include "os.h" 22#include "sysdep/syscalls.h"
23#include "mode_kern.h"
24#include "choose-mode.h"
9 25
10struct { 26/* Unlocked, I don't care if this is a bit off */
11 int syscall; 27int nsyscalls = 0;
12 int pid;
13 long result;
14 unsigned long long start;
15 unsigned long long end;
16} syscall_record[1024];
17 28
18int record_syscall_start(int syscall) 29long sys_fork(void)
19{ 30{
20 int max, index; 31 long ret;
21 32
22 max = sizeof(syscall_record)/sizeof(syscall_record[0]); 33 current->thread.forking = 1;
23 index = next_syscall_index(max); 34 ret = do_fork(SIGCHLD, UPT_SP(&current->thread.regs.regs),
35 &current->thread.regs, 0, NULL, NULL);
36 current->thread.forking = 0;
37 return(ret);
38}
39
40long sys_vfork(void)
41{
42 long ret;
43
44 current->thread.forking = 1;
45 ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
46 UPT_SP(&current->thread.regs.regs),
47 &current->thread.regs, 0, NULL, NULL);
48 current->thread.forking = 0;
49 return(ret);
50}
51
52/* common code for old and new mmaps */
53long sys_mmap2(unsigned long addr, unsigned long len,
54 unsigned long prot, unsigned long flags,
55 unsigned long fd, unsigned long pgoff)
56{
57 long error = -EBADF;
58 struct file * file = NULL;
59
60 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
61 if (!(flags & MAP_ANONYMOUS)) {
62 file = fget(fd);
63 if (!file)
64 goto out;
65 }
66
67 down_write(&current->mm->mmap_sem);
68 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
69 up_write(&current->mm->mmap_sem);
70
71 if (file)
72 fput(file);
73 out:
74 return error;
75}
76
77long old_mmap(unsigned long addr, unsigned long len,
78 unsigned long prot, unsigned long flags,
79 unsigned long fd, unsigned long offset)
80{
81 long err = -EINVAL;
82 if (offset & ~PAGE_MASK)
83 goto out;
84
85 err = sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
86 out:
87 return err;
88}
89/*
90 * sys_pipe() is the normal C calling standard for creating
91 * a pipe. It's not the way unix traditionally does this, though.
92 */
93long sys_pipe(unsigned long __user * fildes)
94{
95 int fd[2];
96 long error;
97
98 error = do_pipe(fd);
99 if (!error) {
100 if (copy_to_user(fildes, fd, sizeof(fd)))
101 error = -EFAULT;
102 }
103 return error;
104}
24 105
25 syscall_record[index].syscall = syscall; 106
26 syscall_record[index].pid = current_pid(); 107long sys_uname(struct old_utsname __user * name)
27 syscall_record[index].result = 0xdeadbeef; 108{
28 syscall_record[index].start = os_nsecs(); 109 long err;
29 return(index); 110 if (!name)
111 return -EFAULT;
112 down_read(&uts_sem);
113 err = copy_to_user(name, &system_utsname, sizeof (*name));
114 up_read(&uts_sem);
115 return err?-EFAULT:0;
30} 116}
31 117
32void record_syscall_end(int index, long result) 118long sys_olduname(struct oldold_utsname __user * name)
33{ 119{
34 syscall_record[index].result = result; 120 long error;
35 syscall_record[index].end = os_nsecs(); 121
122 if (!name)
123 return -EFAULT;
124 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
125 return -EFAULT;
126
127 down_read(&uts_sem);
128
129 error = __copy_to_user(&name->sysname,&system_utsname.sysname,
130 __OLD_UTS_LEN);
131 error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
132 error |= __copy_to_user(&name->nodename,&system_utsname.nodename,
133 __OLD_UTS_LEN);
134 error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
135 error |= __copy_to_user(&name->release,&system_utsname.release,
136 __OLD_UTS_LEN);
137 error |= __put_user(0,name->release+__OLD_UTS_LEN);
138 error |= __copy_to_user(&name->version,&system_utsname.version,
139 __OLD_UTS_LEN);
140 error |= __put_user(0,name->version+__OLD_UTS_LEN);
141 error |= __copy_to_user(&name->machine,&system_utsname.machine,
142 __OLD_UTS_LEN);
143 error |= __put_user(0,name->machine+__OLD_UTS_LEN);
144
145 up_read(&uts_sem);
146
147 error = error ? -EFAULT : 0;
148
149 return error;
150}
151
152DEFINE_SPINLOCK(syscall_lock);
153
154static int syscall_index = 0;
155
156int next_syscall_index(int limit)
157{
158 int ret;
159
160 spin_lock(&syscall_lock);
161 ret = syscall_index;
162 if(++syscall_index == limit)
163 syscall_index = 0;
164 spin_unlock(&syscall_lock);
165 return(ret);
36} 166}